Scrolling Dialogue - Dialogue option text taking up more than one line

Started by Pogwizd, Sun 21/07/2019 11:58:45

Previous topic - Next topic

Pogwizd

Hi all,

I'm relatively new to coding in AGS and I'd really appreciate if someone helped me out with the following problem:

I want my game to have a scrollable dialogue GUI, where, if the option text is too long, it gets broken into two lines and two (or three, if need be) dialogue options above are pushed off the dialogue GUI.

At first, I started writing my own script that would handle it but I've hit upon a wall. I've writen a code that basically checks which dialouge options are ON and what is their length. If there are more than three dialogue options or the length of one of them is too long, then, using the DrawImage method, it draws an icon that is meant to handle the scrolling. I managed to "handle" the click event, so it does display a "test" message but I don't know how can I trigger the render function again (originally I thought I would make it a recursive function, sort of, so that on each mouse click I rerender the dialogue GUI with appropriate dialogue options shown but for the life of my I can't figure out how to trigger one function inside the other).

Here is what I've cobbled together so far:

Code: ags

function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  
   info.Surface.Clear(dlg_opt_color);
  int i = 1,  ypos = 0;
  // Render all the options that are enabled
  while (i <= info.DialogToRender.OptionCount)
  {   
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if (info.ActiveOptionID == i)
        info.Surface.DrawingColor = dlg_opt_acolor;
      else
        info.Surface.DrawingColor = dlg_opt_ncolor;
      
      String currentDialogOption = info.DialogToRender.GetOptionText(i);
      if (currentDialogOption.Length <= 50 && i <= 3)
      {
        
        info.Surface.DrawStringWrapped(5, ypos, info.Width - 50, 
              Game.NormalFont, eAlignLeft, info.DialogToRender.GetOptionText(i));
      ypos += GetTextHeight(info.DialogToRender.GetOptionText(i), Game.NormalFont, info.Width - 10);
      } 
      else 
      {
          DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
          surface.DrawImage(290, 170, 44);
          surface.Release();
      } 
    }
    i++;
  }
}

function dialog_options_mouse_click(DialogOptionsRenderingInfo *info, MouseButton button)
{
  if (info.ActiveOptionID > 0)
    info.RunActiveOption();
  else if(mouse.x>270)
  {
    Display("TEST");
  }
}



If you could direct me on the right path here I'd really appreciate it.

I have also been playing around with monkey0506's module v 3.0 but I'm having a similar issue. If the dialogue text is too long, it gets broken down into two lines but the module doesn't appear to handle it. What I mean is that the line takes up two lines of the GUI but above it only one dialogue option gets pushed up. Also, given my poor experience in scripting, I found monkey0506's code a bit overwhelming and don't even know where to begin with refactoring his code.

Has anyone had similar issues or knows how to sort it out?

Also, I know I've sort of asked about two separate things but I would go with whatever will be simpler to do.

I would appreciate any suggestion.

PS.
Yes, I have spent some time reading the documentation and forum threats but I still can't figure it out.

SMF spam blocked by CleanTalk