Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Hernald on Sun 02/09/2012 03:48:22

Title: Problem setting Height in dialog_options_get_dimensions [Solved]
Post by: Hernald on Sun 02/09/2012 03:48:22
I hope this is a simple scripting problem.
I am creating a custom dialog and no matter what I try the Height of the options box is rendered at what seems to be an arbitary value.
The code is picking up the right dialog, and calculating the number of options and the Height correctly, but this Height and corresponding Y value are not being used.
Here is the code:

Code (AGS) Select


function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info){
  int ocount;
  int oindex;
  ocount=0;
  oindex=1;

  info.Y = 470;
  info.Height = 0;


  while (oindex <= info.DialogToRender.OptionCount) {
    if (info.DialogToRender.GetOptionState(oindex) == eOptionOn) {
      info.Y -=8;
      info.Height +=8;
      ocount++;
    }
    oindex++;
  }
  vDialogNo=info.DialogToRender.ID;
  vOptionCount=ocount;
  vDialogHeight=info.Height;

  info.X = 40;

  info.Width = 560;

}



Any help or advice appreciated.
Title: Re: Problem setting Height in dialog_options_get_dimensions
Post by: Khris on Sun 02/09/2012 10:50:00
A shot in the dark:

Code (ags) Select
function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info){
  int ocount, oindex = 1;

  while (oindex <= info.DialogToRender.OptionCount) {
    if (info.DialogToRender.GetOptionState(oindex) == eOptionOn) ocount++;
    oindex++;
  }

  vDialogNo = info.DialogToRender.ID;
  vOptionCount = ocount;
  vDialogHeight = ocount * 8;

  info.X = 40;
  info.Y = 470 - ocount * 8;
  info.Height = ocount * 8;
  info.Width = 560;
}

It shouldn't make any difference though, and I can't really see what's wrong with the original code. The only thing that's different is I'm not setting info's fields multiple times.
Title: Re: Problem setting Height in dialog_options_get_dimensions
Post by: cat on Sun 02/09/2012 11:47:59
Are you sure you handle it correctly in dialog_options_render?
Title: Re: Problem setting Height in dialog_options_get_dimensions
Post by: Hernald on Sun 02/09/2012 16:14:40
Khris: Yes, I had tried it that way earlier; anything other than a simple uncalculated integer seems to come out wrong;
cat: The dialog_options_render is taken straight from the manual with just the background colour and font changed. Okay I'll post it in case I've messed something up:
Code (AGS) Select


function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  // Clear the area pale green
  info.Surface.Clear(36269);
  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 = 13;
      else info.Surface.DrawingColor = 4;
      info.Surface.DrawStringWrapped(5, ypos, info.Width - 10,
                         eFontNormal, eAlignLeft, info.DialogToRender.GetOptionText(i));
      ypos += GetTextHeight(info.DialogToRender.GetOptionText(i), eFontNormal, info.Width - 10);
    }
    i++;
  }
}


Thank you both for coming back to me, but I'm afraid I'm still in the dark...
Title: Re: Problem setting Height in dialog_options_get_dimensions
Post by: Hernald on Sun 02/09/2012 20:13:12
cat: You were right! The problem was caused by me not measuring the height of the rows of text in dialog_options_render.
I've simplified that code a bit and given the font more space and now it is working fine!
Thank you both for your input.
Title: Re: Problem setting Height in dialog_options_get_dimensions [Solved]
Post by: Khris on Sun 02/09/2012 20:25:13
Just to clarify, the GUI wasn't tall enough because you always used a height of 8 pixels for an option, even if it spanned multiple lines, correct?
Title: Re: Problem setting Height in dialog_options_get_dimensions [Solved]
Post by: Hernald on Sun 02/09/2012 22:34:42
Eight pixels was nowhere near enough for one line let alone multiple lines.
I've  copied up the GetTextHeight function from dialog_options_render to dialog_options_get_dimensions and now it works perfecly:
Code (AGS) Select


function dialog_options_get_dimensions (DialogOptionsRenderingInfo *info){
  int ocount=0, oindex=1;
 
 
  info.X = 40;
  info.Width = 560;
  vDialogHeight=0;
 
  while (oindex <= info.DialogToRender.OptionCount) {
    if (info.DialogToRender.GetOptionState(oindex) == eOptionOn) {
      vDialogHeight+=GetTextHeight(info.DialogToRender.GetOptionText(oindex), eFontSpeech, info.Width - 10);
      ocount++;
    }
    oindex++;
  }

  vOptionCount=ocount;
   
  info.Y = 470 - vDialogHeight;
 
  info.Height = vDialogHeight;
 
  vDialogNo=info.DialogToRender.ID;

}

It was a basic programming issue as I'd hoped; I guess I'd been at it for a while and needed to give my brain a rest, and a fresh perspective.