Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Calin Leafshade on Tue 08/05/2012 04:04:40

Title: Modal/Pausing GUI
Post by: Calin Leafshade on Tue 08/05/2012 04:04:40
Anyone any ideas for easily and sensibly implementing modal GUIs?

Ideally i'd like to do this:


Display("Well hi there! Click Ok on the next GUI you see!");
WaitWhileWeShowGUIModally();
Display("You clicked OK! Good for you!");


This keeps it neat by keeping the code inline and not fucking with program flow.

However, GUI Buttons can't be clicked while the game is blocked so i guess i'd have to check mouse position and stuff manually in a wait loop?

Is that how you guys would do it?
Title: Re: Modal/Pausing GUI
Post by: Sephiroth on Tue 08/05/2012 06:21:44
I needed something like that for a dialog gui, if I'm not misunderstanding it should be similar to your idea, and this is how I did it, although it's not really neat/tidy imho.
This code is for a listbox with up to three entries, acting as a dialog choice system so you can use it like this in the end:

int result = GetDialogChoice(); //wait until you click on one of the dialog options and return its id


//GuiDialogChoice - the Gui
//ChoicesBox - the Listbox

//global variable
  int DialogChoice;

//repeatedly execute always
if(GuiDialogChoice.Visible)
{
  int base_height = ChoicesBox.Height/3;
  if(mouse.x > GuiDialogChoice.X + ChoicesBox.X &&
     mouse.x < GuiDialogChoice.X + ChoicesBox.X + ChoicesBox.Width)
  {
    if(mouse.y > GuiDialogChoice.Y + ChoicesBox.Y &&
       mouse.y < GuiDialogChoice.Y + ChoicesBox.Y + base_height)
    {
      ChoicesBox.SelectedIndex=0;
      if(mouse.IsButtonDown(eMouseLeft))
        DialogChoice = 1;
    }
    else if(mouse.y > GuiDialogChoice.Y + ChoicesBox.Y + base_height &&
            mouse.y < GuiDialogChoice.Y + ChoicesBox.Y + (base_height *2) &&
            ChoicesBox.ItemCount > 1)
    {
      ChoicesBox.SelectedIndex=1;
      if(mouse.IsButtonDown(eMouseLeft))
        DialogChoice = 2;
    }
    else if(mouse.y > GuiDialogChoice.Y + ChoicesBox.Y + (base_height*2) &&
            mouse.y < GuiDialogChoice.Y + ChoicesBox.Y + (base_height*3) &&
            ChoicesBox.ItemCount > 2)
    {
      ChoicesBox.SelectedIndex=2;
      if(mouse.IsButtonDown(eMouseLeft))
        DialogChoice = 3;
    }
  }
}
 

//the blocking function
int GetDialogChoice()
{
  DialogChoice = 0;
  GuiDialogChoice.Visible = true;

  while(!DialogChoice)
    Wait(GetGameSpeed()/10);

  GuiDialogChoice.Visible = false;
  return DialogChoice;
}


But then you will have to handle all the other events in rep_ex_always when your function is blocking.
Title: Re: Modal/Pausing GUI
Post by: Calin Leafshade on Tue 08/05/2012 06:59:38
Thats probably the way I would do it, except i'd put all the checking inside the GetResult function like this:

pseudo:


int GetResult()
{

  int result = -1;
  while (result < 0)
  {
     if (GUIControlUnderMouse == btnOK && IsMouseDown(eLeft))  //repeat for other buttons
     {
        result = 1
     }
     Wait(1)

  }
  return result;

}



I just wondered if anyone else had come up with something a little more elegant.