Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.68 KB | None | 0 0
  1. local component = require("component")
  2. local filesystem = require("Filesystem")
  3. local paths = require("Paths")
  4. local system = require("System")
  5. local GUI = require("GUI")
  6.  
  7. local bar_height = 3
  8. local color_val = 0x000000
  9. local color_active = 0x009900
  10. local color_passive = 0xF0F0F0
  11.  
  12. local stats = {}
  13. stats["last_tick"] = 0
  14. stats["max"] = 1
  15. stats["stored"] = 0
  16. stats["stored_max"] = 1
  17. stats["temp"] = 0
  18. stats["max_temp"] = 1
  19. stats["efficiency"] = 0
  20. stats["process_time"] = 0
  21. stats["cooling_rate"] = 0
  22. stats["process_heat"] = 0
  23. stats["toroid_size"] = 0
  24. stats["is_complete"] = false
  25. stats["is_processing"] = false
  26. stats["is_hot_enough"] = false
  27. stats["problem"] = "No Problem"
  28.  
  29.  
  30. ------------------------------------------------------------------------------------------------------
  31.  
  32. if not component.isAvailable("nc_fusion_reactor") then
  33. GUI.alert("Fusion Reactor not found")
  34. return
  35. end
  36. local reactor = component.nc_fusion_reactor
  37.  
  38. ------------------------------------------------------------------------------------------------------
  39.  
  40. function getLastTempPrefix ()
  41. return "Temperature: " .. stats["temp"] .. " MK ("
  42. end
  43. function getLastTickPrefix ()
  44. return "Power last tick: " .. stats["last_tick"] .. " RF/t ("
  45. end
  46. function getStoredPrefix ()
  47. return "Power stored: " .. stats["stored"] .. " RF ("
  48. end
  49. function getSuffix ()
  50. return "%)"
  51. end
  52. function activate (active)
  53. --reactor.setActive(active)
  54. end
  55.  
  56. ------------------------------------------------------------------------------------------------------
  57.  
  58. local workspace, window = system.addWindow(GUI.titledWindow(1, 1, 88, 26, 'Fusion Reactor', true));
  59.  
  60. local statsContainer = window:addChild(GUI.container(1, 2, math.floor(88 * 0.6), 26))
  61. statsContainer.panel = statsContainer:addChild(GUI.panel(1, 1, statsContainer.width, statsContainer.height, 0xFFFFFF))
  62. statsContainer.itemsContainer = statsContainer:addChild(GUI.container(1, 1, statsContainer.width, statsContainer.height))
  63. statsContainer.panel.eventHandler = function()
  64. update()
  65. end
  66.  
  67. progressTemperature = statsContainer.itemsContainer:addChild(GUI.progressBar(3, 2, 1, color_active, color_passive, color_val, 0, false, true, getLastTempPrefix(), getSuffix()))
  68. progressPower = statsContainer.itemsContainer:addChild(GUI.progressBar(3, progressTemperature.y + bar_height + 1, 1, color_active, color_passive, color_val, 0, false, true, getLastTickPrefix(), getSuffix()))
  69. progressStored = statsContainer.itemsContainer:addChild(GUI.progressBar(3, progressPower.y + bar_height + 1, 1, color_active, color_passive, color_val, 0, false, true, getStoredPrefix(), getSuffix()))
  70.  
  71. textboxContainer = statsContainer.itemsContainer:addChild(GUI.textBox(2, 2, 32, 16, 0xEEEEEE, 0x2D2D2D, {}, 1, 1 0))
  72.  
  73. local controlContainer = window:addChild(GUI.container(statsContainer.width + 1, 2, 1, 26))
  74. controlContainer.panel = controlContainer:addChild(GUI.panel(1, 1, controlContainer.width + 1, controlContainer.height, 0xF0F0F0))
  75. controlContainer.itemsContainer = controlContainer:addChild(GUI.container(1, 1, controlContainer.width + 1, controlContainer.height))
  76.  
  77. local b_on = controlContainer.itemsContainer:addChild(GUI.adaptiveRoundedButton(3, 2, 1, 0, 0xFFFFFF, 0x000000, 0x009900, 0xFFFFFF, "On"))
  78. local b_off = controlContainer.itemsContainer:addChild(GUI.adaptiveRoundedButton(10, 2, 1, 0, 0xFFFFFF, 0x000000, 0xFF0000, 0xFFFFFF, "Off"))
  79.  
  80.  
  81. ------------------------------------------------------------------------------------------------------
  82.  
  83.  
  84.  
  85. local function calculateSizes (width, height)
  86.  
  87. window.titleLabel.width = width
  88. window.titlePanel.width = width
  89. window.backgroundPanel.width = width
  90. window.backgroundPanel.height = height
  91. window.backgroundPanel.localX = 1
  92. window.backgroundPanel.localY = 4
  93.  
  94. statsContainer.height = height
  95. statsContainer.width = math.floor(width * 0.6)
  96. statsContainer.panel.height = statsContainer.height
  97. statsContainer.panel.width = statsContainer.width
  98. statsContainer.itemsContainer.height = statsContainer.height
  99. statsContainer.itemsContainer.width = statsContainer.width
  100.  
  101. progressTemperature.height = bar_height
  102. progressPower.height = bar_height
  103. progressStored.height = bar_height
  104. progressTemperature.width = statsContainer.width - 4
  105. progressPower.width = statsContainer.width - 4
  106. progressStored.width = statsContainer.width - 4
  107.  
  108. controlContainer.height = height
  109. controlContainer.width = width - statsContainer.width
  110. controlContainer.localX = statsContainer.width + 1
  111. controlContainer.panel.height = controlContainer.height
  112. controlContainer.panel.width = controlContainer.width
  113. controlContainer.itemsContainer.height = controlContainer.height
  114. controlContainer.itemsContainer.width = controlContainer.width
  115.  
  116. controlContainer:moveToFront()
  117. window.actionButtons:moveToFront()
  118. end
  119.  
  120. function update ()
  121.  
  122. -- energy last tick
  123. stats["temp"] = math.ceil(reactor.getTemperature())
  124. stats["max_temp"] = math.ceil(reactor.getMaxTemperature())
  125. stats["last_tick"] = math.ceil(reactor.getReactorProcessPower())
  126. stats["stored"] = math.ceil(reactor.getEnergyStored())
  127.  
  128. stats["efficiency"] = math.ceil(reactor.getEfficiency())
  129. stats["process_time"] = math.ceil(reactor.getReactorProcessTime())
  130. stats["cooling_rate"] = math.ceil(reactor.getReactorCoolkingRate())
  131. stats["process_heat"] = math.ceil(reactor.getReactorProcessHeat())
  132. stats["toroid_size"] = math.ceil(reactor.getToroidSize())
  133. stats["is_complete"] = reactor.isComplete()
  134. stats["is_processing"] = reactor.isProcessing()
  135. stats["is_hot_enough"] = reactor.isHotEnough()
  136. stats["problem"] = reactor.getProblem()
  137.  
  138. if stats["max"] < stats["last_tick"] then
  139. stats["max"] = stats["last_tick"]
  140. end
  141. if stats["stored_max"] < stats["stored"] then
  142. stats["stored_max"] = stats["stored"]
  143. end
  144.  
  145. progressTemperature.value = math.ceil(stats["temp"] / stats["max_temp"] * 100)
  146. progressPower.value = math.ceil(stats["last_tick"] / stats["max"] * 100)
  147. progressStored.value = math.ceil(stats["stored"] / stats["stored_max"] * 100)
  148. progressTemperature.valuePrefix = getLastTempPrefix()
  149. progressPower.valuePrefix = getLastTickPrefix()
  150. progressStored.valuePrefix = getStoredPrefix()
  151.  
  152. for i = 1, 9 do
  153. table.remove(1)
  154. end
  155.  
  156.  
  157. table.insert(textboxContainer.lines, stats["efficiency"])
  158. table.insert(textboxContainer.lines, stats["process_time"])
  159. table.insert(textboxContainer.lines, stats["cooling_rate"])
  160. table.insert(textboxContainer.lines, stats["process_heat"])
  161. table.insert(textboxContainer.lines, stats["toroid_size"])
  162. table.insert(textboxContainer.lines, stats["is_complete"])
  163. table.insert(textboxContainer.lines, stats["is_processing"])
  164. table.insert(textboxContainer.lines, stats["is_hot_enough"])
  165. table.insert(textboxContainer.lines, stats["problem"])
  166.  
  167. b_on.disabled = true
  168. b_off.disabled = not true
  169.  
  170. workspace:draw()
  171. end
  172.  
  173. ------------------------------------------------------------------------------------------------------
  174.  
  175. b_on.onTouch = function()
  176. activate(true)
  177. end
  178. b_off.onTouch = function()
  179. activate(false)
  180. end
  181.  
  182. local reactor_path = paths.user.applicationData .. "Reactors/Cache.cfg"
  183. if filesystem.exists(reactor_path) then
  184. stats = filesystem.readTable(reactor_path)
  185. update()
  186. end
  187.  
  188. local close = window.actionButtons.close.onTouch
  189. window.actionButtons.close.onTouch = function()
  190. filesystem.writeTable(reactor_path, stats)
  191. close()
  192. end
  193.  
  194. window.onResize = function(width, height)
  195. calculateSizes(width, height)
  196. workspace:draw()
  197. end
  198. window:resize(window.width, window.height)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement