Trouble wiping custom Dialog Options 'after-image' from background

Started by bx83, Thu 10/01/2019 07:50:57

Previous topic - Next topic

bx83

I'm having trouble, once again, getting the custom dialog rendering options to work.

I first wanted to get an image of the current dialog options, and then keep them there in place while speech continued.
However, since changing the background colour from white to transparent, an 'after image' of my previous option set sits on screen, 'under' the new set of options. (the after-image button graphics are non-functional)

The after image is cleared again when an option is picked.
The after-image lasts between when speech ends, and when the next option is chosen; the speech then starts for this option.

I've tried a few things, and I know the answer is staring me in the face, but I just can't find out where, or what, to put to wipe the after-image options.

Here's a link to my viedo, to demostrate what's happening:
http://redrom.ltd/img/dialog error.webm

Here is my code:
gFakeDialogOptions is a GUI 1366x96 box, that's colour 0
MyDynamicSpriteForTheFakeGUI is a global DynamicSprite*

Code: ags

//----------------------------------------------------------------------------------------------------------------------
// Dialog Options Get Dimensions
//----------------------------------------------------------------------------------------------------------------------

function dialog_options_get_dimensions(DialogOptionsRenderingInfo* info)
{

// Create a 1366x64 dialog options area at (0,704)

  info.X = 0;
  info.Y = 672;
  info.Width = 1366;
  info.Height = 96;
}

//----------------------------------------------------------------------------------------------------------------------
// Draw Dialog Options
//----------------------------------------------------------------------------------------------------------------------

function DrawDialogOptions(DrawingSurface* ds, DialogOptionsRenderingInfo* info)
{
  int i = 1, ypos = 0, xpos = 0;  
  ds.Clear(COLOR_TRANSPARENT);
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      String str = info.DialogToRender.GetOptionText(i);  //get glyph number from option text
      int cur_img = str.AsInt;                            //current image is that number
      ds.DrawImage(xpos, ypos, cur_img);                  //draw this glyph
      xpos += 96;                                         //xpos+=width of glyph
    }
    i++;
  }	
}

//----------------------------------------------------------------------------------------------------------------------
// Dialog Options Render
//----------------------------------------------------------------------------------------------------------------------

function dialog_options_render(DialogOptionsRenderingInfo* info)
{
  DrawDialogOptions(info.Surface, info);
}

//----------------------------------------------------------------------------------------------------------------------
// Dialog Options Repeat Exec
//----------------------------------------------------------------------------------------------------------------------

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+96)
      {
        info.ActiveOptionID = i;
        return;
      }
      xpos += 96;
    }
    i++;
  }
}

//----------------------------------------------------------------------------------------------------------------------
// Dialog Options Mouse Click
//----------------------------------------------------------------------------------------------------------------------

function dialog_options_mouse_click(DialogOptionsRenderingInfo* info, MouseButton button)
{
  if (info.ActiveOptionID > 0)
  {
    MyDynamicSpriteForTheFakeGUI = DynamicSprite.Create(info.Width, info.Height, true);
    DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();
    DrawDialogOptions(ds, info);
    ds.Release();

    gFakeDialogOptions.BackgroundGraphic = MyDynamicSpriteForTheFakeGUI.Graphic;
    gFakeDialogOptions.Visible = true;
    info.RunActiveOption();
  }
}


Any help will be welcome.

Scavenger

Well, one thing I am noticing is that you don't get rid of the DynamicSprite before creating a new one, which will lead to memory leaks. Run this before creating a new sprite:

Code: AGS
if (MyDynamicSpriteForTheFakeGUI != null) MyDynamicSpriteForTheFakeGUI.Delete();


Also, in dialog_options_repexec, add:

Code: AGS
gFakeDialogOptions.Visible = false;


The after image is because you're not actually turning off the GUI before displaying the new dialog options, so it's still there underneath them.

Crimson Wizard

Quote from: Scavenger on Thu 10/01/2019 18:13:25
Well, one thing I am noticing is that you don't get rid of the DynamicSprite before creating a new one, which will lead to memory leaks.

It really should not, managed objects are reference counted, so they all got deleted automatically as soon as the number of references reaches zero.

bx83

Thankyou guys, belatedly :)
Works a treat :)

Code: ags

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+96)
      {
        info.ActiveOptionID = i;
        return;
      }
      xpos += 96;
    }
    i++;
  }
  gFakeDialogOptions.Visible = false;    //THIS LINE ADDED, THAT'S IT
}

SMF spam blocked by CleanTalk