Skip to content

Commit

Permalink
QoL tweaks to stackable item component
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMelbert committed Jan 31, 2024
1 parent 8d2c5fc commit a9d8583
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 66 deletions.
19 changes: 6 additions & 13 deletions code/modules/mob/living/carbon/human/human_update_icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -662,21 +662,14 @@ generate/load female uniform sprites matching all previously decided variables
use_height_offset = TRUE,
)

// NON-MODULE CHANGE // UPSTREAM ME
//Find a valid icon_state from variables+arguments
var/t_state
if(override_state)
t_state = override_state
else
t_state = !isinhands ? (worn_icon_state ? worn_icon_state : icon_state) : (inhand_icon_state ? inhand_icon_state : icon_state)

var/t_state = override_state || (isinhands ? inhand_icon_state : worn_icon_state) || icon_state
//Find a valid icon file from variables+arguments
var/file2use
if(override_file)
file2use = override_file
else
file2use = !isinhands ? (worn_icon ? worn_icon : default_icon_file) : default_icon_file
var/file2use = override_file || (isinhands ? null : worn_icon) || default_icon_file
//Find a valid layer from variables+arguments
var/layer2use = alternate_worn_layer ? alternate_worn_layer : default_layer
var/layer2use = alternate_worn_layer || default_layer
// NON-MODULE CHANGE END

var/mutable_appearance/standing
if(female_uniform)
Expand All @@ -687,7 +680,7 @@ generate/load female uniform sprites matching all previously decided variables
//Get the overlays for this item when it's being worn
//eg: ammo counters, primed grenade flashes, etc.
var/list/worn_overlays = worn_overlays(standing, isinhands, file2use)
if(worn_overlays?.len)
if(length(worn_overlays)) // NON-MODULE CHANGE
if(!isinhands && default_layer && ishuman(loc) && use_height_offset)
var/mob/living/carbon/human/human_loc = loc
if(human_loc.get_mob_height() != HUMAN_HEIGHT_MEDIUM)
Expand Down
3 changes: 0 additions & 3 deletions maplestation_modules/code/__DEFINES/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
/// (Flavor text should stay at the very very bottom though)
#define COMSIG_LIVING_LATE_EXAMINE "late_examine"

/// Item generating their worn icon
#define COMSIG_ITEM_WORN_ICON_MADE "item_worn_icon_made"

/// Entering or exiting a vent.
#define COMSIG_HANDLE_VENTCRAWLING "handle_ventcrawl"
/// Return to block entrance / exit
Expand Down
65 changes: 25 additions & 40 deletions maplestation_modules/code/datums/components/stackable_item.dm
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
/obj/item/build_worn_icon(
default_layer = 0,
default_icon_file = null,
isinhands = FALSE,
female_uniform = NO_FEMALE_UNIFORM,
override_state = null,
override_file = null,
use_height_offset = TRUE,
)
. = ..()
SEND_SIGNAL(src, COMSIG_ITEM_WORN_ICON_MADE, ., default_layer, default_icon_file, isinhands, female_uniform, override_state, override_file)

/**
* Stackble item component
*
Expand All @@ -18,6 +6,8 @@
* When the parent is equipped, so is the attached item. And when the parent is dropped, so is the attached item.
*/
/datum/component/stackable_item
/// Descriptor for what you can attach to this item.
var/wearable_descriptor = ""
/// List of types that can be worn.
/// Swap to a typecache if people make really large lists.
var/list/wearables
Expand All @@ -30,31 +20,34 @@
/// Optional callback that is called when an item is dropped.
var/datum/callback/on_drop

/datum/component/stackable_item/Initialize(list/wearables, datum/callback/can_stack, datum/callback/on_equip, datum/callback/on_drop)
/datum/component/stackable_item/Initialize(list/wearables, wearable_descriptor, datum/callback/can_stack, datum/callback/on_equip, datum/callback/on_drop)
if(!isitem(parent))
return COMPONENT_INCOMPATIBLE

src.wearables = wearables
src.wearable_descriptor = wearable_descriptor
src.can_stack = can_stack
src.on_equip = on_equip
src.on_drop = on_drop

/datum/component/stackable_item/RegisterWithParent()
RegisterSignal(parent, COMSIG_ITEM_WORN_ICON_MADE, PROC_REF(update_worn_icon))
RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, PROC_REF(item_attackby))
RegisterSignal(parent, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
RegisterSignal(parent, COMSIG_ATOM_EXITED, PROC_REF(atom_exited))
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(item_equipped))
RegisterSignal(parent, COMSIG_ITEM_DROPPED, PROC_REF(item_dropped))
RegisterSignal(parent, COMSIG_ATOM_ATTACKBY, PROC_REF(item_attackby))
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(item_equipped))
RegisterSignal(parent, COMSIG_ITEM_GET_WORN_OVERLAYS, PROC_REF(update_worn_icon))
RegisterSignals(parent, list(COMSIG_ATOM_DESTRUCTION, COMSIG_OBJ_DECONSTRUCT), PROC_REF(on_deconstruct))

/datum/component/stackable_item/UnregisterFromParent()
UnregisterSignal(parent, list(
COMSIG_ITEM_WORN_ICON_MADE,
COMSIG_ATOM_EXITED,
COMSIG_ITEM_EQUIPPED,
COMSIG_ITEM_DROPPED,
COMSIG_ATOM_ATTACKBY,
COMSIG_ATOM_DESTRUCTION,
COMSIG_ATOM_EXAMINE,
COMSIG_ATOM_EXITED,
COMSIG_ITEM_DROPPED,
COMSIG_ITEM_EQUIPPED,
COMSIG_ITEM_GET_WORN_OVERLAYS,
COMSIG_OBJ_DECONSTRUCT,
))

Expand All @@ -65,32 +58,24 @@
on_drop = null
return ..()

/datum/component/stackable_item/proc/update_worn_icon(
obj/item/source,
mutable_appearance/created_icon,
default_layer,
default_icon_file,
isinhands,
female_uniform,
override_state,
override_file,
)
/datum/component/stackable_item/proc/on_examine(obj/item/source, mob/user, list/examine_list)
SIGNAL_HANDLER

if(isnull(stacked_on))
if(wearable_descriptor)
examine_list += span_notice("Looks like you could attach [wearable_descriptor] to it.")

else
examine_list += span_notice("It has \a [stacked_on] attached.")

/datum/component/stackable_item/proc/update_worn_icon(obj/item/source, list/overlays, mutable_appearance/standing, isinhands, ...)
SIGNAL_HANDLER

if(isinhands || isnull(stacked_on))
return

var/mutable_appearance/stacked_overlay = stacked_on.build_worn_icon(
default_layer,
default_icon_file,
isinhands,
female_uniform,
override_state,
override_file,
)

// Add in our new worn icon as an overlay of our item's icon.
created_icon.overlays.Add(stacked_overlay)
overlays += stacked_on.build_worn_icon(standing.layer)

/datum/component/stackable_item/proc/atom_exited(obj/item/source, atom/movable/gone, direction)
SIGNAL_HANDLER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@
. = ..()
AddComponent(/datum/component/stackable_item, \
wearables = list(/obj/item/clothing/glasses/hud), \
wearable_descriptor = "a HUD", \
can_stack = CALLBACK(src, PROC_REF(can_attach_hud)), \
on_drop = CALLBACK(src, PROC_REF(on_drop_patch)), \
)

/obj/item/clothing/glasses/eyepatch/proc/can_attach_hud(obj/item/source, obj/item/clothing/glasses/hud/incoming_hud, mob/user)
// Basically, stops you from attaching HUDglasses. We only want the ones with one eye covered.
return (incoming_hud.flash_protect == 0 && incoming_hud.tint == 0)
return !(incoming_hud.flags_cover & GLASSESCOVERSEYES)

/obj/item/clothing/glasses/eyepatch/proc/on_drop_patch(obj/item/clothing/glasses/hud/equipped_hud, mob/living/carbon/user, silent)
if(!istype(user))
if(!equipped_hud.hud_type)
return
if(user.glasses != src)
return
// This is HUGE hack but hud glasses rely on the user.glasses var to be set to the hud glasses
// If this ever changes this must be removed because then it will call dropped twice, which isn't bad but can be weird
var/obj/item/pre_slot = user.glasses
user.glasses = equipped_hud
equipped_hud.dropped(user, silent)
user.glasses = pre_slot

// A bit of a hack but HUD code checks that user.glasses == equipped_hud
// Which it is not here
// So even though equipping the hud works fine, unequipping it will fail
var/datum/atom_hud/our_hud = GLOB.huds[equipped_hud.hud_type]
our_hud.hide_from(user)

0 comments on commit a9d8583

Please sign in to comment.