From 0952de8f1ae9cfd09b7be1e575d9b787bf70e4db Mon Sep 17 00:00:00 2001 From: Iajret Creature <122297233+AnArgonianLizardThatStealsPRs@users.noreply.github.com> Date: Fri, 20 Oct 2023 14:56:49 +0300 Subject: [PATCH] [MIRROR] Fixes modified MA overlays potentially causing duplicate overlays [MDB IGNORE] (#173) * Fixes modified MA overlays potentially causing duplicate overlays (#78719) --------- Co-authored-by: Emmett Gaines --- code/game/atoms.dm | 62 ++++++++++++++----- .../game/objects/items/devices/radio/radio.dm | 4 +- .../reagent_containers/cups/drinks.dm | 2 +- .../reagents/reagent_containers/syringes.dm | 4 +- 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/code/game/atoms.dm b/code/game/atoms.dm index 31af4ca24e6..143c0c8f468 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -782,7 +782,6 @@ /// Updates the icon of the atom /atom/proc/update_icon(updates=ALL) - SIGNAL_HANDLER SHOULD_CALL_PARENT(TRUE) . = NONE @@ -796,19 +795,54 @@ SSvis_overlays.remove_vis_overlay(src, managed_vis_overlays) var/list/new_overlays = update_overlays(updates) - if (managed_overlays) - if (length(overlays) == (islist(managed_overlays) ? length(managed_overlays) : 1)) - overlays = null - POST_OVERLAY_CHANGE(src) - else - cut_overlay(managed_overlays) - managed_overlays = null - if(length(new_overlays)) - if (length(new_overlays) == 1) - managed_overlays = new_overlays[1] - else - managed_overlays = new_overlays - add_overlay(new_overlays) + var/nulls = 0 + for(var/i in 1 to length(new_overlays)) + var/atom/maybe_not_an_atom = new_overlays[i] + if(isnull(maybe_not_an_atom)) + nulls++ + continue + if(istext(maybe_not_an_atom) || isicon(maybe_not_an_atom)) + continue + new_overlays[i] = maybe_not_an_atom.appearance + if(nulls) + for(var/i in 1 to nulls) + new_overlays -= null + + var/identical = FALSE + var/new_length = length(new_overlays) + if(!managed_overlays && !new_length) + identical = TRUE + else if(!islist(managed_overlays)) + if(new_length == 1 && managed_overlays == new_overlays[1]) + identical = TRUE + else if(length(managed_overlays) == new_length) + identical = TRUE + for(var/i in 1 to length(managed_overlays)) + if(managed_overlays[i] != new_overlays[i]) + identical = FALSE + break + + if(!identical) + var/full_control = FALSE + if(managed_overlays) + full_control = length(overlays) == (islist(managed_overlays) ? length(managed_overlays) : 1) + if(full_control) + overlays = null + else + cut_overlay(managed_overlays) + + switch(length(new_overlays)) + if(0) + if(full_control) + POST_OVERLAY_CHANGE(src) + managed_overlays = null + if(1) + add_overlay(new_overlays) + managed_overlays = new_overlays[1] + else + add_overlay(new_overlays) + managed_overlays = new_overlays + . |= UPDATE_OVERLAYS . |= SEND_SIGNAL(src, COMSIG_ATOM_UPDATED_ICON, updates, .) diff --git a/code/game/objects/items/devices/radio/radio.dm b/code/game/objects/items/devices/radio/radio.dm index edd058bedd2..c680056667b 100644 --- a/code/game/objects/items/devices/radio/radio.dm +++ b/code/game/objects/items/devices/radio/radio.dm @@ -484,9 +484,9 @@ . = ..() if(unscrewed) return - if(broadcasting) + if(broadcasting && overlay_mic_idle) . += overlay_mic_idle - if(listening) + if(listening && overlay_speaker_idle) . += overlay_speaker_idle /obj/item/radio/screwdriver_act(mob/living/user, obj/item/tool) diff --git a/code/modules/reagents/reagent_containers/cups/drinks.dm b/code/modules/reagents/reagent_containers/cups/drinks.dm index 2cf34da1a62..88b7d5baabf 100644 --- a/code/modules/reagents/reagent_containers/cups/drinks.dm +++ b/code/modules/reagents/reagent_containers/cups/drinks.dm @@ -227,8 +227,8 @@ custom_price = PAYCHECK_LOWER * 0.8 /obj/item/reagent_containers/cup/glass/waterbottle/Initialize(mapload) - . = ..() cap_overlay = mutable_appearance(cap_icon, cap_icon_state) + . = ..() if(cap_on) spillable = FALSE update_appearance() diff --git a/code/modules/reagents/reagent_containers/syringes.dm b/code/modules/reagents/reagent_containers/syringes.dm index beed3d17ba6..4366482460e 100644 --- a/code/modules/reagents/reagent_containers/syringes.dm +++ b/code/modules/reagents/reagent_containers/syringes.dm @@ -145,7 +145,9 @@ /obj/item/reagent_containers/syringe/update_overlays() . = ..() - . += update_reagent_overlay() + var/list/reagent_overlays = update_reagent_overlay() + if(reagent_overlays) + . += reagent_overlays /// Returns a list of overlays to add that relate to the reagents inside the syringe /obj/item/reagent_containers/syringe/proc/update_reagent_overlay()