diff --git a/code/datums/components/lockable_storage.dm b/code/datums/components/lockable_storage.dm index df230061632..b6bf81cef9d 100644 --- a/code/datums/components/lockable_storage.dm +++ b/code/datums/components/lockable_storage.dm @@ -37,7 +37,7 @@ src.lock_code = lock_code if(!isnull(lock_code)) - atom_parent.atom_storage.locked = STORAGE_FULLY_LOCKED + atom_parent.atom_storage.set_locked(STORAGE_FULLY_LOCKED) src.can_hack_open = can_hack_open atom_parent.update_appearance() @@ -208,9 +208,7 @@ //you can't lock it if it's already locked or lacks a lock code. if(source.atom_storage.locked || isnull(lock_code)) return TRUE - source.atom_storage.locked = STORAGE_FULLY_LOCKED - source.atom_storage.hide_contents(usr) - source.update_appearance(UPDATE_ICON) + source.atom_storage.set_locked(STORAGE_FULLY_LOCKED) return TRUE //setting a password & unlocking if("E") @@ -225,9 +223,8 @@ if(numeric_input != lock_code) return TRUE var/atom/source = parent - source.atom_storage.locked = STORAGE_NOT_LOCKED + source.atom_storage.set_locked(STORAGE_NOT_LOCKED) numeric_input = "" - source.update_appearance(UPDATE_ICON) return TRUE //putting digits in. if("0", "1", "2", "3", "4", "5", "6", "7", "8", "9") diff --git a/code/datums/storage/storage.dm b/code/datums/storage/storage.dm index 42668fb1464..ef2f8919a9a 100644 --- a/code/datums/storage/storage.dm +++ b/code/datums/storage/storage.dm @@ -147,7 +147,7 @@ /datum/storage/Destroy() - for(var/mob/person in is_using) + for(var/mob/person as anything in is_using) hide_contents(person) is_using.Cut() @@ -671,7 +671,7 @@ GLOBAL_LIST_EMPTY(cached_storage_typecaches) /datum/storage/proc/remove_and_refresh(atom/movable/gone) SIGNAL_HANDLER - for(var/mob/user in is_using) + for(var/mob/user as anything in is_using) if(user.client) var/client/cuser = user.client cuser.screen -= gone @@ -958,9 +958,15 @@ GLOBAL_LIST_EMPTY(cached_storage_typecaches) /// Close the storage UI for everyone viewing us. /datum/storage/proc/close_all() - for(var/mob/user in is_using) + for(var/mob/user as anything in is_using) hide_contents(user) +/// Closes the storage UIs of this and everything inside the parent for everyone viewing them. +/datum/storage/proc/close_all_recursive() + close_all() + for(var/atom/movable/movable as anything in parent.get_all_contents()) + movable.atom_storage?.close_all() + /// Refresh the views of everyone currently viewing the storage. /datum/storage/proc/refresh_views() for (var/mob/user in can_see_contents()) @@ -1141,3 +1147,12 @@ GLOBAL_LIST_EMPTY(cached_storage_typecaches) return changed.visible_message(span_warning("[changed] falls out of [parent]!"), vision_distance = COMBAT_MESSAGE_RANGE) + +///Assign a new value to the locked variable. If it's higher than NOT_LOCKED, close the UIs and update the appearance of the parent. +/datum/storage/proc/set_locked(new_locked) + if(locked == new_locked) + return + locked = new_locked + if(new_locked > STORAGE_NOT_LOCKED) + close_all_recursive() + parent.update_appearance() diff --git a/code/game/objects/items/storage/backpack.dm b/code/game/objects/items/storage/backpack.dm index f2ed4287c11..2375ce8e498 100644 --- a/code/game/objects/items/storage/backpack.dm +++ b/code/game/objects/items/storage/backpack.dm @@ -499,19 +499,16 @@ SEND_SIGNAL(src, COMSIG_DUFFEL_ZIP_CHANGE, new_zip) if(zipped_up) slowdown = initial(slowdown) - atom_storage.locked = STORAGE_SOFT_LOCKED + atom_storage.set_locked(STORAGE_SOFT_LOCKED) atom_storage.display_contents = FALSE - for(var/obj/item/weapon as anything in get_all_contents_type(/obj/item)) //close ui of this and all items inside dufflebag - weapon.atom_storage?.close_all() //not everything has storage initialized else slowdown = zip_slowdown - atom_storage.locked = STORAGE_NOT_LOCKED + atom_storage.set_locked(STORAGE_NOT_LOCKED) atom_storage.display_contents = TRUE if(isliving(loc)) var/mob/living/wearer = loc wearer.update_equipment_speed_mods() - update_appearance() /obj/item/storage/backpack/duffelbag/cursed name = "living duffel bag" diff --git a/code/game/objects/items/storage/lockbox.dm b/code/game/objects/items/storage/lockbox.dm index ebe523e91be..ba7e1f08f8b 100644 --- a/code/game/objects/items/storage/lockbox.dm +++ b/code/game/objects/items/storage/lockbox.dm @@ -20,10 +20,9 @@ atom_storage.max_specific_storage = WEIGHT_CLASS_NORMAL atom_storage.max_total_storage = 14 atom_storage.max_slots = 4 - atom_storage.locked = STORAGE_FULLY_LOCKED + atom_storage.set_locked(STORAGE_FULLY_LOCKED) register_context() - update_appearance() /obj/item/storage/lockbox/tool_act(mob/living/user, obj/item/tool, list/modifiers) var/obj/item/card/card = tool.GetID() @@ -44,13 +43,8 @@ return FALSE /obj/item/storage/lockbox/proc/toggle_locked(mob/living/user) - if(atom_storage.locked) - atom_storage.locked = STORAGE_NOT_LOCKED - else - atom_storage.locked = STORAGE_FULLY_LOCKED - atom_storage.close_all() + atom_storage.set_locked(atom_storage.locked ? STORAGE_NOT_LOCKED : STORAGE_FULLY_LOCKED) balloon_alert(user, atom_storage.locked ? "locked" : "unlocked") - update_appearance() /obj/item/storage/lockbox/update_icon_state() . = ..() @@ -66,11 +60,10 @@ /obj/item/storage/lockbox/emag_act(mob/user, obj/item/card/emag/emag_card) if(!broken) broken = TRUE - atom_storage.locked = STORAGE_NOT_LOCKED + atom_storage.set_locked(STORAGE_NOT_LOCKED) balloon_alert(user, "lock destroyed") if (emag_card && user) user.visible_message(span_warning("[user] swipes [emag_card] over [src], breaking it!")) - update_appearance() return TRUE return FALSE diff --git a/code/game/objects/items/storage/toolbox.dm b/code/game/objects/items/storage/toolbox.dm index 010da30b124..bdabaee1d57 100644 --- a/code/game/objects/items/storage/toolbox.dm +++ b/code/game/objects/items/storage/toolbox.dm @@ -643,7 +643,7 @@ /obj/item/storage/toolbox/guncase/monkeycase/Initialize(mapload) . = ..() - atom_storage.locked = STORAGE_SOFT_LOCKED + atom_storage.set_locked(STORAGE_SOFT_LOCKED) /obj/item/storage/toolbox/guncase/monkeycase/attack_self(mob/user, modifiers) if(!monkey_check(user)) diff --git a/code/game/objects/structures/secure_safe.dm b/code/game/objects/structures/secure_safe.dm index 9e1bf9b5ade..e3a74c00300 100644 --- a/code/game/objects/structures/secure_safe.dm +++ b/code/game/objects/structures/secure_safe.dm @@ -13,7 +13,7 @@ max_specific_storage = WEIGHT_CLASS_GIGANTIC, max_total_storage = 20, ) - atom_storage.locked = STORAGE_FULLY_LOCKED + atom_storage.set_locked(STORAGE_FULLY_LOCKED) /obj/item/wallframe/secure_safe/after_attach(obj/attached_to) . = ..() diff --git a/code/modules/lost_crew/lost_crew_manager.dm b/code/modules/lost_crew/lost_crew_manager.dm index ed222e063b6..79efd7a62d2 100644 --- a/code/modules/lost_crew/lost_crew_manager.dm +++ b/code/modules/lost_crew/lost_crew_manager.dm @@ -148,9 +148,8 @@ GLOBAL_DATUM_INIT(lost_crew_manager, /datum/lost_crew_manager, new) if(!atom_storage.locked) return - atom_storage.locked = STORAGE_NOT_LOCKED + atom_storage.set_locked(STORAGE_NOT_LOCKED) balloon_alert(user, "unlocked") - update_appearance() /obj/item/storage/lockbox/mind/add_context(atom/source, list/context, obj/item/held_item, mob/user) if(broken || user.mind != mind) diff --git a/code/modules/mod/modules/modules_general.dm b/code/modules/mod/modules/modules_general.dm index 21ae23ee46d..2ddb7ccdc66 100644 --- a/code/modules/mod/modules/modules_general.dm +++ b/code/modules/mod/modules/modules_general.dm @@ -22,19 +22,19 @@ . = ..() create_storage(max_specific_storage = max_w_class, max_total_storage = max_combined_w_class, max_slots = max_items) atom_storage.allow_big_nesting = TRUE - atom_storage.locked = STORAGE_FULLY_LOCKED + atom_storage.set_locked(STORAGE_FULLY_LOCKED) /obj/item/mod/module/storage/on_install() var/datum/storage/modstorage = mod.create_storage(max_specific_storage = max_w_class, max_total_storage = max_combined_w_class, max_slots = max_items) modstorage.set_real_location(src) modstorage.allow_big_nesting = big_nesting - atom_storage.locked = STORAGE_NOT_LOCKED + atom_storage.set_locked(STORAGE_NOT_LOCKED) var/obj/item/clothing/suit = mod.get_part_from_slot(ITEM_SLOT_OCLOTHING) if(istype(suit)) RegisterSignal(suit, COMSIG_ITEM_PRE_UNEQUIP, PROC_REF(on_suit_unequip)) /obj/item/mod/module/storage/on_uninstall(deleting = FALSE) - atom_storage.locked = STORAGE_FULLY_LOCKED + atom_storage.set_locked(STORAGE_FULLY_LOCKED) QDEL_NULL(mod.atom_storage) if(!deleting) atom_storage.remove_all(mod.drop_location()) diff --git a/code/modules/reagents/chemistry/machinery/portable_chem_mixer.dm b/code/modules/reagents/chemistry/machinery/portable_chem_mixer.dm index b9642f19c12..9ea2603cdf6 100644 --- a/code/modules/reagents/chemistry/machinery/portable_chem_mixer.dm +++ b/code/modules/reagents/chemistry/machinery/portable_chem_mixer.dm @@ -257,12 +257,7 @@ /obj/item/storage/portable_chem_mixer/item_ctrl_click(mob/user) if(atom_storage.locked == STORAGE_FULLY_LOCKED) - atom_storage.locked = STORAGE_NOT_LOCKED replace_beaker(user) SStgui.close_uis(src) - else - atom_storage.locked = STORAGE_FULLY_LOCKED - atom_storage.hide_contents(user) - - update_appearance() + atom_storage.set_locked(atom_storage.locked ? STORAGE_NOT_LOCKED : STORAGE_FULLY_LOCKED) return CLICK_ACTION_SUCCESS