cj89898_2

Untitled

Jan 17th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 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(1)
  23. button.clearTable()
  24. button.setTable("Manual", manualMode, "", 9, 25, 6, 6)
  25. button.setTable("Online", online, "", 3, 13, 8, 8)
  26. button.setTable("Offline", offline, "", 15, 25, 8, 8)
  27. button.setTable("0", setRods, 0, 11,14, 10, 10)
  28. button.setTable("10", setRods, 10, 5,8, 12, 12)
  29. button.setTable("20", setRods, 20, 11,14, 12, 12)
  30. button.setTable("30", setRods, 30, 17,20, 12, 12)
  31. button.setTable("40", setRods, 40, 5,8, 14, 14)
  32. button.setTable("50", setRods, 50, 11,14, 14, 14)
  33. button.setTable("60", setRods, 60, 17,20, 14, 14)
  34. button.setTable("70", setRods, 70, 5,8, 16, 16)
  35. button.setTable("80", setRods, 80, 11,14, 16, 16)
  36. button.setTable("90", setRods, 90, 17,20, 16, 16)
  37. button.setTable("+", rodPlus, "", 23, 25, 12, 12)
  38. button.setTable("-", rodMinus, "", 23, 25, 16, 16)
  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.setTextScale(2)
  110. m.setCursorPos(width-25,2)
  111. m.write("RF Gen: ")
  112. m.setTextColor(colors.green)
  113. m.write(comma_value(math.floor(RFProduction)).."RF/t")
  114. m.setTextColor(colors.white)
  115. m.setTextScale(1)
  116. end
  117.  
  118. function checkEn()
  119. RFProduction = r.getEnergyProducedLastTick()
  120. reactorOnline = r.getActive()
  121. end
  122.  
  123. function fuelRodLevel()
  124. rodLevel = r.getControlRodLevel(0)
  125. --print(rodLevel)
  126. m.setCursorPos(width-6,5)
  127. m.write(tostring(rodLevel).."%")
  128. m.setBackgroundColor(colors.white)
  129. m.setCursorPos(width-8,6)
  130. m.write(" ")
  131. for i = 1,20 do
  132. m.setCursorPos(width-8,i+6)
  133. m.setBackgroundColor(colors.white)
  134. m.write(" ")
  135. m.setBackgroundColor(colors.yellow)
  136. m.write(" ")
  137. if rodLevel/10 >= i then
  138. m.setBackgroundColor(colors.red)
  139. else
  140. m.setBackgroundColor(colors.yellow)
  141. end
  142. m.write(" ")
  143. m.setBackgroundColor(colors.yellow)
  144. m.write(" ")
  145. m.setBackgroundColor(colors.white)
  146. m.write(" ")
  147. end
  148. m.setCursorPos(width-8,27)
  149. m.write(" ")
  150. m.setBackgroundColor(colors.black)
  151. end
  152.  
  153. function getClick()
  154. local event, side, x, y = os.pullEvent("monitor_touch")
  155. button.checkxy(x,y)
  156. end
  157.  
  158.  
  159. function displayScreen()
  160. -- repeat
  161. checkEn()
  162. displayEn()
  163. if menuType == "Reactor" then
  164. fuelRodLevel()
  165. if mode == "Manual" then
  166. manualMenu()
  167. end
  168. end
  169.  
  170. timerCode = os.startTimer(1)
  171. local event, side, x, y
  172. repeat
  173. event, side, x, y = os.pullEvent()
  174. print(event)
  175. if event == "timer" then
  176. print(timerCode..":"..side)
  177. if timerCode ~= side then
  178. print("Wrong Code")
  179. else
  180. print("Right Code")
  181. end
  182. end
  183. until event~= "timer" or timerCode == side
  184. if event == "monitor_touch" then
  185. print(x..":"..y)
  186. button.checkxy(x,y)
  187. end
  188. -- until event ~= "timer"
  189. end
  190.  
  191. while true do
  192. displayScreen()
  193. end
Advertisement
Add Comment
Please, Sign In to add comment