Advertisement
LegoStax

Lithium OS

Jul 24th, 2013
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.28 KB | None | 0 0
  1. --[[
  2.     Lithium Operating System by LegoStax
  3.     I do not own the following programs included in this package: LuaIDE - GravityScore, Firewolf - GravityScore, nPaintPro - NitrogenFingers, Mouse File Browser - BigSHinyToys.  Each program belongs to its owner.
  4.     If you are going to use any of the code in this file and/or package, please give credit to me and/or the correct owner at the top of your code.
  5.     NOTE: DO NOT REDISTRIBUTE THIS PACKAGE AS A WHOLE.  ALL NOTES AT THE TOP OF EVERY FILE IN THIS PACKAGE MUST BE KEPT WHERE THEY ARE.
  6.     Thanks!  Enjoy!
  7. ]]--
  8.  
  9. local openbar = false
  10. local running = true
  11. os.loadAPI(".programs/lith")
  12. if fs.exists(".programs/config") then
  13.     config = {}
  14.     local file = fs.open(".programs/config", "r")
  15.     config = textutils.unserialize(file.readAll())
  16.     file.close()
  17. end
  18. -- self-explanatory-GUI-drawing-function
  19. local function drawClosedStartBar()
  20.     openbar = false
  21.     if config.taskside == "top" then
  22.         term.setTextColor(colors.white)
  23.         term.setBackgroundColor(colors.lightGray)
  24.         term.setCursorPos(1,1)
  25.         term.write("                       [@]                         ")
  26.     elseif config.taskside == "right" then
  27.         term.setTextColor(colors.white)
  28.         term.setBackgroundColor(colors.lightGray)
  29.         for y = 1,19 do
  30.             term.setCursorPos(51,y)
  31.             term.write(" ")
  32.         end
  33.         term.setCursorPos(51,9)
  34.         term.write("<")
  35.     elseif config.taskside == "bottom" then
  36.         term.setTextColor(colors.white)
  37.         term.setBackgroundColor(colors.lightGray)
  38.         term.setCursorPos(1,19)
  39.         term.write("                        ^                          ")
  40.     elseif config.taskside == "left" then
  41.         term.setTextColor(colors.white)
  42.         term.setBackgroundColor(colors.lightGray)
  43.         for y = 1,19 do
  44.             term.setCursorPos(1,y)
  45.             term.write(" ")
  46.         end
  47.         term.setCursorPos(1,9)
  48.         term.write(">")
  49.     end
  50. end
  51. -- self-explanatory-GUI-drawing-function
  52. local function drawOpenStartBar()
  53.     openbar = true
  54.     if config.taskside == "top" then
  55.         term.setBackgroundColor(colors.gray)
  56.         term.setCursorPos(1,1)
  57.         term.write(" Explorer                                          ")
  58.         term.setCursorPos(1,2)
  59.         term.write(" Settings                                          ")
  60.         term.setCursorPos(1,3)
  61.         term.write(" Shutdown                                          ")
  62.         term.setCursorPos(1,4)
  63.         term.write(" Restart                                           ")
  64.         term.setCursorPos(1,5)
  65.         term.write(" CraftOS                                           ")
  66.     elseif config.taskside == "left" then
  67.         term.setBackgroundColor(colors.gray)
  68.         term.setCursorPos(1,1)
  69.         term.write(" Explorer ")
  70.         term.setCursorPos(1,2)
  71.         term.write(" Settings ")
  72.         term.setCursorPos(1,3)
  73.         term.write(" Shutdown ")
  74.         term.setCursorPos(1,4)
  75.         term.write(" Restart  ")
  76.         term.setCursorPos(1,5)
  77.         term.write(" CraftOS  ")
  78.         term.setCursorPos(1,6)
  79.         term.write("          ")
  80.         term.setCursorPos(1,7)
  81.         term.write("          ")
  82.         term.setCursorPos(1,8)
  83.         term.write("          ")
  84.         term.setCursorPos(1,9)
  85.         term.write("          ")
  86.         term.setCursorPos(1,10)
  87.         term.write("          ")
  88.         term.setCursorPos(1,11)
  89.         term.write("          ")
  90.         term.setCursorPos(1,12)
  91.         term.write("          ")
  92.         term.setCursorPos(1,13)
  93.         term.write("          ")
  94.         term.setCursorPos(1,14)
  95.         term.write("          ")
  96.         term.setCursorPos(1,15)
  97.         term.write("          ")
  98.         term.setCursorPos(1,16)
  99.         term.write("          ")
  100.         term.setCursorPos(1,17)
  101.         term.write("          ")
  102.         term.setCursorPos(1,18)
  103.         term.write("          ")
  104.         term.setCursorPos(1,19)
  105.         term.write("          ")
  106.     elseif config.taskside == "bottom" then
  107.         term.setBackgroundColor(colors.gray)
  108.         term.setCursorPos(1,15)
  109.         term.write(" Explorer                                          ")
  110.         term.setCursorPos(1,16)
  111.         term.write(" Settings                                          ")
  112.         term.setCursorPos(1,17)
  113.         term.write(" Shutdown                                          ")
  114.         term.setCursorPos(1,18)
  115.         term.write(" Restart                                           ")
  116.         term.setCursorPos(1,19)
  117.         term.write(" CraftOS                                           ")
  118.     elseif config.taskside == "right" then
  119.         term.setBackgroundColor(colors.gray)
  120.         term.setCursorPos(43,1)
  121.         term.write(" Explorer ")
  122.         term.setCursorPos(43,2)
  123.         term.write(" Settings ")
  124.         term.setCursorPos(43,3)
  125.         term.write(" Shutdown ")
  126.         term.setCursorPos(43,4)
  127.         term.write(" Restart  ")
  128.         term.setCursorPos(43,5)
  129.         term.write(" CraftOS  ")
  130.         term.setCursorPos(43,6)
  131.         term.write("          ")
  132.         term.setCursorPos(43,7)
  133.         term.write("          ")
  134.         term.setCursorPos(43,8)
  135.         term.write("          ")
  136.         term.setCursorPos(43,9)
  137.         term.write("          ")
  138.         term.setCursorPos(43,10)
  139.         term.write("          ")
  140.         term.setCursorPos(43,11)
  141.         term.write("          ")
  142.         term.setCursorPos(43,12)
  143.         term.write("          ")
  144.         term.setCursorPos(43,13)
  145.         term.write("          ")
  146.         term.setCursorPos(43,14)
  147.         term.write("          ")
  148.         term.setCursorPos(43,15)
  149.         term.write("          ")
  150.         term.setCursorPos(43,16)
  151.         term.write("          ")
  152.         term.setCursorPos(43,17)
  153.         term.write("          ")
  154.         term.setCursorPos(43,18)
  155.         term.write("          ")
  156.         term.setCursorPos(43,19)
  157.         term.write("          ")
  158.     end
  159. end
  160. -- self-explanatory-GUI-drawing-function
  161. local function drawDesktop()
  162.     term.setBackgroundColor(config.bgcolor)
  163.     for y = 1,19 do
  164.         for x = 1,51 do
  165.             term.setCursorPos(x,y)
  166.             term.write(" ")
  167.         end
  168.     end
  169.     bg = paintutils.loadImage(config.desktop_img)
  170.     paintutils.drawImage(bg,1,1)
  171. end
  172. -- Time update function
  173. local function displayTime()
  174.     term.setTextColor(colors.white)
  175.     -- check for taskbar side
  176.     if config.taskside == "top" then
  177.         -- update time
  178.         time = textutils.formatTime(os.time(), false)
  179.         term.setCursorPos(44,1)
  180.         term.write(time.." ")
  181.     elseif config.taskside == "bottom" then
  182.         time = textutils.formatTime(os.time(), false)
  183.         term.setCursorPos(44,19)
  184.         term.write(time.." ")
  185.     elseif config.taskside == "left" then
  186.         if openbar == true then
  187.             time = textutils.formatTime(os.time(), false)
  188.             term.setCursorPos(1,19)
  189.             term.write(time.." ")
  190.         end
  191.     elseif config.taskside == "right" then
  192.         if openbar == true then
  193.             time = textutils.formatTime(os.time(), false)
  194.             term.setCursorPos(44,19)
  195.             term.write(time.." ")
  196.         end
  197.     end
  198.     timeout = os.startTimer(0.8)
  199. end
  200.  
  201. function drawRightClick(x,y)
  202.     term.setBackgroundColor(colors.lightGray)
  203.     term.setTextColor(colors.red)
  204.     term.setCursorPos(x,y)
  205.     term.write(" Users ")
  206.     term.setTextColor(colors.white)
  207.     term.setCursorPos(x,y+1)
  208.     term.write(" Run   ")
  209. end
  210.  
  211. function runProgram()
  212.     term.setBackgroundColor(colors.gray)
  213.     term.setCursorPos(18,7)
  214.     term.write(" Run Program     ")
  215.     term.setBackgroundColor(colors.lime)
  216.     term.setCursorPos(18,8)
  217.     term.write("                 ")
  218.     term.setCursorPos(18,9)
  219.     term.write("                 ")
  220.     term.setCursorPos(18,10)
  221.     term.write("                 ")
  222.     term.setCursorPos(19,9)
  223.     write ""
  224.     program = read()
  225.     shell.run(program)
  226. end
  227.  
  228. function drawScreen()
  229.     drawDesktop()
  230.     drawClosedStartBar()
  231.     displayTime()
  232. end
  233. -- draw the screen for the first time
  234. drawScreen()
  235. -- Event handler:
  236. while running do
  237.     event, button, x, y = os.pullEvent()
  238.     if event == "mouse_click" then
  239.         if button == 1 then
  240.             if config.taskside == "top" then
  241.                 if x >= 24 and x <= 26 and y == 1 then
  242.                     drawOpenStartBar()
  243.                     event, button, x, y = os.pullEvent("mouse_click")
  244.                     if button == 1 then
  245.                         if x >= 2 and x <= 8 and y == 1 then
  246.                             shell.run(".programs/explorer")
  247.                             drawScreen()
  248.                         elseif x >= 2 and x <= 8 and y == 2 then
  249.                             shell.run(".programs/settings")
  250.                         elseif x >= 2 and x <= 8 and y == 3 then
  251.                             os.shutdown()
  252.                         elseif x >= 2 and x <= 8 and y == 4 then
  253.                             os.reboot()
  254.                         elseif x >= 2 and x <= 8 and y == 5 then
  255.                             running = false
  256.                         else
  257.                             drawScreen()
  258.                         end
  259.                     end
  260.                 end
  261.             elseif config.taskside == "left" then
  262.                 if x == 1 and y == 9 then
  263.                     drawOpenStartBar()
  264.                     choice = false
  265.                     while not choice do
  266.                         event, button, x, y = os.pullEvent()
  267.                         if event == "mouse_click" then
  268.                             if button == 1 then
  269.                                 if x >= 2 and x <= 8 and y == 1 then
  270.                                     shell.run(".programs/explorer")
  271.                                     drawScreen()
  272.                                     choice = true
  273.                                 elseif x >= 2 and x <= 8 and y == 2 then
  274.                                     shell.run(".programs/settings")
  275.                                     choice = true
  276.                                 elseif x >= 2 and x <= 8 and y == 3 then
  277.                                     os.shutdown()
  278.                                 elseif x >= 2 and x <= 8 and y == 4 then
  279.                                     os.reboot()
  280.                                 elseif x >= 2 and x <= 8 and y == 5 then
  281.                                     running = false
  282.                                     choice = true
  283.                                 else
  284.                                     drawScreen()
  285.                                     choice = true
  286.                                 end
  287.                             end
  288.                         elseif event == "timer" and button == timeout then
  289.                             displayTime()
  290.                         end
  291.                     end
  292.                 end
  293.             elseif config.taskside == "bottom" then
  294.                 if x >= 24 and x <= 26 and y == 19 then
  295.                     drawOpenStartBar()
  296.                     event, button, x, y = os.pullEvent("mouse_click")
  297.                     if button == 1 then
  298.                         if x >= 2 and x <= 8 and y == 15 then
  299.                             shell.run(".programs/explorer")
  300.                             drawScreen()
  301.                         elseif x >= 2 and x <= 8 and y == 16 then
  302.                             shell.run(".programs/settings")
  303.                         elseif x >= 2 and x <= 8 and y == 17 then
  304.                             os.shutdown()
  305.                         elseif x >= 2 and x <= 8 and y == 18 then
  306.                             os.reboot()
  307.                         elseif x >= 2 and x <= 8 and y == 19 then
  308.                             running = false
  309.                         else
  310.                             drawScreen()
  311.                         end
  312.                     end
  313.                 end
  314.             elseif config.taskside == "right" then
  315.                 if x == 51 and y == 9 then
  316.                     drawOpenStartBar()
  317.                     choice = false
  318.                     while not choice do
  319.                         event, button, x, y = os.pullEvent()
  320.                         if event == "mouse_click" then
  321.                             if button == 1 then
  322.                                 if x >= 44 and x <= 51 and y == 1 then
  323.                                     shell.run(".programs/explorer")
  324.                                     drawScreen()
  325.                                     choice = true
  326.                                 elseif x >= 44 and x <= 51 and y == 2 then
  327.                                     shell.run(".programs/settings")
  328.                                     choice = true
  329.                                 elseif x >= 44 and x <= 51 and y == 3 then
  330.                                     os.shutdown()
  331.                                 elseif x >= 44 and x <= 51 and y == 4 then
  332.                                     os.reboot()
  333.                                 elseif x >= 44 and x <= 51 and y == 5 then
  334.                                     running = false
  335.                                     choice = true
  336.                                 else
  337.                                     drawScreen()
  338.                                     choice = true
  339.                                 end
  340.                             end
  341.                         elseif event == "timer" and button == timeout then
  342.                             displayTime()
  343.                         end
  344.                     end
  345.                 end
  346.             end
  347.         elseif button == 2 then
  348.             drawRightClick(x,y)
  349.             choice = false
  350.             while not choice do
  351.                 event, p1, p2, p3 = os.pullEvent()
  352.                 if event == "timer" and button == timeout then
  353.                     displayTime()
  354.                 elseif event == "mouse_click" then
  355.                     if p2 >= x and p2 <= x+7 and p3 == y then
  356.                         shell.run(".programs/users")
  357.                         choice = true
  358.                     elseif p2 >= x and p2 <= x+7 and p3 == y+1 then
  359.                         runProgram()
  360.                         drawScreen()
  361.                         choice = true
  362.                     else
  363.                         drawScreen()
  364.                         choice = true
  365.                     end
  366.                 end
  367.             end
  368.             drawScreen()
  369.         end
  370.     elseif event == "timer" and button == timeout then
  371.         displayTime()
  372.     elseif event == "key" then
  373.         if button == keys.leftCtrl then
  374.             runProgram()
  375.             drawScreen()
  376.             choice = true
  377.         end
  378.     end
  379. end
  380.  
  381. term.setTextColor(colors.white)
  382. term.setBackgroundColor(colors.black)
  383. term.clear()
  384. term.setCursorPos(1,1)
  385. print("Thank you for using Lithium OS by LegoStax")
  386. shell.run("rom/programs/shell")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement