switch72

rtmon

Feb 16th, 2020
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.63 KB | None | 0 0
  1. --Author: MJRLegends
  2. --Modified by: AitchCay
  3. --Modified, only works for 1 reactor + 2 turbine system.
  4. --Designed for single screen display of info, and 2nd screen for control.
  5.  
  6. mouseX = 0
  7. mouseY = 0
  8.  
  9. currentTurbine = 1
  10. setting = false
  11. control = false
  12. monitorFound = false
  13.  
  14. turbines = {}
  15. turbinesManagement = {}
  16. turbine = null
  17. totalreactors = 0
  18. turbine1 = null
  19. turbine2 = null
  20. reactor1 = null
  21. controlrodaverage = 0
  22.  
  23. function draw_line(x, y, length, color)
  24. monitor.setBackgroundColor(color)
  25. monitor.setCursorPos(x,y)
  26. monitor.write(string.rep(" ", length))
  27. end
  28.  
  29. function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
  30. draw_line(x, y, length, bg_color) --backgoround bar
  31. local barSize = math.floor((minVal/maxVal) * length)
  32. draw_line(x, y, barSize, bar_color) --progress so far
  33. end
  34.  
  35. function progress_bar_multi_line(x, y, length, minVal, maxVal, bar_color, bg_color, numberOFLine)
  36. local barSize = math.floor((minVal/maxVal) * length)
  37. y = y - 1
  38. for i=1,numberOFLine,1 do
  39. draw_line(x, y + i, length, bg_color) --background bar
  40. draw_line(x, y + i, barSize, bar_color) --progress so far
  41. end
  42. end
  43.  
  44. function draw_text(x, y, text, text_color, bg_color)
  45. monitor.setBackgroundColor(bg_color)
  46. monitor.setTextColor(text_color)
  47. monitor.setCursorPos(x,y)
  48. monitor.write(text)
  49. end
  50.  
  51. function terminalOutput()
  52. term.clear()
  53. term.setBackgroundColor(colors.black)
  54.  
  55. term.setTextColor(colors.blue)
  56. term.setCursorPos(1,1)
  57. term.write("Turbine Status")
  58.  
  59.  
  60. term.setTextColor(colors.red)
  61. term.setCursorPos(1,3)
  62. term.write("Note: Monitors are optional")
  63.  
  64. term.setTextColor(colors.cyan)
  65. term.setCursorPos(1,5)
  66. term.write("Peripheral Connected:")
  67. end
  68.  
  69. function initPeripherals()
  70. local perList = peripheral.getNames()
  71. local yLevel = 6
  72. local turbineNumber = 1
  73.  
  74. reactorNumber = 1
  75. reactors = {}
  76. reactorsManagement = {}
  77. turbines = {}
  78. turbinesManagement = {}
  79. monitorFound = false
  80. term.setTextColor(colors.yellow)
  81. for i=1,#perList,1 do
  82. if peripheral.getType(perList[i]) == "monitor" and monitorFound == false then
  83. monitor = peripheral.wrap(perList[i])
  84. term.setCursorPos(1,yLevel)
  85. term.write("Monitor Found!")
  86. yLevel = yLevel + 1
  87. monitorFound = true
  88. elseif peripheral.getType(perList[i]) == "BigReactors-Turbine" then
  89. table.insert(turbines, turbineNumber, perList[i])
  90. table.insert(turbinesManagement, turbineNumber, false)
  91. turbineNumber = turbineNumber +1
  92. elseif peripheral.getType(perList[i]) == "BigReactors-Reactor" then
  93. table.insert(reactors, reactorNumber, perList[i])
  94. table.insert(reactorsManagement, reactorNumber, true)
  95. totalreactors = totalreactors +1
  96. reactorNumber = reactorNumber +1
  97. end
  98. end
  99. term.setCursorPos(1,yLevel)
  100. term.write((turbineNumber - 1) .. " Turbine Found!")
  101. turbine = peripheral.wrap(turbines[currentTurbine])
  102. end
  103.  
  104. function drawMainScreen()
  105. displayW,displayH=monitor.getSize()
  106. monitor.clear()
  107. monitor.setTextColour(colours.blue)
  108. monitor.setCursorPos(12,1)
  109. monitor.write("Power System Status")
  110.  
  111.  
  112. monitor.setTextColour(colours.blue)
  113. monitor.setCursorPos(0,2)
  114. monitor.write(string.rep("-", displayW))
  115. monitor.setTextColour(colours.white)
  116.  
  117. turbineDisplayRows = 6
  118. reactorDisplayRows = 3
  119. numberOfActiveTurbines = 0
  120. totalProducedEnergy = 0
  121. totalBufferedEnergy = 0
  122. totalBufferedSteam = 0
  123. totalBufferedWater = 0
  124. for i=1,#turbines,1 do
  125. tempTurbine = peripheral.wrap(turbines[i])
  126. if tempTurbine.getActive() then
  127. numberOfActiveTurbines = numberOfActiveTurbines + 1
  128. end
  129. totalProducedEnergy = totalProducedEnergy + tempTurbine.getEnergyProducedLastTick()
  130. -- totalBufferedEnergy = totalBufferedEnergy + tempTurbine.getEnergyStored()
  131. -- totalBufferedSteam = totalBufferedSteam + tempTurbine.getInputAmount()
  132. -- totalBufferedWater = totalBufferedWater + tempTurbine.getOutputAmount()
  133. end
  134.  
  135. monitor.setCursorPos(1,3)
  136. -- monitor.write("Number of Online Turbines: " .. numberOfActiveTurbines .. "/" .. table.getn(turbines))
  137.  
  138. -- monitor.setTextColour(colours.blue)
  139. -- monitor.setCursorPos(0,5)
  140. -- monitor.write(string.rep("-", displayW))
  141. -- monitor.setTextColour(colours.white)
  142.  
  143. monitor.setCursorPos(1,4)
  144. monitor.setTextColour(colours.white)
  145. if totalProducedEnergy < 1000000 then
  146. monitor.write("Total Energy Production: " .. math.floor(totalProducedEnergy / 1000) .. " KRF/T")
  147. else
  148. monitor.write("Total Energy Production: " .. math.floor(totalProducedEnergy / 1000000) .. " MRF/T")
  149. end
  150. -- monitor.write("Total Turbine Buffer: " .. totalBufferedEnergy / 1000 .. " kRF")
  151. -- progress_bar_multi_line(2, 5, displayW-2, totalBufferedEnergy, (1000000 * table.getn(turbines)), colors.green, colors.gray, 2)
  152. monitor.setBackgroundColor(colours.black)
  153. -- monitor.setCursorPos(1,11)
  154.  
  155. if totalreactors > 0 then
  156. currentReactor = peripheral.wrap(reactors[1])
  157. draw_text(1, 6, "Reactor ", colors.yellow, colors.black)
  158. if currentReactor.getActive() then
  159. draw_text(15, 6, "Online", colors.green, colors.black)
  160. else
  161. draw_text(15, 6, "Offline", colors.red, colors.black)
  162. end
  163. draw_text(2, 7, "Case Temp: ", colors.yellow, colors.black, monitor)
  164. local maxVal = 5000
  165. local minVal = math.floor(currentReactor.getCasingTemperature())
  166. draw_text(15 , 7, minVal.." C", colors.white, colors.black, monitor)
  167.  
  168. -- if minVal < 500 then
  169. -- progress_bar(2, 7, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray, monitor)
  170. -- elseif minVal < 1000 then
  171. -- progress_bar(2, 7, displayW-2, minVal, maxVal, colors.lime, colors.gray, monitor)
  172. -- elseif minVal < 1500 then
  173. -- progress_bar(2, 7, displayW-2, minVal, maxVal, colors.yellow, colors.gray, monitor)
  174. -- elseif minVal >= 1500 then
  175. -- progress_bar(2, 7, displayW-2, minVal, maxVal, colors.red, colors.gray, monitor)
  176. -- end
  177. draw_text(2, 8, "Burn Rate: ", colors.yellow, colors.black, monitor)
  178. draw_text(15, 8, tonumber(string.format("%.3f", currentReactor.getFuelConsumedLastTick())) .." mB/t", colors.white, colors.black, monitor)
  179.  
  180. end
  181.  
  182. for i=1,#turbines,1 do
  183. turbine = peripheral.wrap(turbines[i])
  184. draw_text(1, (turbineDisplayRows * i) + reactorDisplayRows + 1, "Turbine " .. i , colors.yellow, colors.black)
  185. if turbine.getActive() then
  186. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 1, "Online", colors.green, colors.black)
  187. else
  188. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 1, "Disabled", colors.red, colors.black)
  189. end
  190. draw_text(2, (turbineDisplayRows * i) + reactorDisplayRows + 2, "Output: ", colors.yellow, colors.black)
  191. rft = math.floor(turbine.getEnergyProducedLastTick())
  192. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 2, rft.." RF/T", colors.white, colors.black)
  193. draw_text(2, (turbineDisplayRows * i) + reactorDisplayRows + 3, "Rotor Speed: ", colors.yellow, colors.black)
  194.  
  195. local minVal = math.floor(turbine.getRotorSpeed())
  196. --draw_text(15, (turbineDisplayRows * i) + 3, minVal.." rpm", colors.white, colors.black)
  197. if minVal < 700 then
  198. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.lightBlue, colors.black)
  199. elseif minVal < 950 then
  200. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.green, colors.black)
  201. elseif minVal < 1750 then
  202. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.lightBlue, colors.black)
  203. elseif minVal < 1850 then
  204. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.green, colors.black)
  205. elseif minVal < 2000 then
  206. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.yellow, colors.black)
  207. elseif minVal >= 2000 then
  208. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 3, minVal.." rpm", colors.red, colors.black)
  209. end
  210.  
  211.  
  212. draw_text(2, (turbineDisplayRows * i) + reactorDisplayRows + 4, "Steam Flow: ", colors.yellow, colors.black)
  213. flow_rate = turbine.getFluidFlowRateMax()
  214. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 4, flow_rate.." mB/t", colors.white, colors.black)
  215. engaged = turbine.getInductorEngaged()
  216. draw_text(2, (turbineDisplayRows * i) + reactorDisplayRows + 5, "Coils: ", colors.yellow, colors.black)
  217. if engaged then
  218. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 5, "Engaged", colors.green, colors.black)
  219. else
  220. draw_text(15, (turbineDisplayRows * i) + reactorDisplayRows + 5, "Disengaged", colors.red, colors.black)
  221. end
  222. end
  223.  
  224.  
  225.  
  226.  
  227. monitor.setTextColour(colours.white)
  228. monitor.setBackgroundColor(colours.blue)
  229. monitor.setCursorPos(1,displayH - 1)
  230. monitor.write(" Control Screen ")
  231. monitor.setBackgroundColor(colours.black)
  232. end
  233.  
  234. function drawControlScreen()
  235. displayW,displayH=monitor.getSize()
  236. monitor.clear()
  237. monitor.setCursorPos(13, 4)
  238. monitor.setTextColour(colours.blue)
  239. monitor.write(" Power Control ")
  240. monitor.setTextColour(colours.white)
  241. w,h=monitor.getSize()
  242. reactor1DrawOffset = 9
  243. turbine1DrawOffset = 14
  244. turbine2DrawOffset = 19
  245.  
  246. -------------------------- REACTOR --------------------------
  247.  
  248.  
  249. controlrodaverage = 0
  250. active = reactor1.getActive()
  251. monitor.setCursorPos(1, reactor1DrawOffset)
  252. monitor.write("Reactor 1" )
  253. if active then
  254. monitor.setBackgroundColour(colours.green)
  255. else
  256. monitor.setBackgroundColour(colours.grey)
  257. end
  258. monitor.setCursorPos(12, reactor1DrawOffset)
  259. monitor.write("Enable")
  260.  
  261. if active then
  262. monitor.setBackgroundColour(colours.grey)
  263. else
  264. monitor.setBackgroundColour(colours.green)
  265. end
  266. monitor.setCursorPos(19, reactor1DrawOffset)
  267. monitor.write("Disable")
  268. monitor.setBackgroundColour(colours.black)
  269. draw_text(1, reactor1DrawOffset + 2, "Control Rods", colors.white, colors.black)
  270. draw_text(14, reactor1DrawOffset + 2, "Insert", colors.white, colours.blue)
  271. draw_text(21, reactor1DrawOffset + 2, "Retract", colors.white, colours.blue)
  272.  
  273. for i=0,(reactor1.getNumberOfControlRods() -1 ), 1 do
  274. controlrodaverage = controlrodaverage + reactor1.getControlRodLevel(i)
  275. end
  276. controlrodaverage = controlrodaverage / reactor1.getNumberOfControlRods()
  277. draw_text(30, reactor1DrawOffset + 2, math.floor(controlrodaverage) .. "%", colors.white, colours.black)
  278.  
  279. monitor.setBackgroundColour(colours.black)
  280. -------------------------TURBINE 1 -------------------------------
  281.  
  282.  
  283. active = turbine1.getActive()
  284. monitor.setCursorPos(1, turbine1DrawOffset)
  285. monitor.write("Turbine 1" )
  286. if active then
  287. monitor.setBackgroundColour(colours.green)
  288. else
  289. monitor.setBackgroundColour(colours.grey)
  290. end
  291. monitor.setCursorPos(12, turbine1DrawOffset)
  292. monitor.write("Enable")
  293.  
  294. if active then
  295. monitor.setBackgroundColour(colours.grey)
  296. else
  297. monitor.setBackgroundColour(colours.green)
  298. end
  299. monitor.setCursorPos(19, turbine1DrawOffset)
  300. monitor.write("Disable")
  301.  
  302. draw_text(1, turbine1DrawOffset + 2, "Flow Rate", colors.white, colors.black)
  303. draw_text(17, turbine1DrawOffset + 2, "Inc+5", colors.white, colours.blue)
  304. draw_text(23, turbine1DrawOffset + 2, "Dec-5", colors.white, colours.blue)
  305. draw_text(30, turbine1DrawOffset + 2, turbine1.getFluidFlowRateMax() .. " mB/t", colors.white, colours.black)
  306.  
  307.  
  308. monitor.setBackgroundColour(colours.black)
  309.  
  310. -------------------------TURBINE 2 -------------------------------
  311.  
  312.  
  313. active = turbine2.getActive()
  314. monitor.setCursorPos(1, turbine2DrawOffset )
  315. monitor.write("Turbine 2")
  316. if active then
  317. monitor.setBackgroundColour(colours.green)
  318. else
  319. monitor.setBackgroundColour(colours.grey)
  320. end
  321. monitor.setCursorPos(12, turbine2DrawOffset)
  322. monitor.write("Enable")
  323.  
  324. if active then
  325. monitor.setBackgroundColour(colours.grey)
  326. else
  327. monitor.setBackgroundColour(colours.green)
  328. end
  329. monitor.setCursorPos(19, turbine2DrawOffset)
  330. monitor.write("Disable")
  331. monitor.setBackgroundColour(colours.black)
  332.  
  333. draw_text(1, turbine2DrawOffset + 2, "Flow Rate", colors.white, colors.black)
  334. draw_text(17, turbine2DrawOffset + 2, "Inc+5", colors.white, colours.blue)
  335. draw_text(23, turbine2DrawOffset + 2, "Dec-5", colors.white, colours.blue)
  336. draw_text(30, turbine2DrawOffset + 2, turbine2.getFluidFlowRateMax() .. " mB/t", colors.white, colours.black)
  337.  
  338.  
  339.  
  340.  
  341. -----------Bottom Bar Buttons---------------------
  342. -- if setting then
  343. -- monitor.setBackgroundColour(colours.grey)
  344. -- else
  345. -- monitor.setBackgroundColour(colours.blue)
  346. -- end
  347. -- monitor.setCursorPos(displayW - 10,displayH - 1)
  348. -- monitor.write(" Settings ")
  349. -- monitor.setBackgroundColour(colours.black)
  350.  
  351. monitor.setBackgroundColour(colours.blue)
  352. monitor.setCursorPos(2,displayH - 1)
  353. monitor.write(" Main Menu ")
  354. monitor.setBackgroundColour(colours.black)
  355. end
  356.  
  357. function drawDisplayScreen()
  358. displayW,displayH=monitor.getSize()
  359.  
  360. -----------Router speed---------------------
  361. draw_text(2, 5, "Rotor Speed: ", colors.yellow, colors.black)
  362. local maxVal = 2000
  363. local minVal = math.floor(turbine.getRotorSpeed())
  364. draw_text(19, 5, minVal.." rpm", colors.white, colors.black)
  365.  
  366. if minVal < 700 then
  367. progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  368. elseif minVal < 900 then
  369. progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  370. elseif minVal < 1700 then
  371. progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lightBlue, colors.gray)
  372. elseif minVal < 1900 then
  373. progress_bar(2, 6, displayW-2, minVal, maxVal, colors.lime, colors.gray)
  374. elseif minVal < 2000 then
  375. progress_bar(2, 6, displayW-2, minVal, maxVal, colors.yellow, colors.gray)
  376. elseif minVal >= 2000 then
  377. progress_bar(2, 6, displayW-2, minVal, maxVal, colors.red, colors.gray)
  378. end
  379.  
  380. -----------Steam Level---------------------
  381. draw_text(2, 8, "Steam Amount: ", colors.yellow, colors.black)
  382. local maxVal = 4000
  383. local minVal = math.floor(turbine.getInputAmount())
  384. draw_text(19, 8, minVal.." mB", colors.white, colors.black)
  385. progress_bar(2, 9, displayW-2, minVal, maxVal, colors.lightGray, colors.gray)
  386.  
  387.  
  388. -----------Water Level---------------------
  389. draw_text(2, 11, "Water Amount: ", colors.yellow, colors.black)
  390. local maxVal = 4000
  391. local minVal = math.floor(turbine.getOutputAmount())
  392. draw_text(19, 11, minVal.." mB", colors.white, colors.black)
  393. progress_bar(2, 12, displayW-2, minVal, maxVal, colors.blue, colors.gray)
  394.  
  395.  
  396. -------------OUTPUT-------------------
  397. draw_text(2, 14, "RF/tick: ", colors.yellow, colors.black)
  398. rft = math.floor(turbine.getEnergyProducedLastTick())
  399. draw_text(19, 14, rft.." RF/T", colors.white, colors.black)
  400.  
  401. -----------RF STORAGE---------------
  402. -- draw_text(2, 15, "RF Stored:", colors.yellow, colors.black)
  403. -- local maxVal = 1000000
  404. -- local minVal = energy_stored
  405. -- local percent = math.floor((energy_stored/maxVal)*100)
  406. -- draw_text(19, 15, percent.."%", colors.white, colors.black)
  407.  
  408. ------------FLOW RATE----------------
  409. draw_text(2, 16, "Flow Rate: ", colors.yellow, colors.black)
  410. flow_rate = turbine.getFluidFlowRateMax()
  411. draw_text(19, 16, flow_rate.." mB/t", colors.white, colors.black)
  412.  
  413. ------------COILS---------------------------
  414. engaged = turbine.getInductorEngaged()
  415. draw_text(2, 17, "Coils: ", colors.yellow, colors.black)
  416.  
  417. if engaged then
  418. draw_text(19, 17, "Engaged", colors.white, colors.black)
  419. else
  420. draw_text(19, 17, "Disengaged", colors.white, colors.black)
  421. end
  422. end
  423.  
  424. function drawSettingScreen()
  425. displayW,displayH=monitor.getSize()
  426.  
  427. -------------Title-------------------
  428. draw_text(16, 6, "Settings", colors.blue, colors.black)
  429.  
  430. monitor.setTextColour(colours.blue)
  431. monitor.setCursorPos(0,7)
  432. monitor.write(string.rep("-", displayW))
  433. monitor.setTextColour(colours.white)
  434.  
  435. -----------Turbine Management Enable/Disable---------------------
  436. monitor.setCursorPos(1,9)
  437. monitor.write("Turbine Management: ")
  438. if turbinesManagement[currentTurbine] == true then
  439. monitor.setBackgroundColour(colours.blue)
  440. else
  441. monitor.setBackgroundColour(colours.grey)
  442. end
  443. monitor.setCursorPos(20,9)
  444. monitor.write(" ON ")
  445.  
  446. if turbinesManagement[currentTurbine] == true then
  447. monitor.setBackgroundColour(colours.grey)
  448. else
  449. monitor.setBackgroundColour(colours.blue)
  450. end
  451. monitor.setCursorPos(25,9)
  452. monitor.write(" OFF ")
  453. monitor.setBackgroundColour(colours.black)
  454. end
  455.  
  456. function management()
  457. for i=1,#turbines,1 do
  458. if turbinesManagement[i] == true then
  459. tempTurbine = peripheral.wrap(turbines[i])
  460. active = tempTurbine.getActive()
  461. energy_stored = tempTurbine.getEnergyStored()
  462. rotorSpeed = tempTurbine.getRotorSpeed()
  463. local maxVal = 1000000
  464. local minVal = energy_stored
  465. local percent = math.floor((energy_stored/maxVal)*100)
  466. if rotorSpeed < 1801 then
  467. if percent > 99 then
  468. tempTurbine.setActive(false)
  469. elseif percent < 75 then
  470. tempTurbine.setActive(true)
  471. end
  472. else
  473. tempTurbine.setActive(false)
  474. end
  475. end
  476. end
  477. end
  478.  
  479. function checkClickPosition()
  480. displayW,displayH=monitor.getSize()
  481. if control == false then
  482. if mouseX > 0 and mouseX < 20 and mouseY > displayH - 2 and mouseY < displayH then
  483. control = true
  484. end
  485. else
  486. if mouseX > 11 and mouseX < 18 and mouseY == 9 then
  487. reactor1.setActive(true)
  488. elseif mouseX > 18 and mouseX < 26 and mouseY == 9 then
  489. reactor1.setActive(false)
  490. elseif mouseX > 11 and mouseX < 18 and mouseY == 14 then
  491. turbine1.setActive(true)
  492. elseif mouseX > 18 and mouseX < 26 and mouseY == 14 then
  493. turbine1.setActive(false)
  494. elseif mouseX > 11 and mouseX < 18 and mouseY == 19 then
  495. turbine2.setActive(true)
  496. elseif mouseX > 18 and mouseX < 26 and mouseY == 19 then
  497. turbine2.setActive(false)
  498. elseif mouseX > 14 and mouseX < 20 and mouseY == 11 then
  499. reactor1.setAllControlRodLevels(controlrodaverage + 1)
  500. elseif mouseX > 20 and mouseX < 28 and mouseY == 11 then
  501. reactor1.setAllControlRodLevels(controlrodaverage - 1)
  502. elseif mouseX > 16 and mouseX < 22 and mouseY == 16 then
  503. turbine1.setFluidFlowRateMax(turbine1.getFluidFlowRateMax() + 5)
  504. elseif mouseX > 22 and mouseX < 28 and mouseY == 16 then
  505. turbine1.setFluidFlowRateMax(turbine1.getFluidFlowRateMax() - 5)
  506.  
  507. elseif mouseX > 16 and mouseX < 22 and mouseY == 21 then
  508. turbine2.setFluidFlowRateMax(turbine2.getFluidFlowRateMax() + 5)
  509. elseif mouseX > 22 and mouseX < 28 and mouseY == 21 then
  510. turbine2.setFluidFlowRateMax(turbine2.getFluidFlowRateMax() - 5)
  511.  
  512. elseif mouseX > 1 and mouseX < (displayW - 26) and mouseY == (displayH - 1) then
  513. control = false
  514. setting = false
  515. elseif mouseX > (displayW - 10) and mouseX < displayW and mouseY == (displayH - 1) then
  516. if setting then
  517. setting = false
  518. else
  519. setting = true
  520. end
  521. elseif mouseX > (displayW - 9) and mouseX < (displayW - 7) and mouseY == 1 then
  522. if currentTurbine > 1 then
  523. currentTurbine = currentTurbine - 1
  524. turbine = peripheral.wrap(turbines[currentTurbine])
  525. end
  526. elseif mouseX > (displayW - 6) and mouseX < (displayW - 4) and mouseY == 1 then
  527. if currentTurbine < table.getn(turbines) then
  528. currentTurbine = currentTurbine + 1
  529. turbine = peripheral.wrap(turbines[currentTurbine])
  530. end
  531. end
  532. if setting then
  533. if mouseX > 20 and mouseX < 24 and mouseY == 9 then
  534. turbinesManagement[currentTurbine] = true
  535. elseif mouseX > 24 and mouseX < 28 and mouseY == 9 then
  536. turbinesManagement[currentTurbine] = false
  537. end
  538. end
  539. end
  540. sleep(0.5)
  541. end
  542.  
  543. function mainMenu()
  544. terminalOutput()
  545. initPeripherals()
  546. turbine1 = peripheral.wrap(turbines[1])
  547. turbine2 = peripheral.wrap(turbines[2])
  548. reactor1 = peripheral.wrap(reactors[1])
  549. if monitorFound == true then
  550. monitor.setTextScale(1)
  551. end
  552. while true do
  553. if monitorFound == true then
  554. displayW,displayH=monitor.getSize()
  555. if displayH == 26 and displayW == 39 then
  556. if control == true then
  557. drawControlScreen()
  558. -- if setting == true then
  559. -- drawSettingScreen()
  560. -- else
  561. -- drawDisplayScreen()
  562. -- end
  563. else
  564. drawMainScreen()
  565. end
  566. management()
  567. else
  568. print("This program is built for a 4x4 monitor only!")
  569. return
  570. end
  571. else
  572. management()
  573. end
  574. sleep(0.5)
  575. end
  576. end
  577.  
  578. function events()
  579. while true do
  580. event,p1,p2,p3 = os.pullEvent()
  581. if event=="monitor_touch" then
  582. mouseX = p2 -- sets mouseX
  583. mouseY = p3 -- and mouseY
  584. checkClickPosition() -- this runs our function
  585. elseif event=="peripheral" then
  586. terminalOutput()
  587. initPeripherals()
  588. elseif event=="peripheral_detach" then
  589. terminalOutput()
  590. initPeripherals()
  591. end
  592. end
  593. end
  594.  
  595. parallel.waitForAny(mainMenu,events)
Advertisement
Add Comment
Please, Sign In to add comment