Questions about GUIs and cursors

Started by Tornado, Sun 03/05/2015 12:11:48

Previous topic - Next topic

Tornado

Hello. My first game in AGS is slowly taking shape.

I have made a custom GUI that pops up at the top of the screen when the mouse cursor is entering that area. The GUI is basically a horisontal bar. Its main portion contains my inventory, and a button for settings can be found to the far right. Now, what happens is that the Cursor automatically changes to type 6:Pointer, as this GUI becomes visible. Is there a way to prevent this from happening? The normal procedure is that the cursor modes are cycled one step every time I press the right mouse button, and I would like to keep this behaviour for my GUI as well.

I read in the online-manual, in Tutorial / Setting up the game / Cursors, that the Mode 6 (Pointer) cursor is used whenever a modal dialog is displayed (ie. a GUI that pauses the game). What is a "modal dialog" exactly? Is there a non-modal dialog? Perhaps just poor English on my part. I simply don't understand what is meant by this. Can I somehow operate my inventory GUI while the game is running in the background (i.e. not paused)?

Snarky

Yes, the cursor does not need to be set to "pointer" when a GUI is displayed. If you're using a template or module there may be some code that explicitly sets it, which you can change. If it happens on its own, you should be able to override it or simply turn it off.

In UI programming jargon, a "modal" dialog is a dialog (popup box or window) that captures focus, so that you can't interact with any other part of the application while it is displayed. You might know these popup boxes from Windows. In AGS terms, this means that the game is paused while the GUI is shown.

You don't need to pause the game while a GUI is displayed, but this depends on its display mode (the visibility property). If it's set to "Pause game when shown" (otherwise known as "popup modal"), it will do so, and you may see this behavior. I'm not sure whether the y-position setting ("When mouse moves to top of screen") does the same, I always just code that behavior on my own.

Try changing it to "Normal (initially off)" under the GUI properties.


(Incidentally, this is just yet another example of why hardcoding a certain cursor behavior into AGS is a terrible idea.)

Slasher

Quote(Incidentally, this is just yet another example of why hardcoding a certain cursor behavior into AGS is a terrible idea.)

amongst other things (nod)

Tornado

Quote from: Snarky on Sun 03/05/2015 12:42:32
Try changing it to "Normal (initially off)" under the GUI properties.

I had "When mouse moves to top of screen" selected for my GUI Visibility property. Apparently this makes it a modal dialog. I did just what you said and also added the following code to my GlobalScript:

Code: ags

function repeatedly_execute() 
{
  if (mouse.y < 24)
  {
    gMenu.Visible = true;
  }
  else
  {
    gMenu.Visible = false;
  }
}


Both problems solved! The game does not pause and the cursors behaviour is unaffected by the GUI.
Thanks a lot.

Tornado

Hmm, yet another problem. The cursor state does not change when right-clicking as the GUI is open. Is it possible that my conditional statement in the repeatedly_execute function, is blocking the on_mouse_click function?

Code: ags
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
  if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
  {
  }
  else if (button == eMouseLeft) 
  {
    ProcessClick(mouse.x,mouse.y, mouse.Mode);
  }
  else // right-click, so cycle cursor
  {   
    mouse.SelectNextMode();
  }
}

Snarky

No, that's not possible.

However, when you're clicking on a GUI, the on_mouse_click() method doesn't get called by default, and never with the values eMouseLeft/eMouseRight. Instead, you have to provide an event handler for the OnClick event.

The exception (because of course there is an exception) is when you're over an inventory item in an inventory GUI. Then it depends on the game setting "Handle inventory clicks in script": If that's set to true, on_mouse_click() gets called with the special MouseButton values eMouseLeftInv or eMouseRightInv.

So you should do three things:
-Check that "handle inventory clicks in script" is set to true
-Rewrite the on_mouse_click() function to also deal with eMouseLeftInv and eMouseRightInv
-Add an OnClick handler for your inventory window, probably something like:

Code: ags
function gInventory_OnClick(GUI *theGui, MouseButton button)
{
  if(button == eMouseRight)
    mouse.SelectNextMode();
}


(You need to remember to click-to-create this function from the GUI properties/event pane, not just enter it in the script.)

Monsieur OUXX

Just to make Snarky's answer less scary: 1) You need to create the "onclick" event of your GUI to intercept clicks on it. on_mouse_click is more for handling clicks inside of the game. 2) Then, only if you also need to have your right-click behaviour inside the Inventory window, do what Snarky said after his first two sentences.
 

SMF spam blocked by CleanTalk