I need to have a window where I can output text during the game, and that will scroll up any existing text slowly line by line if it reaches the bottom.
Is there already some module/function that helps me, or do I have to code it all from scratch? I suppose it's best done via a GUI element.
Atelier is currently producing a game that does exactly that.
There's working code available, I think I even helped with it.
You could also PM NsMn, I think the code is originally by him.
I've ripped this function real quick from my IRC client project
#define LINE_WIDTH 120 // Max number of characters on a line
#define LINE_COUNT 40 // Max number of lines in the textbox
void PushLine(String line)
{
if (line.Length > LINE_WIDTH)
{
PushLine(line.Truncate(LINE_WIDTH));
PushLine(line.Substring(LINE_WIDTH, line.Length - LINE_WIDTH));
return;
}
String text;
text = String.Format("%s[%s", lblOutput.Text, line);
int i = text.Length;
int count = 0;
int pos = -1;
while (i)
{
if (text.Chars[i] == '[')
count++;
if (count == LINE_COUNT)
{
pos = i;
i = 0;
}
else
i--;
}
lblOutput.Text = text.Substring(pos + 1, text.Length - pos - 1);
}
lblOutput needs to be a label control on some GUI with 'multiple lines' enabled.
You can call the function to put a new line in there. :)
Great, thank you so much! :-) I can even follow this script, but to make it up is something totally different...
I took the liberty to edit the code so it looks for a "space" and line breaks there, deleting the space:
(showing edited portion only)
if (line.Length > LINE_WIDTH)
{
int break=LINE_WIDTH;
while (line.Substring(break, 1)!=" ") break--;
PushLine(line.Truncate(break));
PushLine(line.Substring(break+1, line.Length - break -1));
// PushLine(line.Truncate(LINE_WIDTH));
// PushLine(line.Substring(LINE_WIDTH, line.Length - LINE_WIDTH));
return;
It's still "hard scrolling", so no soft movement of lines upwards (but still very helpful, thank you again). Is this possible without having to awkwardly use, for example, several GUI elements that float up and reappear down below?