mirror of
https://github.com/S4mpsa/InfOS.git
synced 2025-08-04 02:16:05 -04:00
Creating a simple interface
This commit is contained in:
parent
69d3cf09aa
commit
f1964f7af0
27
Programs/monitor-system/api/gui/panel.lua
Normal file
27
Programs/monitor-system/api/gui/panel.lua
Normal file
@ -0,0 +1,27 @@
|
||||
-- Import section
|
||||
Page = require("api.gui.page")
|
||||
Graphics = require("graphics.graphics")
|
||||
Colors = require("colors")
|
||||
Component = require("component")
|
||||
GPU = Component.gpu
|
||||
--
|
||||
|
||||
local panel = {
|
||||
currentPage = Page.overview
|
||||
}
|
||||
|
||||
function panel.render()
|
||||
Graphics.rectangle(GPU, 0, 0, 20, 160, Colors.background)
|
||||
for index, page in ipairs(Page) do
|
||||
if page ~= panel.currentPage then
|
||||
Graphics.text(GPU, 0, 10 * (index - 1), Colors.labelColor, panel.title)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function panel.navigate(page)
|
||||
panel.findText(page.title)
|
||||
page.render()
|
||||
end
|
||||
|
||||
return panel
|
46
Programs/monitor-system/api/gui/widget.lua
Normal file
46
Programs/monitor-system/api/gui/widget.lua
Normal file
@ -0,0 +1,46 @@
|
||||
Component = require("component")
|
||||
GPU = Component.gpu
|
||||
Screen = Component.screen
|
||||
|
||||
-- GPU resolution should be 160 x 50.
|
||||
-- Screen should be 16 blocks by 10 blocks. (Could also be 8 x 5).
|
||||
-- That way, each block should have a resolution of 10 x 10
|
||||
-- Organizing the page:
|
||||
---- Title on top of the page (title)
|
||||
---- Side panel on the left With a width of 20 pixels (panel)
|
||||
---- Two buttons for page navigation (b, f)
|
||||
------- Each with a width of 10 pixels
|
||||
---- 1 Power widget on the bottom, with a width of 40 pixels (power)
|
||||
---- 9 Regular widgets on the right, in a 3 x 3 grid (w)
|
||||
------ Each one with a width of 20 pixels
|
||||
--[[
|
||||
| p | title |
|
||||
| a | w | w | w |
|
||||
| n | w | w | w |
|
||||
| e | w | w | w |
|
||||
| l | power |b|f|
|
||||
--]]
|
||||
|
||||
|
||||
local page = {
|
||||
title = {},
|
||||
panel = {},
|
||||
back = {},
|
||||
forwards = {}
|
||||
}
|
||||
|
||||
local widget = {
|
||||
name = "",
|
||||
leftString = "",
|
||||
middleString = "",
|
||||
rightString = "",
|
||||
height = 10,
|
||||
width = 20,
|
||||
}
|
||||
|
||||
function widget.create(name, leftString, middleString, rightString, screenIndex)
|
||||
widget.name = name or "Unused"
|
||||
widget.leftString = leftString or ""
|
||||
widget.middleString = middleString or ""
|
||||
widget.rightString = rightString or ""
|
||||
end
|
@ -2,10 +2,14 @@
|
||||
MultiBlock = require("data.datasource.multi-block")
|
||||
SingleBlock = require("data.datasource.single-block")
|
||||
EnergyProvider = require("data.datasource.energy-provider")
|
||||
Colors = require("graphics.colors")
|
||||
Unicode = require("unicode")
|
||||
local doubleBuffer = require("graphics.doubleBuffering")
|
||||
--
|
||||
|
||||
local cleanroomAddresses = require("config.addresses.cleanroom")
|
||||
local multiBlockAddresses = require("config.addresses.multi-blocks")
|
||||
local energyBufferAddress = require("config.addresses.energy-buffers")
|
||||
local energyBufferAddresses = require("config.addresses.energy-buffers")
|
||||
|
||||
local protectCleanroomRecipes = require("domain.cleanroom.protect-recipes-usecase")
|
||||
local getMultiblockStatuses = require("domain.multiblock.get-multiblock-status-usecase")
|
||||
@ -14,29 +18,29 @@ local listMiners = require("domain.miner.list-miners-usecase")
|
||||
local getMinersStatuses = require("domain.miner.get-miner-status-usecase")
|
||||
--
|
||||
|
||||
local cleanroom = MultiBlock:new(multiBlockAddresses.cleanroom)
|
||||
cleanroom.name = "cleanroom"
|
||||
local cleanroomMachines = {}
|
||||
for _, address in pairs(cleanroomAddresses) do
|
||||
table.insert(cleanroomMachines, SingleBlock:new(address))
|
||||
for name, address in pairs(cleanroomAddresses) do
|
||||
table.insert(cleanroomMachines, SingleBlock:new(address, name))
|
||||
end
|
||||
|
||||
local EBF11 = MultiBlock:new(multiBlockAddresses.EBF11)
|
||||
EBF11.name = "EBF11"
|
||||
local multiblocks = {}
|
||||
for name, address in pairs(multiBlockAddresses) do
|
||||
table.insert(multiblocks, MultiBlock:new(address, name))
|
||||
end
|
||||
|
||||
local multiblocks = {cleanroom, EBF11}
|
||||
local batteryBuffers = {}
|
||||
for name, address in pairs(energyBufferAddresses) do
|
||||
table.insert(batteryBuffers, EnergyProvider:new(address, name))
|
||||
end
|
||||
|
||||
local energyBuffer = EnergyProvider:new(energyBufferAddress.batteryBuffer1)
|
||||
|
||||
local energyProducers = {}
|
||||
local multiblocksStatuses = {}
|
||||
|
||||
for i = 1, 100 do
|
||||
print(i)
|
||||
|
||||
protectCleanroomRecipes(cleanroom, cleanroomMachines)
|
||||
protectCleanroomRecipes(multiblocks[1], cleanroomMachines)
|
||||
multiblocksStatuses = getMultiblockStatuses(multiblocks)
|
||||
local energyStatus = getEnergyStatus(energyProducers, energyBuffer)
|
||||
-- local energyStatus = getEnergyStatus(batteryBuffers[1])
|
||||
|
||||
local minersList = listMiners()
|
||||
local minersStatuses = getMinersStatuses(minersList)
|
||||
@ -45,9 +49,127 @@ for i = 1, 100 do
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
for multiblock, status in pairs(multiblocksStatuses) do
|
||||
print(multiblock .. ": \
|
||||
problems: " .. status.problems .. "\
|
||||
efficiency: " .. status.efficiencyPercentage)
|
||||
for multiblockName, status in pairs(multiblocksStatuses) do
|
||||
print(
|
||||
multiblockName .. ":",
|
||||
"\n problems: " .. status.problems,
|
||||
"\n efficiency: " .. status.efficiencyPercentage,
|
||||
"\n probably uses: " .. status.probablyUses
|
||||
)
|
||||
end
|
||||
|
||||
require("api.sound.zelda-secret")()
|
||||
|
||||
local component = {
|
||||
name = "Machine",
|
||||
working = true,
|
||||
leftInfo = "LV",
|
||||
middleInfo = "something",
|
||||
rightInfo = "16 / 32 s",
|
||||
progress = 0,
|
||||
maxProgress = 16000
|
||||
}
|
||||
|
||||
local width = 40
|
||||
local height = 10
|
||||
local function drawWidget(index, component, scale)
|
||||
scale = scale or 1
|
||||
local x = width + width * ((index - 1) % 3)
|
||||
local y = height * math.ceil((index) / 3)
|
||||
doubleBuffer.drawRectangle(
|
||||
x + 1,
|
||||
y + 1,
|
||||
width * scale - 1,
|
||||
height - 1,
|
||||
Colors.machineBackground,
|
||||
Colors.machineBackground,
|
||||
"█"
|
||||
)
|
||||
doubleBuffer.drawFrame(x + 1, y + 1, width * scale - 1, height - 1, Colors.labelColor)
|
||||
doubleBuffer.drawLine(x + 3, y + 5, x + width * scale - 3, y + 5, Colors.machineBackground, Colors.mainColor, "─")
|
||||
doubleBuffer.drawText(x + 3, y + 2, Colors.labelColor, component.name)
|
||||
doubleBuffer.drawText(
|
||||
x + 3,
|
||||
y + 7,
|
||||
component.working and Colors.workingColor or Colors.errorColor,
|
||||
component.leftInfo
|
||||
)
|
||||
if component.middleInfo then
|
||||
doubleBuffer.drawText(
|
||||
x + width * scale / 2 - Unicode.len(component.middleInfo) + 3,
|
||||
y + height - 3,
|
||||
Colors.accentB,
|
||||
component.middleInfo
|
||||
)
|
||||
end
|
||||
if component.rightInfo then
|
||||
doubleBuffer.drawText(
|
||||
x + width * scale - Unicode.len(tostring(component.rightInfo)) - 3,
|
||||
y + height - 3,
|
||||
Colors.accentA,
|
||||
tostring(component.rightInfo)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
component.progress = component.progress + math.random(0, 1000)
|
||||
component.rightInfo = component.progress .. " / " .. component.maxProgress
|
||||
if component.progress >= component.maxProgress then
|
||||
component.progress = 0
|
||||
end
|
||||
for index = 1, 10 do
|
||||
if index < 10 then
|
||||
drawWidget(index, component, 1)
|
||||
elseif index == 10 then
|
||||
drawWidget(index, component, 2)
|
||||
end
|
||||
end
|
||||
doubleBuffer.drawChanges()
|
||||
os.sleep(0.5)
|
||||
end
|
||||
|
||||
--[[
|
||||
Page = require("api.gui.page")
|
||||
Notifications = {}
|
||||
local components = {}
|
||||
local function getComponents()
|
||||
local multiBlockAddresses = require("config.addresses.multi-blocks")
|
||||
local energyBufferAddresses = require("config.addresses.energy-buffers")
|
||||
|
||||
local multiblocks = {}
|
||||
for name, address in pairs(multiBlockAddresses) do
|
||||
table.insert(multiblocks, MultiBlock:new(address, name))
|
||||
end
|
||||
|
||||
local batteryBuffers = {}
|
||||
for name, address in pairs(energyBufferAddresses) do
|
||||
table.insert(batteryBuffers, EnergyProvider:new(address, name))
|
||||
end
|
||||
|
||||
return {table.unpack(multiblocks), batteryBuffers}
|
||||
end
|
||||
|
||||
local function setup()
|
||||
components = getComponents()
|
||||
Page.overview.setup()
|
||||
end
|
||||
|
||||
local function loop()
|
||||
while true do
|
||||
for index, component in ipairs(components) do
|
||||
local updated, notification = component:update()
|
||||
if updated then
|
||||
Page:draw(component, index)
|
||||
end
|
||||
if notification then
|
||||
table.insert(Notifications, 1, {notification, os.time()})
|
||||
end
|
||||
end
|
||||
Page:render()
|
||||
end
|
||||
end
|
||||
|
||||
setup()
|
||||
loop()
|
||||
--]]
|
||||
|
Loading…
x
Reference in New Issue
Block a user