Merge pull request #14059 from Kyep/tgui_transfer_valves

[TGUI] Tank Transfer Valves (TTV)
This commit is contained in:
AffectedArc07
2020-09-15 17:30:15 +01:00
committed by GitHub
4 changed files with 145 additions and 110 deletions
@@ -86,64 +86,64 @@
O.hear_message(M, msg)
/obj/item/transfer_valve/attack_self(mob/user)
ui_interact(user)
tgui_interact(user)
/obj/item/transfer_valve/ui_interact(mob/user, ui_key = "main", datum/nanoui/ui = null, force_open = 1)
// 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/item/transfer_valve/tgui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = TRUE, datum/tgui/master_ui = null, datum/tgui_state/state = GLOB.tgui_inventory_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, "transfer_valve.tmpl", "Tank Transfer Valve", 460, 280)
// open the new ui window
ui = new(user, src, ui_key, "TransferValve", name, 460, 320, master_ui, state)
ui.open()
// auto update every Master Controller tick
//ui.set_auto_update(1)
/obj/item/transfer_valve/ui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.default_state)
var/data[0]
data["attachmentOne"] = tank_one ? tank_one.name : null
data["attachmentTwo"] = tank_two ? tank_two.name : null
data["valveAttachment"] = attached_device ? attached_device.name : null
data["valveOpen"] = valve_open ? 1 : 0
/obj/item/transfer_valve/tgui_data(mob/user)
var/list/data = list()
data["tank_one"] = tank_one ? tank_one.name : null
data["tank_two"] = tank_two ? tank_two.name : null
data["attached_device"] = attached_device ? attached_device.name : null
data["valve"] = valve_open
return data
/obj/item/transfer_valve/Topic(href, href_list)
..()
if(usr.incapacitated())
return 0
if(loc != usr)
return 0
if(tank_one && href_list["tankone"])
split_gases()
valve_open = 0
tank_one.forceMove(get_turf(src))
tank_one = null
/obj/item/transfer_valve/tgui_act(action, params)
if(..())
return
. = TRUE
switch(action)
if("tankone")
if(tank_one)
split_gases()
valve_open = FALSE
tank_one.forceMove(get_turf(src))
tank_one = null
update_icon()
if((!tank_two || tank_two.w_class < WEIGHT_CLASS_BULKY) && (w_class > WEIGHT_CLASS_NORMAL))
w_class = WEIGHT_CLASS_NORMAL
if("tanktwo")
if(tank_two)
split_gases()
valve_open = FALSE
tank_two.forceMove(get_turf(src))
tank_two = null
update_icon()
if((!tank_one || tank_one.w_class < WEIGHT_CLASS_BULKY) && (w_class > WEIGHT_CLASS_NORMAL))
w_class = WEIGHT_CLASS_NORMAL
if("toggle")
toggle_valve()
if("device")
if(attached_device)
attached_device.attack_self(usr)
if("remove_device")
if(attached_device)
attached_device.forceMove(get_turf(src))
attached_device.holder = null
attached_device = null
update_icon()
else
. = FALSE
if(.)
update_icon()
if((!tank_two || tank_two.w_class < WEIGHT_CLASS_BULKY) && (w_class > WEIGHT_CLASS_NORMAL))
w_class = WEIGHT_CLASS_NORMAL
else if(tank_two && href_list["tanktwo"])
split_gases()
valve_open = 0
tank_two.forceMove(get_turf(src))
tank_two = null
update_icon()
if((!tank_one || tank_one.w_class < WEIGHT_CLASS_BULKY) && (w_class > WEIGHT_CLASS_NORMAL))
w_class = WEIGHT_CLASS_NORMAL
else if(href_list["open"])
toggle_valve()
else if(attached_device)
if(href_list["rem_device"])
attached_device.forceMove(get_turf(src))
attached_device.holder = null
attached_device = null
update_icon()
if(href_list["device"])
attached_device.attack_self(usr)
add_fingerprint(usr)
return 1 // Returning 1 sends an update to attached UIs
add_fingerprint(usr)
/obj/item/transfer_valve/proc/process_activation(obj/item/D)
if(toggle)
-56
View File
@@ -1,56 +0,0 @@
<div class="item">
<div class="itemLabel">
Attachment One:
</div>
<div class="itemContent">
{{if data.attachmentOne}}
{{:data.attachmentOne}}
{{else}}
<i>None</i>
{{/if}}
{{:helper.link('Remove', 'eject', {'tankone' : 1}, data.attachmentOne ? null : 'disabled')}}
</div>
</div>
<div class="item">
<div class="itemLabel">
Attachment Two:
</div>
<div class="itemContent">
{{if data.attachmentTwo}}
{{:data.attachmentTwo}}
{{else}}
<i>None</i>
{{/if}}
{{:helper.link('Remove', 'eject', {'tanktwo' : 1}, data.attachmentTwo ? null : 'disabled')}}
</div>
</div>
<div class="item">
<div class="itemLabel">
Valve Attachment:
</div>
<div class="itemContent">
{{if data.valveAttachment}}
{{:data.valveAttachment}}
{{else}}
<i>None</i>
{{/if}}
{{:helper.link('Remove', 'eject', {'rem_device' : 1}, data.valveAttachment ? null : 'disabled')}}
{{if data.valveAttachment}}
{{:helper.link('View', 'wrench', {'device' : 1})}}
{{/if}}
</div>
</div>
<div class="item">&nbsp;</div>
<div class="item">
<div class="itemLabel">
Valve Status:
</div>
<div class="itemContent">
{{:helper.link('Open', 'unlock', {'open' : 1}, (!data.attachmentOne || !data.attachmentTwo) ? 'disabled' : (data.valveOpen ? 'selected' : null))}}{{:helper.link('Close', 'lock', {'open' : 1}, (!data.attachmentOne || !data.attachmentTwo) ? 'disabled' : (data.valveOpen ? null : 'selected'))}}
</div>
</div>
@@ -0,0 +1,91 @@
import { useBackend } from '../backend';
import { Button, LabeledList, NoticeBox, Section } from '../components';
import { Window } from '../layouts';
export const TransferValve = (props, context) => {
const { act, data } = useBackend(context);
const {
tank_one,
tank_two,
attached_device,
valve,
} = data;
return (
<Window>
<Window.Content>
<Section>
<LabeledList>
<LabeledList.Item label="Valve Status">
<Button
icon={valve ? "unlock" : "lock"}
content={valve ? "Open" : "Closed"}
disabled={!tank_one || !tank_two}
onClick={() => act('toggle')} />
</LabeledList.Item>
</LabeledList>
</Section>
<Section
title="Assembly"
buttons={(
<Button
textAlign="center"
width="150px"
icon="cog"
content="Configure Assembly"
disabled={(!attached_device)}
onClick={() => act('device')} />
)}>
<LabeledList>
{attached_device ? (
<LabeledList.Item label="Attachment">
<Button
icon="eject"
content={attached_device}
disabled={!attached_device}
onClick={() => act('remove_device')} />
</LabeledList.Item>
) : (
<NoticeBox textAlign="center">
Attach Assembly
</NoticeBox>
)}
</LabeledList>
</Section>
<Section title="Attachment One">
<LabeledList>
{tank_one ? (
<LabeledList.Item label="Attachment">
<Button
icon="eject"
content={tank_one}
disabled={!tank_one}
onClick={() => act('tankone')} />
</LabeledList.Item>
) : (
<NoticeBox textAlign="center">
Attach Tank
</NoticeBox>
)}
</LabeledList>
</Section>
<Section title="Attachment Two">
<LabeledList>
{tank_two ? (
<LabeledList.Item label="Attachment">
<Button
icon="eject"
content={tank_two}
disabled={!tank_two}
onClick={() => act('tanktwo')} />
</LabeledList.Item>
) : (
<NoticeBox textAlign="center">
Attach Tank
</NoticeBox>
)}
</LabeledList>
</Section>
</Window.Content>
</Window>
);
};
File diff suppressed because one or more lines are too long