From eab31f5f841f1c883c03280494df097317f072ba Mon Sep 17 00:00:00 2001 From: Gabriel Moreira Minossi Date: Sun, 17 Jan 2021 13:56:10 -0300 Subject: [PATCH] Adding method to create machine widget --- Programs/monitor-system/api/gui/widget.lua | 41 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/Programs/monitor-system/api/gui/widget.lua b/Programs/monitor-system/api/gui/widget.lua index 6b3f0f6..9df3559 100644 --- a/Programs/monitor-system/api/gui/widget.lua +++ b/Programs/monitor-system/api/gui/widget.lua @@ -15,8 +15,9 @@ local states = { } local types = { - power = "power", - machine = "machine" + POWER = "POWER", + MULTIBLOCK = "MULTIBLOCK", + MACHINE = "MACHINE" } local function drawProgress(x, y, width, height, progress, maxProgress, color) @@ -70,7 +71,7 @@ function widget.drawBaseWidget(x, y, width, height, title) end local function draw(self, index) - if self.type == types.power then + if self.type == types.POWER then index = 10 end local scale = self.scale or 1 @@ -198,7 +199,7 @@ function fake.machineWidget.create() state = state, progress = 0, maxProgress = state ~= states[3] and state ~= states[4] and math.random(500) or 0, - type = "machine", + type = types.MACHINE, update = fake.machineWidget.update, onClick = fake.machineWidget.onClick, getMiddleString = fake.machineWidget.getMiddleString, @@ -206,6 +207,34 @@ function fake.machineWidget.create() } end +function widget.createMachineWidget(address, name) + local getMultiblockStatus = require("domain.multiblock.get-multiblock-status-usecase") + local function update(self) + for key, value in pairs(getMultiblockStatus(address, self.name)) do + self[key] = value + end + end + + local toggleMultiblockWork = require("domain.multiblock.toggle-multiblock-work") + local function onClick() + toggleMultiblockWork(address) + end + + local machineWidget = { + name = name, + type = types.MULTIBLOCK, + update = update, + onClick = onClick, + getMiddleString = function() + end, + draw = draw + } + + machineWidget:update() + + return machineWidget +end + fake.powerWidget = {} function fake.powerWidget:update() @@ -231,7 +260,7 @@ function fake.powerWidget.create() maxProgress = 16000000, dProgress = 1, scale = 2, - type = types.power, + type = types.POWER, update = fake.powerWidget.update, onClick = fake.powerWidget.onClick, getMiddleString = fake.powerWidget.getMiddleString, @@ -269,7 +298,7 @@ function widget.createPowerWidget(address) local powerWidget = { name = "Power", scale = 2, - type = types.power, + type = types.POWER, update = update, onClick = function() end,