[SUGGESTION] GUI.Enabled

Started by subspark, Wed 09/09/2009 07:28:17

Previous topic - Next topic

subspark

While a certain GUI is onscreen (Yes/No Popup), it would be handy to disable other GUIs behind along with all of their controls at once without having to disable the buttons separately, each.

For example:

Code: ags
if (gAskFirst.Visible == true) {
gOptions.Enabled = false; // Disables all clicking in this GUI but does not pass the mouse clicks through it.
}


Cheers,
Sparky.

Khris

#1
You can effectively turn off a visible GUI by setting it's .Clickable property to false.
If you want it to appear disabled (as in the built-in greying out its controls), use an extender function:

Code: ags
void SetAllControls(this GUI*, bool enabled) {
  int i;
  while (i < this.ControlCount) {
    this.Controls[i].Enabled = enabled;
    i++;
  }
}


Alternatively, you could also set the mouse's bounds to the popup GUI.

subspark

#2
QuoteYou can effectively turn off a visible GUI by setting it's .Clickable property to false.
Unfortunately not that simple. When a GUI.Clickable is set to false, the mouse over hilight functions still work on the buttons.
Before I posted this thread, I elaborately worked around this problem by writing the following code:


Global Script:
Code: ags

//=============
// DECLARATIONS
//=============

bool FreezeMainMenu;
export FreezeMainMenu;

//============================
// FREEZE MAIN MENU CONDITIONS
//============================
  
  if (FreezeMainMenu == true) {
    bNewGame.Clickable = false;
    bNewGame.MouseOverGraphic = 394;
    bLoadGame.Clickable = false;
    bLoadGame.MouseOverGraphic = 397;
    bMainOptions.Clickable = false;
    bMainOptions.MouseOverGraphic = 395;
    bCredits.Clickable = false;
    bCredits.MouseOverGraphic = 393;
    bQuit.Clickable = false;
    bQuit.MouseOverGraphic = 396;
  }
  else {
    bNewGame.Clickable = true;
    bNewGame.MouseOverGraphic = 399;
    bLoadGame.Clickable = true;
    bLoadGame.MouseOverGraphic = 402;
    bMainOptions.Clickable = true;
    bMainOptions.MouseOverGraphic = 400;
    bCredits.Clickable = true;
    bCredits.MouseOverGraphic = 398;
    bQuit.Clickable = true;
    bQuit.MouseOverGraphic = 401;
  }


Global Script Header
Code: ags
import bool FreezeMainMenu;


None of this code would be necessary if GUI.Enabled was implemented. Thanks for the general help though Khris. My code could be optimized with your example.

Cheers,
Sparky.

Knox

I actually would really like this feature aswell :)
--All that is necessary for evil to triumph is for good men to do nothing.

Pumaman

Sounds like a reasonable suggestion, though the script Khris posted should do the trick.

subspark

Yeah but I don't want the controls to grey out. I've actually got a separate GUI that pops in underneath the active GUI that fades 30% black over the underlying elements.

Using something.clickable = false; doesn't seem to work with my sound scripts in repeatedly execute. The mouse_down & 'mouse_up' sounds still play and is rather annoying. This is what called for my elaborate workaround.

However as you said, my suggestion seems reasonable enough and it would eliminate these problems while conforming to and extending the excellent AGS scripting standard.

Sparky.

SMF spam blocked by CleanTalk