mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2026-08-23 05:07:51 +01:00
Rewrite RCON UI
This commit is contained in:
committed by
Darlantan
parent
13a0d1b150
commit
ad122fdd96
+12
-1
@@ -462,6 +462,17 @@ GLOBAL_LIST_INIT(all_volume_channels, list(
|
||||
|
||||
#ifndef HTTP_POST_DLL_LOCATION
|
||||
#define HTTP_POST_DLL_LOCATION (world.system_type == MS_WINDOWS ? WINDOWS_HTTP_POST_DLL_LOCATION : UNIX_HTTP_POST_DLL_LOCATION)
|
||||
<<<<<<< HEAD
|
||||
#endif
|
||||
||||||| parent of da19f6f9b3... Merge pull request #10740 from ShadowLarkens/ux_fixes
|
||||
#endif
|
||||
|
||||
#define DOCK_ATTEMPT_TIMEOUT 200 //how long in ticks we wait before assuming the docking controller is broken or blown up.
|
||||
#define DOCK_ATTEMPT_TIMEOUT 200 //how long in ticks we wait before assuming the docking controller is broken or blown up.
|
||||
=======
|
||||
#endif
|
||||
|
||||
#define DOCK_ATTEMPT_TIMEOUT 200 //how long in ticks we wait before assuming the docking controller is broken or blown up.
|
||||
|
||||
#define SMES_TGUI_INPUT 1
|
||||
#define SMES_TGUI_OUTPUT 2
|
||||
>>>>>>> da19f6f9b3... Merge pull request #10740 from ShadowLarkens/ux_fixes
|
||||
|
||||
+53
-34
@@ -375,7 +375,6 @@ GLOBAL_LIST_EMPTY(smeses)
|
||||
return 0
|
||||
return round(100.0*charge/capacity, 0.1)
|
||||
|
||||
|
||||
/obj/machinery/power/smes/tgui_act(action, params)
|
||||
if(..())
|
||||
return TRUE
|
||||
@@ -389,39 +388,30 @@ GLOBAL_LIST_EMPTY(smeses)
|
||||
update_icon()
|
||||
. = TRUE
|
||||
if("input")
|
||||
var/target = params["target"]
|
||||
var/adjust = text2num(params["adjust"])
|
||||
if(target == "min")
|
||||
target = 0
|
||||
. = TRUE
|
||||
else if(target == "max")
|
||||
target = input_level_max
|
||||
. = TRUE
|
||||
else if(adjust)
|
||||
target = input_level + adjust
|
||||
. = TRUE
|
||||
else if(text2num(target) != null)
|
||||
target = text2num(target)
|
||||
. = TRUE
|
||||
if(.)
|
||||
input_level = clamp(target, 0, input_level_max)
|
||||
tgui_set_io(SMES_TGUI_INPUT, params["target"], text2num(params["adjust"]))
|
||||
if("output")
|
||||
var/target = params["target"]
|
||||
var/adjust = text2num(params["adjust"])
|
||||
if(target == "min")
|
||||
target = 0
|
||||
. = TRUE
|
||||
else if(target == "max")
|
||||
target = output_level_max
|
||||
. = TRUE
|
||||
else if(adjust)
|
||||
target = output_level + adjust
|
||||
. = TRUE
|
||||
else if(text2num(target) != null)
|
||||
target = text2num(target)
|
||||
. = TRUE
|
||||
if(.)
|
||||
output_level = clamp(target, 0, output_level_max)
|
||||
tgui_set_io(SMES_TGUI_OUTPUT, params["target"], text2num(params["adjust"]))
|
||||
|
||||
/obj/machinery/power/smes/proc/tgui_set_io(io, target, adjust)
|
||||
if(target == "min")
|
||||
target = 0
|
||||
. = TRUE
|
||||
else if(target == "max")
|
||||
target = output_level_max
|
||||
. = TRUE
|
||||
else if(adjust)
|
||||
target = output_level + adjust
|
||||
. = TRUE
|
||||
else if(text2num(target) != null)
|
||||
target = text2num(target)
|
||||
. = TRUE
|
||||
if(.)
|
||||
switch(io)
|
||||
if(SMES_TGUI_INPUT)
|
||||
set_input(target)
|
||||
if(SMES_TGUI_OUTPUT)
|
||||
set_output(target)
|
||||
|
||||
|
||||
/obj/machinery/power/smes/proc/inputting(var/do_input)
|
||||
input_attempt = do_input
|
||||
@@ -481,4 +471,33 @@ GLOBAL_LIST_EMPTY(smeses)
|
||||
if(25 to 49)
|
||||
. += "<span class='filter_notice'><span class='notice'>It's casing is quite seriously damaged.</span></span>"
|
||||
if(0 to 24)
|
||||
. += "<span class='filter_notice'>It's casing has some minor damage.</span>"
|
||||
. += "<span class='filter_notice'>It's casing has some minor damage.</span>"
|
||||
|
||||
|
||||
// Proc: toggle_input()
|
||||
// Parameters: None
|
||||
// Description: Switches the input on/off depending on previous setting
|
||||
/obj/machinery/power/smes/proc/toggle_input()
|
||||
inputting(!input_attempt)
|
||||
update_icon()
|
||||
|
||||
// Proc: toggle_output()
|
||||
// Parameters: None
|
||||
// Description: Switches the output on/off depending on previous setting
|
||||
/obj/machinery/power/smes/proc/toggle_output()
|
||||
outputting(!output_attempt)
|
||||
update_icon()
|
||||
|
||||
// Proc: set_input()
|
||||
// Parameters: 1 (new_input - New input value in Watts)
|
||||
// Description: Sets input setting on this SMES. Trims it if limits are exceeded.
|
||||
/obj/machinery/power/smes/proc/set_input(var/new_input = 0)
|
||||
input_level = between(0, new_input, input_level_max)
|
||||
update_icon()
|
||||
|
||||
// Proc: set_output()
|
||||
// Parameters: 1 (new_output - New output value in Watts)
|
||||
// Description: Sets output setting on this SMES. Trims it if limits are exceeded.
|
||||
/obj/machinery/power/smes/proc/set_output(var/new_output = 0)
|
||||
output_level = between(0, new_output, output_level_max)
|
||||
update_icon()
|
||||
@@ -361,31 +361,3 @@
|
||||
recalc_coils()
|
||||
else
|
||||
to_chat(user, "<font color='red'>You can't insert more coils into this SMES unit!</font>")
|
||||
|
||||
// Proc: toggle_input()
|
||||
// Parameters: None
|
||||
// Description: Switches the input on/off depending on previous setting
|
||||
/obj/machinery/power/smes/buildable/proc/toggle_input()
|
||||
inputting(!input_attempt)
|
||||
update_icon()
|
||||
|
||||
// Proc: toggle_output()
|
||||
// Parameters: None
|
||||
// Description: Switches the output on/off depending on previous setting
|
||||
/obj/machinery/power/smes/buildable/proc/toggle_output()
|
||||
outputting(!output_attempt)
|
||||
update_icon()
|
||||
|
||||
// Proc: set_input()
|
||||
// Parameters: 1 (new_input - New input value in Watts)
|
||||
// Description: Sets input setting on this SMES. Trims it if limits are exceeded.
|
||||
/obj/machinery/power/smes/buildable/proc/set_input(var/new_input = 0)
|
||||
input_level = between(0, new_input, input_level_max)
|
||||
update_icon()
|
||||
|
||||
// Proc: set_output()
|
||||
// Parameters: 1 (new_output - New output value in Watts)
|
||||
// Description: Sets output setting on this SMES. Trims it if limits are exceeded.
|
||||
/obj/machinery/power/smes/buildable/proc/set_output(var/new_output = 0)
|
||||
output_level = between(0, new_output, output_level_max)
|
||||
update_icon()
|
||||
@@ -12,17 +12,9 @@
|
||||
// SMES DATA (simplified view)
|
||||
var/list/smeslist[0]
|
||||
for(var/obj/machinery/power/smes/buildable/SMES in known_SMESs)
|
||||
smeslist.Add(list(list(
|
||||
"capacity" = SMES.capacity,
|
||||
"capacityPercent" = round(100*SMES.charge/SMES.capacity, 0.1),
|
||||
"charge" = SMES.charge,
|
||||
"input_set" = SMES.input_attempt,
|
||||
"input_val" = round(SMES.input_level/1000, 0.1),
|
||||
"output_set" = SMES.output_attempt,
|
||||
"output_val" = round(SMES.output_level/1000, 0.1),
|
||||
"output_load" = round(SMES.output_used/1000, 0.1),
|
||||
"RCON_tag" = SMES.RCon_tag
|
||||
)))
|
||||
var/list/smes_data = SMES.tgui_data()
|
||||
smes_data["RCON_tag"] = SMES.RCon_tag
|
||||
smeslist.Add(list(smes_data))
|
||||
|
||||
data["smes_info"] = sortByKey(smeslist, "RCON_tag")
|
||||
|
||||
@@ -55,14 +47,16 @@
|
||||
if("smes_in_set")
|
||||
var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(params["smes"])
|
||||
if(SMES)
|
||||
var/inputset = (input(usr, "Enter new input level (0-[SMES.input_level_max/1000] kW)", "SMES Input Power Control", SMES.input_level/1000) as num) * 1000
|
||||
SMES.set_input(inputset)
|
||||
SMES.tgui_set_io(SMES_TGUI_INPUT, params["target"], text2num(params["adjust"]))
|
||||
// var/inputset = (input(usr, "Enter new input level (0-[SMES.input_level_max/1000] kW)", "SMES Input Power Control", SMES.input_level/1000) as num) * 1000
|
||||
// SMES.set_input(inputset)
|
||||
. = TRUE
|
||||
if("smes_out_set")
|
||||
var/obj/machinery/power/smes/buildable/SMES = GetSMESByTag(params["smes"])
|
||||
if(SMES)
|
||||
var/outputset = (input(usr, "Enter new output level (0-[SMES.output_level_max/1000] kW)", "SMES Output Power Control", SMES.output_level/1000) as num) * 1000
|
||||
SMES.set_output(outputset)
|
||||
SMES.tgui_set_io(SMES_TGUI_OUTPUT, params["target"], text2num(params["adjust"]))
|
||||
// var/outputset = (input(usr, "Enter new output level (0-[SMES.output_level_max/1000] kW)", "SMES Output Power Control", SMES.output_level/1000) as num) * 1000
|
||||
// SMES.set_output(outputset)
|
||||
. = TRUE
|
||||
if("toggle_breaker")
|
||||
var/obj/machinery/power/breakerbox/toggle = null
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { round } from 'common/math';
|
||||
import { formatPower } from '../format';
|
||||
import { Fragment } from 'inferno';
|
||||
import { useBackend, useLocalState } from "../backend";
|
||||
import { Box, Button, Flex, Icon, LabeledList, ProgressBar, Section, Tabs } from "../components";
|
||||
import { Box, Button, Flex, Icon, LabeledList, ProgressBar, Stack, Section, Tabs, Slider, AnimatedNumber } from "../components";
|
||||
import { Window } from "../layouts";
|
||||
import { capitalize } from 'common/string';
|
||||
|
||||
// Common power multiplier
|
||||
const POWER_MUL = 1e3;
|
||||
|
||||
|
||||
export const RCON = (props, context) => {
|
||||
return (
|
||||
@@ -59,76 +65,194 @@ const RCONSmesList = (props, context) => {
|
||||
|
||||
return (
|
||||
<Section title="SMESs">
|
||||
<LabeledList>
|
||||
{smes_info ? smes_info.map(smes => (
|
||||
<LabeledList.Item key={smes.RCON_tag} label={smes.RCON_tag}>
|
||||
<Box mb={1}>
|
||||
<ProgressBar
|
||||
value={smes.capacityPercent * 0.01}
|
||||
ranges={{
|
||||
good: [0.5, Infinity],
|
||||
average: [0.15, 0.5],
|
||||
bad: [-Infinity, 0.15],
|
||||
}}>
|
||||
{
|
||||
round(smes.charge/(1000*60), 1)
|
||||
} kWh / {
|
||||
round(smes.capacity/(1000*60))
|
||||
} kWh ({smes.capacityPercent}%)
|
||||
</ProgressBar>
|
||||
</Box>
|
||||
<LabeledList>
|
||||
<LabeledList.Item
|
||||
label="Input"
|
||||
buttons={(
|
||||
<Fragment>
|
||||
<Button
|
||||
icon="power-off"
|
||||
onClick={() => act("smes_in_toggle", {
|
||||
smes: smes.RCON_tag,
|
||||
})} />
|
||||
<Button
|
||||
icon="pen"
|
||||
onClick={() => act("smes_in_set", {
|
||||
smes: smes.RCON_tag,
|
||||
})} />
|
||||
</Fragment>
|
||||
)}>
|
||||
{smes.input_val} kW - {smes.input_set ? "ON" : "OFF"}
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item
|
||||
label="Output"
|
||||
buttons={(
|
||||
<Fragment>
|
||||
<Button
|
||||
icon="power-off"
|
||||
onClick={() => act("smes_out_toggle", {
|
||||
smes: smes.RCON_tag,
|
||||
})} />
|
||||
<Button
|
||||
icon="pen"
|
||||
onClick={() => act("smes_out_set", {
|
||||
smes: smes.RCON_tag,
|
||||
})} />
|
||||
</Fragment>
|
||||
)}>
|
||||
{smes.output_val} kW - {smes.output_set ? "ONLINE" : "OFFLINE"}
|
||||
</LabeledList.Item>
|
||||
<LabeledList.Item label="Output Load">
|
||||
{smes.output_load} kW
|
||||
</LabeledList.Item>
|
||||
</LabeledList>
|
||||
</LabeledList.Item>
|
||||
)) : (
|
||||
<LabeledList.Item color="bad">
|
||||
No SMESs detected.
|
||||
</LabeledList.Item>
|
||||
)}
|
||||
</LabeledList>
|
||||
<Stack vertical>
|
||||
{smes_info.map(smes => (
|
||||
<Stack.Item key={smes.RCON_tag}>
|
||||
<SMESItem smes={smes} />
|
||||
</Stack.Item>
|
||||
))}
|
||||
</Stack>
|
||||
</Section>
|
||||
);
|
||||
};
|
||||
|
||||
const SMESItem = (props, context) => {
|
||||
const { act } = useBackend(context);
|
||||
const {
|
||||
capacityPercent,
|
||||
capacity,
|
||||
charge,
|
||||
inputAttempt,
|
||||
inputting,
|
||||
inputLevel,
|
||||
inputLevelMax,
|
||||
inputAvailable,
|
||||
outputAttempt,
|
||||
outputting,
|
||||
outputLevel,
|
||||
outputLevelMax,
|
||||
outputUsed,
|
||||
RCON_tag,
|
||||
} = props.smes;
|
||||
|
||||
return (
|
||||
<Stack vertical>
|
||||
<Stack.Item>
|
||||
<Stack fill justify="space-between">
|
||||
<Stack.Item flexBasis="40%" fontSize={1.2}>
|
||||
{RCON_tag}
|
||||
</Stack.Item>
|
||||
<Stack.Item grow={1}>
|
||||
<ProgressBar
|
||||
value={capacityPercent * 0.01}
|
||||
ranges={{
|
||||
good: [0.5, Infinity],
|
||||
average: [0.15, 0.5],
|
||||
bad: [-Infinity, 0.15],
|
||||
}}>
|
||||
{round(charge/(1000*60), 1)} kWh / {round(capacity/(1000*60))} kWh
|
||||
({capacityPercent}%)
|
||||
</ProgressBar>
|
||||
</Stack.Item>
|
||||
</Stack>
|
||||
</Stack.Item>
|
||||
<Stack.Item>
|
||||
<SMESControls smes={props.smes} way="input" />
|
||||
</Stack.Item>
|
||||
<Stack.Item>
|
||||
<SMESControls smes={props.smes} way="output" />
|
||||
</Stack.Item>
|
||||
<Stack.Divider />
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
const SMESControls = (props, context) => {
|
||||
const { act } = useBackend(context);
|
||||
const {
|
||||
way,
|
||||
smes,
|
||||
} = props;
|
||||
const {
|
||||
capacityPercent,
|
||||
capacity,
|
||||
charge,
|
||||
inputAttempt,
|
||||
inputting,
|
||||
inputLevel,
|
||||
inputLevelMax,
|
||||
inputAvailable,
|
||||
outputAttempt,
|
||||
outputting,
|
||||
outputLevel,
|
||||
outputLevelMax,
|
||||
outputUsed,
|
||||
RCON_tag,
|
||||
} = smes;
|
||||
|
||||
let level;
|
||||
let levelMax;
|
||||
let available;
|
||||
let direction;
|
||||
let changeStatusAct;
|
||||
let changeAmountAct;
|
||||
let enabled;
|
||||
let powerColor;
|
||||
let powerTooltip;
|
||||
|
||||
switch (way) {
|
||||
case "input":
|
||||
level = inputLevel;
|
||||
levelMax = inputLevelMax;
|
||||
available = inputAvailable;
|
||||
direction = "IN";
|
||||
changeStatusAct = "smes_in_toggle";
|
||||
changeAmountAct = "smes_in_set";
|
||||
enabled = inputAttempt;
|
||||
powerColor = !inputAttempt ? null : (inputting ? "green" : "yellow");
|
||||
powerTooltip = !inputAttempt ? "The SMES input is off." : (inputting ? "The SMES is drawing power." : "The SMES lacks power.");
|
||||
break;
|
||||
case "output":
|
||||
level = outputLevel;
|
||||
levelMax = outputLevelMax;
|
||||
available = outputUsed;
|
||||
direction = "OUT";
|
||||
changeStatusAct = "smes_out_toggle";
|
||||
changeAmountAct = "smes_out_set";
|
||||
enabled = outputAttempt;
|
||||
powerColor = !outputAttempt ? null : (outputting ? "green" : "yellow");
|
||||
powerTooltip = !outputAttempt ? "The SMES output is off." : (outputting ? "The SMES is outputting power." : "The SMES lacks any draw.");
|
||||
break;
|
||||
}
|
||||
|
||||
return (
|
||||
<Stack fill>
|
||||
<Stack.Item basis="20%">
|
||||
{capitalize(way)}
|
||||
</Stack.Item>
|
||||
<Stack.Item grow={1}>
|
||||
<Stack>
|
||||
<Stack.Item>
|
||||
<Button
|
||||
icon="power-off"
|
||||
color={powerColor}
|
||||
tooltip={powerTooltip}
|
||||
onClick={() => act(changeStatusAct, {
|
||||
smes: RCON_tag,
|
||||
})} />
|
||||
</Stack.Item>
|
||||
<Stack.Item>
|
||||
<Button
|
||||
icon="fast-backward"
|
||||
disabled={level === 0}
|
||||
onClick={() => act(changeAmountAct, {
|
||||
target: 'min',
|
||||
smes: RCON_tag,
|
||||
})} />
|
||||
<Button
|
||||
icon="backward"
|
||||
disabled={level === 0}
|
||||
onClick={() => act(changeAmountAct, {
|
||||
adjust: -10000,
|
||||
smes: RCON_tag,
|
||||
})} />
|
||||
</Stack.Item>
|
||||
<Stack.Item grow={1}>
|
||||
<Slider
|
||||
value={level / POWER_MUL}
|
||||
fillValue={available / POWER_MUL}
|
||||
minValue={0}
|
||||
maxValue={levelMax / POWER_MUL}
|
||||
step={5}
|
||||
stepPixelSize={4}
|
||||
format={value => formatPower(available, 1) + "/" + formatPower(value * POWER_MUL, 1)}
|
||||
onDrag={(e, value) => act(changeAmountAct, {
|
||||
target: value * POWER_MUL,
|
||||
smes: RCON_tag,
|
||||
})} />
|
||||
</Stack.Item>
|
||||
<Stack.Item>
|
||||
<Button
|
||||
icon="forward"
|
||||
disabled={level === levelMax}
|
||||
onClick={() => act(changeAmountAct, {
|
||||
adjust: 10000,
|
||||
smes: RCON_tag,
|
||||
})} />
|
||||
<Button
|
||||
icon="fast-forward"
|
||||
disabled={level === levelMax}
|
||||
onClick={() => act(changeAmountAct, {
|
||||
target: 'max',
|
||||
smes: RCON_tag,
|
||||
})} />
|
||||
</Stack.Item>
|
||||
</Stack>
|
||||
</Stack.Item>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
const RCONBreakerList = (props, context) => {
|
||||
const { act, data } = useBackend(context);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user