From a591cab338d9a36d9ca23322aacc41f6f301dd60 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sun, 11 Dec 2022 10:51:45 -0500 Subject: [PATCH] color reactor coolant bars based on coolant type --- coordinator/startup.lua | 2 +- coordinator/ui/components/reactor.lua | 25 ++++++++++++++++------- coordinator/ui/components/unit_detail.lua | 20 ++++++++++++++++-- graphics/element.lua | 6 ++++++ graphics/elements/indicators/hbar.lua | 4 +++- graphics/elements/indicators/vbar.lua | 4 +++- 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/coordinator/startup.lua b/coordinator/startup.lua index 7417bd6..6cfaa0e 100644 --- a/coordinator/startup.lua +++ b/coordinator/startup.lua @@ -19,7 +19,7 @@ local iocontrol = require("coordinator.iocontrol") local renderer = require("coordinator.renderer") local sounder = require("coordinator.sounder") -local COORDINATOR_VERSION = "beta-v0.8.2" +local COORDINATOR_VERSION = "beta-v0.8.3" local print = util.print local println = util.println diff --git a/coordinator/ui/components/reactor.lua b/coordinator/ui/components/reactor.lua index 1c8978b..d81d662 100644 --- a/coordinator/ui/components/reactor.lua +++ b/coordinator/ui/components/reactor.lua @@ -45,16 +45,27 @@ local function new_view(root, x, y, data, ps) TextBox{parent=reactor_fills,text="HCOOL",x=2,y=4,height=1,fg_bg=text_fg_bg} TextBox{parent=reactor_fills,text="WASTE",x=2,y=5,height=1,fg_bg=text_fg_bg} - -- local ccool_color = util.trinary(data.mek_status.ccool_type == "sodium", cpair(colors.lightBlue,colors.gray), cpair(colors.blue,colors.gray)) - -- local hcool_color = util.trinary(data.mek_status.hcool_type == "superheated_sodium", cpair(colors.orange,colors.gray), cpair(colors.white,colors.gray)) - local ccool_color = util.trinary(true, cpair(colors.lightBlue,colors.gray), cpair(colors.blue,colors.gray)) - local hcool_color = util.trinary(true, cpair(colors.orange,colors.gray), cpair(colors.white,colors.gray)) - local fuel = HorizontalBar{parent=reactor_fills,x=8,y=1,show_percent=true,bar_fg_bg=cpair(colors.black,colors.gray),height=1,width=14} - local ccool = HorizontalBar{parent=reactor_fills,x=8,y=2,show_percent=true,bar_fg_bg=ccool_color,height=1,width=14} - local hcool = HorizontalBar{parent=reactor_fills,x=8,y=4,show_percent=true,bar_fg_bg=hcool_color,height=1,width=14} + local ccool = HorizontalBar{parent=reactor_fills,x=8,y=2,show_percent=true,bar_fg_bg=cpair(colors.blue,colors.gray),height=1,width=14} + local hcool = HorizontalBar{parent=reactor_fills,x=8,y=4,show_percent=true,bar_fg_bg=cpair(colors.white,colors.gray),height=1,width=14} local waste = HorizontalBar{parent=reactor_fills,x=8,y=5,show_percent=true,bar_fg_bg=cpair(colors.brown,colors.gray),height=1,width=14} + ps.subscribe("ccool_type", function (type) + if type == "mekanism:sodium" then + ccool.recolor(cpair(colors.lightBlue, colors.gray)) + else + ccool.recolor(cpair(colors.blue, colors.gray)) + end + end) + + ps.subscribe("hcool_type", function (type) + if type == "mekanism:superheated_sodium" then + hcool.recolor(cpair(colors.orange, colors.gray)) + else + hcool.recolor(cpair(colors.white, colors.gray)) + end + end) + ps.subscribe("fuel_fill", fuel.update) ps.subscribe("ccool_fill", ccool.update) ps.subscribe("hcool_fill", hcool.update) diff --git a/coordinator/ui/components/unit_detail.lua b/coordinator/ui/components/unit_detail.lua index 7a95447..9b3d170 100644 --- a/coordinator/ui/components/unit_detail.lua +++ b/coordinator/ui/components/unit_detail.lua @@ -94,8 +94,8 @@ local function init(parent, id) TextBox{parent=main,text="W",x=29,y=22,width=1,height=1,fg_bg=style.label} local fuel = VerticalBar{parent=main,x=23,y=23,fg_bg=cpair(colors.black,colors.gray),height=4,width=1} - local ccool = VerticalBar{parent=main,x=25,y=23,fg_bg=cpair(colors.lightBlue,colors.gray),height=4,width=1} - local hcool = VerticalBar{parent=main,x=27,y=23,fg_bg=cpair(colors.orange,colors.gray),height=4,width=1} + local ccool = VerticalBar{parent=main,x=25,y=23,fg_bg=cpair(colors.blue,colors.gray),height=4,width=1} + local hcool = VerticalBar{parent=main,x=27,y=23,fg_bg=cpair(colors.white,colors.gray),height=4,width=1} local waste = VerticalBar{parent=main,x=29,y=23,fg_bg=cpair(colors.brown,colors.gray),height=4,width=1} r_ps.subscribe("fuel_fill", fuel.update) @@ -103,6 +103,22 @@ local function init(parent, id) r_ps.subscribe("hcool_fill", hcool.update) r_ps.subscribe("waste_fill", waste.update) + r_ps.subscribe("ccool_type", function (type) + if type == "mekanism:sodium" then + ccool.recolor(cpair(colors.lightBlue, colors.gray)) + else + ccool.recolor(cpair(colors.blue, colors.gray)) + end + end) + + r_ps.subscribe("hcool_type", function (type) + if type == "mekanism:superheated_sodium" then + hcool.recolor(cpair(colors.orange, colors.gray)) + else + hcool.recolor(cpair(colors.white, colors.gray)) + end + end) + TextBox{parent=main,x=32,y=22,text="Core Temp",height=1,width=9,fg_bg=style.label} local core_temp = DataIndicator{parent=main,x=32,label="",format="%11.2f",value=0,unit="K",lu_colors=lu_cpair,width=13,fg_bg=stat_fg_bg} r_ps.subscribe("temp", core_temp.update) diff --git a/graphics/element.lua b/graphics/element.lua index 7bf8b71..32a67a7 100644 --- a/graphics/element.lua +++ b/graphics/element.lua @@ -363,6 +363,12 @@ function element.new(args) protected.disable() end + -- custom recolor command, varies by element if implemented + ---@vararg cpair|color color(s) + function public.recolor(...) + protected.recolor(...) + end + -- resize attributes of the element value if supported ---@vararg number dimensions (element specific) function public.resize(...) diff --git a/graphics/elements/indicators/hbar.lua b/graphics/elements/indicators/hbar.lua index 092d88e..a05cdb6 100644 --- a/graphics/elements/indicators/hbar.lua +++ b/graphics/elements/indicators/hbar.lua @@ -106,7 +106,9 @@ local function hbar(args) -- re-draw last_num_bars = 0 - e.on_update(e.value) + if type(e.value) == "number" then + e.on_update(e.value) + end end -- set the percentage value diff --git a/graphics/elements/indicators/vbar.lua b/graphics/elements/indicators/vbar.lua index f56c60c..be7d9e4 100644 --- a/graphics/elements/indicators/vbar.lua +++ b/graphics/elements/indicators/vbar.lua @@ -89,7 +89,9 @@ local function vbar(args) -- re-draw last_num_bars = 0 - e.on_update(e.value) + if type(e.value) == "number" then + e.on_update(e.value) + end end -- set the percentage value