Skip to content

Commit

Permalink
Visual spell cooldowns (from Tau Ceti) (yogstation13#13038)
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy authored Jan 12, 2022
1 parent 5fc7d48 commit 585f776
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
57 changes: 57 additions & 0 deletions code/_onclick/hud/screen_objects.dm
Original file line number Diff line number Diff line change
Expand Up @@ -734,3 +734,60 @@
/obj/screen/component_button/Click(params)
if(parent)
parent.component_click(src, params)

/obj/screen/cooldown_overlay
name = ""
icon_state = "cooldown"
pixel_y = 4
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
appearance_flags = RESET_COLOR | PIXEL_SCALE | RESET_TRANSFORM | KEEP_TOGETHER | RESET_ALPHA
vis_flags = VIS_INHERIT_ID
var/end_time = 0
var/obj/screen/parent_button
var/datum/callback/callback
var/timer

/obj/screen/cooldown_overlay/Initialize(mapload, button)
. = ..(mapload)
parent_button = button

/obj/screen/cooldown_overlay/Destroy()
stop_cooldown()
deltimer(timer)
return ..()

/obj/screen/cooldown_overlay/proc/start_cooldown(end_time, need_timer = TRUE)
parent_button.color = "#8000007c"
parent_button.vis_contents += src
src.end_time = end_time
set_maptext("[round((end_time - world.time) / 10, 1)]")
if(need_timer)
timer = addtimer(CALLBACK(src, .proc/tick), 1 SECONDS, TIMER_STOPPABLE)

/obj/screen/cooldown_overlay/proc/tick()
if(world.time >= end_time)
stop_cooldown()
return
set_maptext("[round((end_time - world.time) / 10, 1)]")
if(timer)
timer = addtimer(CALLBACK(src, .proc/tick), 1 SECONDS, TIMER_STOPPABLE)

/obj/screen/cooldown_overlay/proc/stop_cooldown()
parent_button.color = "#ffffffff"
parent_button.vis_contents -= src
if(callback)
callback.Invoke()

/obj/screen/cooldown_overlay/proc/set_maptext(time)
maptext = "<div style=\"font-size:6pt;font:'Arial Black';text-align:center;\">[time]</div>"

/proc/start_cooldown(obj/screen/button, time, datum/callback/callback)
if(!time)
return
var/obj/screen/cooldown_overlay/cooldown = new(button, button)
if(callback)
cooldown.callback = callback
cooldown.start_cooldown(time)
else
cooldown.start_cooldown(time, FALSE)
return cooldown
5 changes: 5 additions & 0 deletions code/modules/spells/spell.dm
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ GLOBAL_LIST_INIT(spells, typesof(/obj/effect/proc_holder/spell)) //needed for th

var/centcom_cancast = TRUE //Whether or not the spell should be allowed on z2

var/obj/screen/cooldown_overlay/cooldown_overlay

action_icon = 'icons/mob/actions/actions_spells.dmi'
action_icon_state = "spell_default"
action_background_icon_state = "bg_spell"
Expand Down Expand Up @@ -299,15 +301,18 @@ GLOBAL_LIST_INIT(spells, typesof(/obj/effect/proc_holder/spell)) //needed for th
return TRUE

/obj/effect/proc_holder/spell/proc/start_recharge()
cooldown_overlay = start_cooldown(action.button, world.time + charge_max)
recharging = TRUE

/obj/effect/proc_holder/spell/process()
if(recharging && charge_type == "recharge" && (charge_counter < charge_max))
charge_counter += 2 //processes 5 times per second instead of 10.
cooldown_overlay?.tick()
if(charge_counter >= charge_max)
action.UpdateButtonIcon()
charge_counter = charge_max
recharging = FALSE
QDEL_NULL(cooldown_overlay)

/obj/effect/proc_holder/spell/proc/perform(list/targets, recharge = TRUE, mob/user = usr) //if recharge is started is important for the trigger spells
before_cast(targets)
Expand Down
Binary file modified icons/mob/screen_gen.dmi
Binary file not shown.

0 comments on commit 585f776

Please sign in to comment.