Custom dialog tree - with images, a la Sam and Max: Hit the Road

Started by bx83, Wed 20/09/2017 05:50:41

Previous topic - Next topic

bx83

I'm still working my way through the custom dialogue tree (http://www.adventuregamestudio.co.uk/manual/ags44.htm) - but one question, what about image buttons for dialogue choices?
I imagine you could write a sprite number in the question part of the dialogue, then use this to dig the sprite out and use it for the image on the dialogue choice. But how? How do you refer to an image in the sprite file, image.Graphic? Is there a script or plugin to do this already?

Cassiebsg

I never tried doing that, so I don't have an answer for you, but AnasAbdin is doing that for his game Tardigrades: http://www.adventuregamestudio.co.uk/forums/index.php?topic=50444.0
There are those who believe that life here began out there...

Snarky

I can't actually think of a very good way to store the sprite number for the conversation option.

My best suggestion would be to put it in the dialog option string. In dialog_options_render() you can then get it from DialogOptionsRenderingInfo.DialogToRender.GetOptionText() and parse it as an int. You'll have to turn off the "say dialog option" setting so that the line isn't actually spoken when selected, and instead put the line it represents in the dialog itself.

Edit: Oh, and to draw the sprite on your custom-rendered dialog options, you just call DrawingSurface.DrawImage() with the sprite number as the "slot" argument on the provided drawing surface (DialogOptionsRenderingInfo.Surface).

bx83

Thanks :)

Here's what I have so far:

Code: ags

function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info)
{
  // Create a 1024x128 dialog options area at (1,640)
  info.X = 1;
  info.Y = 640;
  info.Width = 1024;
  info.Height = 128;
}

function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  int i = 1,  ypos = 0, xpos=0;
  info.Surface.Clear(15);	
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      String str = info.DialogToRender.GetOptionText(i);
      int cur_img = str.AsInt;
      info.Surface.DrawImage(xpos, ypos, cur_img);
      xpos=xpos+128;
    }
    i++;
  }
}

function dialog_options_get_active(DialogOptionsRenderingInfo *info)
{
  int i = 1,  xpos = 0;
  // Find the option that corresponds to where the player clicked
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if (mouse.y>info.Y && mouse.x >= xpos && mouse.x<=xpos+128)
      {
        info.ActiveOptionID = i;
        Display("%d",info.ActiveOptionID);
        return;
      }
      xpos+=128;
    }
    i++;
  }
}


It displays several 128x128 images next to eachother at the bottom, each corresponding to an answer. The images have the sprite slot number as the option text. Selecting each image/answer plays a piece of pre-recorded dialog.

However, dialog_options_get_active doesn't do anything. It doesn't pick where a user clicked (wherever you click, the dialog does nothing), and it doesn't even display the active option (once you've clicked it, which it doesn't do).

Have I missed something?

Crimson Wizard

Quote from: bx83 on Sun 24/09/2017 14:41:27
However, dialog_options_get_active doesn't do anything. It doesn't pick where a user clicked (wherever you click, the dialog does nothing), and it doesn't even display the active option (once you've clicked it, which it doesn't do).

dialog_options_get_active was deprecated in 3.4.0.
If you really want you may enable it in General Settings (option is called "Use old-style dialog rendering API", or something similar.
Or rather use new style API.
The online manual is outdated (it corresponds to AGS 3.2.1). I've been pointing that out many times, but it still was not updated, and I do not have any control over it.
The help file that comes with AGS Editor should contain up to date information on the topic, however.
There is also post with examples here: http://www.adventuregamestudio.co.uk/forums/index.php?topic=52499.msg636523561#msg636523561

bx83

Code updated and working :)

Code: ags

function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info)
{
  // Create a 1024x128 dialog options area at (1,640)
  info.X = 1;
  info.Y = 640;
  info.Width = 1024;
  info.Height = 128;
}

function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  int i = 1,  ypos = 0, xpos=0;
  info.Surface.Clear(16);	
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      String str = info.DialogToRender.GetOptionText(i);
      int cur_img = str.AsInt;
      info.Surface.DrawImage(xpos, ypos, cur_img);
      xpos=xpos+128;
    }
    i++;
  }
}

function dialog_options_repexec(DialogOptionsRenderingInfo *info)
{  
  int i = 1,  xpos = 0;
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if (mouse.y>info.Y && mouse.x >= xpos && mouse.x<=xpos+128)
      {
        info.ActiveOptionID = i;
        return;
      }
      xpos+=128;
    }
    i++;
  }
}

function dialog_options_mouse_click(DialogOptionsRenderingInfo *info, MouseButton button)
{
    if (info.ActiveOptionID > 0) {
      info.RunActiveOption();
    } else {
      return;
    }
}



However - when I have 2 options left, it crashes. Normal behaviour is say one; then, since there's only one left, say that; quit dialog.
What actually happens is: say one; then say the other; no options left - crash.
:/

Crimson Wizard

Quote from: bx83 on Mon 25/09/2017 02:43:23
However - when I have 2 options left, it crashes. Normal behaviour is say one; then, since there's only one left, say that; quit dialog.
What actually happens is: say one; then say the other; no options left - crash.
:/
Does it tell script line where it crashes, or any other kind of error message?

bx83

Before there was nothing; now, it shows this:

"An error has occured.
ACI 3.4.0.16 NMP
Error: DoDialog: all options haave been turned off."

It just closes the program.

bx83

...it's because of the options had no Stop on them :P
Always have one Stop.

bx83

Here's the final working code - bug's that drove me insane removed - for anyone dumber even than me who wants an example :P

Code: ags

function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info)
{
  info.X = 0;
  info.Y = 704;
  info.Width = 1024;
  info.Height = 64;
}

function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  int i = 1, ypos=0, xpos=0;
  info.Surface.Clear(15);	
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      String str = info.DialogToRender.GetOptionText(i);
      int cur_img = str.AsInt;
      info.Surface.DrawImage(xpos, ypos, cur_img);
      xpos+=64;
    }
    i++;
  }
}

function dialog_options_repexec(DialogOptionsRenderingInfo *info)
{
  int i = 1,  xpos = 0;
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if (mouse.y >= info.Y && mouse.x >= xpos && mouse.x <= xpos+64)
      {
        info.ActiveOptionID = i;
        return;
      }
      xpos+=64;
    }
    i++;
  }
}

function dialog_options_mouse_click(DialogOptionsRenderingInfo *info, MouseButton button)
{
  if (info.ActiveOptionID > 0) {
    info.RunActiveOption();
  } else {
    return;
  }
}

Crimson Wizard

You also do not need:
Code: ags

} else {
    return;
}

in the last function, because it does nothing. :)

bx83


Monsieur OUXX

Isn't there a module that does precisely this?
If not, then you might want to turn your script into a module, bx83
 

SMF spam blocked by CleanTalk