From f54b6904b9edfddc1e476ea23aa2ae90dc341e61 Mon Sep 17 00:00:00 2001 From: nicetoolbox <41554512+nicetoolbox@users.noreply.github.com> Date: Wed, 16 Dec 2020 11:47:26 -0800 Subject: [PATCH] Close storage UI when item becomes inaccessible (#14536) * add hide_from_all to storage objects, to call by something once it's locked/close * lockers call hide_from_all on stored storage items * secure storage calls hide_from_all on lock * throwing storage closes it * adding storage to a disposal chute closes it * adding storage to a crate closes it * adding storage to the destructive analyzer closes it --- code/game/objects/items/weapons/storage/secure.dm | 1 + code/game/objects/items/weapons/storage/storage.dm | 14 ++++++++++++++ .../objects/structures/crates_lockers/closets.dm | 3 +++ .../objects/structures/crates_lockers/crates.dm | 3 +++ code/modules/mob/living/carbon/carbon.dm | 3 +++ code/modules/recycling/disposal.dm | 6 ++++-- code/modules/research/destructive_analyzer.dm | 3 +++ 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/code/game/objects/items/weapons/storage/secure.dm b/code/game/objects/items/weapons/storage/secure.dm index 357cb043ca4..c4382092c6b 100644 --- a/code/game/objects/items/weapons/storage/secure.dm +++ b/code/game/objects/items/weapons/storage/secure.dm @@ -147,6 +147,7 @@ else if((href_list["type"] == "R") && (emagged == 0) && (!l_setshort)) locked = 1 + hide_from_all() overlays = null code = null close(usr) diff --git a/code/game/objects/items/weapons/storage/storage.dm b/code/game/objects/items/weapons/storage/storage.dm index a3bafa5b3cf..0c2a51aa26c 100644 --- a/code/game/objects/items/weapons/storage/storage.dm +++ b/code/game/objects/items/weapons/storage/storage.dm @@ -24,6 +24,7 @@ var/allow_quick_gather //Set this variable to allow the object to have the 'toggle mode' verb, which quickly collects all items from a tile. var/collection_mode = 1; //0 = pick one at a time, 1 = pick all on tile var/use_sound = "rustle" //sound played when used. null for no sound. + var/list/active_users = list() // list of ckey(user.key), who is viewing the inventory? /// What kind of [/obj/item/stack] can this be folded into. (e.g. Boxes and cardboard) var/foldable = null @@ -129,6 +130,8 @@ user.client.screen += closer user.client.screen += contents user.s_active = src + if(user.key) + active_users[ckey(user.key)] = TRUE return /obj/item/storage/proc/hide_from(mob/user as mob) @@ -140,8 +143,19 @@ user.client.screen -= src.contents if(user.s_active == src) user.s_active = null + if(user.key) + active_users.Remove(ckey(user.key)) return +/obj/item/storage/proc/hide_from_all() + for(var/K in active_users) + var/client/C = get_client_by_ckey(K) + if(C) + var/mob/M = C.mob + if(M) + hide_from(M) + + /obj/item/storage/proc/open(mob/user as mob) if(src.use_sound) playsound(src.loc, src.use_sound, 50, 1, -5) diff --git a/code/game/objects/structures/crates_lockers/closets.dm b/code/game/objects/structures/crates_lockers/closets.dm index 124fb69f8d3..2831cfa272e 100644 --- a/code/game/objects/structures/crates_lockers/closets.dm +++ b/code/game/objects/structures/crates_lockers/closets.dm @@ -103,6 +103,9 @@ if(!I.anchored) I.forceMove(src) itemcount++ + if(istype(I, /obj/item/storage)) + var/obj/item/storage/S = I + S.hide_from_all() for(var/mob/M in loc) if(itemcount >= storage_capacity) diff --git a/code/game/objects/structures/crates_lockers/crates.dm b/code/game/objects/structures/crates_lockers/crates.dm index f9403f630b2..e88fd036c69 100644 --- a/code/game/objects/structures/crates_lockers/crates.dm +++ b/code/game/objects/structures/crates_lockers/crates.dm @@ -81,6 +81,9 @@ continue O.forceMove(src) itemcount++ + if(istype(O, /obj/item/storage)) + var/obj/item/storage/S = O + S.hide_from_all() icon_state = icon_closed src.opened = FALSE diff --git a/code/modules/mob/living/carbon/carbon.dm b/code/modules/mob/living/carbon/carbon.dm index 7d30b1266fd..9c4e3811df0 100644 --- a/code/modules/mob/living/carbon/carbon.dm +++ b/code/modules/mob/living/carbon/carbon.dm @@ -629,6 +629,9 @@ GLOBAL_LIST_INIT(ventcrawl_machinery, list(/obj/machinery/atmospherics/unary/ven return if(thrown_thing) + if(istype(thrown_thing, /obj/item/storage)) + var/obj/item/storage/S = thrown_thing + S.hide_from_all() visible_message("[src] has thrown [thrown_thing].") newtonian_move(get_dir(target, src)) thrown_thing.throw_at(target, thrown_thing.throw_range, thrown_thing.throw_speed, src, null, null, null, move_force) diff --git a/code/modules/recycling/disposal.dm b/code/modules/recycling/disposal.dm index 9cc426aed0e..f2379320c62 100644 --- a/code/modules/recycling/disposal.dm +++ b/code/modules/recycling/disposal.dm @@ -103,8 +103,8 @@ to_chat(user, "You can't place that item inside the disposal unit.") return - if(istype(I, /obj/item/storage)) - var/obj/item/storage/S = I + var/obj/item/storage/S = I + if(istype(S)) if((S.allow_quick_empty || S.allow_quick_gather) && S.contents.len) S.hide_from(user) user.visible_message("[user] empties \the [S] into \the [src].", "You empty \the [S] into \the [src].") @@ -134,6 +134,8 @@ if(!user.drop_item()) return if(I) + if(istype(S)) + S.hide_from_all() I.forceMove(src) to_chat(user, "You place \the [I] into the [src].") diff --git a/code/modules/research/destructive_analyzer.dm b/code/modules/research/destructive_analyzer.dm index 58a8ab21284..957b54f40b8 100644 --- a/code/modules/research/destructive_analyzer.dm +++ b/code/modules/research/destructive_analyzer.dm @@ -81,6 +81,9 @@ Note: Must be placed within 3 tiles of the R&D Console busy = 1 loaded_item = O O.loc = src + if(istype(O, /obj/item/storage)) + var/obj/item/storage/S = O + S.hide_from_all() to_chat(user, "You add the [O.name] to the [src.name]!") flick("d_analyzer_la", src) spawn(10)