Makes the Shield Capacitor UI into a TGUI. (#17719)

* Makes the Shield Capacitor UI into a TGUI.

* Update code/modules/shieldgen/shield_capacitor.dm

Co-authored-by: SleepyGemmy <99297919+SleepyGemmy@users.noreply.github.com>

---------

Co-authored-by: Matt Atlas <liermattia@gmail.com>
Co-authored-by: SleepyGemmy <99297919+SleepyGemmy@users.noreply.github.com>
This commit is contained in:
Matt Atlas
2023-11-06 17:48:49 +01:00
committed by GitHub
parent 97db278cab
commit 91cff3d0a9
3 changed files with 165 additions and 52 deletions
+40 -52
View File
@@ -1,25 +1,25 @@
//---------- shield capacitor
//pulls energy out of a power net and charges an adjacent generator
/obj/machinery/shield_capacitor
name = "shield capacitor"
desc = "Machine that charges a shield generator."
icon = 'icons/obj/machinery/shielding.dmi'
icon_state = "capacitor"
obj_flags = OBJ_FLAG_ROTATABLE
var/active = FALSE
density = TRUE
var/stored_charge = 0 //not to be confused with power cell charge, this is in Joules
/// Doesn't use APC power.
use_power = POWER_USE_OFF
req_one_access = list(access_captain, access_security, access_engine)
var/active = FALSE
/// Not to be confused with power cell charge, this is in Joules.
var/stored_charge = 0
var/last_stored_charge = 0
var/time_since_fail = 100
var/max_charge = 8e6 //8 MJ
var/max_charge_rate = 400000 //400 kW
var/locked = FALSE
use_power = POWER_USE_OFF //doesn't use APC power
var/charge_rate = 100000 //100 kW
var/obj/machinery/shield_gen/owned_gen
req_one_access = list(access_captain, access_security, access_engine)
/obj/machinery/shield_capacitor/Initialize()
..()
@@ -68,36 +68,40 @@
/obj/machinery/shield_capacitor/attack_hand(mob/user)
if(stat & (BROKEN))
return
interact(user)
ui_interact(user)
/obj/machinery/shield_capacitor/interact(mob/user)
if ( !in_range(src, user) || (stat & (BROKEN)) )
if (!issilicon(user))
user.unset_machine()
user << browse(null, "window=shield_capacitor")
return
var/t = "<B>Shield Capacitor Control Console</B><br><br>"
if(locked)
t += "<i>Swipe your ID card to begin.</i>"
else
t += "This capacitor is: [active ? "<font color=green>Online</font>" : "<font color=red>Offline</font>" ] <a href='?src=\ref[src];toggle=1'>[active ? "\[Deactivate\]" : "\[Activate\]"]</a><br>"
t += "Capacitor Status: [time_since_fail > 2 ? "<font color=green>OK.</font>" : "<font color=red>Discharging!</font>"]<br>"
t += "Stored Energy: [round(stored_charge/1000, 0.1)] kJ ([100 * round(stored_charge/max_charge, 0.1)]%)<br>"
t += "Charge Rate: \
<a href='?src=\ref[src];charge_rate=-100000'>\[----\]</a> \
<a href='?src=\ref[src];charge_rate=-10000'>\[---\]</a> \
<a href='?src=\ref[src];charge_rate=-1000'>\[--\]</a> \
<a href='?src=\ref[src];charge_rate=-100'>\[-\]</a>[charge_rate] W \
<a href='?src=\ref[src];charge_rate=100'>\[+\]</a> \
<a href='?src=\ref[src];charge_rate=1000'>\[++\]</a> \
<a href='?src=\ref[src];charge_rate=10000'>\[+++\]</a> \
<a href='?src=\ref[src];charge_rate=100000'>\[+++\]</a><br>"
t += "<hr>"
t += "<A href='?src=\ref[src]'>Refresh</A> "
t += "<A href='?src=\ref[src];close=1'>Close</A><BR>"
/obj/machinery/shield_capacitor/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "ShieldCapacitor", "Shield Capacitor", 400, 300)
ui.open()
user << browse(t, "window=shield_capacitor;size=500x400")
user.set_machine(src)
/obj/machinery/shield_capacitor/ui_data(mob/user)
var/list/data = list()
data["anchored"] = anchored
data["locked"] = locked
data["active"] = active
data["time_since_fail"] = time_since_fail
data["charge_rate"] = charge_rate
data["stored_charge"] = stored_charge
data["max_charge"] = max_charge
data["max_charge_rate"] = max_charge_rate
return data
/obj/machinery/shield_capacitor/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return
switch(action)
if("toggle")
if(!active && !anchored)
to_chat(usr, SPAN_WARNING("\The [src] needs to be firmly secured to the floor first."))
return
active = !active
. = TRUE
if("charge_rate")
charge_rate = between(10000, params["charge_rate"], max_charge_rate)
. = TRUE
/obj/machinery/shield_capacitor/process()
if (!anchored)
@@ -126,22 +130,6 @@
time_since_fail = 0 //losing charge faster than we can draw from PN
last_stored_charge = stored_charge
/obj/machinery/shield_capacitor/Topic(href, href_list[])
..()
if( href_list["close"] )
usr << browse(null, "window=shield_capacitor")
usr.unset_machine()
return
if( href_list["toggle"] )
if(!active && !anchored)
to_chat(usr, "<span class='warning'>The [src] needs to be firmly secured to the floor first.</span>")
return
active = !active
if( href_list["charge_rate"] )
charge_rate = between(10000, charge_rate + text2num(href_list["charge_rate"]), max_charge_rate)
updateDialog()
/obj/machinery/shield_capacitor/power_change()
if(stat & BROKEN)
icon_state = "broke"
+41
View File
@@ -0,0 +1,41 @@
################################
# Example Changelog File
#
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
#
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
# When it is, any changes listed below will disappear.
#
# Valid Prefixes:
# bugfix
# wip (For works in progress)
# tweak
# soundadd
# sounddel
# rscadd (general adding of nice things)
# rscdel (general deleting of nice things)
# imageadd
# imagedel
# maptweak
# spellcheck (typo fixes)
# experiment
# balance
# admin
# backend
# security
# refactor
#################################
# Your name.
author: MattAtlas
# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
delete-after: True
# Any changes you've made. See valid prefix list above.
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
# SCREW THIS UP AND IT WON'T WORK.
# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries.
# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog.
changes:
- rscadd: "Made the Shield Capacitor UI into a TGUI."
@@ -0,0 +1,84 @@
import { BooleanLike } from '../../common/react';
import { useBackend } from '../backend';
import { Box, Button, LabeledList, NoticeBox, NumberInput, ProgressBar, Section } from '../components';
import { Window } from '../layouts';
export type CapacitorData = {
anchored: BooleanLike;
locked: BooleanLike;
active: BooleanLike;
time_since_fail: number;
charge_rate: number;
stored_charge: number;
max_charge: number;
max_charge_rate: number;
};
export const ShieldCapacitor = (props, context) => {
const { act, data } = useBackend<CapacitorData>(context);
return (
<Window resizable theme="hephaestus">
<Window.Content scrollable>
<Section>
{data.locked ? (
<NoticeBox>Swipe ID to unlock.</NoticeBox>
) : (
<CapacitorWindow />
)}
</Section>
</Window.Content>
</Window>
);
};
export const CapacitorWindow = (props, context) => {
const { act, data } = useBackend<CapacitorData>(context);
return (
<Section
title="Shield Capacitor"
buttons={
<Button
content={data.active ? 'Online' : 'Offline'}
color={data.active ? 'good' : 'bad'}
icon={data.active ? 'power-off' : 'times'}
disabled={!data.anchored && !data.active}
onClick={() => act('toggle')}
/>
}>
<Box fontSize={1.5}>
Capacitor status:{' '}
<Box as="span" bold color={data.time_since_fail > 2 ? 'good' : 'bad'}>
{data.time_since_fail > 2 ? 'OK' : 'Discharging'}.
</Box>
</Box>
<LabeledList>
<LabeledList.Item label="Stored Charge">
<ProgressBar
ranges={{
good: [data.max_charge * 0.75, data.max_charge],
average: [data.max_charge * 0.3, data.max_charge * 0.75],
bad: [0, data.max_charge * 0.3],
}}
value={data.stored_charge}
minValue={0}
maxValue={data.max_charge}>
{data.stored_charge} / {data.max_charge} W
</ProgressBar>
</LabeledList.Item>
<LabeledList.Item label="Charge Rate">
<NumberInput
value={data.charge_rate}
minValue={0}
maxValue={data.max_charge_rate}
step={10000}
stepPixelSize={3}
onDrag={(e, v) => act('charge_rate', { charge_rate: v })}
unit="W"
/>
</LabeledList.Item>
</LabeledList>
</Section>
);
};