mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-20 19:44:09 +01:00
refactor action buttons (#29416)
* refactor action buttons * fix cult spell charge overlay * lewc review * update for a/mhelp buttons and xenobio organs * update for minebot * properly create button each time * directly add/remove unavail overlay for reasons * lewc review
This commit is contained in:
committed by
GitHub
parent
f9016e65ff
commit
56f4960ed4
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Apply to an action to allow it to take an item
|
||||
* and apply it as an overlay of the action button
|
||||
*/
|
||||
/datum/component/action_item_overlay
|
||||
/// UID of the item the component uses to apply as an overlay.
|
||||
var/item_uid
|
||||
/// Callback that dictates what item the component uses to apply as an overlay.
|
||||
var/datum/callback/item_callback
|
||||
|
||||
/// The appearance of the item we've applied
|
||||
var/mutable_appearance/item_appearance
|
||||
|
||||
/datum/component/action_item_overlay/Initialize(atom/movable/item, datum/callback/item_callback)
|
||||
if(!istype(parent, /datum/action))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
|
||||
if(item && !istype(item))
|
||||
stack_trace("[type] created with a non-null, non-movable item; item must be null or movable")
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
|
||||
if(!item && !item_callback)
|
||||
stack_trace("[type] created without a reference item or an item callback - one or the other is required.")
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
|
||||
src.item_uid = item.UID()
|
||||
src.item_callback = item_callback
|
||||
|
||||
/datum/component/action_item_overlay/Destroy(force)
|
||||
item_uid = null
|
||||
item_callback = null
|
||||
item_appearance = null
|
||||
return ..()
|
||||
|
||||
/datum/component/action_item_overlay/RegisterWithParent()
|
||||
RegisterSignal(parent, COMSIG_ACTION_OVERLAY_APPLY, PROC_REF(on_overlays_applied))
|
||||
|
||||
var/datum/action/parent_action = parent
|
||||
parent_action.build_all_button_icons(UPDATE_BUTTON_OVERLAY)
|
||||
|
||||
/datum/component/action_item_overlay/UnregisterFromParent()
|
||||
UnregisterSignal(parent, COMSIG_ACTION_OVERLAY_APPLY)
|
||||
|
||||
// If we're being unregistered / deleted but our parent is sticking around,
|
||||
// force an overlay update to get rid of our item appearance
|
||||
if(!QDELING(parent))
|
||||
var/datum/action/parent_action = parent
|
||||
parent_action.build_all_button_icons(UPDATE_BUTTON_OVERLAY)
|
||||
|
||||
/// Signal proc for [COMSIG_ACTION_OVERLAY_APPLY], applies the item appearance if possible.
|
||||
/datum/component/action_item_overlay/proc/on_overlays_applied(datum/action/source, atom/movable/screen/movable/action_button/current_button, force)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
// We're in the middle of being removed / deleted, remove our associated overlay
|
||||
if(QDELING(src))
|
||||
if(item_appearance)
|
||||
current_button.cut_overlay(item_appearance)
|
||||
item_appearance = null
|
||||
return
|
||||
|
||||
var/atom/movable/muse = item_callback?.Invoke() || locateUID(item_uid)
|
||||
if(!istype(muse))
|
||||
if(item_appearance) // New item does not exist but we have an old appearance
|
||||
current_button.cut_overlay(item_appearance)
|
||||
item_appearance = null
|
||||
return
|
||||
|
||||
if(item_appearance)
|
||||
// For caching purposes, we will try not to update if we don't need to
|
||||
if(!force && item_appearance.icon == muse.icon && item_appearance.icon_state == muse.icon_state)
|
||||
return
|
||||
current_button.cut_overlay(item_appearance)
|
||||
|
||||
var/mutable_appearance/muse_appearance = new(muse.appearance)
|
||||
muse_appearance.plane = FLOAT_PLANE
|
||||
muse_appearance.layer = FLOAT_LAYER
|
||||
muse_appearance.pixel_x = 0
|
||||
muse_appearance.pixel_y = 0
|
||||
|
||||
current_button.add_overlay(muse_appearance)
|
||||
item_appearance = muse_appearance
|
||||
@@ -276,4 +276,4 @@
|
||||
/datum/action/zoom
|
||||
name = "Toggle Scope"
|
||||
check_flags = AB_CHECK_CONSCIOUS|AB_CHECK_RESTRAINED|AB_CHECK_STUNNED|AB_CHECK_LYING
|
||||
button_overlay_icon_state = "sniper_zoom"
|
||||
button_icon_state = "sniper_zoom"
|
||||
|
||||
Reference in New Issue
Block a user