From 04c53c7074b652600e675220de5b61cefa3304b2 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sat, 26 Apr 2025 15:24:50 -0400 Subject: [PATCH] #616 pocket pellet color options --- pocket/config/system.lua | 35 ++++++++++++++++++++++------ pocket/configure.lua | 5 +++- pocket/pocket.lua | 2 ++ pocket/startup.lua | 2 +- pocket/ui/apps/waste.lua | 8 +++---- pocket/ui/style.lua | 49 +++++++++++++++++++++++++--------------- 6 files changed, 70 insertions(+), 31 deletions(-) diff --git a/pocket/config/system.lua b/pocket/config/system.lua index 321ef59..110a6cf 100644 --- a/pocket/config/system.lua +++ b/pocket/config/system.lua @@ -53,25 +53,43 @@ function system.create(tool_ctl, main_pane, cfg_sys, divs, style, exit) --#region Pocket UI local ui_c_1 = Div{parent=ui_cfg,x=2,y=4,width=24} + local ui_c_2 = Div{parent=ui_cfg,x=2,y=4,width=24} + + local ui_pane = MultiPane{parent=net_cfg,x=1,y=4,panes={ui_c_1,ui_c_2}} TextBox{parent=ui_cfg,x=1,y=2,text=" Pocket UI",fg_bg=cpair(colors.black,colors.lime)} - TextBox{parent=ui_c_1,x=1,y=1,height=3,text="You may customize units below."} + TextBox{parent=ui_c_1,x=1,y=1,height=3,text="You may customize UI options below."} - TextBox{parent=ui_c_1,x=1,y=4,text="Temperature Scale"} - local temp_scale = RadioButton{parent=ui_c_1,x=1,y=5,default=ini_cfg.TempScale,options=types.TEMP_SCALE_NAMES,callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.lime} + TextBox{parent=ui_c_1,y=4,text="Po/Pu Pellet Color"} + local pellet_color = RadioButton{parent=ui_c_1,y=5,default=util.trinary(ini_cfg.GreenPuPellet,1,2),options={"Green Pu/Cyan Po","Cyan Pu/Green Po"},callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.lime} - TextBox{parent=ui_c_1,x=1,y=10,text="Energy Scale"} - local energy_scale = RadioButton{parent=ui_c_1,x=1,y=11,default=ini_cfg.EnergyScale,options=types.ENERGY_SCALE_NAMES,callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.lime} + TextBox{parent=ui_c_1,y=8,height=4,text="In Mekanism 10.4 and later, pellet colors now match gas colors (Cyan Pu/Green Po).",fg_bg=g_lg_fg_bg} local function submit_ui_opts() + tmp_cfg.GreenPuPellet = pellet_color.get_value() == 1 + ui_pane.set_value(2) + end + + PushButton{parent=ui_c_1,x=1,y=15,text="\x1b Back",callback=function()main_pane.set_value(1)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + PushButton{parent=ui_c_1,x=19,y=15,text="Next \x1a",callback=submit_ui_opts,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + + TextBox{parent=ui_c_2,x=1,y=1,height=3,text="You may customize units below."} + + TextBox{parent=ui_c_2,x=1,y=4,text="Temperature Scale"} + local temp_scale = RadioButton{parent=ui_c_2,x=1,y=5,default=ini_cfg.TempScale,options=types.TEMP_SCALE_NAMES,callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.lime} + + TextBox{parent=ui_c_2,x=1,y=10,text="Energy Scale"} + local energy_scale = RadioButton{parent=ui_c_2,x=1,y=11,default=ini_cfg.EnergyScale,options=types.ENERGY_SCALE_NAMES,callback=function()end,radio_colors=cpair(colors.lightGray,colors.black),select_color=colors.lime} + + local function submit_ui_units() tmp_cfg.TempScale = temp_scale.get_value() tmp_cfg.EnergyScale = energy_scale.get_value() main_pane.set_value(3) end - PushButton{parent=ui_c_1,x=1,y=15,text="\x1b Back",callback=function()main_pane.set_value(1)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} - PushButton{parent=ui_c_1,x=19,y=15,text="Next \x1a",callback=submit_ui_opts,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + PushButton{parent=ui_c_2,x=1,y=15,text="\x1b Back",callback=function()ui_pane.set_value(1)end,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} + PushButton{parent=ui_c_2,x=19,y=15,text="Next \x1a",callback=submit_ui_units,fg_bg=nav_fg_bg,active_fg_bg=btn_act_fg_bg} --#endregion @@ -266,6 +284,7 @@ function system.create(tool_ctl, main_pane, cfg_sys, divs, style, exit) load_settings(settings_cfg, true) load_settings(ini_cfg) + try_set(pellet_color, ini_cfg.GreenPuPellet) try_set(temp_scale, ini_cfg.TempScale) try_set(energy_scale, ini_cfg.EnergyScale) try_set(svr_chan, ini_cfg.SVR_Channel) @@ -374,6 +393,8 @@ function system.create(tool_ctl, main_pane, cfg_sys, divs, style, exit) val = string.rep("*", string.len(val)) elseif f[1] == "LogMode" then val = tri(raw == log.MODE.APPEND, "append", "replace") + elseif f[1] == "GreenPuPellet" then + val = tri(raw, "Green Pu/Cyan Po", "Cyan Pu/Green Po") elseif f[1] == "TempScale" then val = util.strval(types.TEMP_SCALE_NAMES[raw]) elseif f[1] == "EnergyScale" then diff --git a/pocket/configure.lua b/pocket/configure.lua index 175be03..d714d9f 100644 --- a/pocket/configure.lua +++ b/pocket/configure.lua @@ -29,7 +29,8 @@ local CENTER = core.ALIGN.CENTER -- changes to the config data/format to let the user know local changes = { { "v0.9.2", { "Added temperature scale options" } }, - { "v0.11.3", { "Added energy scale options" } } + { "v0.11.3", { "Added energy scale options" } }, + { "v0.13.2", { "Added option for Po/Pu pellet green/cyan pairing" } } } ---@class pkt_configurator @@ -64,6 +65,7 @@ local tool_ctl = { ---@class pkt_config local tmp_cfg = { + GreenPuPellet = false, TempScale = 1, ---@type TEMP_SCALE EnergyScale = 1, ---@type ENERGY_SCALE SVR_Channel = nil, ---@type integer @@ -84,6 +86,7 @@ local settings_cfg = {} -- all settings fields, their nice names, and their default values local fields = { + { "GreenPuPellet", "Pellet Colors", false }, { "TempScale", "Temperature Scale", types.TEMP_SCALE.KELVIN }, { "EnergyScale", "Energy Scale", types.ENERGY_SCALE.FE }, { "SVR_Channel", "SVR Channel", 16240 }, diff --git a/pocket/pocket.lua b/pocket/pocket.lua index 7bfe669..e0e285c 100644 --- a/pocket/pocket.lua +++ b/pocket/pocket.lua @@ -38,6 +38,7 @@ pocket.config = config function pocket.load_config() if not settings.load("/pocket.settings") then return false end + config.GreenPuPellet = settings.get("GreenPuPellet") config.TempScale = settings.get("TempScale") config.EnergyScale = settings.get("EnergyScale") @@ -54,6 +55,7 @@ function pocket.load_config() local cfv = util.new_validator() + cfv.assert_type_bool(config.GreenPuPellet) cfv.assert_type_int(config.TempScale) cfv.assert_range(config.TempScale, 1, 4) cfv.assert_type_int(config.EnergyScale) diff --git a/pocket/startup.lua b/pocket/startup.lua index c1d55ef..a2eddd6 100644 --- a/pocket/startup.lua +++ b/pocket/startup.lua @@ -22,7 +22,7 @@ local pocket = require("pocket.pocket") local renderer = require("pocket.renderer") local threads = require("pocket.threads") -local POCKET_VERSION = "v0.13.1-beta" +local POCKET_VERSION = "v0.13.2-beta" local println = util.println local println_ts = util.println_ts diff --git a/pocket/ui/apps/waste.lua b/pocket/ui/apps/waste.lua index 8037d82..bd39e7c 100644 --- a/pocket/ui/apps/waste.lua +++ b/pocket/ui/apps/waste.lua @@ -95,8 +95,8 @@ local function new_view(root) local function set_waste(mode) process.set_unit_waste(i, mode) end - local waste_prod = StateIndicator{parent=u_div,x=16,y=3,states=style.waste.states_abbrv,value=1,min_width=6} - local waste_mode = RadioButton{parent=u_div,y=3,options=style.waste.unit_opts,callback=set_waste,radio_colors=cpair(colors.lightGray,colors.gray),select_color=colors.white} + local waste_prod = StateIndicator{parent=u_div,x=16,y=3,states=style.get_waste().states_abbrv,value=1,min_width=6} + local waste_mode = RadioButton{parent=u_div,y=3,options=style.get_waste().unit_opts,callback=set_waste,radio_colors=cpair(colors.lightGray,colors.gray),select_color=colors.white} waste_prod.register(u_ps, "U_WasteProduct", waste_prod.update) waste_mode.register(u_ps, "U_WasteMode", waste_mode.set_value) @@ -159,8 +159,8 @@ local function new_view(root) TextBox{parent=c_div,y=1,text="Waste Control",alignment=ALIGN.CENTER} - local status = StateIndicator{parent=c_div,x=3,y=3,states=style.waste.states,value=1,min_width=17} - local waste_prod = RadioButton{parent=c_div,y=5,options=style.waste.options,callback=process.set_process_waste,radio_colors=cpair(colors.lightGray,colors.gray),select_color=colors.white} + local status = StateIndicator{parent=c_div,x=3,y=3,states=style.get_waste().states,value=1,min_width=17} + local waste_prod = RadioButton{parent=c_div,y=5,options=style.get_waste().options,callback=process.set_process_waste,radio_colors=cpair(colors.lightGray,colors.gray),select_color=colors.white} status.register(f_ps, "current_waste_product", status.update) waste_prod.register(f_ps, "process_waste_product", waste_prod.set_value) diff --git a/pocket/ui/style.lua b/pocket/ui/style.lua index 7b35cc4..0c77806 100644 --- a/pocket/ui/style.lua +++ b/pocket/ui/style.lua @@ -2,12 +2,18 @@ -- Graphics Style Options -- -local core = require("graphics.core") +local util = require("scada-common.util") + +local core = require("graphics.core") + +local pocket = require("pocket.pocket") local style = {} local cpair = core.cpair +local config = pocket.config + -- GLOBAL -- style.root = cpair(colors.white, colors.black) @@ -171,22 +177,29 @@ style.sps = { } } -style.waste = { - -- auto waste processing states - states = { - { color = cpair(colors.black, colors.green), text = "PLUTONIUM" }, - { color = cpair(colors.black, colors.cyan), text = "POLONIUM" }, - { color = cpair(colors.black, colors.purple), text = "ANTI MATTER" } - }, - states_abbrv = { - { color = cpair(colors.black, colors.green), text = "Pu" }, - { color = cpair(colors.black, colors.cyan), text = "Po" }, - { color = cpair(colors.black, colors.purple), text = "AM" } - }, - -- process radio button options - options = { "Plutonium", "Polonium", "Antimatter" }, - -- unit waste selection - unit_opts = { "Auto", "Plutonium", "Polonium", "Antimatter" } -} +-- get waste styling, which depends on the configuration +---@return { states: { color: color, text: string }, states_abbrv: { color: color, text: string }, options: string[], unit_opts: string[] } +function style.get_waste() + local pu_color = util.trinary(config.GreenPuPellet, colors.green, colors.cyan) + local po_color = util.trinary(config.GreenPuPellet, colors.cyan, colors.green) + + return { + -- auto waste processing states + states = { + { color = cpair(colors.black, pu_color), text = "PLUTONIUM" }, + { color = cpair(colors.black, po_color), text = "POLONIUM" }, + { color = cpair(colors.black, colors.purple), text = "ANTI MATTER" } + }, + states_abbrv = { + { color = cpair(colors.black, pu_color), text = "Pu" }, + { color = cpair(colors.black, po_color), text = "Po" }, + { color = cpair(colors.black, colors.purple), text = "AM" } + }, + -- process radio button options + options = { "Plutonium", "Polonium", "Antimatter" }, + -- unit waste selection + unit_opts = { "Auto", "Plutonium", "Polonium", "Antimatter" } + } +end return style