Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability Cooldown Timers #157

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions code/__DEFINES/action.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions code/datums/actions/ability_actions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
. = ..()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
47 changes: 47 additions & 0 deletions code/game/objects/effects/countdown.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<font size = [text_size]>[displayed_text]</font>"
else
maptext = null
Loading