Improved cooldown visualisation on spells with charges (#21065)

* improved cooldown on spells with charges, now you see amount of current charges and process of recharging new one

* update

* cleanup

* somehow sometimes it returns more than 1, taking min(1, val) then

* created proc ShouldShowCooldown especially for HUD panels

* bug fix && little cleanup

* ssssnakes

* moved some procs to cooldown handler class

* if button is dark again if it is not available
This commit is contained in:
HMBGERDO
2023-06-05 20:03:54 +02:00
committed by GitHub
parent 391c71c246
commit 50ec7d1adc
3 changed files with 38 additions and 15 deletions
+5 -8
View File
@@ -106,9 +106,8 @@
button.desc = desc
ApplyIcon(button)
// If the action isn't available, darken the button
if(!IsAvailable())
var/obj/effect/proc_holder/spell/S = target
if(istype(S) && S.cooldown_handler.should_draw_cooldown() || !IsAvailable())
apply_unavailable_effect()
else
return TRUE
@@ -583,11 +582,8 @@
var/obj/effect/proc_holder/spell/S = target
if(!istype(S))
return ..()
var/progress = S.cooldown_handler.get_availability_percentage()
if(progress == 1)
return ..() // This means that the spell is charged but unavailable due to something else
var/alpha = 220 - 140 * progress
var/alpha = S.cooldown_handler.get_cooldown_alpha()
var/image/img = image('icons/mob/screen_white.dmi', icon_state = "template")
img.alpha = alpha
@@ -598,7 +594,8 @@
// Make a holder for the charge text
var/image/count_down_holder = image('icons/effects/effects.dmi', icon_state = "nothing")
count_down_holder.plane = FLOAT_PLANE + 1.1
count_down_holder.maptext = "<div style=\"font-size:6pt;color:[recharge_text_color];font:'Small Fonts';text-align:center;\" valign=\"bottom\">[round_down(progress * 100)]%</div>"
var/text = S.cooldown_handler.statpanel_info()
count_down_holder.maptext = "<div style=\"font-size:6pt;color:[recharge_text_color];font:'Small Fonts';text-align:center;\" valign=\"bottom\">[text]</div>"
button.add_overlay(count_down_holder)
/*
+19 -4
View File
@@ -13,6 +13,14 @@
if(starts_off_cooldown)
current_charges = max_charges
/datum/spell_cooldown/charges/get_cooldown_alpha()
if(current_charges == 0 || charge_time > world.time)
return 220 - 140 * get_availability_percentage()
return 60
/datum/spell_cooldown/charges/should_draw_cooldown()
return recharge_time > world.time || current_charges < max_charges
/datum/spell_cooldown/charges/is_on_cooldown()
return !current_charges || charge_time >= world.time
@@ -20,6 +28,7 @@
if(recharge_time > world.time)
return FALSE
current_charges++
spell_parent.action.UpdateButtonIcon()
if(current_charges < max_charges) // we have more recharges to go
recharge_time = world.time + recharge_duration
return FALSE
@@ -31,18 +40,24 @@
charge_time = world.time + charge_duration
..()
/datum/spell_cooldown/charges/get_recharge_time()
if(recharge_time > world.time)
return recharge_time
return ..()
/datum/spell_cooldown/charges/revert_cast()
..()
charge_time = world.time
/datum/spell_cooldown/charges/statpanel_info()
return "[current_charges] / [max_charges], [..()]"
var/charge_string = charge_duration != 0 ? round(min(1, (charge_duration - (charge_time - world.time)) / charge_duration), 0.01) * 100 : 100 // need this for possible 0 charge duration
var/recharge_string = recharge_duration != 0 ? round(min(1, (recharge_duration - (recharge_time - world.time)) / recharge_duration), 0.01) * 100 : 100
return "[charge_string != 100 ? "[charge_string]%\n" : ""][recharge_string != 100 ? "[recharge_string]%\n" : ""][current_charges]/[max_charges]"
/datum/spell_cooldown/charges/get_availability_percentage()
if(max_charges == current_charges)
return 1
if(charge_time > world.time)
return (charge_duration - (charge_time - world.time)) / charge_duration
return (recharge_duration - (recharge_time - world.time)) / recharge_duration //parent proc without the on cooldown check
return min(1, (charge_duration - (charge_time - world.time)) / charge_duration)
return min(1, (recharge_duration - (recharge_time - world.time)) / recharge_duration) //parent proc without the on cooldown check
+14 -3
View File
@@ -17,6 +17,12 @@
if(!starts_off_cooldown)
start_recharge()
/datum/spell_cooldown/proc/should_draw_cooldown()
return is_on_cooldown()
/datum/spell_cooldown/proc/get_cooldown_alpha()
return 220 - 140 * get_availability_percentage()
/datum/spell_cooldown/proc/is_on_cooldown()
return recharge_time > world.time
@@ -45,11 +51,16 @@
/datum/spell_cooldown/proc/get_availability_percentage()
if(!is_on_cooldown()) // if off cooldown, we don't bother with the maths
return 1
return (recharge_duration - (recharge_time - world.time)) / recharge_duration
return min(1, (recharge_duration - (recharge_time - world.time)) / recharge_duration)
/datum/spell_cooldown/proc/get_recharge_time()
return world.time + recharge_duration
/datum/spell_cooldown/proc/start_recharge(recharge_duration_override = 0)
var/recharge_increment = recharge_duration_override || recharge_duration
recharge_time = world.time + recharge_increment
if(recharge_duration_override)
recharge_time = world.time + recharge_duration_override
else
recharge_time = get_recharge_time()
if(spell_parent.action)
spell_parent.action.UpdateButtonIcon()
START_PROCESSING(SSfastprocess, src)