HUD Groups

by Forum_account
An easy way to manage screen objects.
ID:858528
 
Keywords: problems
Okay well I've been using this library for some time now and have never encountered a problem like this, I didn't want to put it as a bug because I don't have enough info about it.

Basically I have on screen "windows" created with your library, there is a background, a border, a title bar and some bits for map text. The group is hidden most if the time except when you want to view it's contents, the problem is after being hidden for about 5 minutes every part of the group disappears when I show it except the background. Here is the code for the group.
Stat
parent_type= /HudGroup
icon = 'menu.dmi'
layer = 53
var
HudObject
base
L
R
T
B
TL
TR
BL
BR
Text
titmid
titright
titleft
title
closebutton

New(mob/m)
..()

base= add(0,0, width = 9, height = 9, icon_state = "center", layer= 52)
L = add(-29,0, width = 1, height = 9, icon_state = "left")
R = add(261,0, width = 1, height = 9, icon_state = "right")
T = add(0,261, width = 9, height = 1, icon_state = "top")
B = add(0,-5, width = 9, height = 1, icon_state = "bottom")
TL = add(-32,288, icon_state = "topleft")
TR = add(261,288, icon_state = "topright")
BL = add(-32,-5, icon_state = "bottomleft")
BR = add(261,-5, icon_state = "bottomright")
Text = add(-1,5, layer = 54)
Text.set_maptext(maptext = "<center><font face = Arial><font color=#777><b>Name:</b> [m.key]<p> <b>Health:</b> [m.hp]/[m.maxhp] <br> <b>Mana:</b> [m.mp]/[m.maxmp]<br><b>Experience:</b> [m.xp]/[m.maxxp]<p><p><p><p><p><p><p><p><p><p><p><p><p>", width = 288, height = 288)

titleft = add(0,257, icon_state = "titleft")
titright = add(256,257, icon_state = "titright")
titmid = add(32,257, width = 7, icon_state = "titmid")
title = add(-2, 270)

title.set_maptext(maptext = "<center><font face = Arial Black><font color=#777><b>Stats</b>", width = 288, height = 32)



closebutton = add(253,270, icon_state = "close", layer = 54)
closebutton.name = "stat close"

pos(128,128)
hide()
looks all good :D
I know that's why I don't understand bits of it randomly disappearing.
My guess is that it's a layering issue. Since all the objects have the same layer when you create the HUD they're layered correctly but, later on, they end up being drawn in the wrong order and the title/text are below the background. The add() proc has a named argument for setting the layer of the object. If you don't specify one it uses the HudGroup's layer. You can either specify a layer for each object or do something like this:

layer = 53
// create the background objects

layer = 54
// create the title bar

layer = 55
// create the text elements
That doesn't explain the close button and the text disappearing as they are both above the backgrounds layer and still disappear. Also the background's layer is lower than the groups default layer.
If you can provide some code that'll reliably produce this problem I can test it out.

There was one bug fix I have for the library that I haven't posted yet, but I think it only applied to adding and removing HudObjects from HudGroups. If you're only showing or hiding the whole group I don't think it'd be related to that.
HudObject
Click()
switch(name)
if("stat")
if(usr.stat_open)
return
else
usr.stat.toggle()
usr.stat_open = 1
usr.frozen = 1

if("stat close")
if(!usr.stat_open)
return
else
usr.stat.hide()
usr.stat_open = 0
usr.frozen = 0


That's the code I'm using for the buttons, I didn't want to use usr but I couldn't see an easier way. Hope you can provide an answer also, it does only happen after like 5 minutes of being hidden.
I have a temporary fix, I'm just removing the group when the window is closed and making a new one when it is opened, this seems to have improved performance a tad as well.