tgui portable scrubber

This commit is contained in:
SteelSlayer
2020-09-19 09:47:19 -05:00
parent 9a50149fa2
commit c8f8b21eef
7 changed files with 276 additions and 132 deletions
@@ -274,3 +274,10 @@
return
else
return ..()
#undef FILTER_NOTHING
#undef FILTER_TOXINS
#undef FILTER_OXYGEN
#undef FILTER_NITROGEN
#undef FILTER_CO2
#undef FILTER_N2O
+4
View File
@@ -176,3 +176,7 @@
return TRUE
add_fingerprint(usr)
#undef MAX_TARGET_PRESSURE
#undef DIRECTION_IN
#undef DIRECTION_OUT
+57 -55
View File
@@ -1,18 +1,18 @@
#define MAX_RATE 10 * ONE_ATMOSPHERE
/obj/machinery/portable_atmospherics/scrubber
name = "Portable Air Scrubber"
icon = 'icons/obj/atmos.dmi'
icon_state = "pscrubber:0"
density = 1
var/on = 0
var/volume_rate = 800
var/widenet = 0 //is this scrubber acting on the 3x3 area around it.
density = TRUE
volume = 750
var/minrate = 0//probably useless, but whatever
var/maxrate = 10 * ONE_ATMOSPHERE
/// Whether the scrubber is switched on or off.
var/on = FALSE
/// The volume of gas that can be scrubbed every time `process_atmos()` is called (0.5 seconds).
var/volume_rate = 101.325
/// Is this scrubber acting on the 3x3 area around it.
var/widenet = FALSE
/obj/machinery/portable_atmospherics/scrubber/emp_act(severity)
if(stat & (BROKEN|NOPOWER))
@@ -26,7 +26,7 @@
..(severity)
/obj/machinery/portable_atmospherics/scrubber/update_icon()
src.overlays = 0
overlays = 0
if(on)
icon_state = "pscrubber:1"
@@ -53,7 +53,7 @@
for(var/turf/simulated/tile in T.GetAtmosAdjacentTurfs(alldir=1))
scrub(tile)
/obj/machinery/portable_atmospherics/scrubber/proc/scrub(var/turf/simulated/tile)
/obj/machinery/portable_atmospherics/scrubber/proc/scrub(turf/simulated/tile)
var/datum/gas_mixture/environment
if(holding)
environment = holding.air_contents
@@ -99,62 +99,62 @@
/obj/machinery/portable_atmospherics/scrubber/return_air()
return air_contents
/obj/machinery/portable_atmospherics/scrubber/attack_ai(var/mob/user as mob)
src.add_hiddenprint(user)
return src.attack_hand(user)
/obj/machinery/portable_atmospherics/scrubber/attack_ai(mob/user)
add_hiddenprint(user)
return attack_hand(user)
/obj/machinery/portable_atmospherics/scrubber/attack_ghost(var/mob/user as mob)
return src.attack_hand(user)
/obj/machinery/portable_atmospherics/scrubber/attack_ghost(mob/user)
return attack_hand(user)
/obj/machinery/portable_atmospherics/scrubber/attack_hand(var/mob/user as mob)
ui_interact(user)
/obj/machinery/portable_atmospherics/scrubber/attack_hand(mob/user)
tgui_interact(user)
return
/obj/machinery/portable_atmospherics/scrubber/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/topic_state/state = GLOB.physical_state)
// update the ui if it exists, returns null if no ui is passed/found
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, force_open)
/obj/machinery/portable_atmospherics/scrubber/tgui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/tgui_state/state = GLOB.tgui_default_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
// the ui does not exist, so we'll create a new() one
// for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm
ui = new(user, src, ui_key, "portscrubber.tmpl", "Portable Scrubber", 480, 400, state = state)
// open the new ui window
ui = new(user, src, ui_key, "PortableScrubber", "Portable Scrubber", 433, 346, master_ui, state)
ui.open()
// auto update every Master Controller tick
ui.set_auto_update(1)
ui.set_autoupdate(TRUE)
/obj/machinery/portable_atmospherics/scrubber/ui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.physical_state)
var/data[0]
data["portConnected"] = connected_port ? 1 : 0
data["tankPressure"] = round(air_contents.return_pressure() > 0 ? air_contents.return_pressure() : 0)
data["rate"] = round(volume_rate)
data["minrate"] = round(minrate)
data["maxrate"] = round(maxrate)
data["on"] = on ? 1 : 0
data["hasHoldingTank"] = holding ? 1 : 0
/obj/machinery/portable_atmospherics/scrubber/tgui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.physical_state)
var/list/data = list(
"on" = on,
"port_connected" = connected_port ? TRUE : FALSE,
"max_rate" = MAX_RATE,
"rate" = round(volume_rate, 0.001),
"tank_pressure" = air_contents.return_pressure() > 0 ? round(air_contents.return_pressure(), 0.001) : 0
)
if(holding)
data["holdingTank"] = list("name" = holding.name, "tankPressure" = round(holding.air_contents.return_pressure() > 0 ? holding.air_contents.return_pressure() : 0))
data["has_holding_tank"] = TRUE
data["holding_tank"] = list("name" = holding.name, "tank_pressure" = holding.air_contents.return_pressure() > 0 ? round(holding.air_contents.return_pressure(), 0.001) : 0)
else
data["has_holding_tank"] = FALSE
return data
/obj/machinery/portable_atmospherics/scrubber/Topic(href, href_list)
/obj/machinery/portable_atmospherics/scrubber/tgui_act(action, list/params)
if(..())
return 1
return
if(href_list["power"])
on = !on
update_icon()
switch(action)
if("power")
on = !on
update_icon()
return TRUE
if(href_list["remove_tank"])
if(holding)
holding.loc = loc
holding = null
if("remove_tank")
if(holding)
holding.forceMove(get_turf(src))
holding = null
update_icon()
return TRUE
if(href_list["volume_adj"])
var/diff = text2num(href_list["volume_adj"])
volume_rate = clamp(volume_rate+diff, minrate, maxrate)
if("set_rate")
volume_rate = clamp(text2num(params["rate"]), 0, MAX_RATE)
return TRUE
src.add_fingerprint(usr)
add_fingerprint(usr)
/obj/machinery/portable_atmospherics/scrubber/huge
name = "Huge Air Scrubber"
@@ -175,18 +175,18 @@
name = "[name] (ID [id])"
/obj/machinery/portable_atmospherics/scrubber/huge/attack_hand(var/mob/user as mob)
/obj/machinery/portable_atmospherics/scrubber/huge/attack_hand(mob/user)
to_chat(usr, "<span class='warning'>You can't directly interact with this machine. Use the area atmos computer.</span>")
/obj/machinery/portable_atmospherics/scrubber/huge/update_icon()
src.overlays = 0
overlays = 0
if(on)
icon_state = "scrubber:1"
else
icon_state = "scrubber:0"
/obj/machinery/portable_atmospherics/scrubber/huge/attackby(var/obj/item/W as obj, var/mob/user as mob, params)
/obj/machinery/portable_atmospherics/scrubber/huge/attackby(obj/item/W, mob/user, params)
if((istype(W, /obj/item/analyzer)) && get_dist(user, src) <= 1)
atmosanalyzer_scan(air_contents, user)
return
@@ -208,3 +208,5 @@
/obj/machinery/portable_atmospherics/scrubber/huge/stationary
name = "Stationary Air Scrubber"
stationary = 1
#undef MAX_RATE
-74
View File
@@ -1,74 +0,0 @@
<h3>Scrubber Status</h3>
<div class="item">
<div class="itemLabel">
Tank Pressure:
</div>
<div class="itemContent">
{{:helper.smoothRound(data.tankPressure)}} kPa
</div>
</div>
<div class="item">
<div class="itemLabel">
Port Status:
</div>
<div class="itemContent">
{{:data.portConnected ? '<span class="good">Connected</span>' : '<span class="average">Disconnected</span>'}}
</div>
</div>
<h3>Holding Tank Status</h3>
{{if data.hasHoldingTank}}
<div class="item">
<div class="itemLabel">
Tank Label:
</div>
<div class="itemContent">
<div style="float: left; width: 180px;">{{:data.holdingTank.name}}</div> {{:helper.link('Eject', 'eject', {'remove_tank' : 1})}}
</div>
</div>
<div class="item">
<div class="itemLabel">
Tank Pressure:
</div>
<div class="itemContent">
{{:helper.smoothRound(data.holdingTank.tankPressure)}} kPa
</div>
</div>
{{else}}
<div class="item"><span class="average"><i>No holding tank inserted.</i></span></div>
<div class="item">&nbsp;</div>
{{/if}}
<h3>Power Regulator Status</h3>
<div class="item">
<div class="itemLabel">
Volume Rate:
</div>
<div class="itemContent">
{{:helper.displayBar(data.rate, data.minrate, data.maxrate)}}
<div style="clear: both; padding-top: 4px;">
{{:helper.link('-', null, {'volume_adj' : -1000}, (data.rate > data.minrate) ? null : 'disabled')}}
{{:helper.link('-', null, {'volume_adj' : -100}, (data.rate > data.minrate) ? null : 'disabled')}}
{{:helper.link('-', null, {'volume_adj' : -10}, (data.rate > data.minrate) ? null : 'disabled')}}
{{:helper.link('-', null, {'volume_adj' : -1}, (data.rate > data.minrate) ? null : 'disabled')}}
<div style="float: left; width: 80px; text-align: center;">&nbsp;{{:data.rate}} kPa&nbsp;</div>
{{:helper.link('+', null, {'volume_adj' : 1}, (data.rate < data.maxrate) ? null : 'disabled')}}
{{:helper.link('+', null, {'volume_adj' : 10}, (data.rate < data.maxrate) ? null : 'disabled')}}
{{:helper.link('+', null, {'volume_adj' : 100}, (data.rate < data.maxrate) ? null : 'disabled')}}
{{:helper.link('+', null, {'volume_adj' : 1000}, (data.rate < data.maxrate) ? null : 'disabled')}}
</div>
</div>
</div>
<div class="item">
<div class="itemLabel">
Power Switch:
</div>
<div class="itemContent">
{{:helper.link('On', 'unlock', {'power' : 1}, data.on ? 'selected' : null)}}{{:helper.link('Off', 'lock', {'power' : 1}, data.on ? null : 'selected')}}
</div>
</div>
@@ -7,7 +7,7 @@ export const PortablePump = (props, context) => {
const { has_holding_tank } = data;
return (
<Window resizable>
<Window>
<Window.Content>
<PumpSettings />
<PressureSettings />
@@ -0,0 +1,205 @@
import { useBackend } from "../backend";
import { Button, Section, LabeledList, Slider, Box, ProgressBar, Flex } from "../components";
import { Window } from "../layouts";
export const PortableScrubber = (props, context) => {
const { act, data } = useBackend(context);
const { has_holding_tank } = data;
return (
<Window>
<Window.Content>
<PumpSettings />
<PressureSettings />
{has_holding_tank ? (
<HoldingTank />
) : (
<Section title="Holding Tank">
<Box color="average" bold={1}>
No Holding Tank Inserted.
</Box>
</Section>
)}
</Window.Content>
</Window>
);
};
const PumpSettings = (props, context) => {
const { act, data } = useBackend(context);
const {
on,
port_connected,
} = data;
return (
<Section title="Pump Settings">
<Flex>
<Flex.Item
mb={2.5}
mt={0.5}
mr={11.9}
color="label">
Power:
</Flex.Item>
<Flex.Item>
<Button
icon={on ? "power-off" : "power-off"}
content={on ? "On" : "Off"}
color={on ? null : "red"}
selected={on}
onClick={() => act('power')} />
</Flex.Item>
</Flex>
<Flex>
<Flex.Item
mr={6.8}
color="label">
Port Status:
</Flex.Item>
<Flex.Item
color={port_connected ? "green" : "average"}
bold={1}>
{port_connected ? "Connected" : "Disconnected"}
</Flex.Item>
</Flex>
</Section>
);
};
const PressureSettings = (props, context) => {
const { act, data } = useBackend(context);
const {
tank_pressure,
rate,
max_rate,
} = data;
const average_pressure = max_rate * 0.70;
const bad_pressure = max_rate * 0.25;
return (
<Section title="Pressure Settings">
<LabeledList>
<LabeledList.Item label="Stored pressure">
<ProgressBar
value={tank_pressure}
minValue={0}
maxValue={max_rate}
ranges={{
good: [average_pressure, Infinity],
average: [bad_pressure, average_pressure],
bad: [-Infinity, bad_pressure],
}}>
{tank_pressure} kPa
</ProgressBar>
</LabeledList.Item>
</LabeledList>
<Flex mt={2}>
<Flex.Item
mt={0.4}
grow={1}
color="label">
Target pressure:
</Flex.Item>
<Flex.Item>
<Button
icon="undo"
mr={0.5}
width={2.2}
textAlign="center"
onClick={() => act('set_rate', {
rate: 101.325,
})} />
<Button
icon="fast-backward"
mr={0.5}
width={2.2}
textAlign="center"
onClick={() => act('set_rate', {
rate: 0,
})} />
</Flex.Item>
<Flex.Item>
<Slider
animated
unit="kPa"
width={17.3}
stepPixelSize={0.22}
minValue={0}
maxValue={max_rate}
value={rate}
onChange={(e, value) => act('set_rate', {
rate: value,
})} />
</Flex.Item>
<Flex.Item>
<Button
icon="fast-forward"
ml={0.5}
width={2.2}
textAlign="center"
onClick={() => act('set_rate', {
rate: max_rate,
})} />
</Flex.Item>
</Flex>
</Section>
);
};
const HoldingTank = (props, context) => {
const { act, data } = useBackend(context);
const {
holding_tank,
max_rate,
} = data;
const average_pressure = max_rate * 0.70;
const bad_pressure = max_rate * 0.25;
return (
<Section
title="Holding Tank"
buttons={
<Button
onClick={() => act('remove_tank')}
icon="eject">
Eject
</Button>
}>
<Flex>
<Flex.Item
color="label"
mr={7.2}
mb={2.2}>
Tank Label:
</Flex.Item>
<Flex.Item mb={1} color="silver">
{holding_tank.name}
</Flex.Item>
</Flex>
<Flex>
<Flex.Item
color="label"
mt={0.5}
mr={3.8}>
Tank Pressure:
</Flex.Item>
<Flex.Item grow={1}>
<ProgressBar
value={holding_tank.tank_pressure}
minValue={0}
maxValue={max_rate}
ranges={{
good: [average_pressure, Infinity],
average: [bad_pressure, average_pressure],
bad: [-Infinity, bad_pressure],
}}>
{holding_tank.tank_pressure} kPa
</ProgressBar>
</Flex.Item>
</Flex>
</Section>
);
};
File diff suppressed because one or more lines are too long