Guest User

Untitled

a guest
Dec 12th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.95 KB | None | 0 0
  1. --[[ VARIABLES ]]--
  2. local x, y = term.getSize()
  3. local SolarPanelsStat = true
  4. local QuarryStat = false
  5. local rSide = "left"
  6. local selectedItem = 1
  7. local inMainMenu = true
  8.  
  9. --[[ HANDLER FUNCTIONS ]]--
  10.  
  11. function Quarry()
  12.     QuarryStat = not QuarryStat
  13. end
  14.  
  15.  
  16. --[[ FUNCTIONS ]]--
  17.  
  18. function Clear()
  19.     term.setBackgroundColor(colors.black)
  20.     term.setTextColor(colors.white)
  21.     term.clear()
  22.     term.setCursorPos(1, 1)
  23. end
  24.  
  25. function writeSolarPanelsStatus()
  26.     term.setCursorPos(x/1.3, 2)
  27.     if SolarPanelsStat == true then
  28.         term.setTextColor(colors.green)
  29.         print("On ")
  30.     elseif SolarPanelsStat == false then
  31.         term.setTextColor(colors.red)
  32.         print("Off")
  33.     end
  34. end
  35.  
  36. function writeStats()
  37.     writeSolarPanelsStatus()
  38. end
  39.  
  40. function ReceiveStats()
  41.     rednet.open("left")
  42.     local event, id, msg = os.pullEvent("rednet_message")
  43.             if msg == "SolarPanelsOn" then
  44.                 SolarPanelsStat = true
  45.             elseif msg == "SolarPanelsOff" then
  46.                 SolarPanelsStat = false
  47.             elseif msg == "QuarryOn" then
  48.                 QuarryStat = true
  49.             elseif msg == "QuarryOff" then
  50.                 QuarryStat = false
  51.             end
  52.         end
  53.        
  54. function CheckTime()
  55.     term.setCursorPos(x/2-4.5, 1)
  56.     local time = os.time()
  57.     time = textutils.formatTime(time, false)
  58.     term.setTextColor(colors.white)
  59.     print(time)
  60. end    
  61.  
  62. function printDisplay()
  63.     for i=1 , #display do
  64.         term.setCursorPos(x/2, i+1)
  65.         term.setTextColor(colors.white)
  66.         print(display[i].text)
  67.         term.setCursorPos(x/.5, 3)
  68.        
  69.         writeStats()
  70.     end
  71. end
  72.  
  73. function printMenu(menu)
  74.     for i=1, #menu do
  75.         if i == selectedItem then
  76.             print(">> "..menu[i].text)
  77.         else
  78.             print("   "..menu[i].text)
  79.         end
  80.     end
  81. end
  82.  
  83. function onItemSelected(menu)
  84.     menu[selectedItem].handler()
  85. end
  86.  
  87. function onKeyPressed(key, menu)
  88.     if key == keys.enter then
  89.         onItemSelected(menu)
  90.     elseif key == keys.up then
  91.         if selectedItem > 1 then
  92.             selectedItem = selectedItem - 1
  93.         end
  94.     elseif key == keys.down then
  95.         if selectedItem < #menu then
  96.             selectedItem = selectedItem + 1
  97.         end
  98.     end
  99. end
  100.  
  101. function writeQuarryStats()
  102.     term.setCursorPos(x/4, 2)
  103.     if QuarryStat == true then
  104.         term.setTextColor(colors.green)
  105.         print("On ")
  106.     elseif QuarryStat == false then
  107.         term.setTextColor(colors.red)
  108.         print("Off")
  109.     end
  110. end
  111.  
  112. function writeMenuStats()
  113.     writeQuarryStats()
  114. end
  115.  
  116. function main()
  117.     while inMainMenu do
  118.     Clear()
  119.     term.setTextColor(colors.white)
  120.     term.setCursorPos(1, 2)
  121.     printMenu(mainMenu)
  122.     writeMenuStats()
  123.    
  124.     local event,key = os.pullEvent("key")
  125.     onKeyPressed(key, mainMenu)
  126.     end
  127. end
  128.  
  129. function PrintFinalStats()
  130.     while true do
  131.     CheckTime()
  132.     printDisplay()
  133.     ReceiveStats()
  134.     end
  135. end
  136.  
  137. function Parallel1()
  138.     parallel.waitForAny(PrintFinalStats(),main())
  139. end
  140.  
  141. function Parallel2()
  142.     parallel.waitForAny(main(), PrintFinalStats())
  143. end
  144.  
  145. --[[ TABLES ]]--
  146.  
  147. mainMenu = {
  148. [1] = {text = "Quarry", handler = Quarry}
  149. }
  150.  
  151. display = {
  152. [1] = {text = "SolarPanels"}
  153. }
  154.  
  155. --[[ MAIN CODE ]]--
  156.  
  157. Clear()
  158. parallel.waitForAny(Parallel1, Parallel2)
Advertisement
Add Comment
Please, Sign In to add comment