Skip to content

Commit

Permalink
TGUI: Microwave.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crowbar764 committed Sep 26, 2023
1 parent 933efa9 commit 0fde1c7
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 69 deletions.
144 changes: 75 additions & 69 deletions code/game/machinery/kitchen/microwave.dm
Original file line number Diff line number Diff line change
Expand Up @@ -154,72 +154,81 @@
user.set_interaction(src)
interact(user)

tgui_interact(user)

/obj/structure/machinery/microwave/tgui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if (!ui)
ui = new(user, src, "Microwave", "Microwave Controls")
ui.open()

//*******************
//* Microwave Menu
//********************/
/obj/structure/machinery/microwave/ui_data(mob/user)
var/list/data = list()

/obj/structure/machinery/microwave/interact(mob/user as mob) // The microwave Menu
var/dat = ""
if(src.broken > 0)
dat = {"<TT>Bzzzzttttt</TT>"}
else if(src.operating)
dat = {"<TT>Microwaving in progress!<BR>Please wait...!</TT>"}
else if(src.dirty==100)
dat = {"<TT>This microwave is dirty!<BR>Please clean it before use!</TT>"}
else
var/list/items_counts = new
var/list/items_measures = new
var/list/items_measures_p = new
for (var/obj/O in contents)
var/display_name = O.name
if (istype(O,/obj/item/reagent_container/food/snacks/egg))
items_measures[display_name] = "egg"
items_measures_p[display_name] = "eggs"
if (istype(O,/obj/item/reagent_container/food/snacks/tofu))
items_measures[display_name] = "tofu chunk"
items_measures_p[display_name] = "tofu chunks"
if (istype(O,/obj/item/reagent_container/food/snacks/meat)) //any meat
items_measures[display_name] = "slab of meat"
items_measures_p[display_name] = "slabs of meat"
if (istype(O,/obj/item/reagent_container/food/snacks/donkpocket))
display_name = "Turnovers"
items_measures[display_name] = "turnover"
items_measures_p[display_name] = "turnovers"
if (istype(O,/obj/item/reagent_container/food/snacks/carpmeat))
items_measures[display_name] = "fillet of meat"
items_measures_p[display_name] = "fillets of meat"
items_counts[display_name]++
for (var/O in items_counts)
var/N = items_counts[O]
if (!(O in items_measures))
dat += {"<B>[capitalize(O)]:</B> [N] [lowertext(O)]\s<BR>"}
else
if (N==1)
dat += {"<B>[capitalize(O)]:</B> [N] [items_measures[O]]<BR>"}
else
dat += {"<B>[capitalize(O)]:</B> [N] [items_measures_p[O]]<BR>"}

for (var/datum/reagent/R in reagents.reagent_list)
var/display_name = R.name
if (R.id == "hotsauce")
display_name = "Hotsauce"
if (R.id == "frostoil")
display_name = "Coldsauce"
dat += {"<B>[display_name]:</B> [R.volume] unit\s<BR>"}

if (items_counts.len==0 && reagents.reagent_list.len==0)
dat = {"<B>The microwave is empty</B><BR>"}
data["operating"] = src.operating
data["broken"] = src.broken
data["dirty"] = (src.dirty == 100)

var/list/ingredients = new
var/list/items_counts = new
var/list/items_measures = new
var/list/items_measures_p = new

for (var/obj/O in contents)
var/display_name = O.name

if (istype(O,/obj/item/reagent_container/food/snacks/egg))
items_measures[display_name] = "egg"
items_measures_p[display_name] = "eggs"
if (istype(O,/obj/item/reagent_container/food/snacks/tofu))
items_measures[display_name] = "tofu chunk"
items_measures_p[display_name] = "tofu chunks"
if (istype(O,/obj/item/reagent_container/food/snacks/meat)) //any meat
items_measures[display_name] = "slab of meat"
items_measures_p[display_name] = "slabs of meat"
if (istype(O,/obj/item/reagent_container/food/snacks/donkpocket))
display_name = "Turnovers"
items_measures[display_name] = "turnover"
items_measures_p[display_name] = "turnovers"
if (istype(O,/obj/item/reagent_container/food/snacks/carpmeat))
items_measures[display_name] = "fillet of meat"
items_measures_p[display_name] = "fillets of meat"
items_counts[display_name]++

for (var/O in items_counts)
var/list/item = new

item["name"] = capitalize(O)
item["count"] = items_counts[O]

if (!(O in items_measures))
item["measure"] = "[lowertext(O)][items_counts[O] > 1 ? "s" : ""]" // Adds 's' for plurals.
else if (items_counts[O] == 1)
item["measure"] = items_measures[O]
else
dat = {"<b>Ingredients:</b><br>[dat]"}
dat += {"<HR><BR>\
<A href='?src=\ref[src];action=cook'>Turn on!<BR>\
<A href='?src=\ref[src];action=dispose'>Eject ingredients!<BR>\
"}
item["measure"] = items_measures_p[O]

show_browser(user, dat, "Microwave Controls", "microwave")
return
ingredients += list(item)

for (var/datum/reagent/R in reagents.reagent_list)
var/list/reagent = new

reagent["count"] = R.volume
reagent["measure"] = R.volume > 1 ? "units" : "unit"

reagent["name"] = R.name
if (R.id == "hotsauce")
reagent["name"] = "Hotsauce"
if (R.id == "frostoil")
reagent["name"] = "Coldsauce"

ingredients += list(reagent)

data["ingredients"] = ingredients
return data

//***********************************
//* Microwave Menu Handling/Cooking
Expand Down Expand Up @@ -322,7 +331,7 @@
if (src.reagents.total_volume)
src.dirty++
src.reagents.clear_reagents()
to_chat(usr, SPAN_NOTICE(" You dispose of the microwave contents."))
to_chat(usr, SPAN_NOTICE("You dispose of the microwave contents."))
src.updateUsrDialog()

/obj/structure/machinery/microwave/proc/muck_start()
Expand Down Expand Up @@ -365,19 +374,16 @@
ffuu.reagents.add_reagent("toxin", amount/10)
return ffuu

/obj/structure/machinery/microwave/Topic(href, href_list)
if(..())
return

usr.set_interaction(src)
if(src.operating)
src.updateUsrDialog()
/obj/structure/machinery/microwave/ui_act(action, params)
. = ..()
if(.)
return

switch(href_list["action"])
switch (action)
if ("cook")
cook(usr.get_skill_duration_multiplier(SKILL_DOMESTIC)) // picking the right microwave setting for the right food. when's the last time you used the special setting on the microwave? i bet you just slam the 30 second increment. Do you know how much programming went into putting the Pizza setting into a microwave emitter?

if ("dispose")
if ("eject_all")
dispose()
return

return TRUE
72 changes: 72 additions & 0 deletions tgui/packages/tgui/interfaces/Microwave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { useBackend } from '../backend';
import { Button, NoticeBox, Section, Flex, Box } from '../components';
import { Window } from '../layouts';

export const Microwave = (props, context) => {
const { data, act } = useBackend(context);
const { operating, broken, dirty, ingredients } = data;

return (
<Window width={350} height={350}>
<Window.Content scrollable>
<Section
fill
title="Ingredients:"
buttons={
<Flex>
<Button
height="100%"
icon="power-off"
disabled={!!operating || !!dirty || !!broken}
onClick={() => act('cook')}>
Activate
</Button>

<Button
height="100%"
icon="eject"
disabled={!ingredients.length || !!operating}
onClick={() => act('eject_all')}>
Eject all
</Button>
</Flex>
}>
{!!operating && (
<NoticeBox
width="100%"
textAlign="center"
p=".5rem"
fontSize="1.5rem">
Cooking..
</NoticeBox>
)}

{!!broken && (
<NoticeBox danger width="100%" textAlign="center" p="1rem">
Appliance broken. Please contact your local technician.
</NoticeBox>
)}

{!!dirty && (
<NoticeBox danger width="100%" textAlign="center" p="1rem">
This microwave is too dirty. Cleaning required.
</NoticeBox>
)}

{!ingredients.length && <Box>None</Box>}

<Flex direction="column">
{ingredients.map((ingredient) => {
return (
<Flex.Item key={ingredient.name} py=".2rem">
<b>{ingredient.name}</b>: {ingredient.count}{' '}
{ingredient.measure}
</Flex.Item>
);
})}
</Flex>
</Section>
</Window.Content>
</Window>
);
};

0 comments on commit 0fde1c7

Please sign in to comment.