cj89898_2

Untitled

Jan 17th, 2016
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. os.loadAPI("button")
  2.  
  3. m = peripheral.find("monitor")
  4. r = peripheral.find("BigReactors-Reactor")
  5.  
  6. local width, height = m.getSize()
  7.  
  8. local menuType = "Reactor"
  9.  
  10. local targetSpeed = 1840
  11.  
  12. local timerCode
  13. local mode = "Manual"
  14. local RFProduction = 0
  15. local coreTemp = 0
  16. local reactorOnline = false
  17. local rodLevel = 0
  18.  
  19. local OptFuelRodLevel = 0
  20.  
  21. function manualMenu()
  22. m.setTextScale(2)
  23. button.clearTable()
  24. button.setTable("Manual", manualMode, "", 4, 12, 3, 3)
  25. button.setTable("Online", online, "", 1, 6, 4, 4)
  26. button.setTable("Offline", offline, "", 7, 12, 4, 4)
  27. button.setTable("0", setRods, 0, 5,14, 5, 5)
  28. button.setTable("10", setRods, 10, 2,8, 6, 6)
  29. button.setTable("20", setRods, 20, 5,14, 6, 6)
  30. button.setTable("30", setRods, 30, 8,20, 6, 6)
  31. button.setTable("40", setRods, 40, 2,8, 7, 7)
  32. button.setTable("50", setRods, 50, 5,14, 7, 7)
  33. button.setTable("60", setRods, 60, 8,20, 7, 7)
  34. button.setTable("70", setRods, 70, 2,8, 8, 8)
  35. button.setTable("80", setRods, 80, 5,14, 8, 8)
  36. button.setTable("90", setRods, 90, 8,20, 8, 8)
  37. button.setTable("+", rodPlus, "", 11, 25, 6, 6)
  38. button.setTable("-", rodMinus, "", 11, 25, 8, 8)
  39.  
  40. button.screen()
  41. checkMode()
  42. reactorOnOff()
  43. end
  44.  
  45. function reactorMenu()
  46. menuType = "Reactor"
  47. displayScreen()
  48. end
  49.  
  50. function online()
  51. r.setActive(true)
  52. --button.flash("Online")
  53. end
  54.  
  55. function offline()
  56. r.setActive(false)
  57. --button.flash("Offline")
  58. end
  59.  
  60. function reactorOnOff()
  61. button.setButton("Online", r.getActive())
  62. button.setButton("Offline", not r.getActive())
  63. end
  64.  
  65. function setRods(setLevel)
  66. print("Setting Rod Level: "..setLevel)
  67. button.flash(tostring(setLevel))
  68. r.setAllControlRodLevels(setLevel)
  69. fuelRodLevel()
  70. end
  71.  
  72. function rodPlus()
  73. button.flash("+")
  74. r.setAllControlRodLevels(rodLevel+1)
  75. fuelRodLevel()
  76. end
  77.  
  78. function rodMinus()
  79. button.flash("-")
  80. r.setAllControlRodLevels(rodLevel-1)
  81. fuelRodLevel()
  82. end
  83.  
  84. function checkMode()
  85. button.toggleButton(mode)
  86. end
  87.  
  88. function comma_value(amount)
  89. local formatted = amount
  90. local swap = false
  91. if formatted < 0 then
  92. formatted = formatted*-1
  93. swap = true
  94. end
  95. while true do
  96. formatted, k = string.gsub(formatted, "^(%d+)(%d%d%d)", '%1,%2')
  97. if k == 0 then
  98. break
  99. end
  100. end
  101. if swap then
  102. formatted = "-"..formatted
  103. end
  104. return formatted
  105. end
  106.  
  107. function displayEn()
  108. m.clear()
  109. m.setCursorPos(width-12,1)
  110. m.write("RF Gen: ")
  111. m.setTextColor(colors.green)
  112. m.write(comma_value(math.floor(RFProduction)).."RF/t")
  113. m.setTextColor(colors.white)
  114. end
  115.  
  116. function checkEn()
  117. RFProduction = r.getEnergyProducedLastTick()
  118. reactorOnline = r.getActive()
  119. end
  120.  
  121. function fuelRodLevel()
  122. rodLevel = r.getControlRodLevel(0)
  123. --print(rodLevel)
  124. m.setCursorPos(width-3,2)
  125. m.write(tostring(rodLevel).."%")
  126. m.setBackgroundColor(colors.white)
  127. m.setCursorPos(width-4,3)
  128. m.write(" ")
  129. for i = 1,10 do
  130. m.setCursorPos(width-4,i+3)
  131. m.setBackgroundColor(colors.white)
  132. m.write(" ")
  133. m.setBackgroundColor(colors.yellow)
  134. m.write(" ")
  135. if rodLevel/10 >= i then
  136. m.setBackgroundColor(colors.red)
  137. else
  138. m.setBackgroundColor(colors.yellow)
  139. end
  140. m.write(" ")
  141. m.setBackgroundColor(colors.yellow)
  142. m.write(" ")
  143. m.setBackgroundColor(colors.white)
  144. m.write(" ")
  145. end
  146. m.setCursorPos(width-4,14)
  147. m.write(" ")
  148. m.setBackgroundColor(colors.black)
  149. end
  150.  
  151. function getClick()
  152. local event, side, x, y = os.pullEvent("monitor_touch")
  153. button.checkxy(x,y)
  154. end
  155.  
  156.  
  157. function displayScreen()
  158. -- repeat
  159. checkEn()
  160. displayEn()
  161. if menuType == "Reactor" then
  162. fuelRodLevel()
  163. if mode == "Manual" then
  164. manualMenu()
  165. end
  166. end
  167.  
  168. timerCode = os.startTimer(1)
  169. local event, side, x, y
  170. repeat
  171. event, side, x, y = os.pullEvent()
  172. print(event)
  173. if event == "timer" then
  174. print(timerCode..":"..side)
  175. if timerCode ~= side then
  176. print("Wrong Code")
  177. else
  178. print("Right Code")
  179. end
  180. end
  181. until event~= "timer" or timerCode == side
  182. if event == "monitor_touch" then
  183. print(x..":"..y)
  184. button.checkxy(x,y)
  185. end
  186. -- until event ~= "timer"
  187. end
  188.  
  189. while true do
  190. displayScreen()
  191. end
Advertisement
Add Comment
Please, Sign In to add comment