Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local filesystem = require("Filesystem")
- local paths = require("Paths")
- local system = require("System")
- local GUI = require("GUI")
- local bar_height = 3
- local color_val = 0x000000
- local color_active = 0x009900
- local color_passive = 0xF0F0F0
- local stats = {}
- stats["last_tick"] = 0
- stats["max"] = 1
- stats["stored"] = 0
- stats["stored_max"] = 1
- stats["temp"] = 0
- stats["max_temp"] = 1
- stats["efficiency"] = 0
- stats["process_time"] = 0
- stats["cooling_rate"] = 0
- stats["process_heat"] = 0
- stats["toroid_size"] = 0
- stats["is_complete"] = false
- stats["is_processing"] = false
- stats["is_hot_enough"] = false
- stats["problem"] = "No Problem"
- ------------------------------------------------------------------------------------------------------
- if not component.isAvailable("nc_fusion_reactor") then
- GUI.alert("Fusion Reactor not found")
- return
- end
- local reactor = component.nc_fusion_reactor
- ------------------------------------------------------------------------------------------------------
- function getLastTempPrefix ()
- return "Temperature: " .. stats["temp"] .. " MK ("
- end
- function getLastTickPrefix ()
- return "Power last tick: " .. stats["last_tick"] .. " RF/t ("
- end
- function getStoredPrefix ()
- return "Power stored: " .. stats["stored"] .. " RF ("
- end
- function getSuffix ()
- return "%)"
- end
- function activate (active)
- --reactor.setActive(active)
- end
- ------------------------------------------------------------------------------------------------------
- local workspace, window = system.addWindow(GUI.titledWindow(1, 1, 88, 26, 'Fusion Reactor', true));
- local statsContainer = window:addChild(GUI.container(1, 2, math.floor(88 * 0.6), 26))
- statsContainer.panel = statsContainer:addChild(GUI.panel(1, 1, statsContainer.width, statsContainer.height, 0xFFFFFF))
- statsContainer.itemsContainer = statsContainer:addChild(GUI.container(1, 1, statsContainer.width, statsContainer.height))
- statsContainer.panel.eventHandler = function()
- update()
- end
- progressTemperature = statsContainer.itemsContainer:addChild(GUI.progressBar(3, 2, 1, color_active, color_passive, color_val, 0, false, true, getLastTempPrefix(), getSuffix()))
- progressPower = statsContainer.itemsContainer:addChild(GUI.progressBar(3, progressTemperature.y + bar_height + 1, 1, color_active, color_passive, color_val, 0, false, true, getLastTickPrefix(), getSuffix()))
- progressStored = statsContainer.itemsContainer:addChild(GUI.progressBar(3, progressPower.y + bar_height + 1, 1, color_active, color_passive, color_val, 0, false, true, getStoredPrefix(), getSuffix()))
- textboxContainer = statsContainer.itemsContainer:addChild(GUI.textBox(2, 2, 32, 16, 0xEEEEEE, 0x2D2D2D, {}, 1, 1 0))
- local controlContainer = window:addChild(GUI.container(statsContainer.width + 1, 2, 1, 26))
- controlContainer.panel = controlContainer:addChild(GUI.panel(1, 1, controlContainer.width + 1, controlContainer.height, 0xF0F0F0))
- controlContainer.itemsContainer = controlContainer:addChild(GUI.container(1, 1, controlContainer.width + 1, controlContainer.height))
- local b_on = controlContainer.itemsContainer:addChild(GUI.adaptiveRoundedButton(3, 2, 1, 0, 0xFFFFFF, 0x000000, 0x009900, 0xFFFFFF, "On"))
- local b_off = controlContainer.itemsContainer:addChild(GUI.adaptiveRoundedButton(10, 2, 1, 0, 0xFFFFFF, 0x000000, 0xFF0000, 0xFFFFFF, "Off"))
- ------------------------------------------------------------------------------------------------------
- local function calculateSizes (width, height)
- window.titleLabel.width = width
- window.titlePanel.width = width
- window.backgroundPanel.width = width
- window.backgroundPanel.height = height
- window.backgroundPanel.localX = 1
- window.backgroundPanel.localY = 4
- statsContainer.height = height
- statsContainer.width = math.floor(width * 0.6)
- statsContainer.panel.height = statsContainer.height
- statsContainer.panel.width = statsContainer.width
- statsContainer.itemsContainer.height = statsContainer.height
- statsContainer.itemsContainer.width = statsContainer.width
- progressTemperature.height = bar_height
- progressPower.height = bar_height
- progressStored.height = bar_height
- progressTemperature.width = statsContainer.width - 4
- progressPower.width = statsContainer.width - 4
- progressStored.width = statsContainer.width - 4
- controlContainer.height = height
- controlContainer.width = width - statsContainer.width
- controlContainer.localX = statsContainer.width + 1
- controlContainer.panel.height = controlContainer.height
- controlContainer.panel.width = controlContainer.width
- controlContainer.itemsContainer.height = controlContainer.height
- controlContainer.itemsContainer.width = controlContainer.width
- controlContainer:moveToFront()
- window.actionButtons:moveToFront()
- end
- function update ()
- -- energy last tick
- stats["temp"] = math.ceil(reactor.getTemperature())
- stats["max_temp"] = math.ceil(reactor.getMaxTemperature())
- stats["last_tick"] = math.ceil(reactor.getReactorProcessPower())
- stats["stored"] = math.ceil(reactor.getEnergyStored())
- stats["efficiency"] = math.ceil(reactor.getEfficiency())
- stats["process_time"] = math.ceil(reactor.getReactorProcessTime())
- stats["cooling_rate"] = math.ceil(reactor.getReactorCoolkingRate())
- stats["process_heat"] = math.ceil(reactor.getReactorProcessHeat())
- stats["toroid_size"] = math.ceil(reactor.getToroidSize())
- stats["is_complete"] = reactor.isComplete()
- stats["is_processing"] = reactor.isProcessing()
- stats["is_hot_enough"] = reactor.isHotEnough()
- stats["problem"] = reactor.getProblem()
- if stats["max"] < stats["last_tick"] then
- stats["max"] = stats["last_tick"]
- end
- if stats["stored_max"] < stats["stored"] then
- stats["stored_max"] = stats["stored"]
- end
- progressTemperature.value = math.ceil(stats["temp"] / stats["max_temp"] * 100)
- progressPower.value = math.ceil(stats["last_tick"] / stats["max"] * 100)
- progressStored.value = math.ceil(stats["stored"] / stats["stored_max"] * 100)
- progressTemperature.valuePrefix = getLastTempPrefix()
- progressPower.valuePrefix = getLastTickPrefix()
- progressStored.valuePrefix = getStoredPrefix()
- for i = 1, 9 do
- table.remove(1)
- end
- table.insert(textboxContainer.lines, stats["efficiency"])
- table.insert(textboxContainer.lines, stats["process_time"])
- table.insert(textboxContainer.lines, stats["cooling_rate"])
- table.insert(textboxContainer.lines, stats["process_heat"])
- table.insert(textboxContainer.lines, stats["toroid_size"])
- table.insert(textboxContainer.lines, stats["is_complete"])
- table.insert(textboxContainer.lines, stats["is_processing"])
- table.insert(textboxContainer.lines, stats["is_hot_enough"])
- table.insert(textboxContainer.lines, stats["problem"])
- b_on.disabled = true
- b_off.disabled = not true
- workspace:draw()
- end
- ------------------------------------------------------------------------------------------------------
- b_on.onTouch = function()
- activate(true)
- end
- b_off.onTouch = function()
- activate(false)
- end
- local reactor_path = paths.user.applicationData .. "Reactors/Cache.cfg"
- if filesystem.exists(reactor_path) then
- stats = filesystem.readTable(reactor_path)
- update()
- end
- local close = window.actionButtons.close.onTouch
- window.actionButtons.close.onTouch = function()
- filesystem.writeTable(reactor_path, stats)
- close()
- end
- window.onResize = function(width, height)
- calculateSizes(width, height)
- workspace:draw()
- end
- window:resize(window.width, window.height)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement