Jibble

Author Topic: Custom dialogue issue with dimensions  (Read 794 times)

bx83

  • benjamin.rich@protonmail.com
Custom dialogue issue with dimensions
« on: 05 Jun 2020, 08:40 »
I've recently sort to edit my code to give the options a left indent of 11px.

Here's the code:
Code: [Select]
//----------------------------------------------------------------------------------------------------------------------
// DIALOGUE
//----------------------------------------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------------------------------------
// Dialogue Options Get Dimensions
//----------------------------------------------------------------------------------------------------------------------

function dialog_options_get_dimensions(DialogOptionsRenderingInfo* info)
{
ConversationIsOn=true;
//sprtFloatingText.Delete();

// Create a 1366x96 dialog options area at (0,704)
  dialog_left=11;

  info.X = dialog_left;
  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 = 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;
       
        //transplanted in from dialogue_options_mouse_click() to get rid of background/old buttons in real time
        MyDynamicSpriteForTheFakeGUI = DynamicSprite.Create(info.Width, info.Height, true);
        DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();
        DrawDialogOptions(ds, info);
        ds.Release();
       
        return;
      }
      xpos += 96;
    }
    i++;
  }
  gFakeDialogOptions.Visible = false;
}

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

function dialog_options_mouse_click(DialogOptionsRenderingInfo* info, MouseButton button)
{
//ConversationIsOn=true;

  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();
  }
}


// END DIALOG FUNCTIONS

I expect all options to be drawn with an initial 11px indent. However, once I choose an option, it defaults to 0px indent; then when speech is over, it flips constantly between 11px and 0px indent.

Video:

https://bluekeystudios.com/img/conversation_error.mov

How can I get it to have an 11px indent at all times, including when selecting an option (ie. selection isn't always off by 11px if I click near the border)?
I think it's something in dialog_options_repexec() doing this weird overdrawing, but not sure. I've tried a few things, nothing works.

Bonus question: I'm thinking of having a large background image to frame the conversation icons -- where do I put the drawing code, once in dialog_options_render()?
« Last Edit: 27 May 2021, 12:51 by bx83 »

Re: Custom dialogue issue with dimensions
« Reply #1 on: 05 Jun 2020, 09:50 »
I'm guessing the dialog_options_repexec needs  xpos  to start at 11 since it compares that to mouse.x, which isn't relative to the GUI's origin.
Also you should probably do  #define DIALOG_OFFSET_X 11 at the top of that script and use  DIALOG_OFFSET_X  inside instead of hard-coding it to 11.
« Last Edit: 05 Jun 2020, 10:01 by Khris »

bx83

  • benjamin.rich@protonmail.com
Re: Custom dialogue issue with dimensions
« Reply #2 on: 05 Jun 2020, 11:39 »
Works now - I think...
I was going to use a define, but dialog_left is good enough.

Code: [Select]
//----------------------------------------------------------------------------------------------------------------------
// Dialogue Options Get Dimensions
//----------------------------------------------------------------------------------------------------------------------

function dialog_options_get_dimensions(DialogOptionsRenderingInfo* info)
{
ConversationIsOn=true;

// Create a 1366x96 dialog options area at (0,704)
dialog_left=11;

  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 = dialog_left; //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 = 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 = dialog_left;
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
      if ( mouse.y >= info.Y
&& mouse.x >= xpos
&& mouse.x <= xpos+96)//+dialog_left)
      {
        info.ActiveOptionID = i;
       
        //transplanted in from dialogue_options_mouse_click() to get rid of background/old buttons in real time
        MyDynamicSpriteForTheFakeGUI = DynamicSprite.Create(info.Width, info.Height, true);
        DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();
        DrawDialogOptions(ds, info);
        ds.Release();
       
        return;
      }
      xpos += 96;
    }
    i++;
  }
  gFakeDialogOptions.Visible = false;
}

//----------------------------------------------------------------------------------------------------------------------
// 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();
  }
}

bx83

  • benjamin.rich@protonmail.com
Re: Custom dialogue issue with dimensions
« Reply #3 on: 05 Jun 2020, 12:13 »
As for drawing a background image, over which I draw the glyphs already there....

I have this code:
Code: [Select]
MyBackgroundSpriteForFakeGUI = DynamicSprite.Create(1366, 96, false);
DrawingSurface* button_bg = MyBackgroundSpriteForFakeGUI.GetDrawingSurface();
button_bg.DrawImage(0, 672, 2639);
button_bg.Release();
...Which I've tried putting in the functions (before any other code) dialog_options_repexec(), dialog_options_render(), and DrawDialogOptions(), and nothing seems to work.

I'm trying to put this image:

Behind the button images you see on the screen.

In all situations, nothing is drawn to screen, just the option images you see in the video.
« Last Edit: 27 May 2021, 13:06 by bx83 »

bx83

  • benjamin.rich@protonmail.com
Re: Custom dialogue issue with dimensions
« Reply #4 on: 05 Jun 2020, 14:37 »
I’ve changed the above code to work ds for dynamic sprite and used the same MyFakeGUI etc, removed all ds.clear(), and changed the dimension and sprite to maybe show up on the screen somewhere; then, I put it in all functions. Still nothing; yes to option icons, no to ‘wood finish’ picture.

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: Custom dialogue issue with dimensions
« Reply #5 on: 05 Jun 2020, 14:40 »
You're probably declaring MyBackgroundSpriteForFakeGUI inside a function? That means it goes out of scope and gets deleted as soon as you exit the function.

bx83

  • benjamin.rich@protonmail.com
Re: Custom dialogue issue with dimensions
« Reply #6 on: 05 Jun 2020, 16:41 »
MyBackgroundSpriteForFakeGUI Is a global variable, and I’m not using it anymore. The line you see now is just ds.DrawImage(0,672,WOODPANEL)

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: Custom dialogue issue with dimensions
« Reply #7 on: 05 Jun 2020, 21:47 »
Well, whatever dynamic sprite you're actually using in the current version of the code, then.

Re: Custom dialogue issue with dimensions
« Reply #8 on: 05 Jun 2020, 22:03 »
You're probably declaring MyBackgroundSpriteForFakeGUI inside a function? That means it goes out of scope and gets deleted as soon as you exit the function.

If dynamic sprite is deleted, and assigned to a GUI at the same time, then the engine will likely crash.

bx83

  • benjamin.rich@protonmail.com
Re: Custom dialogue issue with dimensions
« Reply #9 on: 06 Jun 2020, 01:18 »
Here's my updated code. Doesn't crash: simply doesn't show the woodpanel graphic (sprite 2639) anywhere, at any any time.

Code: [Select]
function dialog_options_get_dimensions(DialogOptionsRenderingInfo* info)
{
  ConversationIsOn=true;
  dialog_left=11;

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

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

function DrawDialogOptions(DrawingSurface* ds, DialogOptionsRenderingInfo* info)
{
ds.DrawImage(0, 672, 2639);

int i = 1, ypos = 0, xpos = dialog_left; 
  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 = 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 = dialog_left;
  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;
       
        //transplanted in from dialogue_options_mouse_click() to get rid of background/old buttons in real time
        MyDynamicSpriteForTheFakeGUI = DynamicSprite.Create(info.Width, info.Height, true);
        DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();
       

ds.DrawImage(0, 672, 2639);

DrawDialogOptions(ds, info);
        ds.Release();
       
        return;
      }
      xpos += 96;
    }
    i++;
  }
  gFakeDialogOptions.Visible = false;
}

//----------------------------------------------------------------------------------------------------------------------
// 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();
    ds.DrawImage(0, 672, 2639);
    DrawDialogOptions(ds, info);
    ds.Release();

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

Still stumped.

Re: Custom dialogue issue with dimensions
« Reply #10 on: 06 Jun 2020, 01:33 »
You create a new MyDynamicSpriteForTheFakeGUI sprite every time a mouse is clicked, and every tick while a cursor is in some location, which is very inefficient, but besides that there's a mistake:
in dialog_options_mouse_click you create new sprite and assign it to gFakeDialogOptions.BackgroundGraphic, but in dialog_options_repexec you don't assign a new sprite anywhere.

Now, I have to admit I am surprised this does not crash, as previous sprite is supposed to be deleted when you replace MyDynamicSpriteForTheFakeGUI.

The proper approach would be to create dynamic sprite only once when dialog options first show up, and then redraw on same sprite without recreating it.
« Last Edit: 06 Jun 2020, 01:35 by Crimson Wizard »

bx83

  • benjamin.rich@protonmail.com
Re: Custom dialogue issue with dimensions
« Reply #11 on: 06 Jun 2020, 01:55 »
Okay I've tried this:

Code: [Select]
function dialog_options_get_dimensions(DialogOptionsRenderingInfo* info)
{
ConversationIsOn=true;

// Create a 1366x96 dialog options area at (0,704)
dialog_left=11;

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

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

function DrawDialogOptions(DrawingSurface* ds, DialogOptionsRenderingInfo* info)
{
ds.DrawImage(0, 672, 2639);

int i = 1, ypos = 0, xpos = dialog_left; 
  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 = 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)
{
MyDynamicSpriteForTheFakeGUI = DynamicSprite.Create(info.Width, info.Height, true);
  DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();
ds.DrawImage(0, 672, 2639);

int i = 1, xpos = dialog_left;
  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;
       
        //transplanted in from dialogue_options_mouse_click() to get rid of background/old buttons in real time
DrawDialogOptions(ds, info);
        ds.Release();
       
        return;
      }
      xpos += 96;
    }
    i++;
  }
  gFakeDialogOptions.Visible = false;
}

//----------------------------------------------------------------------------------------------------------------------
// 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();
    ds.DrawImage(0, 672, 2639);
    DrawDialogOptions(ds, info);
    ds.Release();

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

Still doesn't work - doesn't show up sprite 2639 anywhere, at any time, even for an instant. Could you point out the lines which don't have to be there? I'm trying but the stupid is strong in me today.

Re: Custom dialogue issue with dimensions
« Reply #12 on: 06 Jun 2020, 02:10 »
There are few things that seem strange to me in this code. For example, DrawDialogOptions is called with the dialog option's own surface in dialog_options_render(), but it's also called with your dynamic sprite everywhere else. So it's like you are drawing same thing on two different surfaces.

Maybe I missed something in previous discussion.

Is this what you are trying to do right now?
Quote
Bonus question: I'm thinking of having a large background image to frame the conversation icons -- where do I put the drawing code, once in dialog_options_render()?
« Last Edit: 06 Jun 2020, 02:12 by Crimson Wizard »

bx83

  • benjamin.rich@protonmail.com
Re: Custom dialogue issue with dimensions
« Reply #13 on: 06 Jun 2020, 02:18 »
Yes - I’m trying to draw the woodpanel graphic above (4th post), and then the option icons on top of that.

Re: Custom dialogue issue with dimensions
« Reply #14 on: 06 Jun 2020, 02:21 »
Yes - I’m trying to draw the woodpanel graphic above (4th post), and then the option icons on top of that.

But the woodpanel has to be drawn only once, and never changed, correct? If so, then you need to draw it only 1 time, in dialog_options_get_dimensions (this is where you decide the size of options surface), and assigned to GUI gFakeDialogOptions.

bx83

  • benjamin.rich@protonmail.com
Re: Custom dialogue issue with dimensions
« Reply #15 on: 06 Jun 2020, 05:43 »
I think I've followed your instructions; still doesn't show sprite 2639.


Code: [Select]
function dialog_options_get_dimensions(DialogOptionsRenderingInfo* info)
{
  ConversationIsOn=true;

  dialog_left=11;

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

  MyDynamicSpriteForTheFakeGUI = DynamicSprite.Create(info.Width, info.Height, true);
  DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();
  ds.DrawImage(0, 672, 2639);
  ds.Release();
}

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

function DrawDialogOptions(DrawingSurface* ds, DialogOptionsRenderingInfo* info)
{
  int i = 1, ypos = 0, xpos = dialog_left; 
  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 = 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 = dialog_left;
  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;
       
        //transplanted in from dialogue_options_mouse_click() to get rid of background/old buttons in real time
        DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();
DrawDialogOptions(ds, info);
        ds.Release();
       
        return;
      }
      xpos += 96;
    }
    i++;
  }
  gFakeDialogOptions.Visible = false;
}

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

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

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

bx83

  • benjamin.rich@protonmail.com
[SOLVED] Custom dialogue issue with dimensions
« Reply #16 on: 06 Jun 2020, 09:05 »
Alright - code is working :)
Here it is, though no doubt doing some things twice when it only has to do them once:

Code: [Select]
function dialog_options_get_dimensions(DialogOptionsRenderingInfo* info)
{
ConversationIsOn=true;


dialog_left=11;

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

MyDynamicSpriteForTheFakeGUI = DynamicSprite.Create(info.Width, info.Height, true);
  DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();
ds.DrawImage(0, 0, 2639);
ds.Release();

gFakeDialogOptions.BackgroundGraphic = MyDynamicSpriteForTheFakeGUI.Graphic;
  gFakeDialogOptions.Visible = true;
}

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

function DrawDialogOptions(DrawingSurface* ds, DialogOptionsRenderingInfo* info)
{
int i = 1, ypos = 0, xpos = dialog_left; 
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    {
gFakeDialogOptions.BackgroundGraphic = MyDynamicSpriteForTheFakeGUI.Graphic;
gFakeDialogOptions.Visible = true;

      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 = 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)
{

gFakeDialogOptions.BackgroundGraphic = MyDynamicSpriteForTheFakeGUI.Graphic;
  gFakeDialogOptions.Visible = true;

int i = 1, xpos = dialog_left;
  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;
       

        DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();
       

DrawDialogOptions(ds, info);
        ds.Release();
       
        return;
      }
      xpos += 96;
    }
    i++;
  }
}

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

function dialog_options_mouse_click(DialogOptionsRenderingInfo* info, MouseButton button)
{
  if (info.ActiveOptionID > 0)
  {

    DrawingSurface* ds = MyDynamicSpriteForTheFakeGUI.GetDrawingSurface();

DrawDialogOptions(ds, info);
    ds.Release();

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

Re: Custom dialogue issue with dimensions
« Reply #17 on: 06 Jun 2020, 10:35 »
Here it is, though no doubt doing some things twice when it only has to do them once:

Yes, it repeats same thing few times.

There's no need to redraw anything in dialog_options_mouse_click and dialog_options_repexec. IDK how that works, because you're redrawing options on background GUI.
Also no need to do this DrawDialogOptions:
Quote
gFakeDialogOptions.BackgroundGraphic = MyDynamicSpriteForTheFakeGUI.Graphic;
gFakeDialogOptions.Visible = true;
« Last Edit: 06 Jun 2020, 10:39 by Crimson Wizard »