diff --git a/Libraries/graphics/colors.lua b/Libraries/graphics/colors.lua index d1288dd..76c95f8 100644 --- a/Libraries/graphics/colors.lua +++ b/Libraries/graphics/colors.lua @@ -20,22 +20,22 @@ local colors = { ---[[ local newColors = { - machineBackground = colors.darkGray, - progressBackground = colors.lightGray, - labelColor = colors.chocolate, - errorColor = colors.red, - idleColor = colors.purple, - workingColor = colors.steelBlue, - positiveEUColor = colors.lime, - negativeEUColor = colors.brown, - timeColor = colors.purple, - textColor = colors.black, - hudColor = colors.darkSlateGrey, - mainColor = colors.rosyBrown, background = colors.black, + machineBackground = colors.darkSlateGrey, + progressBackground = colors.purple, + barColor = colors.magenta, + labelColor = colors.chocolate, + idleColor = colors.brown, + workingColor = colors.green, + errorColor = colors.red, + positiveEUColor = colors.lime, + negativeEUColor = colors.red, + timeColor = colors.purple, + textColor = colors.brown, + hudColor = colors.darkSlateGrey, + mainColor = colors.steelBlue, accentA = colors.cyan, - accentB = colors.magenta, - barColor = colors.blue + accentB = colors.blue } for name, color in pairs(newColors) do diff --git a/Libraries/graphics/widgets.lua b/Libraries/graphics/widgets.lua index 6672bd4..b9b1e30 100644 --- a/Libraries/graphics/widgets.lua +++ b/Libraries/graphics/widgets.lua @@ -4,7 +4,7 @@ Colors = require("colors") local widgets = {} -function widgets.gtMachineInit(GPU, name, address) +function widgets.gtMabchineInit(GPU, name, address) local maintenanceIndex = 0 local machine = util.machine(address) Graphics.rectangle(GPU, 1, 1, 28, 9, Colors.background) @@ -99,7 +99,8 @@ function widgets.gtMachine(GPU, name, address) end _, f, _ = GPU.get(6, 1) if - ((Graphics.windows[name].data == 0 or string.match(machine.getSensorInformation()[Graphics.windows[name].data], ".*c0.*")) and + ((Graphics.windows[name].data == 0 or + string.match(machine.getSensorInformation()[Graphics.windows[name].data], ".*c0.*")) and machine.isWorkAllowed()) == true then if f ~= Colors.background then diff --git a/Programs/monitor-system/init.lua b/Programs/monitor-system/init.lua index 86831f1..6db7930 100755 --- a/Programs/monitor-system/init.lua +++ b/Programs/monitor-system/init.lua @@ -4,8 +4,8 @@ SingleBlock = require("data.datasource.single-block") EnergyProvider = require("data.datasource.energy-provider") Colors = require("graphics.colors") Unicode = require("unicode") -local doubleBuffer = require("graphics.doubleBuffering") --- +Graphics = require("graphics.graphics") +DoubleBuffer = require("graphics.doubleBuffering") local cleanroomAddresses = require("config.addresses.cleanroom") local multiBlockAddresses = require("config.addresses.multi-blocks") @@ -16,8 +16,11 @@ local getMultiblockStatuses = require("domain.multiblock.get-multiblock-status-u local getEnergyStatus = require("domain.energy.get-energy-status-usecase") local listMiners = require("domain.miner.list-miners-usecase") local getMinersStatuses = require("domain.miner.get-miner-status-usecase") + +local GPU = Component.gpu -- +--[[ local cleanroomMachines = {} for name, address in pairs(cleanroomAddresses) do table.insert(cleanroomMachines, SingleBlock:new(address, name)) @@ -59,24 +62,25 @@ for multiblockName, status in pairs(multiblocksStatuses) do end require("api.sound.zelda-secret")() - +--]] local component = { name = "Machine", working = true, - leftInfo = "LV", + leftInfo = "ON", middleInfo = "something", rightInfo = "16 / 32 s", progress = 0, - maxProgress = 16000 + maxProgress = 1000 } 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( + +local function drawTitle(title) + local x = width + local y = 0 + local scale = 3 + DoubleBuffer.drawRectangle( x + 1, y + 1, width * scale - 1, @@ -85,25 +89,62 @@ local function drawWidget(index, component, scale) 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( + DoubleBuffer.drawFrame(x + 1, y + 1, width * scale - 1, height - 1, Colors.labelColor) + DoubleBuffer.drawLine(x + 3, y + 6, x + width * scale - 3, y + 6, Colors.machineBackground, Colors.textColor, "─") + DoubleBuffer.drawText(x + (width * scale - Unicode.len(title)) / 2, y + 5, Colors.mainColor, title) +end + +local function drawProgress(x, y, width, height, progress, maxProgress, color) + progress = math.floor(progress * (width + height - 2) / maxProgress) + + local lengths = { + first = progress > 5 and 5 or progress, + second = progress > height - 2 + 5 and height - 2 or progress - (5), + third = progress > width - 6 + height - 2 + 5 and width - 6 or progress - (height - 2 + 5) + } + DoubleBuffer.drawRectangle(x + 6 - lengths.first, y + 1, lengths.first, 1, color, color, "█") + DoubleBuffer.drawRectangle(x + 1, y + 2, 1, lengths.second, color, color, "█") + DoubleBuffer.drawRectangle(x + 1, y + height, lengths.third, 1, color, color, "█") + DoubleBuffer.drawRectangle(x + width - 4, y + height, lengths.first, 1, color, color, "█") + DoubleBuffer.drawRectangle(x + width, y + height - lengths.second, 1, lengths.second, color, color, "█") + DoubleBuffer.drawRectangle(x + 1 + width - lengths.third, y + 1, lengths.third, 1, color, color, "█") +end + +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, + "█" + ) + + drawProgress(x, y, width * scale - 1, height - 1, 1, 1, Colors.progressBackground) + drawProgress(x, y, width * scale - 1, height - 1, component.progress, component.maxProgress, Colors.barColor) + + DoubleBuffer.drawLine(x + 3, y + 5, x + width * scale - 3, y + 5, Colors.machineBackground, Colors.textColor, "─") + DoubleBuffer.drawText(x + 3, y + 3, 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, + DoubleBuffer.drawText( + x + 3 + 3 + Unicode.len(component.leftInfo), y + height - 3, - Colors.accentB, + Colors.textColor, component.middleInfo ) end if component.rightInfo then - doubleBuffer.drawText( + DoubleBuffer.drawText( x + width * scale - Unicode.len(tostring(component.rightInfo)) - 3, y + height - 3, Colors.accentA, @@ -112,10 +153,12 @@ local function drawWidget(index, component, scale) end end +drawTitle("Overview") while true do - component.progress = component.progress + math.random(0, 1000) - component.rightInfo = component.progress .. " / " .. component.maxProgress + component.progress = component.progress + 1 + component.rightInfo = component.progress .. " / " .. component.maxProgress .. " s" if component.progress >= component.maxProgress then + os.sleep(0.5) component.progress = 0 end for index = 1, 10 do @@ -125,8 +168,8 @@ while true do drawWidget(index, component, 2) end end - doubleBuffer.drawChanges() - os.sleep(0.5) + DoubleBuffer.drawChanges() + os.sleep(0) end --[[