Files
SmArtKar 8eed335b94 Refactors inventory UI to be completely datum and vis_contents-based (#95998)
## About The Pull Request

Completely removes individual inventory UI handling from mob and HUD
code and moves it to slot datums.
``/datum/inventory_slot`` now is responsible for displaying items on the
player UI and does so through vis_contests as opposed to screen_loc -
which ensures that wide items will display properly rather than be
offset to the right.
Centralized, slot_id based handling allows us to significantly simplify
inventory and HUD code (see how many lines were removed) as you no
longer need to individually track all items for both the HUD owner and
the observer, and makes it easier for us to fully datumize inventory
handling in the future.

Also fixes a bug where observers would see players' storage UI and have
the items linger on-screen after its closed.

## Why It's Good For The Game

Makes working with inventories and HUDs easier, fixes visual issues with
wide items, I need this for human rendering refactors.

## Changelog
🆑
refactor: Refactors inventory UI to be completely datum and
vis_contents-based
fix: Observers should no longer see doubled up inventory UIs
/🆑

---------

Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
2026-05-31 14:27:23 -07:00

81 lines
2.1 KiB
Plaintext

// Drone inventory procs
/mob/living/basic/drone/doUnEquip(obj/item/item_dropping, force, newloc, no_move, invdrop = TRUE, silent = FALSE)
if(..())
update_held_items()
if(item_dropping == head)
head = null
update_worn_head()
if(item_dropping == internal_storage)
internal_storage = null
update_inv_internal_storage()
return TRUE
return FALSE
/mob/living/basic/drone/can_equip(obj/item/item, slot, disable_warning = FALSE, bypass_equip_delay_self = FALSE, ignore_equipped = FALSE, indirect_action = FALSE)
switch(slot)
if(ITEM_SLOT_HEAD)
if(head)
return FALSE
if(!((item.slot_flags & ITEM_SLOT_HEAD) || (item.slot_flags & ITEM_SLOT_MASK)))
return FALSE
return TRUE
if(ITEM_SLOT_DEX_STORAGE)
if(internal_storage)
return FALSE
return TRUE
..()
/mob/living/basic/drone/get_item_by_slot(slot_id)
switch(slot_id)
if(ITEM_SLOT_HEAD)
return head
if(ITEM_SLOT_DEX_STORAGE)
return internal_storage
return ..()
/mob/living/basic/drone/get_slot_by_item(obj/item/looking_for)
if(internal_storage == looking_for)
return ITEM_SLOT_DEX_STORAGE
if(head == looking_for)
return ITEM_SLOT_HEAD
return ..()
/mob/living/basic/drone/equip_to_slot(obj/item/equipping, slot, initial = FALSE, redraw_mob = FALSE, indirect_action = FALSE)
if(!slot)
return
if(!istype(equipping))
return
var/index = get_held_index_of_item(equipping)
if(index)
held_items[index] = null
update_held_items()
if(equipping.pulledby)
equipping.pulledby.stop_pulling()
hud_used?.update_inventory_slot(slot)
equipping.forceMove(src) //This has to come before has_equipped is called.
SET_PLANE_EXPLICIT(equipping, ABOVE_HUD_PLANE, src)
switch(slot)
if(ITEM_SLOT_HEAD)
head = equipping
update_worn_head()
if(ITEM_SLOT_DEX_STORAGE)
internal_storage = equipping
update_inv_internal_storage()
else
to_chat(src, span_danger("You are trying to equip this item to an unsupported inventory slot. Report this to a coder!"))
return
//Call back for item being equipped to drone
has_equipped(equipping, slot)
/mob/living/basic/drone/getBackSlot()
return ITEM_SLOT_DEX_STORAGE