How to ignore right clicks in GUI [SOLVED]

Started by WHAM, Wed 29/02/2012 23:05:26

Previous topic - Next topic

WHAM

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?
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

monkey0506

#1
GUI click handlers take a MouseButton parameter passed in by the editor...

Code: ags
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...

WHAM

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
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Khris

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.

WHAM

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.
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Ghost

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.

WHAM

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.

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, eModeInteract);
  }
  else if (button == eMouseRight)  // right-click
  {   
    // This should do nothing, but it still works on GUI buttons
  } else {
    // More nothing
  }
}
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

Khris

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.

WHAM

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!
Wrongthinker and anticitizen one. Utterly untrustworthy. Pending removal to memory hole.

SMF spam blocked by CleanTalk