Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: WHAM on Wed 29/02/2012 23:05:26

Title: How to ignore right clicks in GUI [SOLVED]
Post by: WHAM on Wed 29/02/2012 23:05:26
Small and simple question, I fear the answer may be all but...
Is there a way to make a GUI button only accept clicks from the left mouse button and not all mouse buttons? Or will this require some serious coding magic?
Title: Re: How to ignore right clicks in GUI
Post by: monkey0506 on Wed 29/02/2012 23:07:39
GUI click handlers take a MouseButton parameter passed in by the editor...

function gNorightclick_OnClick(GUI *theGUI, MouseButton button)
{
 if (button != eMouseLeft) return; // or whatever appropriate condition
}


So...coding magic, fair enough..."serious" coding magic? No. ;)

Edit: Sorry, you said GUI button. Same thing applies as they also take a MouseButton parameter. For other controls you could always use on_event with eEventGUIMouseDown and eEventGUIMouseUp alongside mouse.IsButtonDown...
Title: Re: How to ignore right clicks in GUI
Post by: WHAM on Wed 29/02/2012 23:24:57
Oh Ye Gods!

Monkey, please don't tell me I need to have this check for each and every button in a game that has, like, 150 buttons?  :o
Title: Re: How to ignore right clicks in GUI
Post by: Khris on Wed 29/02/2012 23:36:20
Short answer: yes.

Long answer:
150 buttons...?
Do they all perform radically different functions?

I'm asking because to code, say, a telephone keypad, you only need one function. Every keypad button's onClick is linked to it, and the function figures out the button using the GUIControl parameter (or more specifically, its .ID).
Judging from your screenshots (and the amount, 150), I'd say it's a safe bet that you can group lots of those buttons together, significantly reducing the number of click checks.
Title: Re: How to ignore right clicks in GUI
Post by: WHAM on Wed 29/02/2012 23:43:18
Quote from: Khris on Wed 29/02/2012 23:36:20
Short answer: yes.

Long answer:
150 buttons...?
Do they all perform radically different functions?

I'm asking because to code, say, a telephone keypad, you only need one function. Every keypad button's onClick is linked to it, and the function figures out the button using the GUIControl parameter (or more specifically, its .ID).
Judging from your screenshots (and the amount, 150), I'd say it's a safe bet that you can group lots of those buttons together, significantly reducing the number of click checks.

The project in question is my MAGS game, deadline looming in 2 days. I don't have time for big fixes and even though I probably COULD combine many of the existing (and hastily scripted) gui button scripts into single functions, I would still be left with too much work for such a short time. The game is mostly just a ton of buttons, so even with combining functions I would still be left with at least a few dozen scripts to fix like this, and the combining of the functions will take much more time.

I might look into this later, but for now, in-game notifications can only be skipped by pressing the space-bar, not by mouse clicking.
Title: Re: How to ignore right clicks in GUI
Post by: on Thu 01/03/2012 01:51:23
Isn't it possible to check in on_mouse_click if the mous is over a GUI?
If NO button must respond to RMB, you could just disable it whenever ANY button is clicked.
Title: Re: How to ignore right clicks in GUI
Post by: WHAM on Thu 01/03/2012 08:30:15
Quote from: Ghost on Thu 01/03/2012 01:51:23
Isn't it possible to check in on_mouse_click if the mous is over a GUI?
If NO button must respond to RMB, you could just disable it whenever ANY button is clicked.


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, eModeInteract);
  }
  else if (button == eMouseRight)  // right-click
  {   
    // This should do nothing, but it still works on GUI buttons
  } else {
    // More nothing
  }
}
Title: Re: How to ignore right clicks in GUI
Post by: Khris on Thu 01/03/2012 09:04:49
on_mouse_click isn't called if the user clicks a GUI (or GUI element). The only exception is the part of an InventoryWindow that contains an item, and only if the option is set in General settings; then on_mouse_click is called with button being eMouse...Inv.
Title: Re: How to ignore right clicks in GUI
Post by: WHAM on Thu 01/03/2012 09:15:16
Thanks for confirming that, Khris. I will be leaving this out of the game for now, might look into fixing it with Mokney's solution after MAGS if I feel like going back to polish the game further.

Thanks everyone!