Scrolling text output window

Started by Tamanegi, Fri 14/01/2011 17:07:32

Previous topic - Next topic

Tamanegi

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.
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

Khris

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.

Wyz

I've ripped this function real quick from my IRC client project
Code: ags


#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. :)
Life is like an adventure without the pixel hunts.

Tamanegi

Great, thank you so much! :-) I can even follow this script, but to make it up is something totally different...
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

Tamanegi

#4
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)
Code: ags
  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?
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

SMF spam blocked by CleanTalk