Visual spell cooldowns (from Tau Ceti) (#13038)

This commit is contained in:
Lucy
2022-01-12 12:42:45 -05:00
committed by GitHub
parent 5fc7d48d62
commit 585f7767c3
3 changed files with 62 additions and 0 deletions

View File

@@ -734,3 +734,60 @@
/obj/screen/component_button/Click(params) /obj/screen/component_button/Click(params)
if(parent) if(parent)
parent.component_click(src, params) 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

View File

@@ -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/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 = 'icons/mob/actions/actions_spells.dmi'
action_icon_state = "spell_default" action_icon_state = "spell_default"
action_background_icon_state = "bg_spell" action_background_icon_state = "bg_spell"
@@ -299,15 +301,18 @@ GLOBAL_LIST_INIT(spells, typesof(/obj/effect/proc_holder/spell)) //needed for th
return TRUE return TRUE
/obj/effect/proc_holder/spell/proc/start_recharge() /obj/effect/proc_holder/spell/proc/start_recharge()
cooldown_overlay = start_cooldown(action.button, world.time + charge_max)
recharging = TRUE recharging = TRUE
/obj/effect/proc_holder/spell/process() /obj/effect/proc_holder/spell/process()
if(recharging && charge_type == "recharge" && (charge_counter < charge_max)) if(recharging && charge_type == "recharge" && (charge_counter < charge_max))
charge_counter += 2 //processes 5 times per second instead of 10. charge_counter += 2 //processes 5 times per second instead of 10.
cooldown_overlay?.tick()
if(charge_counter >= charge_max) if(charge_counter >= charge_max)
action.UpdateButtonIcon() action.UpdateButtonIcon()
charge_counter = charge_max charge_counter = charge_max
recharging = FALSE 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 /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) before_cast(targets)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 KiB

After

Width:  |  Height:  |  Size: 113 KiB