diff --git a/code/datums/progressbar.dm b/code/datums/progressbar.dm index 01e4119b552..af200c14f19 100644 --- a/code/datums/progressbar.dm +++ b/code/datums/progressbar.dm @@ -1,46 +1,70 @@ +#define PROGRESSBAR_HEIGHT 6 + /datum/progressbar var/goal = 1 var/image/bar var/shown = 0 var/mob/user var/client/client + var/listindex -/datum/progressbar/New(mob/user, goal_number, atom/target) +/datum/progressbar/New(mob/User, goal_number, atom/target) . = ..() - if(!target) target = user - if (!istype(target)) - EXCEPTION("Invalid target given") - if (goal_number) + if(!istype(target)) + target = User + if(goal_number) goal = goal_number - bar = image('icons/effects/progessbar.dmi', target, "prog_bar_0") - bar.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA - bar.pixel_y = 32 + bar = image('icons/effects/progressbar.dmi', target, "prog_bar_0") + bar.alpha = 0 bar.plane = PLANE_PLAYER_HUD - src.user = user + bar.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA + user = User if(user) client = user.client -/datum/progressbar/Destroy() - if (client) - client.images -= bar - QDEL_NULL(bar) - user = null - client = null - return ..() + LAZYINITLIST(user.progressbars) + LAZYINITLIST(user.progressbars[bar.loc]) + var/list/bars = user.progressbars[bar.loc] + bars.Add(src) + listindex = bars.len + animate(bar, pixel_y = 32 + (PROGRESSBAR_HEIGHT * (listindex - 1)), alpha = 255, time = 5, easing = SINE_EASING) /datum/progressbar/proc/update(progress) - //to_world("Update [progress] - [goal] - [(progress / goal)] - [((progress / goal) * 100)] - [round(((progress / goal) * 100), 5)]") - if (!user || !user.client) + if(!user || !user.client) shown = 0 return - if (user.client != client) - if (client) + if(user.client != client) + if(client) client.images -= bar - shown = 0 - client = user.client + if(user.client) + user.client.images += bar - progress = CLAMP(progress, 0, goal) + progress = clamp(progress, 0, goal) bar.icon_state = "prog_bar_[round(((progress / goal) * 100), 5)]" - if (!shown && user.is_preference_enabled(/datum/client_preference/show_progress_bar)) + if(!shown && user.is_preference_enabled(/datum/client_preference/show_progress_bar)) user.client.images += bar shown = 1 + +/datum/progressbar/proc/shiftDown() + --listindex + var/shiftheight = bar.pixel_y - PROGRESSBAR_HEIGHT + animate(bar, pixel_y = shiftheight, time = 5, easing = SINE_EASING) + +/datum/progressbar/Destroy() + for(var/I in user.progressbars[bar.loc]) + var/datum/progressbar/P = I + if(P != src && P.listindex > listindex) + P.shiftDown() + + var/list/bars = user.progressbars[bar.loc] + bars.Remove(src) + if(!bars.len) + LAZYREMOVE(user.progressbars, bar.loc) + animate(bar, alpha = 0, time = 5) + spawn(5) + if(client) + client.images -= bar + qdel(bar) + . = ..() + +#undef PROGRESSBAR_HEIGHT \ No newline at end of file diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index 9091e338ab1..111bcab7995 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -230,3 +230,5 @@ var/attack_icon_state //State for above var/registered_z + + var/list/progressbars = null //for stacking do_after bars \ No newline at end of file