Advertisement
LegoStax

Lithium OS Settings

Sep 30th, 2013
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.92 KB | None | 0 0
  1. --[[
  2.     Settings Program by LegoStax
  3. ]]--
  4. local w,h = term.getSize()
  5. local running = true
  6.  
  7. function saveConfig()
  8.     local file = fs.open(".programs/config", "w")
  9.     file.write(textutils.serialize(config))
  10.     file.close()
  11. end
  12.  
  13. function loadConfig()
  14.     if fs.exists(".programs/config") then
  15.         config = {
  16.             autoupdate = nil,
  17.             desktop_img = nil,
  18.             bgcolor = nil,
  19.             taskside = nil
  20.         }
  21.         local file = fs.open(".programs/config", "r")
  22.         config = textutils.unserialize(file.readAll())
  23.         file.close()
  24.     else
  25.         config = {
  26.             autoupdate = false,
  27.             desktop_img = ".programs/desktop",
  28.             bgcolor = colors.white,
  29.             taskside = "top"
  30.         }
  31.         saveConfig()
  32.     end
  33. end
  34.  
  35. function drawTopBar()
  36.     bg = paintutils.loadImage(".programs/set-bg")
  37.     paintutils.drawImage(bg, 1, 1)
  38.     term.setBackgroundColor(colors.lightGray)
  39.     term.setTextColor(colors.white)
  40.     term.setCursorPos(3,1)
  41.     term.write("Settings")
  42.     term.setBackgroundColor(colors.red)
  43.     term.setCursorPos(51,1)
  44.     term.write("X")
  45. end
  46.  
  47. function drawDropDown()
  48.     term.setBackgroundColor(colors.lightGray)
  49.     term.setCursorPos(x2,8)
  50.     term.write(" Top    ")
  51.     term.setCursorPos(x2,9)
  52.     term.write(" Left   ")
  53.     term.setCursorPos(x2,10)
  54.     term.write(" Right  ")
  55.     term.setCursorPos(x2,11)
  56.     term.write(" Bottom ")
  57. end
  58.  
  59. function drawColorDropDown()
  60.     term.setBackgroundColor(colors.white)
  61.     term.setCursorPos(34,10)
  62.     term.write(" ")
  63.     term.setBackgroundColor(colors.orange)
  64.     term.setCursorPos(35,10)
  65.     term.write(" ")
  66.     term.setBackgroundColor(colors.magenta)
  67.     term.setCursorPos(36,10)
  68.     term.write(" ")
  69.     term.setBackgroundColor(colors.lightBlue)
  70.     term.setCursorPos(37,10)
  71.     term.write(" ")
  72.     term.setBackgroundColor(colors.yellow)
  73.     term.setCursorPos(38,10)
  74.     term.write(" ")
  75.     term.setBackgroundColor(colors.lime)
  76.     term.setCursorPos(39,10)
  77.     term.write(" ")
  78.     term.setBackgroundColor(colors.pink)
  79.     term.setCursorPos(40,10)
  80.     term.write(" ")
  81.     term.setBackgroundColor(colors.gray)
  82.     term.setCursorPos(41,10)
  83.     term.write(" ")
  84.     term.setBackgroundColor(colors.lightGray)
  85.     term.setCursorPos(42,10)
  86.     term.write(" ")
  87.     term.setBackgroundColor(colors.cyan)
  88.     term.setCursorPos(43,10)
  89.     term.write(" ")
  90.     term.setBackgroundColor(colors.purple)
  91.     term.setCursorPos(44,10)
  92.     term.write(" ")
  93.     term.setBackgroundColor(colors.blue)
  94.     term.setCursorPos(45,10)
  95.     term.write(" ")
  96.     term.setBackgroundColor(colors.brown)
  97.     term.setCursorPos(46,10)
  98.     term.write(" ")
  99.     term.setBackgroundColor(colors.green)
  100.     term.setCursorPos(47,10)
  101.     term.write(" ")
  102.     term.setBackgroundColor(colors.red)
  103.     term.setCursorPos(48,10)
  104.     term.write(" ")
  105.     term.setBackgroundColor(colors.black)
  106.     term.setCursorPos(49,10)
  107.     term.write(" ")
  108. end
  109.  
  110. function drawMenu()
  111.     x = 15
  112.     term.setBackgroundColor(colors.blue)
  113.     term.setTextColor(colors.white)
  114.     term.setCursorPos(15,13)
  115.     term.write("Desktop Image: "..config.desktop_img)
  116.     term.setCursorPos(15,12)
  117.     term.setBackgroundColor(colors.lightGray)
  118.     term.write(" Change ")
  119.     term.setCursorPos(15,5)
  120.     if config.autoupdate == true then
  121.         term.setBackgroundColor(colors.lime)
  122.         term.write(" ")
  123.     elseif config.autoupdate == false then
  124.         term.setBackgroundColor(colors.lightGray)
  125.         term.write(" ")
  126.     end
  127.     term.setBackgroundColor(colors.blue)
  128.     term.write(" Check for Updates")
  129.     term.setCursorPos(15,7)
  130.     term.write("Task bar side: ")
  131.     term.setBackgroundColor(colors.lightGray)
  132.     term.setCursorPos(x,8)
  133.     term.write(" "..config.taskside.." > ")
  134.     term.setCursorPos(14,10)
  135.     term.write(" Background Color > ")
  136. end
  137.  
  138. function getDesktopImg()
  139.     term.setBackgroundColor(colors.lightBlue)
  140.     term.setCursorPos(17,9)
  141.     term.write(" Change Desktop Image ")
  142.     term.setCursorPos(17,10)
  143.     term.setBackgroundColor(colors.lightGray)
  144.     term.write("                      ")
  145.     term.setCursorPos(17,11)
  146.     term.write("                      ")
  147.     term.setCursorPos(17,12)
  148.     term.write("                      ")
  149.     term.setCursorPos(18,11)
  150.     write ""
  151.     config.desktop_img = read()
  152.     if not fs.exists(config.desktop_img) then
  153.         getDesktopImg()
  154.     end
  155. end
  156.  
  157. local function changeCheckmark()
  158.     term.setCursorPos(15,5)
  159.     if config.autoupdate == false then
  160.         term.setBackgroundColor(colors.lightGray)
  161.         term.write(" ")
  162.     else
  163.         term.setBackgroundColor(colors.lime)
  164.         term.write(" ")
  165.     end
  166. end
  167.  
  168. loadConfig()
  169. drawTopBar()
  170. drawMenu()
  171. changeCheckmark()
  172. x2 = x + 4
  173. x2 = x2 + #config.taskside
  174. while running do
  175.     event, button, x, y = os.pullEvent("mouse_click")
  176.     if button == 1 then
  177.         if x == 15 and y == 5 then
  178.             if config.autoupdate == false then
  179.                 config.autoupdate = true
  180.                 changeCheckmark()
  181.             else
  182.                 config.autoupdate = false
  183.                 changeCheckmark()
  184.             end
  185.         elseif x == 51 and y == 1 then
  186.             running = false
  187.         elseif x >= 15 and x <= 22 and y == 12 then
  188.             getDesktopImg()
  189.             drawTopBar()
  190.             drawMenu()
  191.         elseif x >= x2-2 and x <= x2 and y == 8 then
  192.             drawDropDown()
  193.             event, button, x, y = os.pullEvent("mouse_click")
  194.             if button == 1 then
  195.                 if x >= x2 and x <= x2+8 and y == 8 then
  196.                     config.taskside = "top"
  197.                     x2 = 19
  198.                     x2 = x2 + #config.taskside
  199.                     drawTopBar()
  200.                     drawMenu()
  201.                 elseif x >= x2 and x <= x2+8 and y == 9 then
  202.                     config.taskside = "left"
  203.                     x2 = 19
  204.                     x2 = x2 + #config.taskside
  205.                     drawTopBar()
  206.                     drawMenu()
  207.                 elseif x >= x2 and x <= x2+8 and y == 10 then
  208.                     config.taskside = "right"
  209.                     x2 = 19
  210.                     x2 = x2 + #config.taskside
  211.                     drawTopBar()
  212.                     drawMenu()
  213.                 elseif x >= x2 and x <= x2+8 and y == 11 then
  214.                     config.taskside = "bottom"
  215.                     x2 = 19
  216.                     x2 = x2 + #config.taskside
  217.                     drawTopBar()
  218.                     drawMenu()
  219.                 else
  220.                     drawTopBar()
  221.                     drawMenu()
  222.                 end
  223.             end
  224.             drawTopBar()
  225.             drawMenu()
  226.         elseif x >= 15 and x <= 33 and y == 10 then
  227.             drawColorDropDown()
  228.             event, button, x, y = os.pullEvent("mouse_click")
  229.             if button == 1 then
  230.                 if y == 10 then
  231.                     if x == 34 then
  232.                         config.bgcolor = colors.white
  233.                     elseif x == 35 then
  234.                         config.bgcolor = colors.orange
  235.                     elseif x == 36 then
  236.                         config.bgcolor = colors.magenta
  237.                     elseif x == 37 then
  238.                         config.bgcolor = colors.lightBlue
  239.                     elseif x == 38 then
  240.                         config.bgcolor = colors.yellow
  241.                     elseif x == 39 then
  242.                         config.bgcolor = colors.lime
  243.                     elseif x == 40 then
  244.                         config.bgcolor = colors.pink
  245.                     elseif x == 41 then
  246.                         config.bgcolor = colors.gray
  247.                     elseif x == 42 then
  248.                         config.bgcolor = colors.lightGray
  249.                     elseif x == 43 then
  250.                         config.bgcolor = colors.cyan
  251.                     elseif x == 44 then
  252.                         config.bgcolor = colors.purple
  253.                     elseif x == 45 then
  254.                         config.bgcolor = colors.blue
  255.                     elseif x == 46 then
  256.                         config.bgcolor = colors.brown
  257.                     elseif x == 47 then
  258.                         config.bgcolor = colors.green
  259.                     elseif x == 48 then
  260.                         config.bgcolor = colors.red
  261.                     elseif x == 49 then
  262.                         config.bgcolor = colors.black
  263.                     else
  264.                         drawTopBar()
  265.                         drawMenu()
  266.                     end
  267.                 else
  268.                     drawTopBar()
  269.                     drawMenu()
  270.                 end
  271.             end
  272.             drawTopBar()
  273.             drawMenu()
  274.         end
  275.     end
  276. end
  277.  
  278. saveConfig()
  279. shell.run("lithos")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement