Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2014
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | None | 0 0
  1. os.loadAPI("touchpoint")
  2.  
  3. local modem = peripheral.wrap("back")
  4. local monSide = "right"
  5. local mon = peripheral.wrap(monSide)
  6.  
  7. modem.open(1)
  8.  
  9. cells = {}
  10. turbine = "BigReactors-Turbine_0"
  11. reactor = "BigReactors-Reactor_0"
  12. reactorActive = modem.callRemote(reactor, "getActive")
  13. turbineActive = modem.callRemote(turbine, "getActive")
  14.  
  15. pages =
  16. {
  17.     mainMenu = touchpoint.new(monSide),
  18.     reactorControl = touchpoint.new(monSide),
  19.     energyNetwork = touchpoint.new(monSide),
  20.     machines = touchpoint.new(monSide)
  21. }
  22.  
  23. t = pages[mainMenu]
  24.  
  25. maxEnergy = 0
  26. energy = {}
  27. curTotalEnergy = -1
  28. curTotalEnergyPercent = 0
  29. energyLastTick = -1
  30. energyPerTick = -1
  31.  
  32. -- Fetch the names of the cells from the modems net
  33. function getCells()
  34.     names = modem.getNamesRemote()
  35.    
  36.     for i, v in ipairs(names) do
  37.         if v:find("cofh_thermalexpansion_energycell_") ~= nil then
  38.             table.insert(cells, v)
  39.         end
  40.     end
  41. end
  42.  
  43. -- Get current amount of energy from each cell
  44. function getEnergy()
  45.     if curTotalEnergy ~= -1 then
  46.         energyLastTick = curTotalEnergy
  47.     end
  48.    
  49.     curTotalEnergy = 0
  50.     curTotalEnergyPercent = 0
  51.     energy = {}
  52.    
  53.     for token in p4:gmatch("%d+") do
  54.         table.insert(energy, tonumber(token))
  55.         curTotalEnergy = curTotalEnergy + tonumber(token)
  56.     end
  57.    
  58.     curTotalEnergyPercent = curTotalEnergy / maxEnergy * 100
  59.  
  60.     if energyLastTick ~= -1 then
  61.         energyPerTick = (curTotalEnergy - energyLastTick) / #energy
  62.     end
  63. end
  64.  
  65. function toggleReactor()
  66.     pages.reactorControl:toggleButton("reactor")
  67.     reactorActive = not reactorActive
  68.     modem.callRemote(reactor, "setActive", reactorActive)
  69. end
  70.  
  71. function toggleTurbine()
  72.     pages.reactorControl:toggleButton("turbine")
  73.     turbineActive = not turbineActive
  74.     modem.callRemote(turbine, "setActive", turbineActive)
  75. end
  76.  
  77. function toggleQuarry()
  78.  
  79. end
  80.  
  81. function toggleDrill()
  82.  
  83. end
  84.  
  85. function drawGUI()
  86. end
  87.  
  88. function changePage(page)
  89.     t = pages.page
  90. end
  91.    
  92.  
  93. -- Initialize Buttons
  94. buttons =
  95. {
  96.     mainMenu =
  97.     {
  98.         {
  99.             "                       ",
  100.             "    Reactor Control    ",
  101.             "                       ",
  102.             label = "reactorControl"
  103.         },
  104.         {
  105.             "                       ",
  106.             "    Energy Network     ",
  107.             "                       ",
  108.             label = "energyNetwork"
  109.         },
  110.         {
  111.             "                       ",
  112.             "   Various Machines    ",
  113.             "                       ",
  114.             label = "machines"
  115.         }
  116.     },
  117.     reactorControl =
  118.     {
  119.         {
  120.             "         ",
  121.             " Reactor ",
  122.             "         ",
  123.             label = "reactor"
  124.         },
  125.         {
  126.             "         ",
  127.             " Turbine ",
  128.             "         ",
  129.             label = "turbine"
  130.         },
  131.         {
  132.             "         ",
  133.             "  Back   ",
  134.             "         ",
  135.             label = "backReactor"
  136.         }
  137.     },
  138.     energyNetwork =
  139.     {
  140.         "      ",
  141.         " Back ",
  142.         "      ",
  143.         label = "backEnergy"
  144.     },
  145.     machines =
  146.     {
  147.         {
  148.             "             ",
  149.             "   Quarry    ",
  150.             "             ",
  151.             label = "quarry"
  152.         },
  153.         {
  154.             "             ",
  155.             " Laser Drill ",
  156.             "             ",
  157.             label = "drill"
  158.         },
  159.         {
  160.             "             ",
  161.             "    Back     ",
  162.             "             ",
  163.             label = "backMachines"
  164.         }
  165.     }
  166. }
  167. print("New1")
  168. -- ERROR RIGHT HERE
  169. buttonFuncs =
  170. {
  171.     mainMenu = {changePage(reactorControl), changePage(energyNetwork), changePage(machines)},
  172.     reactorControl = {toggleReactor(), toggleTurbine(), changePage(mainMenu)},
  173.     energyNetwork = {changePage(mainMenu)},
  174.     machines = {toggleQuarry(), toggleDrill(), changePage(mainMenu)}
  175. }
  176. -- RIGHT HERE
  177. print("New2")
  178.  
  179. local xPos
  180. local yPos = 3
  181.  
  182. for i = 1, #buttons.mainMenu do
  183.     local width = 22
  184.     local height = 2
  185.    
  186.     if i % 2 == 1 then
  187.         xPos = 2
  188.         yPos = yPos + 4
  189.     else
  190.         xPos = 27
  191.     end
  192.    
  193.     pages.mainMenu:add(buttons.mainMenu[i], buttonFuncs.mainMenu[i],  xPos, yPos, xPos + width, yPos + height, colors.red, colors.lime)
  194. end
  195.  
  196. --[[for i = 1, #buttons.reactorControl do
  197.     local width = 22
  198.     local height = 2
  199.    
  200.     if i % 2 == 1 then
  201.         xPos = 2
  202.         yPos = yPos + 4
  203.     else
  204.         xPos = 27
  205.     end
  206.    
  207.     print(xPos)
  208.     print(yPos)
  209.     mainMenu:add(buttons.reactorControl[i], buttonFuncs.reactorControl[i],  xPos, yPos, xPos + width, yPos + height, colors.red, colors.lime)
  210. end]]--
  211.  
  212. -- Fetch cells
  213. getCells()
  214.  
  215. -- Get amount of total storage available
  216. for i,v in ipairs(cells) do
  217.     maxEnergy = maxEnergy + modem.callRemote(v, "getMaxEnergyStored", "direction")
  218. end
  219.  
  220. while true do
  221.     t:draw()
  222.     e, p1, p2, p3, p4, p5 = mainMenu:handleEvents(os.pullEvent())
  223.  
  224.     if e == "modem_message" then
  225.         getEnergy()
  226.         if curTotalEnergyPercent <= 10 then
  227.             setEnergy(true)
  228.         elseif curTotalEnergyPercent >= 90 then
  229.             setEnergy(false)
  230.         end
  231.     elseif e == "button_click" then
  232.         t.buttonList[p1].func()
  233.     end
  234.  
  235.     drawGUI()
  236. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement