Advertisement
NAPTlME

BigReactors Monitor

Jun 30th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.80 KB | None | 0 0
  1. --BigReactors Monitor
  2. --NAPTlME
  3. --using 4x3 monitor, size 79x38
  4.  
  5. rednet.open('right')
  6. os.loadAPI("button")
  7. m = peripheral.wrap("left")
  8. n = peripheral.wrap("BigReactors-Reactor_0")
  9. p = peripheral.wrap("ep_dialling_device_0")
  10. c = peripheral.wrap("ep_controller_1")
  11. m.clear()
  12. rs.setAnalogOutput('front',0)
  13.  
  14.  
  15. function white()
  16.   m.setBackgroundColor(colors.white)
  17.   w,h = m.getSize()
  18.   for i = 4,h do
  19.     m.setCursorPos(1,i)
  20.     for j = 1,w do
  21.       m.write(" ")
  22.     end
  23.   end
  24. end
  25.  
  26. white()
  27.  
  28. function start()
  29.   m.setBackgroundColor(colors.lightBlue)
  30.   for i = 4,25 do
  31.     m.setCursorPos(28,i)
  32.     m.write(" ")
  33.   end
  34.   m.setCursorPos(1,25)
  35.   for i = 1,28 do
  36.     m.write(" ")
  37.   end
  38.   for i = 1,3 do
  39.     m.setCursorPos(1,i)
  40.     for j = 1,w do
  41.       m.write(" ")
  42.     end
  43.  end
  44.   m.setBackgroundColor(colors.white)
  45. end
  46. start()
  47.  
  48. function fillTable()
  49.    button.setTable("Ocean", ocean, nil, 31,51,4,6)
  50.    button.setTable("Overdrive", overdrive, nil, 3,26,21,23)
  51.    button.setTable("Brain's Base", brain, nil, 54,74,4,6)
  52.    button.screen()
  53. end
  54.  
  55. function getClick()
  56.    event,side,x,y = os.pullEvent("monitor_touch")
  57.    button.checkxy(x,y)
  58. end
  59.  
  60. function ocean()
  61.    button.flash("Ocean")
  62.    white()
  63.    m.clear()
  64.    m.setTextScale(0.75)
  65.    w,h = m.getSize()
  66.    m.setTextColor(colors.black)
  67.    line1 = "Aligning Gateway to Ocean base."
  68.    m.setCursorPos((w-string.len(line1))/2+1,7)
  69.    m.write(line1)
  70.    line2 = "Please make your way to the Gateway and enjoy your stay at RestEasy"
  71.    m.setCursorPos((w-string.len(line2))/2+1,9)
  72.    m.write(line2)
  73.    rs.setOutput('back', true)
  74.    sleep(1)
  75.    rs.setOutput('back', false)
  76.    rednet.send(630, "switch")
  77.    --rednet.send(#, "switch")
  78.    id, msg = rednet.receive(10)  
  79.    m.clear()
  80.    m.setTextScale(0.5)
  81.    w,h = m.getSize()
  82.    white()
  83.    start()
  84.    button.heading("Rest Easy: Secure Solutions", "")
  85.    m.setTextColor(colors.black)
  86.    button.screen()
  87. end
  88.  
  89. function brain()
  90.    button.flash("Brain's Base")
  91.    m.setBackgroundColor(colors.white)
  92.    m.clear()
  93.    m.setTextScale(0.75)
  94.    w,h = m.getSize()
  95.    w = w - 28
  96.    m.setTextColor(colors.black)
  97.    line1 = "Aligning Portal to Brain's Base."
  98.    m.setCursorPos((w-string.len(line1))/2+29,7)
  99.    m.write(line1)
  100.    line2 = "Please make your way to the Portal"
  101.    m.setCursorPos((w-string.len(line2))/2+29,9)
  102.    m.write(line2)
  103.    line3 = "And enjoy your stay at RestEasy"
  104.    m.setCursorPos((w-string.len(line3))/2+29,11)
  105.    m.write(line3)
  106.    rs.setAnalogOutput('front',1)
  107.    z = os.pullEvent("monitor_touch")
  108.    rs.setAnalogOutput('front',0)
  109.    m.clear()
  110.    m.setTextScale(0.5)
  111.    w,h = m.getSize()
  112.    white()
  113.    start()
  114.    m.setTextColor(colors.black)
  115.    button.heading("Rest Easy: Secure Solutions", "")
  116.    button.screen()
  117. end
  118.  
  119. function overdrive()
  120.    button.toggleButton("Overdrive")
  121.    rednet.send(73, "overdrive")
  122.    sleep(30)
  123.    button.toggleButton("Overdrive")  
  124.    button.screen()
  125. end
  126.  
  127.  
  128. function test2()
  129.    button.toggleButton("Test2")
  130.    print("Test2")
  131. end
  132.  
  133. function test3()
  134.    print("Test3")
  135. end
  136.  
  137. function test4()
  138.    print("Test4")
  139. end
  140.  
  141.  
  142.  
  143. function is_Active()
  144.   if n.getActive() then
  145.     rActive = "Active "
  146.     local x_min = 3
  147.     local x_max = 26
  148.     local x_spot = math.floor((x_max - x_min - string.len(rActive)) /2) +1
  149.     m.setBackgroundColor(colors.white)
  150.     m.setCursorPos(3,8)
  151.     for l = 1, (((x_max - x_min) - string.len(rActive)) +1) do
  152.       if l == x_spot then
  153.         m.write(rActive)
  154.       else
  155.         m.write(" ")
  156.       end
  157.     end
  158.     energy = math.floor(n.getEnergyProducedLastTick() + 0.5)
  159.     rEnergy = "Energy/tick: "..energy
  160.     local x_min= 3
  161.     local x_max = 26
  162.     local x_spot = math.floor((x_max-x_min - string.len(rEnergy))/2) +1
  163.     m.setCursorPos(3,10)
  164.     for l = 0, x_max - x_min - string.len(rEnergy) +1 do
  165.       if l == x_spot then
  166.         m.write(rEnergy)
  167.       else
  168.         m.write(" ")
  169.       end
  170.     end
  171.     rod = n.getControlRodLevel(1)
  172.     rRod = "Fuel Rod Insertion: "..rod.."%"
  173.     local x_min= 3
  174.     local x_max = 26
  175.     local x_spot = math.floor((x_max-x_min - string.len(rRod))/2) +1
  176.     m.setCursorPos(3,12)
  177.     for l = 0, x_max - x_min - string.len(rRod) +1 do
  178.       if l == x_spot then
  179.         m.write(rRod)
  180.       else
  181.         m.write(" ")
  182.       end
  183.     end
  184.     stored = n.getEnergyStored()
  185.     rStored = stored.." RF"
  186.     local x_min= 3
  187.     local x_max = 26
  188.     local x_spot = math.floor((x_max-x_min - string.len(rStored))/2) +1
  189.     m.setCursorPos(3,14)
  190.     for l = 0, x_max - x_min - string.len(rStored) +1 do
  191.       if l == x_spot then
  192.         m.write(rStored)
  193.       else
  194.         m.write(" ")
  195.       end
  196.     end
  197.   else
  198.     rActive = "Idle"
  199.     local x_min = 3
  200.     local x_max = 26
  201.     local x_spot = math.floor((x_max - x_min - string.len(rActive)) /2) +1
  202.     m.setBackgroundColor(colors.white)
  203.     m.setCursorPos(3,8)
  204.     for l = 0, x_max - x_min - string.len(rActive) +1 do
  205.       if l == x_spot then
  206.         m.write(rActive)
  207.       else
  208.         m.write(" ")
  209.       end
  210.     end
  211.   end
  212. end
  213.  
  214. function connected()
  215.   if n.getConnected() then
  216.     rName = "Reactor"
  217.     local x_min = 3
  218.     local x_max = 26
  219.     local x_spot = math.floor((x_max - x_min - string.len(rName)) /2) +1
  220.     m.setBackgroundColor(colors.white)
  221.     m.setCursorPos(3,6)
  222.     for l = 0, x_max - x_min - string.len(rName) +1 do
  223.       if l == x_spot then
  224.         m.write(rName)
  225.       else
  226.         m.write(" ")
  227.       end
  228.     end
  229.   is_Active()
  230.   end
  231. end
  232.  
  233.  
  234. fillTable()
  235. button.heading("Rest Easy: Secure Solutions", "")
  236. --button.label(1,5,"Demo!")
  237. m.setTextColor(colors.black)
  238.  
  239. function touch()
  240.   while true do
  241.      getClick()
  242.   end
  243. end
  244.  
  245. function reactor()
  246.   while true do
  247.     connected()
  248.     sleep(1)
  249.   end
  250. end
  251.  
  252. function main()
  253.   fillTable()
  254.   parallel.waitForAll(touch,reactor)
  255. end
  256.  
  257. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement