AquaJD

dtv2

Jul 10th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. -- Setup
  2. local bRunning = true
  3. local nTerm_Width, nTerm_Height = term.getSize()
  4. local oTerm = term.current()
  5.  
  6. -- Desktop Tables
  7. local tDesktop_Windows = {}
  8. local tDesktop_Files = {}
  9. local tDesktop_Folders = {}
  10. local tDesktop_ActiveWindow = nil
  11.  
  12. -- Config Tables
  13. local tColours = {}
  14. local tMenus = {}
  15. local tPrograms = fs.list("/rom/programs")
  16. local tBackgroundEvents = {
  17.   "alarm",
  18.   "timer",
  19.   "redstone",
  20.   "rednet_message",
  21.   "disk",
  22.   "disk_eject",
  23.   "peripheral",
  24.   "peripheral_detach",
  25.   "modem_message"
  26. }
  27. local tColourPalette = {
  28.   ["white"] = 1,
  29.   ["orange"] = 2,
  30.   ["magenta"] = 4,
  31.   ["light blue"] = 8,
  32.   ["lightblue"] = 8,
  33.   ["yellow"] = 16,
  34.   ["lime"] = 32,
  35.   ["pink"] = 64,
  36.   ["gray"] = 128,
  37.   ["light gray"] = 256,
  38.   ["lightgray"] = 256,
  39.   ["cyan"] = 512,
  40.   ["purple"] = 1024,
  41.   ["blue"] = 2048,
  42.   ["brown"] = 4096,
  43.   ["green"] = 8192,
  44.   ["red"] = 16384,
  45.   ["black"] = 32768
  46. }
  47.  
  48. -- Quick aliases
  49. local fTC = term.setTextColor
  50. local fBC = term.setBackgroundColor
  51.  
  52. -- OS Filepaths
  53. local sFile_Config_Colours = "/djos/dj_colours.cfg"
  54. local sFile_ActiveDir = "/desktop/"
  55.  
  56. -- Selectors
  57. local sMenu = ""
  58.  
  59. -- Init
  60. if not fs.exists("/desktop") then
  61.     fs.makeDir("/desktop")
  62. end
  63. if not fs.exists("/djos") then
  64.     fs.makeDir("/djos")
  65. end
  66.  
  67. -- Config loading
  68. local function fConfig_Load()
  69.     local _f = fs.open(sFile_Config_Colours,"r")
  70.     tColours = textutils.unserialise(_f.readAll())
  71.     _f.close()
  72.     local _f = fs.open(sFile_Config_Menus,"r")
  73.     tMenus = textutils.unserialise(_f.readAll())
  74.     _f.close()
  75.     local _f = fs.open(sFile_Config_Menus,"r")
  76.     tButtons = textutils.unserialise(_f.readAll())
  77.     _f.close()
  78. end
  79.  
  80. -- Config saving
  81. local function fConfig_Save()
  82.     local _f = fs.open(sFile_Config_Colours,"w")
  83.     _f.write(textutils.serialise(tColours))
  84.     _f.close()
  85. end
  86.  
  87. -- Convert number to corresponding number
  88. function fConvert_NTC(n)
  89.     for k,v in pairs(tColourPalette) do
  90.         if v == n then
  91.             return k
  92.         end
  93.     end
  94. end
  95.  
  96. -- Draw status bar above windows/menus
  97. function fDraw_Bar(w)
  98.     fBC(tColours["bar"].bg)
  99.     fCP(w.x,w.y-1)
  100.     for i=1,w.w do
  101.         write(" ")
  102.     end
  103.     local nIcon = 1
  104.     if w.bClose then
  105.         term.setCursorPos(w.x+w.w-nIcon,w.y-1)
  106.         term.setTextColor(tColors["bar"].close)
  107.         print(string.char(7))
  108.         nIcon = nIcon + 1
  109.     end
  110.     if w.bEdit then
  111.         term.setCursorPos(w.x+w.w-nIcon,w.y-1)
  112.         term.setTextColor(tColors["bar"].edit)
  113.         print(string.char(7))
  114.     end
  115.     if w.bDrag then
  116.         term.setCursorPos(w.x,w.y-1)
  117.         term.setTextColor(tColors["bar"].drag)
  118.         print(string.char(7))
  119.     end
  120.     if w.title then
  121.         fCP(w.x+(w.w/2)-(#w.title/2),w.y-1)
  122.         fTC(tColours["bar"].fg)
  123.         print(w.title)
  124.     end
  125. end
  126.  
  127. -- Draw window
  128. function fDraw_Window(w)
  129.     fDraw_Bar(w)
  130. end
Advertisement
Add Comment
Please, Sign In to add comment