Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning up action/action button/item qdels. #4821

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions code/_onclick/hud/action.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions code/_onclick/hud/screen/screen_action_button.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..()
Expand Down
10 changes: 9 additions & 1 deletion code/game/objects/items/__item.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/augment/active.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
16 changes: 9 additions & 7 deletions code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion code/modules/organs/organ.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mods/species/adherent/organs/organs_internal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions mods/species/ascent/mobs/bodyparts.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion mods/species/ascent/mobs/bodyparts_insectoid.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions mods/species/serpentid/mobs/bodyparts_serpentid.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down