Лишь бы не бомбануло втихаря

This commit is contained in:
Igor Timofeev 2018-08-26 15:44:13 +03:00
parent 67323560f3
commit c48a2f6473
2 changed files with 285 additions and 0 deletions

View File

@ -0,0 +1,159 @@
local component = require("component")
local color = require("color")
local buffer = require("doubleBuffering")
local GUI = require("GUI")
local event = require("event")
local scale = require("scale")
local unicode = require("unicode")
--------------------------------------------------------------------------------
local elementWidth = 32
local GPUProxy = buffer.getGPUProxy()
local mainScreenAddress = GPUProxy.getScreen()
--------------------------------------------------------------------------------
local mainContainer = GUI.fullScreenContainer()
mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0x1E1E1E))
local layout = mainContainer:addChild(GUI.layout(1, 1, mainContainer.width, mainContainer.height, 1, 1))
local function addButton(text)
return layout:addChild(GUI.button(1, 1, elementWidth, 3, 0x3C3C3C, 0x969696, 0x969696, 0x3C3C3C, text))
end
local mainMenu
local function calibrationMenu()
layout:removeChildren()
local hSlider = layout:addChild(GUI.slider(1, 1, elementWidth, 0x66DB80, 0x0, 0xFFFFFF, 0xAAAAAA, 1, 10, 5, false, "Screens by horizontal: ", ""))
hSlider.roundValues = true
hSlider.height = 2
local vSlider = layout:addChild(GUI.slider(1, 1, elementWidth, 0x66DB80, 0x0, 0xFFFFFF, 0xAAAAAA, 1, 10, 4, false, "Screens by vertical: ", ""))
vSlider.roundValues = true
vSlider.height = 2
addButton("Next").onTouch = function()
local connectedCount = -1
for address in component.list("screen") do
connectedCount = connectedCount + 1
end
hSlider.value, vSlider.value = math.floor(hSlider.value), math.floor(vSlider.value)
local specifiedCount = hSlider.value * vSlider.value
if specifiedCount <= connectedCount then
layout:removeChildren()
local SSX, SSY = 1, 1
local function screenObjectDraw(object)
buffer.drawRectangle(object.x, object.y, object.width, object.height, (SSX == object.SX and SSY == object.SY) and 0x22FF22 or 0xE1E1E1, 0x0, " ")
end
local function newScreen(SX, SY)
local object = GUI.object(1, 1, 8, 3)
object.draw = screenObjectDraw
object.SX = SX
object.SY = SY
return object
end
local function newScreenLine(SY)
local lineLayout = GUI.layout(1, 1, layout.width, 3, 1, 1)
lineLayout:setDirection(1, 1, GUI.DIRECTION_HORIZONTAL)
lineLayout:setSpacing(1, 1, 2)
for SX = 1, hSlider.value do
lineLayout:addChild(newScreen(SX, SY))
end
return lineLayout
end
for SY = 1, vSlider.value do
layout:addChild(newScreenLine(SY))
end
mainContainer:drawOnScreen()
local map = {}
local hue, hueStep = 0, 360 / specifiedCount
while true do
local e1, e2 = event.pull("touch")
if e2 ~= mainScreenAddress then
GPUProxy.bind(e2, false)
local RW, RH = scale.getResolution(1)
GPUProxy.setResolution(RW, RH)
GPUProxy.setBackground(color.HSBToInteger(hue, 1, 1))
GPUProxy.setForeground(0x0)
GPUProxy.fill(1, 1, RW, RH, " ")
local text = "Screen " .. SSX .. "x" .. SSY .. " has been calibrated"
GPUProxy.set(math.floor(RW / 2 - unicode.len(text) / 2), math.floor(RH / 2), text)
GPUProxy.bind(mainScreenAddress, false)
SSX, hue = SSX + 1, hue + hueStep
if SSX > hSlider.value then
SSX, SSY = 1, SSY + 1
if SSY > vSlider.value then
table.toFile("/MultiScreen.cfg", map, true)
break
end
end
map[SSY] = map[SSY] or {}
map[SSY][SSX] = {
address = e2,
resolution = {
width = RW,
height = RH
}
}
mainContainer:drawOnScreen()
end
end
GUI.alert("All screens has been successfully calibrated")
mainMenu()
else
GUI.alert("Invalid count of connected screens. You're specified " .. specifiedCount .. " of screens, but there's " .. connectedCount .. " connected screens")
end
end
mainContainer:drawOnScreen()
end
mainMenu = function(force)
layout:removeChildren()
local actionComboBox = layout:addChild(GUI.comboBox(1, 1, elementWidth, 3, 0xEEEEEE, 0x2D2D2D, 0xCCCCCC, 0x888888))
actionComboBox:addItem("Draw image")
actionComboBox:addItem("Clear screens")
actionComboBox:addItem("Calibrate")
addButton("Next").onTouch = function()
if actionComboBox.selectedItem == 1 then
elseif actionComboBox.selectedItem == 2 then
else
calibrationMenu()
end
end
mainContainer:drawOnScreen(force)
end
--------------------------------------------------------------------------------
mainMenu(true)
mainContainer:startEventHandling()

View File

@ -0,0 +1,126 @@
local computer = require("computer")
local component = require("component")
local GUI = require("GUI")
local buffer = require("doubleBuffering")
local fs = require("filesystem")
--------------------------------------------------------------------------------
local redstones = {}
for address in component.list("redstone") do
table.insert(redstones, component.proxy(address))
end
local databasePath = "/reactors.cfg"
local database = {}
if fs.exists(databasePath) then
database = table.fromFile(databasePath)
end
local palette = {0x00FF00,0x00B600,0x33DB00,0x99FF00,0xCCFF00,0xFFDB00,0xFFB600,0xFF9200,0xFF6D00,0xFF4900,0xFF2400,0xFF0000}
local mainContainer = GUI.fullScreenContainer()
--------------------------------------------------------------------------------
mainContainer:addChild(GUI.panel(1, 1, mainContainer.width, mainContainer.height, 0x1E1E1E))
local function newController(x, y, proxy)
local contoroller = GUI.window(x, y, 40, 6)
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"))
button.localX = contoroller.width - button.width + 1
button.switchMode = true
button.animated = false
local comboBox = contoroller:addChild(GUI.comboBox(button.localX, button.localY + button.height, button.width, button.height, 0x3C3C3C, 0x787878, 0x4B4B4B, 0x5A5A5A))
comboBox.dropDownMenu.itemHeight = 1
comboBox:addItem("Not assigned")
for i = 1, #redstones do
comboBox:addItem("I/O " .. redstones[i].address)
if database[proxy.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)
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)
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
button.onTouch = function()
button.text = button.pressed and "ACTV" or "PASV"
mainContainer:drawOnScreen()
getRedstoneProxy().setOutput(1, button.pressed and 15 or 0)
end
comboBox.onItemSelected = function()
updateButton()
mainContainer:drawOnScreen()
database[proxy.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
button.text, button.pressed = "ACTV", true
end
return contoroller
end
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))
y = y + contoroller.height + 1
if y > mainContainer.height - 4 then
x, y = x + contoroller.width + 2, yStart
end
end
--------------------------------------------------------------------------------
mainContainer:drawOnScreen(true)
mainContainer:startEventHandling(0)