From 046dfc2fc32bbded4029f50d154246709ea05211 Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Sun, 26 Aug 2018 23:22:37 +0300 Subject: [PATCH] aefaef --- Applications/SemyonIC2Reactors.lua | 76 +++++++++++++++--------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/Applications/SemyonIC2Reactors.lua b/Applications/SemyonIC2Reactors.lua index 214eb4f4..a7fcd73f 100644 --- a/Applications/SemyonIC2Reactors.lua +++ b/Applications/SemyonIC2Reactors.lua @@ -40,12 +40,16 @@ totalEnergyObject.draw = function() bigLetters.drawText(math.floor(totalEnergyObject.x + totalEnergyObject.width / 2 - bigLetters.getTextSize(text) / 2), totalEnergyObject.y, 0xFFFFFF, text) end -local totalEnable = statLayout:addChild(GUI.button(1, 1, statLayout.width, 3, 0x2D2D2D, 0x969696, 0x008800, 0xFFFFFF, "MASTER ENABLE")) -local totalDisable = statLayout:addChild(GUI.button(1, 1, statLayout.width, 3, 0x2D2D2D, 0x969696, 0x880000, 0xFFFFFF, "MASTER DISABLE")) +local masterEnable = statLayout:addChild(GUI.button(1, 1, statLayout.width, 3, 0x2D2D2D, 0x969696, 0x008800, 0xFFFFFF, "MASTER ENABLE")) +local masterDisable = statLayout:addChild(GUI.button(1, 1, statLayout.width, 3, 0x2D2D2D, 0x969696, 0x880000, 0xFFFFFF, "MASTER DISABLE")) +masterDisable.animated, masterDisable.animated = false, false -local function newController(x, y, proxy) +local contorollersContainer = mainContainer:addChild(GUI.container(1, 1, mainContainer.width, mainContainer.height)) + +local function newController(x, y, reactorProxy) local contoroller = GUI.window(x, y, 40, 6) - + + contoroller.reactorProxy = reactorProxy contoroller:addChild(GUI.panel(1, 1, contoroller.width, contoroller.height, 0x2D2D2D)) local button = contoroller:addChild(GUI.button(1, 1, 16, 3, 0x880000, 0xFFFFFF, 0x008800, 0xFFFFFF, "PASV")) @@ -58,30 +62,21 @@ local function newController(x, y, proxy) comboBox:addItem("Not assigned") for i = 1, #redstones do comboBox:addItem("I/O " .. redstones[i].address) - if database[proxy.address] == redstones[i].address then + if database[reactorProxy.address] == redstones[i].address then comboBox.selectedItem = i + 1 end end - contoroller:addChild(GUI.label(1, 2, contoroller.width - button.width, 1, 0x969696, "RCTR " .. proxy.address:sub(1, 5))):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP) + contoroller:addChild(GUI.label(1, 2, contoroller.width - button.width, 1, 0x969696, "RCTR " .. reactorProxy.address:sub(1, 5))):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP) - local temperatureBar = contoroller:addChild(GUI.progressBar(2, 3, contoroller.width - button.width - 2, 0x3366CC, 0x1E1E1E, 0x969696, 80, true, false)) - local temperatureLabel = contoroller:addChild(GUI.label(2, 4, temperatureBar.width, 1, 0x5A5A5A, "")):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP) - local energyLabel = contoroller:addChild(GUI.label(2, 5, temperatureBar.width, 1, 0x5A5A5A, "")):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP) + contoroller.temperatureBar = contoroller:addChild(GUI.progressBar(2, 3, contoroller.width - button.width - 2, 0x3366CC, 0x1E1E1E, 0x969696, 80, true, false)) + contoroller.temperatureLabel = contoroller:addChild(GUI.label(2, 4, temperatureBar.width, 1, 0x5A5A5A, "")):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP) + contoroller.energyLabel = contoroller:addChild(GUI.label(2, 5, temperatureBar.width, 1, 0x5A5A5A, "")):setAlignment(GUI.ALIGNMENT_HORIZONTAL_CENTER, GUI.ALIGNMENT_VERTICAL_TOP) local function getRedstoneProxy() return component.proxy(redstones[comboBox.selectedItem - 1].address) end - local function update() - local heat = proxy.getHeat() - local value = heat / proxy.getMaxHeat() - temperatureBar.value = value * 100 - temperatureBar.colors.active = palette[math.floor(value * #palette)] or palette[1] - temperatureLabel.text = "TEMP: " .. math.floor(heat) .. " °C" - energyLabel.text = "ENRG: " .. math.floor(proxy.getReactorEUOutput()) .. " eU/t" - end - local function updateButton() button.disabled = comboBox.selectedItem == 1 end @@ -97,24 +92,10 @@ local function newController(x, y, proxy) updateButton() mainContainer:drawOnScreen() - database[proxy.address] = comboBox.selectedItem > 1 and redstones[comboBox.selectedItem - 1].address or nil + database[reactorProxy.address] = comboBox.selectedItem > 1 and redstones[comboBox.selectedItem - 1].address or nil table.toFile(databasePath, database) end - local overrideEventHandler = contoroller.eventHandler - local uptime = computer.uptime() - contoroller.eventHandler = function(mainContainer, object, e1, ...) - if e1 then - overrideEventHandler(mainContainer, object, e1, ...) - elseif computer.uptime() - uptime > 2 then - update() - mainContainer:drawOnScreen() - - uptime = computer.uptime() - end - end - - update() updateButton() if comboBox.selectedItem > 1 and getRedstoneProxy().getOutput(1) > 0 then @@ -128,16 +109,37 @@ local x, y, xStart, yStart = 3, 2, 3, 2 for address in component.list("reactor_chamber") do local proxy = component.proxy(address) - local contoroller = mainContainer:addChild(newController(x, y, proxy)) + local contoroller = contorollersContainer:addChild(newController(x, y, proxy)) y = y + contoroller.height + 1 - if y > mainContainer.height - 4 then + if y > contorollersContainer.height - 4 then x, y = x + contoroller.width + 2, yStart end end +local uptime = computer.uptime() +contorollersContainer.eventHandler = function(mainContainer, object, e1) + if computer.uptime() - uptime > 1 then + totalEnergy = 0 + for i = 1, #contorollersContainer.children do + local child = contorollersContainer.children[i] + + local heat = child.reactorProxy.getHeat() + local value = heat / child.reactorProxy.getMaxHeat() + child.temperatureBar.value = value * 100 + child.temperatureBar.colors.active = palette[math.floor(value * #palette)] or palette[1] + child.temperatureLabel.text = "TEMP: " .. math.floor(heat) .. " °C" + child.energyLabel.text = "ENRG: " .. math.floor(child.reactorProxy.getReactorEUOutput()) .. " eU/t" + + totalEnergy = totalEnergy + math.floor(child.reactorProxy.getReactorEUOutput()) + end + + mainContainer:drawOnScreen() + uptime = computer.uptime() + end +end + -------------------------------------------------------------------------------- mainContainer:drawOnScreen(true) -mainContainer:startEventHandling(0) - +mainContainer:startEventHandling()