Screentips for anomaly neutralizer / null rod (and other effect removers) (#65221)

This commit is contained in:
MrMelbert
2022-03-09 17:47:40 -08:00
committed by GitHub
parent 6000729e23
commit 8aa42a3833
5 changed files with 33 additions and 1 deletions
+28 -1
View File
@@ -8,6 +8,8 @@
var/success_feedback
/// Line forcesaid by the user on successful removal.
var/success_forcesay
/// The text used in the screentip when our parent is hovering over an item we can clear. Ex "Destroy rune"
var/tip_text
/// Callback invoked with removal is done.
var/datum/callback/on_clear_callback
/// A typecache of all effects we can clear with our item.
@@ -16,6 +18,7 @@
/datum/component/effect_remover/Initialize(
success_forcesay,
success_feedback,
tip_text,
on_clear_callback,
effects_we_clear,
)
@@ -30,14 +33,24 @@
src.success_feedback = success_feedback
src.success_forcesay = success_forcesay
src.tip_text = tip_text
src.on_clear_callback = on_clear_callback
src.effects_we_clear = typecacheof(effects_we_clear)
/datum/component/effect_remover/Destroy(force, silent)
QDEL_NULL(on_clear_callback)
return ..()
/datum/component/effect_remover/RegisterWithParent()
RegisterSignal(parent, COMSIG_ITEM_ATTACK_EFFECT, .proc/try_remove_effect)
if(tip_text)
var/obj/item/item_parent = parent
item_parent.item_flags |= ITEM_HAS_CONTEXTUAL_SCREENTIPS
RegisterSignal(parent, COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET, .proc/add_item_context)
/datum/component/effect_remover/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_ITEM_ATTACK_EFFECT)
UnregisterSignal(parent, list(COMSIG_ITEM_ATTACK_EFFECT, COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET))
/*
* Signal proc for [COMSIG_ITEM_ATTACK_EFFECT].
@@ -67,3 +80,17 @@
if(!QDELETED(target))
qdel(target)
/*
* Signal proc for [COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET].
*
* Adds some context for the target, if we have one set and it's a valid target.
*/
/datum/component/effect_remover/proc/add_item_context(obj/item/source, list/context, atom/target, mob/living/user)
SIGNAL_HANDLER
if(effects_we_clear[target.type])
context[SCREENTIP_CONTEXT_LMB] = tip_text
return CONTEXTUAL_SCREENTIP_SET
return NONE