From 2fdc9feea7ed8e1e1b7c95a52f11b194ee4a3870 Mon Sep 17 00:00:00 2001 From: Mikayla Date: Thu, 9 Jan 2025 00:15:12 +0000 Subject: [PATCH] #557 work on induction matrix page --- pocket/ui/pages/facility_matrix.lua | 39 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/pocket/ui/pages/facility_matrix.lua b/pocket/ui/pages/facility_matrix.lua index 6f16986..7287457 100644 --- a/pocket/ui/pages/facility_matrix.lua +++ b/pocket/ui/pages/facility_matrix.lua @@ -13,6 +13,7 @@ local TextBox = require("graphics.elements.TextBox") local DataIndicator = require("graphics.elements.indicators.DataIndicator") local HorizontalBar = require("graphics.elements.indicators.HorizontalBar") local IconIndicator = require("graphics.elements.indicators.IconIndicator") +local PowerIndicator = require("graphics.elements.indicators.PowerIndicator") local StateIndicator = require("graphics.elements.indicators.StateIndicator") local cpair = core.cpair @@ -33,7 +34,8 @@ local mode_ind_s = { ---@param ps psil ---@param update function return function (app, panes, tank_pane, ps, update) - local fac = iocontrol.get_db().facility + local db = iocontrol.get_db() + local fac = db.facility local mtx_div = Div{parent=tank_pane,x=2,width=tank_pane.get_width()-2} table.insert(panes, mtx_div) @@ -45,14 +47,37 @@ return function (app, panes, tank_pane, ps, update) local status = StateIndicator{parent=mtx_div,x=10,y=1,states=style.imatrix.states,value=1,min_width=12} status.register(ps, "InductionMatrixStateStatus", status.update) - TextBox{parent=mtx_div,y=3,text="Fill",width=10,fg_bg=label} - local chg_pcnt = DataIndicator{parent=mtx_div,x=14,y=3,label="",format="%5.2f",value=100,unit="%",lu_colors=lu_col,width=8,fg_bg=text_fg} - local chg_amnt = DataIndicator{parent=mtx_div,label="",format="%18d",value=0,commas=true,unit="mB",lu_colors=lu_col,width=21,fg_bg=text_fg} + TextBox{parent=mtx_div,text="Charge",x=1,y=5,fg_bg=label} + local chg_bar = HorizontalBar{parent=mtx_div,x=1,y=6,fg_bg=cpair(colors.green,colors.gray)} + TextBox{parent=mtx_div,text="Input",x=1,y=7,fg_bg=label} + local in_bar = HorizontalBar{parent=mtx_div,x=1,y=8,fg_bg=cpair(colors.blue,colors.gray)} + TextBox{parent=mtx_div,text="Output",x=21,y=9,fg_bg=label} + local out_bar = HorizontalBar{parent=mtx_div,x=1,y=10,fg_bg=cpair(colors.red,colors.gray)} - TextBox{parent=mtx_div,y=6,text="Charge Level",width=12,fg_bg=label} - local level = HorizontalBar{parent=mtx_div,y=7,bar_fg_bg=cpair(colors.green,colors.gray),height=1,width=21} + local function calc_saturation(val) + local data = fac.induction_data_tbl[1] + if (type(data.build) == "table") and (type(data.build.transfer_cap) == "number") and (data.build.transfer_cap > 0) then + return val / data.build.transfer_cap + else return 0 end + end - level.register(ps, "fill", level.update) + chg_bar.register(ps, "energy_fill", chg_bar.update) + in_bar.register(ps, "last_input", function (val) in_bar.update(calc_saturation(val)) end) + out_bar.register(ps, "last_output", function (val) out_bar.update(calc_saturation(val)) end) + + local energy = PowerIndicator{parent=mtx_div,x=1,y=12,lu_colors=lu_col,label="Chg: ",unit=db.energy_label,format="%8.2f",value=0,width=22,fg_bg=text_fg} + local avg_chg = PowerIndicator{parent=mtx_div,x=1,lu_colors=lu_col,label="\xb7Avg:",unit=db.energy_label,format="%8.2f",value=0,width=22,fg_bg=text_fg} + local input = PowerIndicator{parent=mtx_div,x=1,lu_colors=lu_col,label="In: ",unit=db.energy_label,format="%8.2f",rate=true,value=0,width=22,fg_bg=text_fg} + local avg_in = PowerIndicator{parent=mtx_div,x=1,lu_colors=lu_col,label="\xb7Avg:",unit=db.energy_label,format="%8.2f",rate=true,value=0,width=22,fg_bg=text_fg} + local output = PowerIndicator{parent=mtx_div,x=1,lu_colors=lu_col,label="Out: ",unit=db.energy_label,format="%8.2f",rate=true,value=0,width=22,fg_bg=text_fg} + local avg_out = PowerIndicator{parent=mtx_div,x=1,lu_colors=lu_col,label="\xb7Avg:",unit=db.energy_label,format="%8.2f",rate=true,value=0,width=22,fg_bg=text_fg} + + energy.register(ps, "energy", function (val) energy.update(db.energy_convert(val)) end) + avg_chg.register(fac.ps, "avg_charge", avg_chg.update) + input.register(ps, "last_input", function (val) input.update(db.energy_convert(val)) end) + avg_in.register(fac.ps, "avg_inflow", avg_in.update) + output.register(ps, "last_output", function (val) output.update(db.energy_convert(val)) end) + avg_out.register(fac.ps, "avg_outflow", avg_out.update) return matrix_page.nav_to end