diff --git a/code/__DEFINES/action.dm b/code/__DEFINES/action.dm index a62a864a60c..52b21e90cd8 100644 --- a/code/__DEFINES/action.dm +++ b/code/__DEFINES/action.dm @@ -20,8 +20,6 @@ // /datum/action/ability/xeno_action. Additional references /// A mutable appearance to add the "empowered" frame around the edges #define VREF_MUTABLE_EMPOWERED_FRAME "VREF_EMPOWERED_FRAME" -/// A image to show the clock delay ticking. -#define VREF_IMAGE_XENO_CLOCK "VREF_ACTION_CLOCK" /// A reference for the build counter of a xeno #define VREF_MUTABLE_BUILDING_COUNTER "VREF_BUILD_COUNTER" // extra reference for the amount of landslide charges we have diff --git a/code/datums/actions/ability_actions.dm b/code/datums/actions/ability_actions.dm index 202cbc67f0f..f1f0109ac6b 100644 --- a/code/datums/actions/ability_actions.dm +++ b/code/datums/actions/ability_actions.dm @@ -17,15 +17,14 @@ var/target_flags = NONE /// flags to restrict an ability to certain gamemode var/gamemode_flags = ABILITY_ALL_GAMEMODE + ///Cooldown map text holder + var/obj/effect/countdown/action_cooldown/countdown /datum/action/ability/New(Target) . = ..() if(ability_cost) name = "[name] ([ability_cost])" - var/image/cooldown_image = image('icons/effects/progressicons.dmi', null, "busy_clock", ACTION_LAYER_CLOCK) - cooldown_image.pixel_y = 7 - cooldown_image.appearance_flags = RESET_COLOR|RESET_ALPHA - visual_references[VREF_IMAGE_XENO_CLOCK] = cooldown_image + countdown = new(button, src) /datum/action/ability/give_action(mob/living/L) . = ..() @@ -136,7 +135,8 @@ if(cooldown_timer || !cooldown_length) // stop doubling up or waiting on zero return cooldown_timer = addtimer(CALLBACK(src, PROC_REF(on_cooldown_finish)), cooldown_length, TIMER_STOPPABLE) - button.add_overlay(visual_references[VREF_IMAGE_XENO_CLOCK]) + countdown.start() + update_button_icon() ///Time remaining on cooldown /datum/action/ability/proc/cooldown_remaining() @@ -147,7 +147,8 @@ cooldown_timer = null if(!button) CRASH("no button object on finishing ability action cooldown") - button.cut_overlay(visual_references[VREF_IMAGE_XENO_CLOCK]) + countdown.stop() + update_button_icon() ///Any changes when a xeno with this ability evolves /datum/action/ability/proc/on_xeno_upgrade() diff --git a/code/game/objects/effects/countdown.dm b/code/game/objects/effects/countdown.dm index 3cef3174bd5..d0137907d35 100644 --- a/code/game/objects/effects/countdown.dm +++ b/code/game/objects/effects/countdown.dm @@ -85,3 +85,50 @@ return var/obj/structure/campaign_objective/capture_objective/objective = attached_to return objective.get_time_left() + +/obj/effect/countdown/action_cooldown + name = "cooldown" + color = "#d1d1d1" + invisibility = SEE_INVISIBLE_LIVING + mouse_opacity = MOUSE_OPACITY_TRANSPARENT + layer = ABOVE_HUD_LAYER + plane = HUD_PLANE + pixel_x = 5 + pixel_y = 8 + appearance_flags = KEEP_APART|RESET_COLOR + ///The action this countdown is associated with + var/datum/action/ability/attached_action + +/obj/effect/countdown/action_cooldown/Destroy() + attached_action = null + return ..() + +/obj/effect/countdown/action_cooldown/attach(atom/A) + var/atom/movable/screen/action_button/button = A + if(!istype(button)) + qdel(src) + return + attached_to = button + button.vis_contents += src + attached_action = button.source_action + +/obj/effect/countdown/action_cooldown/start() + if(!started) + START_PROCESSING(SSfastprocess, src) + started = TRUE + +/obj/effect/countdown/action_cooldown/process() + if(QDELETED(attached_to)) + qdel(src) + return + var/new_val = round(attached_action.cooldown_remaining(), 0.1) + if(new_val == displayed_text) + return + if(new_val >= 10) //avoid cropping, and deciseconds don't really matter if you're 10+ seconds away + new_val = floor(new_val) + displayed_text = new_val + + if(displayed_text) + maptext = "[displayed_text]" + else + maptext = null