Files
S.P.L.U.R.T-Station-13/code/datums/progressbar.dm
2017-12-17 10:02:43 -06:00

67 lines
1.5 KiB
Plaintext

#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))
EXCEPTION("Invalid target given")
if (goal_number)
goal = goal_number
bar = image('icons/effects/progessbar.dmi', target, "prog_bar_0", HUD_LAYER)
bar.plane = HUD_PLANE
bar.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA
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)
if (!user || !user.client)
shown = 0
return
if (user.client != client)
if (client)
client.images -= bar
if (user.client)
user.client.images += bar
progress = CLAMP(progress, 0, goal)
bar.icon_state = "prog_bar_[round(((progress / goal) * 100), 5)]"
if (!shown)
user.client.images += bar
shown = 1
/datum/progressbar/proc/shiftDown()
--listindex
bar.pixel_y -= PROGRESSBAR_HEIGHT
/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)
if (client)
client.images -= bar
qdel(bar)
. = ..()
#undef PROGRESSBAR_HEIGHT