diff --git a/code/modules/mining/machine_processing.dm b/code/modules/mining/machine_processing.dm index f4510741968..62458347bf0 100644 --- a/code/modules/mining/machine_processing.dm +++ b/code/modules/mining/machine_processing.dm @@ -70,7 +70,7 @@ icon = 'icons/obj/machines/mining_machines.dmi' icon_state = "console" density = TRUE - interaction_flags_machine = INTERACT_MACHINE_WIRES_IF_OPEN|INTERACT_MACHINE_ALLOW_SILICON|INTERACT_MACHINE_OPEN_SILICON|INTERACT_MACHINE_SET_MACHINE + interaction_flags_machine = INTERACT_MACHINE_WIRES_IF_OPEN|INTERACT_MACHINE_ALLOW_SILICON|INTERACT_MACHINE_OPEN_SILICON /// Connected ore processing machine. var/obj/machinery/mineral/processing_unit/processing_machine @@ -82,39 +82,43 @@ else return INITIALIZE_HINT_QDEL -/obj/machinery/mineral/processing_unit_console/ui_interact(mob/user) - . = ..() - if(!processing_machine) - return +/obj/machinery/mineral/processing_unit_console/ui_interact(mob/user, datum/tgui/ui) + ui = SStgui.try_update_ui(user, src, ui) + if(!ui) + ui = new(user, src, "ProcessingConsole") + ui.open() - var/dat = processing_machine.get_machine_data() +/obj/machinery/mineral/processing_unit_console/ui_static_data(mob/user) + return processing_machine.ui_static_data() - var/datum/browser/popup = new(user, "processing", "Smelting Console", 300, 500) - popup.set_content(dat) - popup.open() +/obj/machinery/mineral/processing_unit_console/ui_data(mob/user) + return processing_machine.ui_data() -/obj/machinery/mineral/processing_unit_console/Topic(href, href_list) - if(..()) +/obj/machinery/mineral/processing_unit_console/ui_act(action, list/params) + . = ..() + if(.) return - usr.set_machine(src) - add_fingerprint(usr) - if(href_list["material"]) - var/datum/material/new_material = locate(href_list["material"]) - if(istype(new_material)) + switch(action) + if("setMaterial") + var/datum/material/new_material = locate(params["value"]) + if(!istype(new_material)) + return + processing_machine.selected_material = new_material processing_machine.selected_alloy = null + return TRUE - if(href_list["alloy"]) - processing_machine.selected_material = null - processing_machine.selected_alloy = href_list["alloy"] + if("setAlloy") + processing_machine.selected_material = null + processing_machine.selected_alloy = params["value"] + return TRUE - if(href_list["set_on"]) - processing_machine.on = (href_list["set_on"] == "on") - processing_machine.begin_processing() - - updateUsrDialog() - return + if("toggle") + processing_machine.on = !processing_machine.on + if(processing_machine.on) + processing_machine.begin_processing() + return TRUE /obj/machinery/mineral/processing_unit_console/Destroy() processing_machine = null @@ -181,41 +185,53 @@ unload_mineral(O) else materials.insert_item(O) - if(mineral_machine) - mineral_machine.updateUsrDialog() - -/obj/machinery/mineral/processing_unit/proc/get_machine_data() - var/dat = "Smelter control console

" - for(var/datum/material/all_materials as anything in materials.materials) - var/amount = materials.materials[all_materials] - dat += "[all_materials.name]: [amount] cm³" - if (selected_material == all_materials) - dat += " Smelting" - else - dat += " Not Smelting " - dat += "
" - - dat += "

" - dat += "Smelt Alloys
" + +/obj/machinery/mineral/processing_unit/ui_static_data() + var/list/data = list() + + for(var/datum/material/material as anything in materials.materials) + var/obj/display = initial(material.sheet_type) + data["materialIcons"] += list( + list( + "id" = REF(material), + "icon" = icon2base64(icon(initial(display.icon), icon_state = initial(display.icon_state), frame = 1)), + ) + ) for(var/research in stored_research.researched_designs) - var/datum/design/designs = SSresearch.techweb_design_by_id(research) - dat += "[designs.name] " - if (selected_alloy == designs.id) - dat += " Smelting" - else - dat += " Not Smelting " - dat += "
" - - dat += "

" - //On or off - dat += "Machine is currently " - if (on) - dat += "On " - else - dat += "Off " + var/datum/design/design = SSresearch.techweb_design_by_id(research) + var/obj/display = initial(design.build_path) + data["alloyIcons"] += list( + list( + "id" = design.id, + "icon" = icon2base64(icon(initial(display.icon), icon_state = initial(display.icon_state), frame = 1)), + ) + ) - return dat + data += materials.ui_static_data() + + return data + +/obj/machinery/mineral/processing_unit/ui_data() + var/list/data = list() + + data["materials"] = materials.ui_data() + data["selectedMaterial"] = selected_material?.name + + data["alloys"] = list() + for(var/research in stored_research.researched_designs) + var/datum/design/design = SSresearch.techweb_design_by_id(research) + data["alloys"] += list( + list( + "name" = design.name, + "id" = design.id, + ) + ) + data["selectedAlloy"] = selected_alloy + + data["state"] = on + + return data /obj/machinery/mineral/processing_unit/pickup_item(datum/source, atom/movable/target, direction) if(QDELETED(target)) @@ -225,19 +241,13 @@ /obj/machinery/mineral/processing_unit/process(seconds_per_tick) if(!on) - end_processing() - if(mineral_machine) - mineral_machine.updateUsrDialog() - return + return PROCESS_KILL if(selected_material) smelt_ore(seconds_per_tick) else if(selected_alloy) smelt_alloy(seconds_per_tick) - if(mineral_machine) - mineral_machine.updateUsrDialog() - /obj/machinery/mineral/processing_unit/proc/smelt_ore(seconds_per_tick = 2) var/datum/material/mat = selected_material if(!mat) diff --git a/tgui/packages/tgui/interfaces/ProcessingConsole.tsx b/tgui/packages/tgui/interfaces/ProcessingConsole.tsx new file mode 100644 index 00000000000..e61705fbeb5 --- /dev/null +++ b/tgui/packages/tgui/interfaces/ProcessingConsole.tsx @@ -0,0 +1,169 @@ +import { toTitleCase } from 'common/string'; + +import { useBackend } from '../backend'; +import { + Box, + Button, + Icon, + Image, + NoticeBox, + Section, + Stack, + Table, +} from '../components'; +import { formatSiUnit } from '../format'; +import { Window } from '../layouts'; +import { Material } from './Fabrication/Types'; + +type IconData = { + id: string; + icon: string; +}; + +type Alloy = { + name: string; + id: string; +}; + +type Data = { + materials: Material[]; + materialIcons: IconData[]; + selectedMaterial: string | null; + alloys: Alloy[]; + alloyIcons: IconData[]; + selectedAlloy: string | null; + state: boolean; + SHEET_MATERIAL_AMOUNT: number; +}; + +export const ProcessingConsole = (props: any) => { + const { act, data } = useBackend(); + const { state } = data; + + return ( + + + + + + +
+ +
+
+ +
+ +
+
+
+
+ + + +
+
+
+ ); +}; + +const MaterialSelection = (props: any) => { + const { act, data } = useBackend(); + const { materials, materialIcons, selectedMaterial, SHEET_MATERIAL_AMOUNT } = + data; + + return materials.length > 0 ? ( + + {materials.map((material) => ( + icon.id === material.ref)?.icon} + amount={Math.floor(material.amount / SHEET_MATERIAL_AMOUNT)} + selected={selectedMaterial === material.name} + onSelect={() => act('setMaterial', { value: material.ref })} + /> + ))} +
+ ) : ( + No material recipes found! + ); +}; + +const AlloySelection = (props: any) => { + const { act, data } = useBackend(); + const { alloys, alloyIcons, selectedAlloy } = data; + + return alloys.length > 0 ? ( + + {alloys.map((alloy) => ( + icon.id === alloy.id)?.icon} + selected={selectedAlloy === alloy.id} + onSelect={() => act('setAlloy', { value: alloy.id })} + /> + ))} +
+ ) : ( + No alloy recipes found! + ); +}; + +type DisplayRowProps = { + name: string; + icon?: string; + amount?: number; + selected: boolean; + onSelect: () => void; +}; + +const DisplayRow = (props: DisplayRowProps) => { + const { name, icon, amount, selected, onSelect } = props; + + return ( + + + {icon ? ( + + ) : ( + + )} + + + {toTitleCase(name)} + + {amount !== undefined ? ( + + {`${formatSiUnit(amount, 0)} ${amount === 1 ? 'sheet' : 'sheets'}`} + + ) : null} + + onSelect()} + /> + + + ); +};