Advertisement
Guest User

startup

a guest
Jan 22nd, 2020
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.60 KB | None | 0 0
  1. --Global variables
  2. IsOnFlag = true
  3. mouseWidth = 0
  4. mouseHeight = 0
  5. ColorMix = 0
  6. ------------------
  7. --initialize
  8. monitor = peripheral.wrap("top")
  9. monitor.clear()
  10. monitor.setCursorPos(1,1)
  11. reactor = peripheral.wrap("back")
  12.  
  13. --Write On/Off button
  14. function WriteButtons(IsOn)
  15.     monitor.setTextColor(colors.white)
  16.     if IsOn == true then
  17.         monitor.setBackgroundColour((colours.lime))
  18.         monitor.setCursorPos(24,2)
  19.         monitor.write("     ")
  20.         monitor.setCursorPos(24,3)
  21.         monitor.write(" ON  ")
  22.         monitor.setCursorPos(24,4)
  23.         monitor.write("     ")
  24.     else
  25.         monitor.setBackgroundColour((colours.red))
  26.         monitor.setCursorPos(24,2)
  27.         monitor.write("     ")
  28.         monitor.setCursorPos(24,3)
  29.         monitor.write(" OFF ")
  30.         monitor.setCursorPos(24,4)
  31.         monitor.write("     ")
  32.     end
  33.     monitor.setBackgroundColour((colours.black))  
  34. end
  35.  
  36. --Check mouse to button click
  37. function checkClickPosition()
  38.   if mouseWidth >= 24 and mouseWidth <= 28 and mouseHeight >= 2 and mouseHeight <= 4 then
  39.     if IsOnFlag == true then
  40.       IsOnFlag = false
  41.     else
  42.       IsOnFlag = true
  43.     end
  44.    
  45.     WriteButtons(IsOnFlag)
  46.     UpdateSensors()
  47.   end
  48. end
  49.  
  50. --
  51. function DrawTextLine(State, Color, Line, TextH, TextOk, TextFail)
  52.   monitor.setCursorPos(1,Line)
  53.   monitor.setTextColor(colors.white)
  54.   monitor.write(TextH)
  55.   monitor.setCursorPos(14,Line)
  56.   monitor.setTextColor(Color)
  57.   if State then
  58.     monitor.write(TextOk)
  59.   else
  60.     monitor.write(TextFail)
  61.   end
  62. end
  63.  
  64. --
  65. function DrawValueLine(value, Color, Line, TextH)
  66.   monitor.setCursorPos(1,Line)
  67.   monitor.setTextColor(colors.white)
  68.   monitor.write(TextH)
  69.   monitor.setCursorPos(14,Line)
  70.   monitor.setTextColor(Color)
  71.   val = math.floor(value)
  72.   monitor.write(val)
  73. end
  74.  
  75. --draw data from redstone channels (sensors)
  76. function UpdateSensors()
  77.   monitor.setBackgroundColor(colours.black)
  78.    
  79.   S_Status = reactor.getActive()
  80.  
  81.   EnergyLevel = reactor.getEnergyStored()
  82.  
  83.   PowerPercent = (EnergyLevel / 10000000) * 100
  84.   PowerPercent = math.floor(PowerPercent)
  85.  
  86.   --RodsLevel = PowerPercent
  87.   RodsLevel = 100
  88.    
  89.   ProduceLevel = reactor.getEnergyProducedLastTick()
  90.   ProducePercent = math.floor((ProduceLevel / 3960) * 100)
  91.  
  92.   Coolant = reactor.getCoolantAmount()
  93.   HotFluid = reactor.getHotFluidAmount()
  94.  
  95.   if Coolant < 1000 then
  96.     RodsLevel = 100
  97.   elseif HotFluid > 9000 then
  98.     RodsLevel = 100
  99.   else
  100.     RodsLevel = 110 - math.floor(Coolant / 98)
  101.   end
  102.  
  103.   if RodsLevel < 0 then
  104.     RodsLevel = 0
  105.   end
  106.  
  107.   DrawTextLine(S_Status  , colors.green  , 1, "STATUS:"      , " ON " , " OFF ")
  108.   --DrawValueLine(PowerPercent, colors.red, 2,  "ENERGY:")
  109.   --DrawValueLine(ProducePercent, colors.blue, 3, "POWER:")
  110.   DrawValueLine(100-RodsLevel, colors.yellow, 2, "RODS: ")
  111.   DrawValueLine(Coolant, colors.white, 3, "COOL:  ")
  112.   DrawValueLine(HotFluid, colors.white, 4, "HOT:   ")  
  113.      
  114.   reactor.setAllControlRodLevels(RodsLevel)
  115.  
  116.   if IsOnFlag then
  117.     reactor.setActive(true)
  118.   else
  119.     reactor.setActive(false)
  120.   end
  121.  
  122.   WriteButtons(IsOnFlag)
  123. end
  124.  
  125. w,h=monitor.getSize()
  126. print(w)
  127. print(h)
  128.  
  129. checkClickPosition()
  130. WriteButtons(false)
  131. UpdateSensors()
  132.  
  133. repeat
  134.     local myTimer = os.startTimer(0.25)
  135.    
  136.     event,p1,p2,p3 = os.pullEvent()
  137.     if event=="monitor_touch" then
  138.         mouseWidth = p2 -- sets mouseWidth
  139.         mouseHeight = p3 -- and mouseHeight
  140.         checkClickPosition() -- this runs our function
  141.     end
  142.  
  143.   if event=="timer" then
  144.     UpdateSensors()
  145.   end
  146. until event=="char" and p1==("q")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement