Closing a custom GUI when... [SOLVED]

Started by LeChuck, Mon 17/01/2005 23:11:23

Previous topic - Next topic

LeChuck

Does anyone know how to get AGS to automatically close the GUI when the mouse hovers outside it? I'm trying to make a custom inventory GUI that closes when the mouse is outside of it...

Code: ags
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE

function show_inventory_window() {
  
  GUIOn (INVENTORY);  
  // switch to the Use cursor (to select items with)
    SetCursorMode (MODE_USE);
  // But, override the appearance to look like the arrow
  SetMouseCursor (6);
}



Additionally, does anyone know why the SetMouseCursor command doesn't change the cursors appearance to cursor number 6, but instead it uses the "Use" cursor instead? If I understand the function correctly, you're supposed to be able to have the cursor appear as you like, but with the use function.

Does anyone know why this isn't working?

I couldn't find any answers anywhere to these little riddles...

Necro

Automatically closing the GUI will probably need you entering mouse detection code in repeatidly exec function...

Code: ags

if ((IsGUIOn(YOURGUI) && (mouse.y >30)) {
   // If your Gui is currently ON and the mouse moves out of bounds...
   GUIOff(YOURGUI);
   }

LeChuck

Yes, that seemed to work, but with some modifications. Here's the code I'm using:

Code: ags


if (IsGUIOn(INVENTORY)){
Ã,  Ã,  // Checks if mouse has moved onto GUI...
Ã,  Ã,  if (((mouse.x > 50) && (mouse.x < 270)) && ((mouse.y > 35) && (mouse.y < 165))) {
Ã,  Ã,  SetGlobalInt(1, 1); // Mouse HAS entered GUI!
Ã,  Ã,  }
Ã,  
Ã,  Ã,  // Checks if the mouse has entered the GUI...
Ã,  Ã,  if (GetGlobalInt(1)==1) {
Ã,  Ã,  Ã,  Ã, // Checks if mouse is still over the GUI...
Ã,  Ã,  Ã,  Ã, if ((mouse.x < 50) || (mouse.x > 270) || (mouse.y < 35) || (mouse.y > 165)) {
Ã,  Ã,  Ã,  Ã,  Ã,  //If not:
Ã,  Ã,  Ã,  Ã,  Ã,  GUIOff(INVENTORY);
Ã,  Ã,  Ã,  Ã,  Ã,  SetGlobalInt(1, 0);
Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã, }
Ã,  Ã,  }
Ã,  
Ã,  Ã,  // Closes GUI if clicked outside GUI before entering it
Ã,  Ã,  if (GetGlobalInt(1)==0) {
Ã,  Ã,  Ã,  if ((IsButtonDown(RIGHT)) || (IsButtonDown(LEFT))) {
Ã,  Ã,  Ã,  Ã,  GUIOff(INVENTORY);
Ã,  Ã,  Ã,  Ã,  SetGlobalInt(1, 0);
Ã,  Ã,  Ã,  }
Ã,  Ã,  }



This way, the inventory window works as in Monkey Island 3. I'm sure it can be written shorter, but it works! :)

Scorpiorus

QuoteAdditionally, does anyone know why the SetMouseCursor command doesn't change the cursors appearance to cursor number 6, but instead it uses the "Use" cursor instead?
Hmm, it should work. For example, in the "open inventory GUI" script, you've posted, the "Use" cursor appearance is changed to cursor 6 (pointer), thus when a GUI is opened you should see a pointer instead of the hand cursor. But keep in mind, that changing cursor mode will restore its appearance:

SetCursorMode(MODE_USE); // hand cursor (mode_use)
SetMouseCursor(6);Ã,  // pointer cursor (mode_use)
SetCursorMode(MODE_USE); // again changed to hand cursor (mode_use)

SMF spam blocked by CleanTalk