Skip to content

Commit 036951a

Browse files
Bobbanz1Bokkiewokkie
andauthoredMar 10, 2023
Updates the Smelter UI into a TGUI format (#2326)
Co-authored-by: Bokkiewokkie <[email protected]>
1 parent 32f1414 commit 036951a

File tree

2 files changed

+155
-63
lines changed

2 files changed

+155
-63
lines changed
 

‎code/modules/mining/machine_processing.dm

+56-63
Original file line numberDiff line numberDiff line change
@@ -78,50 +78,53 @@
7878
machine.CONSOLE = src
7979
return
8080

81-
/obj/machinery/mineral/processing_unit_console/ui_interact(mob/user)
81+
//NSV13 - Furnace TGUI - Start
82+
/obj/machinery/mineral/processing_unit_console/ui_interact(mob/user, datum/tgui/ui)
83+
ui = SStgui.try_update_ui(user, src, ui)
84+
if(!ui)
85+
ui = new(user, src, "Smelter")
86+
ui.open()
87+
ui.set_autoupdate(TRUE) // Material amounts
88+
89+
/obj/machinery/mineral/processing_unit_console/ui_data(mob/user)
8290
. = ..()
91+
var/list/data = list()
8392
if(!machine)
8493
return
8594

86-
var/dat = machine.get_machine_data()
95+
data = machine.get_machine_data()
96+
return data
8797

88-
var/datum/browser/popup = new(user, "processing", "Smelting Console", 300, 500)
89-
popup.set_content(dat)
90-
popup.open()
91-
92-
/obj/machinery/mineral/processing_unit_console/Topic(href, href_list)
98+
/obj/machinery/mineral/processing_unit_console/ui_act(action, params)
9399
if(..())
94100
return
95-
usr.set_machine(src)
96-
add_fingerprint(usr)
97-
98-
if(href_list["material"])
99-
var/datum/material/new_material = locate(href_list["material"])
100-
if(istype(new_material))
101-
machine.selected_material = new_material
102-
machine.selected_alloy = null
103-
104-
if(href_list["alloy"])
105-
machine.selected_material = null
106-
machine.selected_alloy = href_list["alloy"]
107-
108-
if(href_list["toggle_on"])
109-
machine.toggle_on()
110-
111-
if(href_list["redeem"])
112-
var/mob/M = usr
113-
var/obj/item/card/id/I = M.get_idcard(TRUE)
114-
if(!I)
115-
to_chat(usr, "<span class='warning'>No ID detected.</span>")
116-
return
117-
if(!machine.points)
118-
to_chat(usr, "<span class='warning'>No points to claim.</span>")
119-
return
120-
I.mining_points += machine.points
121-
machine.points = 0
122101

123-
updateUsrDialog()
124-
return
102+
switch(action)
103+
if("Redeem")
104+
var/mob/M = usr
105+
var/obj/item/card/id/I = M.get_idcard(TRUE)
106+
if(!I)
107+
to_chat(usr, "<span class='warning'>No ID detected.</span>")
108+
return
109+
if(!machine.points)
110+
to_chat(usr, "<span class='warning'>No points to claim.</span>")
111+
return
112+
I.mining_points += machine.points
113+
machine.points = 0
114+
115+
if("Toggle_on")
116+
machine.toggle_on()
117+
118+
if("Material")
119+
var/datum/material/new_material = locate(params["id"])
120+
if(istype(new_material))
121+
machine.selected_material = new_material
122+
machine.selected_alloy = null
123+
124+
if("Alloy")
125+
machine.selected_material = null
126+
machine.selected_alloy = params["id"]
127+
//NSV13 - Furnace TGUI - Stop
125128

126129
/obj/machinery/mineral/processing_unit_console/Destroy()
127130
machine = null
@@ -173,47 +176,36 @@
173176
points += O.points * O.amount
174177
materials.insert_item(O)
175178
qdel(O)
179+
/* NSV13 - Disabled due to our TGUI version
176180
if(CONSOLE)
177181
CONSOLE.updateUsrDialog()
182+
*/
178183

184+
//NSV13 - Furnace TGUI - Start
179185
/obj/machinery/mineral/processing_unit/proc/get_machine_data()
180-
var/dat = "<b>Smelter control console</b><br><br>"
181-
182-
//On or off - on the console so we don't fail can_interact when doing Topic
183-
dat += "Machine is currently <A href='?src=[REF(CONSOLE)];toggle_on=1'>[ on ? "On" : "Off"]</A>"
184-
dat += "<br><br>"
186+
var/list/data = list()
187+
data["on"] = on
188+
data["allowredeem"] = allow_point_redemption
185189

186190
//Points
187191
if(allow_point_redemption)
188-
dat += "Stored points: [points] "
189-
dat += "<A href='?src=[REF(CONSOLE)];redeem=1'><b>Redeem</b></A> "
190-
dat += "<br><br>"
192+
data["points"] = points
191193

194+
data["materials"] = list()
192195
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
193196
for(var/datum/material/M in materials.materials)
194197
var/amount = materials.materials[M]
195-
dat += "<span class=\"res_name\">[M.name]: </span>[amount] cm&sup3;"
196-
if (selected_material == M)
197-
dat += " <i>Smelting</i>"
198-
else
199-
dat += " <A href='?src=[REF(CONSOLE)];material=[REF(M)]'><b>Not Smelting</b></A> "
200-
dat += "<br>"
201-
202-
dat += "<br><br>"
203-
dat += "<b>Smelt Alloys</b><br>"
198+
var/sheet_amount = amount / MINERAL_MATERIAL_AMOUNT
199+
var/ref = REF(M)
200+
data["materials"] += list(list("name" = M.name, "id" = ref, "amount" = sheet_amount, "smelting" = (selected_material == M)))
204201

202+
data["alloys"] = list()
205203
for(var/v in stored_research.researched_designs)
206204
var/datum/design/D = SSresearch.techweb_design_by_id(v)
207-
dat += "<span class=\"res_name\">[D.name] "
208-
if (selected_alloy == D.id)
209-
dat += " <i>Smelting</i>"
210-
else
211-
dat += " <A href='?src=[REF(CONSOLE)];alloy=[D.id]'><b>Not Smelting</b></A> "
212-
dat += "<br>"
205+
data["alloys"] += list(list("name" = D.name, "id" = D.id, "smelting" = (selected_alloy == D.id), "amount" = can_smelt(D)))
213206

214-
dat += "<br><br>"
215-
216-
return dat
207+
return data
208+
//NSV13 - Furnace TGUI - Stop
217209

218210
/obj/machinery/mineral/processing_unit/pickup_item(datum/source, atom/movable/target, atom/oldLoc)
219211
if(QDELETED(target))
@@ -234,9 +226,10 @@
234226
else if(selected_alloy)
235227
smelt_alloy(delta_time)
236228

237-
229+
/* NSV13 - Disabled due to our TGUI version
238230
if(CONSOLE)
239231
CONSOLE.updateUsrDialog()
232+
*/
240233
else
241234
end_processing()
242235

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { toTitleCase } from 'common/string';
2+
import { useBackend } from '../backend';
3+
import { Box, Button, Section, Table } from '../components';
4+
import { Window } from '../layouts';
5+
6+
export const Smelter = (props, context) => {
7+
const { act, data } = useBackend(context);
8+
const {
9+
on,
10+
allowredeem,
11+
stored_points,
12+
materials,
13+
alloys,
14+
} = data;
15+
return (
16+
<Window
17+
width={440}
18+
height={550}>
19+
<Window.Content scrollable>
20+
<Section>
21+
<Table.Row>
22+
<Table.Cell>
23+
<Box inline color="label" mr={1}>
24+
Machine Status:
25+
</Box>
26+
<Button
27+
icon={on ? 'power-off' : 'times'}
28+
content={on ? 'On' : 'Off'}
29+
onClick={() => act('Toggle_on')} />
30+
</Table.Cell>
31+
{!!allowredeem && (
32+
<Table.Cell collapsing textAlign="right">
33+
<Box>
34+
<Box inline color="label" mr={1}>
35+
Stored Points:
36+
</Box>
37+
{stored_points}
38+
<Button
39+
ml={2}
40+
content="Redeem"
41+
disabled={stored_points === 0}
42+
onClick={() => act('Redeem')} />
43+
</Box>
44+
</Table.Cell>
45+
)}
46+
</Table.Row>
47+
</Section>
48+
<Section title="Materials">
49+
<Table>
50+
{materials.map(material => (
51+
<MaterialRow
52+
key={material.id}
53+
material={material}
54+
onRelease={() => act('Material', {
55+
id: material.id,
56+
})} />
57+
))}
58+
</Table>
59+
</Section>
60+
<Section title="Alloys">
61+
<Table>
62+
{alloys.map(material => (
63+
<MaterialRow
64+
key={material.id}
65+
material={material}
66+
onRelease={() => act('Alloy', {
67+
id: material.id,
68+
})} />
69+
))}
70+
</Table>
71+
</Section>
72+
</Window.Content>
73+
</Window>
74+
);
75+
};
76+
77+
const MaterialRow = (props, context) => {
78+
const { material, onRelease } = props;
79+
80+
const amountAvailable = Math.floor(material.amount);
81+
return (
82+
<Table.Row>
83+
<Table.Cell>
84+
{toTitleCase(material.name).replace('Alloy', '')}
85+
</Table.Cell>
86+
<Table.Cell collapsing textAlign="right">
87+
<Box mr={2} color="label" inline>
88+
{amountAvailable} sheets
89+
</Box>
90+
</Table.Cell>
91+
<Table.Cell collapsing>
92+
<Button
93+
color={material.smelting ? "good" : "bad"}
94+
content={material.smelting ? "Smelting" : "Not Smelting"}
95+
onClick={() => onRelease()} />
96+
</Table.Cell>
97+
</Table.Row>
98+
);
99+
};

0 commit comments

Comments
 (0)
Please sign in to comment.