Advertisement
infiniteblock

Untitled

Nov 7th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.96 KB | None | 0 0
  1.  
  2. ----------- Made BY MJRLegends (Please dont claim as your own code) -----------
  3. version = "1.0.2"
  4.  
  5. mouseWidth = 0
  6. mouseHeight = 0
  7.  
  8. setting = false
  9.  
  10. function draw_line(x, y, length, color)
  11. monitor.setBackgroundColor(color)
  12. monitor.setCursorPos(x,y)
  13. monitor.write(string.rep(" ", length))
  14. end
  15.  
  16. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  17. draw_line(x, y, length, bg_color) --backgoround bar
  18. local barSize = math.floor((minVal/maxVal) * length)
  19. draw_line(x, y, barSize, bar_color) --progress so far
  20. end
  21.  
  22. function draw_text(x, y, text, text_color, bg_color)
  23. monitor.setBackgroundColor(bg_color)
  24. monitor.setTextColor(text_color)
  25. monitor.setCursorPos(x,y)
  26. monitor.write(text)
  27. end
  28.  
  29. function initPeripherals()
  30. local perList = peripheral.getNames()
  31. for i=1,#perList,1 do
  32. if peripheral.getType(perList[i]) == "monitor" then
  33. monitor = peripheral.wrap(perList[i])
  34. term.setCursorPos(1,3)
  35. term.write("Monitor Found!")
  36. end
  37. if peripheral.getType(perList[i]) == "mekanism_machine" then
  38. reactor = peripheral.wrap(perList[i])
  39. term.setCursorPos(1,4)
  40. term.write("Fusion Reactor Found!")
  41. end
  42. end
  43. end
  44.  
  45. function drawControlScreen()
  46. term.setBackgroundColor(colors.black)
  47. term.setTextColor(colors.blue)
  48. term.setCursorPos(1,1)
  49. term.write("MJRLegends Fusion Reactor Management")
  50. term.setCursorPos(1,2)
  51. term.write("Version: " .. version)
  52. monitor.setTextScale(1)
  53. monitor.clear()
  54. active = reactor.isIgnited()
  55.  
  56. -----------Title---------------------
  57. monitor.setTextColour((colours.blue))
  58. monitor.setCursorPos(1,1)
  59. monitor.write("MJRLegends Fusion Reactor Management")
  60. monitor.setTextColour((colours.white))
  61.  
  62. -----------Reactor Enable/Disable---------------------
  63. monitor.setCursorPos(1,3)
  64. monitor.write("Reactor: ")
  65. if active then
  66. monitor.setBackgroundColour((colours.blue))
  67. else
  68. monitor.setBackgroundColour((colours.grey))
  69. end
  70. monitor.setCursorPos(20,3)
  71. monitor.write(" ON ")
  72.  
  73. if active then
  74. monitor.setBackgroundColour((colours.grey))
  75. else
  76. monitor.setBackgroundColour((colours.blue))
  77. end
  78. monitor.setCursorPos(25,3)
  79. monitor.write(" OFF ")
  80. monitor.setBackgroundColour((colours.black))
  81.  
  82. -----------Section Lines---------------------
  83. displayW,displayH=monitor.getSize()
  84.  
  85. monitor.setTextColour((colours.blue))
  86. monitor.setCursorPos(0,2)
  87. monitor.write(string.rep("-", displayW))
  88. monitor.setTextColour((colours.white))
  89.  
  90. monitor.setTextColour((colours.blue))
  91. monitor.setCursorPos(0,4)
  92. monitor.write(string.rep("-", displayW))
  93. monitor.setTextColour((colours.white))
  94.  
  95. monitor.setTextColour((colours.blue))
  96. monitor.setCursorPos(0,displayH - 2)
  97. monitor.write(string.rep("-", displayW))
  98. monitor.setTextColour((colours.white))
  99.  
  100. monitor.setTextColour((colours.blue))
  101. monitor.setCursorPos(0,displayH - 0)
  102. monitor.write(string.rep("-", displayW))
  103. monitor.setTextColour((colours.white))
  104.  
  105. -----------Bottom Bar Buttons---------------------
  106. if setting then
  107. monitor.setBackgroundColour((colours.grey))
  108. else
  109. monitor.setBackgroundColour((colours.blue))
  110. end
  111. monitor.setCursorPos(displayW - 10,displayH - 1)
  112. monitor.write(" Settings ")
  113. monitor.setBackgroundColour((colours.black))
  114. end
  115.  
  116. function drawDisplayScreen()
  117. displayW,displayH=monitor.getSize()
  118. monitor.setTextScale(1)
  119.  
  120. -----------Casing Heat---------------------
  121. draw_text(2, 5, "Casing Heat: ", colors.yellow, colors.black)
  122. local maxVal = 5000000000
  123. local minVal = math.floor(tonumber(reactor.getCaseHeat()))
  124. draw_text(19, 5, minVal.." C", colors.white, colors.black)
  125.  
  126. if minVal < 100000 then
  127. progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  128. elseif minVal < math.floor((1000000000 / 2)/2) then
  129. progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  130. elseif minVal < math.floor(1000000000 / 2) then
  131. progress_bar(2, 6, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
  132. elseif minVal >= math.floor(1000000000 / 2) then
  133. progress_bar(2, 6, displayW-2, minVal, maxVal, colors.red, colors.gray)
  134. end
  135. monitor.setBackgroundColour((colours.black))
  136.  
  137. -----------Plasma Heat---------------------
  138. draw_text(2, 8, "Plasma Heat: ", colors.yellow, colors.black)
  139. local maxVal = 7350000000
  140. local minVal = math.floor(tonumber(reactor.getPlasmaHeat()))
  141. draw_text(19, 8, minVal.." C", colors.white, colors.black)
  142.  
  143. if minVal < 100000 then
  144. progress_bar(2, 9, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  145. elseif minVal < math.floor((1000000000 / 2)/2) then
  146. progress_bar(2, 9, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  147. elseif minVal < math.floor(1000000000 / 2) then
  148. progress_bar(2, 9, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
  149. elseif minVal >= math.floor(1000000000 / 2) then
  150. progress_bar(2, 9, displayW-2, minVal, maxVal, colors.red, colors.gray)
  151. end
  152. monitor.setBackgroundColour((colours.black))
  153.  
  154. -----------Ignition Heat---------------------
  155. draw_text(2, 11, "Ignition Heat: ", colors.yellow, colors.black)
  156. local maxVal = 100000000
  157. local minVal = math.floor(tonumber(reactor.getIgnitionTemp()))
  158. draw_text(19, 11, minVal.." C", colors.white, colors.black)
  159.  
  160. if minVal < 100000 then
  161. progress_bar(2, 12, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  162. elseif minVal < math.floor((100000000 / 2)/2) then
  163. progress_bar(2, 12, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  164. elseif minVal < math.floor(100000000 / 2) then
  165. progress_bar(2, 12, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
  166. elseif minVal >= math.floor(100000000 / 2) then
  167. progress_bar(2, 12, displayW-2, minVal, maxVal, colors.red, colors.gray)
  168. end
  169. monitor.setBackgroundColour((colours.black))
  170.  
  171. -----------Energy---------------------
  172. draw_text(2, 14, "Power: ", colors.yellow, colors.black)
  173. local maxVal = reactor.getMaxEnergy()
  174. local minVal = math.floor(tonumber(reactor.getEnergy()))
  175. draw_text(19, 14, math.floor(minVal / 2.5).." RF", colors.white, colors.black)
  176.  
  177. progress_bar(2, 15, displayW-2, minVal, maxVal, colors.lightGray, colors.gray)
  178. monitor.setBackgroundColour((colours.black))
  179.  
  180. -----------Fuel---------------------
  181. draw_text(2, 17, "Fuel: ", colors.yellow, colors.black)
  182. local maxVal = reactor.getMaxEnergy()
  183. local minVal = tonumber(reactor.getFuel())
  184. draw_text(19, 17, minVal.." mb", colors.white, colors.black)
  185.  
  186. progress_bar(2, 18, displayW-2, minVal, maxVal, colors.pink, colors.gray)
  187. monitor.setBackgroundColour((colours.black))
  188.  
  189. -----------Injection Rate---------------------
  190. draw_text(2, 20, "Injection Rate: ", colors.yellow, colors.black)
  191. draw_text(24, 20, reactor.getInjectionRate(), colors.white, colors.black)
  192.  
  193. -----------Has Fuel---------------------
  194. --draw_text(2, 18, "Fuel: ", colors.yellow, colors.black)
  195. --draw_text(24, 18, reactor.hasFuel(), colors.white, colors.black)
  196.  
  197. -----------Engery Producing---------------------
  198. --draw_text(2, 19, "Engery Producing J/T: ", colors.yellow, colors.black)
  199. --draw_text(24, 19, math.floor(tonumber(reactor.getProducing())) .. " J/T", colors.white, colors.black)
  200. draw_text(2, 21, "Engery Producing RF/T: ", colors.yellow, colors.black)
  201. draw_text(24, 21, math.floor(tonumber(reactor.getProducing()) / 2.5) .. " RF/T", colors.white, colors.black)
  202.  
  203. -----------Can Ignite---------------------
  204. --draw_text(2, 21, "Can Ignite: ", colors.yellow, colors.black)
  205. --draw_text(24, 21, reactor.canIgnite(), colors.white, colors.black)
  206.  
  207. end
  208.  
  209. function drawSettingScreen()
  210. displayW,displayH=monitor.getSize()
  211.  
  212. -------------Title-------------------
  213. draw_text(16, 6, "Settings", colors.blue, colors.black)
  214.  
  215. monitor.setTextColour((colours.blue))
  216. monitor.setCursorPos(0,7)
  217. monitor.write(string.rep("-", displayW))
  218. monitor.setTextColour((colours.white))
  219. end
  220.  
  221. function checkClickPosition()
  222. displayW,displayH=monitor.getSize()
  223. --if mouseWidth > 20 and mouseWidth < 24 and mouseHeight == 3 then
  224. -- reactor.setActive(true)
  225. --elseif mouseWidth > 24 and mouseWidth < 28 and mouseHeight == 3 then
  226. -- reactor.setActive(false)
  227. if mouseWidth > (displayW - 10) and mouseWidth < displayW and mouseHeight == (displayH - 1) then
  228. if setting then
  229. setting = false
  230. else
  231. setting = true
  232. end
  233. end
  234. sleep(0.5)
  235. end
  236.  
  237.  
  238. function mainMenu()
  239. initPeripherals()
  240. while true do
  241. displayW,displayH=monitor.getSize()
  242. if displayH == 26 and displayW == 39 then
  243. drawControlScreen()
  244. if setting == true then
  245. drawSettingScreen()
  246. else
  247. drawDisplayScreen()
  248. end
  249. else
  250. print("This program is built for a 4x4 monitor only!")
  251. return
  252. end
  253. sleep(1.0)
  254. end
  255. end
  256.  
  257. function events()
  258. while true do
  259. event,p1,p2,p3 = os.pullEvent()
  260. if event=="monitor_touch" then
  261. mouseWidth = p2 -- sets mouseWidth
  262. mouseHeight = p3 -- and mouseHeight
  263. checkClickPosition() -- this runs our function
  264. end
  265. end
  266. end
  267.  
  268. parallel.waitForAny(mainMenu,events)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement