HUD Groups

by Forum_account
An easy way to manage screen objects.
ID:239584
 
Keywords: problem
Okay I decided to here this time instead(didn't want to clutter your shout box with my problems.
Here is the Screen_output proc now:
Screen_output(txt, /Font/font)
var/Text = font.wrap_text(txt, width_limit+2)
var/list/words = list()
var/word = ""
var/output = ""
for(var/i = 1 to length(Text))
var/c = copytext(Text, i, i + 1)

if(c == " ")
words += word
word = ""
else
word += c
if(word)
words += word

for(var/W = 1 to words.len)
var/text = "[words[W]]"
world << "[words[W]]"
if(findtext(text, "\n"))
add_line(output)
output = ""
else
output += text
output += " "

if(W == words.len)
add_line(output)

Any ideas? I still get the problem where if a word takes up too much of the line it simply doesn't show the line.
I'm not sure where the problem is, but here's how I'd do it:

ChatLog
proc
add_message(txt)

// insert line breaks into the string
txt = font.wrap_text(txt, 184)

// split the string into a list of strings
var/list/lines = list()

var/start = 1
var/pos = findtext(txt, "\n")

while(pos > 0)
lines += copytext(txt, start, pos)
start = pos + 1
pos = findtext(txt, "\n", start)

lines += copytext(txt, start)

// display each line
for(var/l in lines)
add_line(l)
Works perfectly thank you so much.
Hey you wouldn't be able to show me how to make it so the first line is at the top and the last at the bottom would you? I've tried everything and nothing works.
In response to GreatFisher
Change the add_line proc to this:

        add_line(txt)

// trim the text so it fits inside the chat log
txt = font.cut_word(txt, 184)

// I'm not sure why this is necessary, but it is. without it,
// when you use the Say verb you'll see the top line of the
// chat log change its text, then get moved to the bottom.
spawn()
// we loop through all lines because we need to reposition them all
for(var/i = 1 to lines.len)
var/HudObject/h = lines[i]

// move the screen object up 16 pixels
var/py = h.sy - 16

// if it's sbove the top, wrap it around to the bottom
if(py < 0)
py = lines.len * 16 - 16

// update its position
h.pos(0, py)

// if its the next line, update its text too
if(i == next_line)
h.set_text(txt)

// keep track of which line will be used next
next_line -= 1
if(next_line < 1)
next_line = lines.len

And change the line in the New() proc to this (add the " + 16"):

var/py = (line_count - i) * 16 + 16
Okay that didn't work at all the lines ended up everywhere lol. here is how i want it to look:
below represents the chat box
[-------------------------]
[ blah < first line ]
[ blah < second line ]
[ ect. ]
[-------------------------]

Do you uderstand how i want it to look? could you tell me how to do this?


Forget that it did work I just had to giggle it a bit lol.
If you display the lines in the opposite order you may need to call add_line in the opposite order (for multi-line messages).
yeah I got it to work thanks for all the help.