From 74117fc20d519972e08b1a0ac84104dfa421f26c Mon Sep 17 00:00:00 2001 From: MistakeNot4892 Date: Mon, 27 Jan 2025 21:27:10 +1100 Subject: [PATCH] Cleaning up action/action button/item qdels. --- code/_onclick/hud/action.dm | 6 ++++++ code/_onclick/hud/screen/screen_action_button.dm | 8 ++++++++ code/game/objects/items/__item.dm | 10 +++++++++- code/modules/augment/active.dm | 2 +- code/modules/mob/living/living.dm | 16 +++++++++------- code/modules/organs/organ.dm | 3 ++- mods/species/adherent/organs/organs_internal.dm | 4 ++-- mods/species/ascent/mobs/bodyparts.dm | 4 ++-- mods/species/ascent/mobs/bodyparts_insectoid.dm | 2 +- .../serpentid/mobs/bodyparts_serpentid.dm | 6 +++--- 10 files changed, 43 insertions(+), 18 deletions(-) diff --git a/code/_onclick/hud/action.dm b/code/_onclick/hud/action.dm index e122262cdb9..54ff7214507 100644 --- a/code/_onclick/hud/action.dm +++ b/code/_onclick/hud/action.dm @@ -34,6 +34,12 @@ /datum/action/Destroy() if(owner) Remove(owner) + QDEL_NULL(button) + if(target) + var/obj/item/target_item = target + if(istype(target_item) && target_item.action == src) + target_item.action = null + target = null return ..() /datum/action/proc/SetTarget(var/atom/Target) diff --git a/code/_onclick/hud/screen/screen_action_button.dm b/code/_onclick/hud/screen/screen_action_button.dm index df79fa29ce4..5d551299698 100644 --- a/code/_onclick/hud/screen/screen_action_button.dm +++ b/code/_onclick/hud/screen/screen_action_button.dm @@ -3,6 +3,14 @@ requires_ui_style = FALSE var/datum/action/action +/obj/screen/action_button/Destroy() + if(!QDELETED(action)) + if(action.button == src) + action.button = null + QDEL_NULL(action) + action = null + return ..() + /obj/screen/action_button/Initialize(mapload, mob/_owner, ui_style, ui_color, ui_alpha, ui_cat, _action) action = _action return ..() diff --git a/code/game/objects/items/__item.dm b/code/game/objects/items/__item.dm index 7c41d0aa13f..4c117c1333d 100644 --- a/code/game/objects/items/__item.dm +++ b/code/game/objects/items/__item.dm @@ -38,7 +38,7 @@ var/max_pressure_protection // Set this variable if the item protects its wearer against high pressures below an upper bound. Keep at null to disable protection. var/min_pressure_protection // Set this variable if the item protects its wearer against low pressures above a lower bound. Keep at null to disable protection. 0 represents protection against hard vacuum. - var/datum/action/item_action/action = null + var/datum/action/item_action/action var/action_button_name //It is also the text which gets displayed on the action button. If not set it defaults to 'Use [name]'. If it's not set, there'll be no button. var/action_button_desc //A description for action button which will be displayed as tooltip. var/default_action_type = /datum/action/item_action // Specify the default type and behavior of the action button for this atom. @@ -242,6 +242,14 @@ QDEL_NULL(hidden_uplink) QDEL_NULL(coating) + if(istype(action)) + if(action.target == src) + action.target = null + if(!QDELETED(action)) + QDEL_NULL(action) + else + action = null + if(ismob(loc)) var/mob/M = loc LAZYREMOVE(M.pinned, src) diff --git a/code/modules/augment/active.dm b/code/modules/augment/active.dm index ff063b65cc4..e338d1e763c 100644 --- a/code/modules/augment/active.dm +++ b/code/modules/augment/active.dm @@ -19,6 +19,6 @@ //Need to change icon? /obj/item/organ/internal/augment/active/refresh_action_button() . = ..() - if(.) + if(. && istype(action)) action.button_icon_state = icon_state action.button?.update_icon() diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index dcbc0d2917e..5d8a988c673 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -1134,13 +1134,15 @@ default behaviour is: if(A.CheckRemoval(src)) A.Remove(src) for(var/obj/item/I in src) - if(I.action_button_name) - if(!I.action) - I.action = new I.default_action_type - I.action.name = I.action_button_name - I.action.desc = I.action_button_desc - I.action.SetTarget(I) - I.action.Grant(src) + if(QDELETED(I)) + continue + if(!I.action_button_name) + continue + I.action ||= new I.default_action_type + I.action.name = I.action_button_name + I.action.desc = I.action_button_desc + I.action.SetTarget(I) + I.action.Grant(src) return /mob/living/update_action_buttons() diff --git a/code/modules/organs/organ.dm b/code/modules/organs/organ.dm index 36d6a3ac531..f8d2c163442 100644 --- a/code/modules/organs/organ.dm +++ b/code/modules/organs/organ.dm @@ -57,7 +57,8 @@ return /obj/item/organ/proc/refresh_action_button() - return action + if(!QDELETED(src) && istype(action)) + return action /obj/item/organ/attack_self(var/mob/user) return (owner && loc == owner && owner == user) diff --git a/mods/species/adherent/organs/organs_internal.dm b/mods/species/adherent/organs/organs_internal.dm index 94990cd3f5e..ecf758dde07 100644 --- a/mods/species/adherent/organs/organs_internal.dm +++ b/mods/species/adherent/organs/organs_internal.dm @@ -16,7 +16,7 @@ /obj/item/organ/internal/brain/adherent/refresh_action_button() . = ..() - if(.) + if(. && istype(action)) action.button_icon_state = "adherent-brain" action.button?.update_icon() @@ -66,7 +66,7 @@ /obj/item/organ/internal/powered/refresh_action_button() . = ..() - if(.) + if(. && istype(action)) action.button_icon_state = "[base_action_state]-[active ? "on" : "off"]" action.button?.update_icon() diff --git a/mods/species/ascent/mobs/bodyparts.dm b/mods/species/ascent/mobs/bodyparts.dm index dba73c0e121..ec27acd8e0f 100644 --- a/mods/species/ascent/mobs/bodyparts.dm +++ b/mods/species/ascent/mobs/bodyparts.dm @@ -19,7 +19,7 @@ /obj/item/organ/external/groin/insectoid/mantid/refresh_action_button() . = ..() - if(.) + if(. && istype(action)) action.button_icon_state = "weave-web-[organ_cooldown ? "off" : "on"]" action.button?.update_icon() @@ -64,7 +64,7 @@ /obj/item/organ/external/head/insectoid/mantid/refresh_action_button() . = ..() - if(.) + if(. && istype(action)) action.button_icon_state = "shot-web-[organ_cooldown ? "off" : "on"]" action.button?.update_icon() diff --git a/mods/species/ascent/mobs/bodyparts_insectoid.dm b/mods/species/ascent/mobs/bodyparts_insectoid.dm index 5198e90b337..f083fe98fec 100644 --- a/mods/species/ascent/mobs/bodyparts_insectoid.dm +++ b/mods/species/ascent/mobs/bodyparts_insectoid.dm @@ -10,7 +10,7 @@ /obj/item/organ/internal/egg_sac/insectoid/refresh_action_button() . = ..() - if(.) + if(. && istype(action)) action.button_icon_state = "egg-on" action.button?.update_icon() diff --git a/mods/species/serpentid/mobs/bodyparts_serpentid.dm b/mods/species/serpentid/mobs/bodyparts_serpentid.dm index 31f79e3f7c9..ac2db4bd238 100644 --- a/mods/species/serpentid/mobs/bodyparts_serpentid.dm +++ b/mods/species/serpentid/mobs/bodyparts_serpentid.dm @@ -20,7 +20,7 @@ /obj/item/organ/internal/eyes/insectoid/serpentid/refresh_action_button() . = ..() - if(.) + if(. && istype(action)) action.button_icon_state = "shield-[eyes_shielded ? 1 : 0]" action.button?.update_icon() @@ -129,7 +129,7 @@ /obj/item/organ/external/chest/insectoid/serpentid/refresh_action_button() . = ..() - if(.) + if(. && istype(action)) action.button_icon_state = "threat" action.button?.update_icon() @@ -184,7 +184,7 @@ /obj/item/organ/external/groin/insectoid/serpentid/refresh_action_button() . = ..() - if(.) + if(. && istype(action)) action.button_icon_state = "cloak-[owner && owner.is_cloaked_by(species) ? 1 : 0]" action.button?.update_icon()