Advertisement
Xylem_Gaming

Big Reactors Monitor

Feb 4th, 2016
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.70 KB | None | 0 0
  1. --[[
  2. This is the variables for the reactor function
  3. ]]
  4.  
  5. mon = peripheral.find("monitor")
  6. if mon ~= nil then
  7.   local term = mon
  8. end
  9.  
  10. max = 10000000
  11.  
  12. reactor1 = peripheral.wrap("BigReactors-Reactor_2")
  13. reactor2 = peripheral.wrap("")
  14. reactor3 = peripheral.wrap("")
  15. reactor4 = peripheral.wrap("")
  16.  
  17. --[[
  18. Variables for the main program, please do not touch
  19. ]]
  20. x,y = term.getSize()
  21. running = true
  22. index = 1
  23.  
  24. default = {
  25. background = "black",
  26. textC = "white"
  27. }
  28.  
  29. button = {
  30. button1 = {text = "Back",bx = 1, by = y},
  31. button2 = {text = "Select", bx = math.floor((x/2)-(string.len("Select")/2)), by = y},
  32. button3 = {text = "Next",bx = x-string.len("Next")+1, by = y}
  33. }
  34. buttonSize = table.getn(button)
  35. local function drawButton(state1,state2,state3,colour)
  36.   if colour == nil then colour = "red" end
  37.   term.setBackgroundColour(colours[colour])
  38.   if state1 then
  39.     term.setCursorPos(button.button1.bx,button.button1.by)
  40.     term.write(button.button1.text)
  41.   end
  42.   if state2 then
  43.     term.setCursorPos(button.button2.bx,button.button2.by)
  44.     term.write(button.button2.text)
  45.   end
  46.   if state3 then
  47.     term.setCursorPos(button.button3.bx,button.button3.by)
  48.     term.write(button.button3.text)
  49.   end
  50.   term.setBackgroundColour(colours[default.background])
  51. end
  52.  
  53. local function flashButton(b)
  54.   if b == 1 then drawButton(true,false,false,"green") end
  55.   if b == 2 then drawButton(false,true,false,"green") end
  56.   if b == 3 then drawButton(false,false,true,"green") end
  57.   sleep(0.25)
  58.   drawButton(true,true,true)
  59. end
  60.  
  61. local function clearScreen()
  62.   for i = 1,y-1 do
  63.     term.setCursorPos(1,i)
  64.     term.clearLine()
  65.   end
  66. end
  67.  
  68. term.clear()
  69.  
  70. local function printBar(x,y,val,per)
  71.   term.setCursorPos(x,y)
  72.   term.setBackgroundColour(colours[default.background])
  73.   term.clearLine()
  74.   term.setBackgroundColour(colours.red)
  75.   for i = 1,25 do
  76.     term.write(" ")
  77.   end
  78.   term.setCursorPos(x,y)
  79.   term.setBackgroundColour(colours.green)
  80.   for i = 1,val do
  81.     term.write(" ")
  82.   end
  83.   term.setBackgroundColour(colours[default.background])
  84.   term.setCursorPos(x+26,y)
  85.   term.write(per.."%")  
  86. end
  87.  
  88. function printReactor()
  89.   while running do
  90.     clearScreen()
  91.     term.setCursorPos(1,1)
  92.     term.setBackgroundColour(colours[default.background])
  93.     term.setTextColour(colours.yellow)
  94.     term.write("Reactor: "..index)
  95.     term.setBackgroundColour(colours[colour])
  96.     term.setTextColour(colours[default.textC])
  97.     term.setBackgroundColour(colours[default.background])
  98.     if index == 1 then
  99.       cur1 = math.random(1,max)
  100.       pert1 = math.floor((cur1/max)*100)
  101.       per1 = math.floor(pert1/4)
  102.       term.setCursorPos(1,3)
  103.       term.write("RF Stored: "..cur1.."/"..max)
  104.       printBar(1,4,per1,pert1)
  105.     elseif index == 2 then
  106.       cur1 = math.random(1,max)
  107.       pert1 = math.floor((cur1/max)*100)
  108.       per1 = math.floor(pert1/4)
  109.       term.setCursorPos(1,2)
  110.       term.write("RF Stored: "..cur1.."/"..max)
  111.       printBar(1,3,per1,pert1)
  112.     elseif index == 3 then
  113.       cur1 = math.random(1,max)
  114.       pert1 = math.floor((cur1/max)*100)
  115.       per1 = math.floor(pert1/4)
  116.       term.setCursorPos(1,2)
  117.       term.write("RF Stored: "..cur1.."/"..max)
  118.       printBar(1,3,per1,pert1)
  119.     elseif index == 4 then
  120.       cur1 = math.random(1,max)
  121.       pert1 = math.floor((cur1/max)*100)
  122.       per1 = math.floor(pert1/4)
  123.       term.setCursorPos(1,2)
  124.       term.write("RF Stored: "..cur1.."/"..max)
  125.       printBar(1,3,per1,pert1)
  126.     end
  127.     sleep(0.5)
  128.   end
  129. end
  130.  
  131. function gui()
  132.   while running do
  133.     if index == 1 then
  134.       drawButton(false,true,true)
  135.     elseif index == 4 then
  136.       drawButton(true,true,false)
  137.     else
  138.       drawButton(true,true,true)
  139.     end
  140.     event, param1, param2, param3 = os.pullEvent()
  141.     if event == "mouse_click" then
  142.       if param2 >= button.button1.bx and param2 <= (button.button1.bx + #button.button1.text) and param3 == button.button1.by and index ~= 1 then
  143.         flashButton(1)
  144.         index = index - 1
  145.         clearScreen()
  146.       elseif param2 >= button.button2.bx and param2 <= (button.button2.bx + #button.button2.text) and param3 == button.button2.by then
  147.         flashButton(2)
  148.       elseif param2 >= button.button3.bx and param2 <= (button.button3.bx + #button.button3.text) and param3 == button.button3.by and index ~= 4 then
  149.         flashButton(3)
  150.         index = index + 1
  151.         clearScreen()
  152.       end
  153.     elseif event == "key" then
  154.         if param1 == keys.y then
  155.           running = false
  156.           term.setBackgroundColour(colours[default.background])
  157.           term.clear()
  158.           term.setCursorPos(1,1)
  159.         end
  160.     end
  161.   term.setCursorPos(1,y)
  162.   term.clearLine()
  163.   end
  164. end
  165.  
  166. parallel.waitForAny(gui,printReactor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement