Files
Bubberstation/code/datums/components/style/style_meter.dm
LemonInTheDark ae5a4f955d Pulls apart the vestiges of components still hanging onto signals (#75914)
## About The Pull Request

Signals were initially only usable with component listeners, which while
no longer the case has lead to outdated documentation, names, and a
similar location in code.

This pr pulls the two apart. Partially because mso thinks we should, but
also because they really aren't directly linked anymore, and having them
in this midstate just confuses people.

[Renames comp_lookup to listen_lookup, since that's what it
does](102b79694f)

[Moves signal procs over to their own
file](33d07d01fd)

[Renames the PREQDELETING and QDELETING comsigs to drop the parent bit
since they can hook to more then just comps
now](335ea4ad08)

[Does something similar to the attackby comsigs (PARENT ->
ATOM)](210e57051d)

[And finally passes over the examine
signals](65917658fb)

## Why It's Good For The Game

Code makes more sense, things are better teased apart, s just good imo

## Changelog
🆑
refactor: Pulled apart the last vestiges of names/docs directly linking
signals to components
/🆑
2023-06-09 06:14:31 +00:00

140 lines
4.8 KiB
Plaintext

/obj/item/style_meter
name = "style meter attachment"
desc = "Attach this to a pair of glasses to install a style meter system in them. \
You get style points from performing stylish acts and lose them for breaking your style. \
The style affects the quality of your mining, with you being able to mine ore better during a good chain. \
A responsive data HUD gives you the ability to reflect lavaland-based projectiles by punching them with an empty hand. \
In addition, at high style, you are able to swap an item in your hand with one in your backpack by <b>hitting</b> one with another."
icon_state = "style_meter"
icon = 'icons/obj/clothing/glasses.dmi'
/// The style meter component we give.
var/datum/component/style/style_meter
/// Mutable appearance added to the attached glasses
var/mutable_appearance/meter_appearance
/// If this is multitooled, which is passed onto the component on-creation, if one doesn't currently exist
var/multitooled = FALSE
/obj/item/style_meter/Initialize(mapload)
. = ..()
meter_appearance = mutable_appearance(icon, icon_state)
RegisterSignal(src, COMSIG_ATOM_TOOL_ACT(TOOL_MULTITOOL), PROC_REF(on_multitool))
/obj/item/style_meter/Destroy(force)
if(istype(loc, /obj/item/clothing/glasses))
clean_up(loc)
return ..()
/obj/item/style_meter/examine(mob/user)
. = ..()
. += span_notice("You feel like a <b>multitool</b> could be used on this.")
/obj/item/style_meter/afterattack(atom/movable/attacked_atom, mob/user, proximity_flag, click_parameters)
. = ..()
if(!istype(attacked_atom, /obj/item/clothing/glasses))
return
forceMove(attacked_atom)
attacked_atom.add_overlay(meter_appearance)
RegisterSignal(attacked_atom, COMSIG_ITEM_EQUIPPED, PROC_REF(check_wearing))
RegisterSignal(attacked_atom, COMSIG_ITEM_DROPPED, PROC_REF(on_drop))
RegisterSignal(attacked_atom, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
RegisterSignal(attacked_atom, COMSIG_CLICK_ALT, PROC_REF(on_altclick))
RegisterSignal(attacked_atom, COMSIG_ATOM_TOOL_ACT(TOOL_MULTITOOL), PROC_REF(on_multitool))
balloon_alert(user, "style meter attached")
playsound(src, 'sound/machines/click.ogg', 30, TRUE)
if(!iscarbon(attacked_atom.loc))
return
var/mob/living/carbon/carbon_wearer = attacked_atom.loc
if(carbon_wearer.glasses != attacked_atom)
return
style_meter = carbon_wearer.AddComponent(/datum/component/style, multitooled)
/obj/item/style_meter/Moved(atom/old_loc, Dir, momentum_change)
. = ..()
if(!istype(old_loc, /obj/item/clothing/glasses))
return
clean_up(old_loc)
/// Check if the glasses that this meter is linked with are being worn
/obj/item/style_meter/proc/check_wearing(datum/source, mob/equipper, slot)
SIGNAL_HANDLER
if(!(slot & ITEM_SLOT_EYES))
if(style_meter)
QDEL_NULL(style_meter)
return
style_meter = equipper.AddComponent(/datum/component/style, multitooled)
/// Signal proc for when the meter-holding glasses are dropped/unequipped
/obj/item/style_meter/proc/on_drop(datum/source, mob/user)
SIGNAL_HANDLER
if(!style_meter)
return
QDEL_NULL(style_meter)
/// Signal proc for on-examine
/obj/item/style_meter/proc/on_examine(datum/source, mob/user, list/examine_list)
SIGNAL_HANDLER
examine_list += span_notice("You feel like a <b>multitool</b> could be used on this.")
examine_list += span_notice("<b>Alt-click</b> to remove the style meter.")
/// Signal proc to remove from glasses
/obj/item/style_meter/proc/on_altclick(datum/source, mob/user)
SIGNAL_HANDLER
if(istype(loc, /obj/item/clothing/glasses))
clean_up()
forceMove(get_turf(src))
return COMPONENT_CANCEL_CLICK_ALT
/// Signal proc for when the glasses or the meter is multitooled
/obj/item/style_meter/proc/on_multitool(datum/source, mob/living/user, obj/item/tool, list/recipes)
multitooled = !multitooled
if(style_meter)
SEND_SIGNAL(style_meter, COMSIG_ATOM_TOOL_ACT(TOOL_MULTITOOL), user, tool, recipes)
else
balloon_alert(user, "meter [multitooled ? "" : "un"]hacked")
/// Unregister signals and just generally clean up ourselves after being removed from glasses
/obj/item/style_meter/proc/clean_up(atom/movable/old_location)
old_location.cut_overlay(meter_appearance)
UnregisterSignal(old_location, COMSIG_ITEM_EQUIPPED)
UnregisterSignal(old_location, COMSIG_ITEM_DROPPED)
UnregisterSignal(old_location, COMSIG_ATOM_EXAMINE)
UnregisterSignal(old_location, COMSIG_ATOM_TOOL_ACT(TOOL_MULTITOOL))
if(!style_meter)
return
QDEL_NULL(style_meter)
/atom/movable/screen/style_meter_background
icon_state = "style_meter_background"
icon = 'icons/hud/style_meter.dmi'
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
screen_loc = "WEST,CENTER:16"
maptext_height = 120
maptext_width = 105
maptext_x = 5
maptext_y = 100
maptext = ""
layer = SCREENTIP_LAYER
/atom/movable/screen/style_meter
icon_state = "style_meter"
icon = 'icons/hud/style_meter.dmi'
layer = SCREENTIP_LAYER
mouse_opacity = MOUSE_OPACITY_TRANSPARENT