From 50ec7d1adc2085455b82e7c2c799e7e92df1a3bc Mon Sep 17 00:00:00 2001 From: HMBGERDO <61080616+HMBGERDO@users.noreply.github.com> Date: Mon, 5 Jun 2023 20:03:54 +0200 Subject: [PATCH] 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 --- code/datums/action.dm | 13 +++++------ code/datums/spell_cooldown/spell_charges.dm | 23 ++++++++++++++++---- code/datums/spell_cooldown/spell_cooldown.dm | 17 ++++++++++++--- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/code/datums/action.dm b/code/datums/action.dm index fed9d4d5341..1381c537076 100644 --- a/code/datums/action.dm +++ b/code/datums/action.dm @@ -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 = "
[round_down(progress * 100)]%
" + var/text = S.cooldown_handler.statpanel_info() + count_down_holder.maptext = "
[text]
" button.add_overlay(count_down_holder) /* diff --git a/code/datums/spell_cooldown/spell_charges.dm b/code/datums/spell_cooldown/spell_charges.dm index 27353ada921..165caeba027 100644 --- a/code/datums/spell_cooldown/spell_charges.dm +++ b/code/datums/spell_cooldown/spell_charges.dm @@ -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 diff --git a/code/datums/spell_cooldown/spell_cooldown.dm b/code/datums/spell_cooldown/spell_cooldown.dm index 41d25e036e8..aa08e9491e4 100644 --- a/code/datums/spell_cooldown/spell_cooldown.dm +++ b/code/datums/spell_cooldown/spell_cooldown.dm @@ -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)