From c55145299a5cdaea3442318e400a57cd7feeb70b Mon Sep 17 00:00:00 2001 From: Razharas Date: Wed, 5 Jun 2019 00:01:45 +0300 Subject: [PATCH] Componentizes menucrafting (#44221) Fixes menucrafting opening a new window when finishing construction --- code/__DEFINES/components.dm | 1 + code/_onclick/hud/generic_dextrous.dm | 4 -- code/_onclick/hud/human.dm | 6 --- code/_onclick/hud/screen_objects.dm | 6 --- .../components/crafting/crafting.dm} | 54 ++++++++++++------- .../components}/crafting/guncrafting.dm | 0 .../components}/crafting/recipes.dm | 0 .../components}/crafting/tailoring.dm | 0 code/modules/mob/living/carbon/human/human.dm | 6 +-- .../mob/living/carbon/human/human_defines.dm | 1 - .../mob/living/simple_animal/simple_animal.dm | 12 ++--- code/modules/mob/login.dm | 1 + tgstation.dme | 8 +-- 13 files changed, 45 insertions(+), 54 deletions(-) rename code/{modules/crafting/craft.dm => datums/components/crafting/crafting.dm} (87%) rename code/{modules => datums/components}/crafting/guncrafting.dm (100%) rename code/{modules => datums/components}/crafting/recipes.dm (100%) rename code/{modules => datums/components}/crafting/tailoring.dm (100%) diff --git a/code/__DEFINES/components.dm b/code/__DEFINES/components.dm index 5cc94feba4b..609c06722a1 100644 --- a/code/__DEFINES/components.dm +++ b/code/__DEFINES/components.dm @@ -148,6 +148,7 @@ #define COMSIG_LIVING_EXTINGUISHED "living_extinguished" //from base of mob/living/ExtinguishMob() (/mob/living) #define COMSIG_LIVING_ELECTROCUTE_ACT "living_electrocute_act" //from base of mob/living/electrocute_act(): (shock_damage) #define COMSIG_LIVING_MINOR_SHOCK "living_minor_shock" //sent by stuff like stunbatons and tasers: () +#define COMSIG_MOB_CLIENT_LOGIN "comsig_mob_client_login" //sent when a mob/login() finishes: (client) //ALL OF THESE DO NOT TAKE INTO ACCOUNT WHETHER AMOUNT IS 0 OR LOWER AND ARE SENT REGARDLESS! #define COMSIG_LIVING_STATUS_STUN "living_stun" //from base of mob/living/Stun() (amount, update, ignore) diff --git a/code/_onclick/hud/generic_dextrous.dm b/code/_onclick/hud/generic_dextrous.dm index 131b510f9b2..ad8eb775fae 100644 --- a/code/_onclick/hud/generic_dextrous.dm +++ b/code/_onclick/hud/generic_dextrous.dm @@ -44,10 +44,6 @@ zone_select.update_icon(mymob) static_inventory += zone_select - using = new /obj/screen/craft - using.icon = ui_style - static_inventory += using - using = new /obj/screen/area_creator using.icon = ui_style static_inventory += using diff --git a/code/_onclick/hud/human.dm b/code/_onclick/hud/human.dm index 5bf11719999..99c77464276 100644 --- a/code/_onclick/hud/human.dm +++ b/code/_onclick/hud/human.dm @@ -91,12 +91,6 @@ var/obj/screen/using var/obj/screen/inventory/inv_box - using = new /obj/screen/craft - using.icon = ui_style - if(!widescreen_layout) - using.screen_loc = UI_BOXCRAFT - static_inventory += using - using = new/obj/screen/language_menu using.icon = ui_style if(!widescreen_layout) diff --git a/code/_onclick/hud/screen_objects.dm b/code/_onclick/hud/screen_objects.dm index 1825be1e24c..ac11c532ca6 100644 --- a/code/_onclick/hud/screen_objects.dm +++ b/code/_onclick/hud/screen_objects.dm @@ -66,12 +66,6 @@ icon_state = "craft" screen_loc = ui_crafting -/obj/screen/craft/Click() - var/mob/living/M = usr - if(isobserver(usr)) - return - M.OpenCraftingMenu() - /obj/screen/area_creator name = "create new area" icon = 'icons/mob/screen_midnight.dmi' diff --git a/code/modules/crafting/craft.dm b/code/datums/components/crafting/crafting.dm similarity index 87% rename from code/modules/crafting/craft.dm rename to code/datums/components/crafting/crafting.dm index 6d20daf9acf..2012d32178e 100644 --- a/code/modules/crafting/craft.dm +++ b/code/datums/components/crafting/crafting.dm @@ -1,4 +1,17 @@ -/datum/personal_crafting +/datum/component/personal_crafting/Initialize() + if(!ismob(parent)) + return COMPONENT_INCOMPATIBLE + RegisterSignal(parent, COMSIG_MOB_CLIENT_LOGIN, .proc/create_mob_button) + +/datum/component/personal_crafting/proc/create_mob_button(mob/user, client/CL) + var/datum/hud/H = user.hud_used + var/obj/screen/craft/C = new() + C.icon = H.ui_style + H.static_inventory += C + CL.screen += C + RegisterSignal(C, COMSIG_CLICK, .proc/component_ui_interact) + +/datum/component/personal_crafting var/busy var/viewing_category = 1 //typical powergamer starting on the Weapons tab var/viewing_subcategory = 1 @@ -51,7 +64,7 @@ -/datum/personal_crafting/proc/check_contents(datum/crafting_recipe/R, list/contents) +/datum/component/personal_crafting/proc/check_contents(datum/crafting_recipe/R, list/contents) contents = contents["other"] main_loop: for(var/A in R.reqs) @@ -74,7 +87,7 @@ return 0 return 1 -/datum/personal_crafting/proc/get_environment(mob/user) +/datum/component/personal_crafting/proc/get_environment(mob/user) . = list() for(var/obj/item/I in user.held_items) . += I @@ -90,7 +103,7 @@ continue . += AM -/datum/personal_crafting/proc/get_surroundings(mob/user) +/datum/component/personal_crafting/proc/get_surroundings(mob/user) . = list() .["tool_behaviour"] = list() .["other"] = list() @@ -111,7 +124,7 @@ .["other"][A.type] += A.volume .["other"][I.type] += 1 -/datum/personal_crafting/proc/check_tools(mob/user, datum/crafting_recipe/R, list/contents) +/datum/component/personal_crafting/proc/check_tools(mob/user, datum/crafting_recipe/R, list/contents) if(!R.tools.len) return TRUE var/list/possible_tools = list() @@ -142,7 +155,7 @@ return FALSE return TRUE -/datum/personal_crafting/proc/construct_item(mob/user, datum/crafting_recipe/R) +/datum/component/personal_crafting/proc/construct_item(mob/user, datum/crafting_recipe/R) var/list/contents = get_surroundings(user) var/send_feedback = 1 if(check_contents(R, contents)) @@ -188,7 +201,7 @@ del_reqs return the list of parts resulting object will receive as argument of CheckParts proc, on the atom level it will add them all to the contents, on all other levels it calls ..() and does whatever is needed afterwards but from contents list already */ -/datum/personal_crafting/proc/del_reqs(datum/crafting_recipe/R, mob/user) +/datum/component/personal_crafting/proc/del_reqs(datum/crafting_recipe/R, mob/user) var/list/surroundings var/list/Deletion = list() . = list() @@ -286,15 +299,18 @@ Deletion.Cut(Deletion.len) qdel(DL) +/datum/component/personal_crafting/proc/component_ui_interact(obj/screen/crafting/image, location, control, params, user) + if(user == parent) + ui_interact(user) -/datum/personal_crafting/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.not_incapacitated_turf_state) +/datum/component/personal_crafting/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.not_incapacitated_turf_state) ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open) if(!ui) ui = new(user, src, ui_key, "personal_crafting", "Crafting Menu", 700, 800, master_ui, state) ui.open() -/datum/personal_crafting/ui_data(mob/user) +/datum/component/personal_crafting/ui_data(mob/user) var/list/data = list() var/list/subs = list() var/cur_subcategory = CAT_NONE @@ -317,7 +333,7 @@ var/list/cant_craft = list() for(var/rec in GLOB.crafting_recipes) var/datum/crafting_recipe/R = rec - + if(!R.always_availible && !(R.type in user?.mind?.learned_recipes)) //User doesn't actually know how to make this. continue @@ -332,21 +348,20 @@ return data -/datum/personal_crafting/ui_act(action, params) +/datum/component/personal_crafting/ui_act(action, params) if(..()) return switch(action) if("make") var/datum/crafting_recipe/TR = locate(params["recipe"]) in GLOB.crafting_recipes busy = TRUE - ui_interact(usr) //explicit call to show the busy display + ui_interact(usr) var/fail_msg = construct_item(usr, TR) if(!fail_msg) to_chat(usr, "[TR.name] constructed.") else to_chat(usr, "Construction failed[fail_msg]") busy = FALSE - ui_interact(usr) if("forwardCat") //Meow viewing_category = next_cat(FALSE) . = TRUE @@ -366,21 +381,20 @@ display_compact = !display_compact . = TRUE - //Next works nicely with modular arithmetic -/datum/personal_crafting/proc/next_cat(readonly = TRUE) +/datum/component/personal_crafting/proc/next_cat(readonly = TRUE) if (!readonly) viewing_subcategory = 1 . = viewing_category % categories.len + 1 -/datum/personal_crafting/proc/next_subcat() +/datum/component/personal_crafting/proc/next_subcat() if(islist(subcategories[viewing_category])) var/list/subs = subcategories[viewing_category] . = viewing_subcategory % subs.len + 1 //Previous can go fuck itself -/datum/personal_crafting/proc/prev_cat(readonly = TRUE) +/datum/component/personal_crafting/proc/prev_cat(readonly = TRUE) if (!readonly) viewing_subcategory = 1 if(viewing_category == categories.len) @@ -390,7 +404,7 @@ if(. <= 0) . = categories.len -/datum/personal_crafting/proc/prev_subcat() +/datum/component/personal_crafting/proc/prev_subcat() if(islist(subcategories[viewing_category])) var/list/subs = subcategories[viewing_category] if(viewing_subcategory == subs.len) @@ -403,7 +417,7 @@ . = null -/datum/personal_crafting/proc/build_recipe_data(datum/crafting_recipe/R) +/datum/component/personal_crafting/proc/build_recipe_data(datum/crafting_recipe/R) var/list/data = list() data["name"] = R.name data["ref"] = "[REF(R)]" @@ -441,4 +455,4 @@ /datum/mind/proc/teach_crafting_recipe(R) if(!learned_recipes) learned_recipes = list() - learned_recipes |= R \ No newline at end of file + learned_recipes |= R diff --git a/code/modules/crafting/guncrafting.dm b/code/datums/components/crafting/guncrafting.dm similarity index 100% rename from code/modules/crafting/guncrafting.dm rename to code/datums/components/crafting/guncrafting.dm diff --git a/code/modules/crafting/recipes.dm b/code/datums/components/crafting/recipes.dm similarity index 100% rename from code/modules/crafting/recipes.dm rename to code/datums/components/crafting/recipes.dm diff --git a/code/modules/crafting/tailoring.dm b/code/datums/components/crafting/tailoring.dm similarity index 100% rename from code/modules/crafting/tailoring.dm rename to code/datums/components/crafting/tailoring.dm diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index 35a17b8984a..e603834f83e 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -23,11 +23,10 @@ create_internal_organs() //most of it is done in set_species now, this is only for parent call physiology = new() - handcrafting = new() - . = ..() AddComponent(/datum/component/redirect, list(COMSIG_COMPONENT_CLEAN_ACT = CALLBACK(src, .proc/clean_blood))) + AddComponent(/datum/component/personal_crafting) /mob/living/carbon/human/proc/setup_human_dna() //initialize dna. for spawned humans; overwritten by other code @@ -45,9 +44,6 @@ return ..() -/mob/living/carbon/human/OpenCraftingMenu() - handcrafting.ui_interact(src) - /mob/living/carbon/human/prepare_data_huds() //Update med hud images... ..() diff --git a/code/modules/mob/living/carbon/human/human_defines.dm b/code/modules/mob/living/carbon/human/human_defines.dm index ea771639b20..0d54d993e99 100644 --- a/code/modules/mob/living/carbon/human/human_defines.dm +++ b/code/modules/mob/living/carbon/human/human_defines.dm @@ -47,7 +47,6 @@ var/name_override //For temporary visible name changes - var/datum/personal_crafting/handcrafting var/datum/physiology/physiology var/list/datum/bioware = list() diff --git a/code/modules/mob/living/simple_animal/simple_animal.dm b/code/modules/mob/living/simple_animal/simple_animal.dm index e37fc9df28a..7ca69de467b 100644 --- a/code/modules/mob/living/simple_animal/simple_animal.dm +++ b/code/modules/mob/living/simple_animal/simple_animal.dm @@ -80,7 +80,6 @@ var/dextrous = FALSE //If the creature has, and can use, hands var/dextrous_hud_type = /datum/hud/dextrous - var/datum/personal_crafting/handcrafting var/AIStatus = AI_ON //The Status of our AI, can be set to AI_ON (On, usual processing), AI_IDLE (Will not process, but will return to AI_ON if an enemy comes near), AI_OFF (Off, Not processing ever), AI_Z_OFF (Temporarily off due to nonpresence of players) var/can_have_ai = TRUE //once we have become sentient, we can never go back @@ -97,7 +96,6 @@ /mob/living/simple_animal/Initialize() . = ..() GLOB.simple_animals[AIStatus] += src - handcrafting = new() if(gender == PLURAL) gender = pick(MALE,FEMALE) if(!real_name) @@ -105,6 +103,8 @@ if(!loc) stack_trace("Simple animal being instantiated in nullspace") update_simplemob_varspeed() + if(dextrous) + AddComponent(/datum/component/personal_crafting) /mob/living/simple_animal/Destroy() GLOB.simple_animals[AIStatus] -= src @@ -429,9 +429,9 @@ mobility_flags = MOBILITY_FLAGS_DEFAULT else mobility_flags = NONE - if(!(mobility_flags & MOBILITY_MOVE)) + if(!(mobility_flags & MOBILITY_MOVE)) walk(src, 0) //stop mid walk - + update_transform() update_action_buttons_icon() @@ -473,10 +473,6 @@ /mob/living/simple_animal/get_idcard(hand_first) return access_card -/mob/living/simple_animal/OpenCraftingMenu() - if(dextrous) - handcrafting.ui_interact(src) - /mob/living/simple_animal/can_hold_items() return dextrous diff --git a/code/modules/mob/login.dm b/code/modules/mob/login.dm index 0b486b498e0..8a4205306e1 100644 --- a/code/modules/mob/login.dm +++ b/code/modules/mob/login.dm @@ -55,6 +55,7 @@ auto_deadmin_on_login() log_message("Client [key_name(src)] has taken ownership of mob [src]([src.type])", LOG_OWNERSHIP) + SEND_SIGNAL(src, COMSIG_MOB_CLIENT_LOGIN, client) /mob/proc/auto_deadmin_on_login() //return true if they're not an admin at the end. if(!client?.holder) diff --git a/tgstation.dme b/tgstation.dme index fbe9a8f8ac2..39f3eb21eda 100755 --- a/tgstation.dme +++ b/tgstation.dme @@ -393,6 +393,10 @@ #include "code\datums\components\waddling.dm" #include "code\datums\components\wearertargeting.dm" #include "code\datums\components\wet_floor.dm" +#include "code\datums\components\crafting\crafting.dm" +#include "code\datums\components\crafting\guncrafting.dm" +#include "code\datums\components\crafting\recipes.dm" +#include "code\datums\components\crafting\tailoring.dm" #include "code\datums\components\decals\blood.dm" #include "code\datums\components\fantasy\_fantasy.dm" #include "code\datums\components\fantasy\affix.dm" @@ -1602,10 +1606,6 @@ #include "code\modules\clothing\under\jobs\Plasmaman\engineering.dm" #include "code\modules\clothing\under\jobs\Plasmaman\medsci.dm" #include "code\modules\clothing\under\jobs\Plasmaman\security.dm" -#include "code\modules\crafting\craft.dm" -#include "code\modules\crafting\guncrafting.dm" -#include "code\modules\crafting\recipes.dm" -#include "code\modules\crafting\tailoring.dm" #include "code\modules\detectivework\detective_work.dm" #include "code\modules\detectivework\evidence.dm" #include "code\modules\detectivework\footprints_and_rag.dm"