Advertisement
Guest User

Untitled

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