From d0247fff2ce2628cd9b010e622bde7287df17878 Mon Sep 17 00:00:00 2001 From: Markolie Date: Sun, 12 Feb 2017 23:51:50 +0100 Subject: [PATCH] Progress bars now stack vertically. Also adds a bunch of lazy list helpers. --- code/__HELPERS/lists.dm | 12 ++++++++ code/datums/progressbar.dm | 50 +++++++++++++++++++++++++-------- code/modules/mob/mob_defines.dm | 2 ++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/code/__HELPERS/lists.dm b/code/__HELPERS/lists.dm index 9fa27c93356..1cad4d1a9df 100644 --- a/code/__HELPERS/lists.dm +++ b/code/__HELPERS/lists.dm @@ -625,3 +625,15 @@ proc/dd_sortedObjectList(list/incoming) /datum/alarm/dd_SortValue() return "[sanitize(last_name)]" + +//Picks from the list, with some safeties, and returns the "default" arg if it fails +#define DEFAULTPICK(L, default) ((istype(L, /list) && L:len) ? pick(L) : default) + +#define LAZYINITLIST(L) if (!L) L = list() + +#define UNSETEMPTY(L) if (L && !L.len) L = null +#define LAZYREMOVE(L, I) if(L) { L -= I; if(!L.len) { L = null; } } +#define LAZYADD(L, I) if(!L) { L = list(); } L += I; +#define LAZYACCESS(L, I) (L ? (isnum(I) ? (I > 0 && I <= L.len ? L[I] : null) : L[I]) : null) +#define LAZYLEN(L) length(L) +#define LAZYCLEARLIST(L) if(L) L.Cut() diff --git a/code/datums/progressbar.dm b/code/datums/progressbar.dm index acac430399b..ec8cda24eb3 100644 --- a/code/datums/progressbar.dm +++ b/code/datums/progressbar.dm @@ -1,42 +1,68 @@ +#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) . = ..() - if(!istype(target)) + if (!istype(target)) EXCEPTION("Invalid target given") - if(goal_number) + if (goal_number) goal = goal_number - bar = image('icons/effects/progessbar.dmi', target, "prog_bar_0") + bar = image('icons/effects/progessbar.dmi', target, "prog_bar_0", HUD_LAYER) + bar.plane = HUD_PLANE bar.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA - bar.pixel_y = 32 user = User if(user) client = user.client + LAZYINITLIST(user.progressbars) + LAZYINITLIST(user.progressbars[bar.loc]) + var/list/bars = user.progressbars[bar.loc] + bars.Add(src) + listindex = bars.len + bar.pixel_y = 32 + (PROGRESSBAR_HEIGHT * (listindex - 1)) + /datum/progressbar/proc/update(progress) -// to_chat(world, "Update [progress] - [goal] - [(progress / goal)] - [((progress / goal) * 100)] - [round(((progress / goal) * 100), 5)]") - if(!user || !user.client) + //world << "Update [progress] - [goal] - [(progress / goal)] - [((progress / goal) * 100)] - [round(((progress / goal) * 100), 5)]" + if (!user || !user.client) shown = 0 return - if(user.client != client) - if(client) + if (user.client != client) + if (client) client.images -= bar - if(user.client) + if (user.client) user.client.images += bar progress = Clamp(progress, 0, goal) bar.icon_state = "prog_bar_[round(((progress / goal) * 100), 5)]" - if(!shown) + if (!shown) user.client.images += bar shown = 1 +/datum/progressbar/proc/shiftDown() + --listindex + bar.pixel_y -= PROGRESSBAR_HEIGHT + /datum/progressbar/Destroy() - if(client) + 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) + + if (client) client.images -= bar qdel(bar) - . = ..() \ No newline at end of file + . = ..() + +#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 962987dcc3f..2988363ffb9 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -196,3 +196,5 @@ var/list/permanent_huds = list() var/list/actions = list() + + var/list/progressbars = null //for stacking do_after bars