right click GUI button

Started by gregp, Mon 21/02/2005 07:56:33

Previous topic - Next topic

gregp

I have another question:

How do tell the game to do something when a button in a GUI is right-clicked?
for example:  to open another GUI.


Radiant

Check the on_event(GUI_MDOWN).

gregp

#2
I checked my help file, but I'm afraid I still don't understand.

GUI_MDOWN  : mouse button pressed over a GUI

DATA=GUI number

how do I specify a right button click?
furthurmore, I only need one particular button in that GUI to respond to right clicks.
/////
EDIT:

okay, I got a little furthur:

function on_event (int event, int data) {
  if (event==GUI_MDOWN)&&(data==8){
          if (IsButtonDown(RIGHT)) {
}
}
}

but now what?
I still need to specify only the one button in the GUI.
I know i can't use :

if (button==so&so);

because that's for the interface_click function, yes?


*help?*

greg

strazer

Try this:

Code: ags

// main global script file

int guimb; // stores mouse button clicked on gui

function on_event(int event, int data) {
  //...

  if (event == GUI_MDOWN) { // if mouse clicked over a gui
    if (IsButtonDown(LEFT)) guimb = LEFT; // if left mouse button pressed, store it in variable
    else if (IsButtonDown(RIGHT)) guimb = RIGHT; // if right mouse button pressed, store it in variable
    // more buttons here...
  }

  //...
}


function interface_click(int interface, int button) {
  //...

  if (interface == THEGUINAME) {
    if (button == THEBUTTONNUMBER && guimb == RIGHT) {
      // do stuff
    }
  }

  //...
}

gregp

that works and it makes sense.

I keep forgetting how pwerful those variables are.

thank you, mr. strazer

greg

strazer


Etcher Squared Games

Ok, I recently had this same problem, came upon this thread and it fixed my problem...almost.


I wanted people to be able to right click in my inventory window and have it change the cursor, and nothing else.

I ended up with this...

Code: ags


int ignore_interface_click = 0;

function on_event(int event, int data)
{
Ã,  if (event == GUI_MDOWN)
Ã,  {
Ã,  Ã,  if (IsButtonDown(RIGHT))
Ã,  Ã,  {
Ã,  Ã,  Ã,  ignore_interface_click = 1;
Ã,  Ã,  Ã,  SetNextCursorMode();Ã,  Ã,  
Ã,  Ã,  }
Ã,  }
}




#sectionstart interface_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button) {
Ã,  if (ignore_interface_click == 1)
Ã,  {
Ã,  Ã,  ignore_interface_click = 0;
Ã,  Ã,  return;
Ã,  }

Ã,  //Ã,  .... other stuff here.....

}




What I would like explained to me is why are the mouse clicks I have to capture in on_event are not triggering on_mouse_clicks?

I tried using "IsButtonDown" inside the interface, but it just never took.

So, I'm just a bit confused...Why is on_event needed vs on_mouse_click and stuff in general.

Oh and one more thing...I AM "Handle inventory clicks in script" since I'm doing some custom code that makes the inventory handling simpler.

(strazer, can you simplify this?)
website: http://www.etcher2games.com/
email: etcher2games@yahoo.com
forum: http://www.etcher2games.com/forums

Anyone want to make my website for free?

strazer

Quote from: Worm III on Wed 18/05/2005 01:16:44
What I would like explained to me is why are the mouse clicks I have to capture in on_event are not triggering on_mouse_clicks?

When the mouse is clicked over a GUI, interface_click is called instead of on_mouse_click.
This is just how AGS works. A bit inconsistent I guess.

Quote from: Worm III on Wed 18/05/2005 01:16:44
I tried using "IsButtonDown" inside the interface, but it just never took.

The interface_click function is triggered when the mouse button is released so by the time the function runs, IsButtonDown always returns 0.
That's why the on_event function is needed to store the pressed mouse button before the interface_click function runs. on_event/GUI_MDOWN runs when the mouse button is pressed down.

Quote from: Worm III on Wed 18/05/2005 01:16:44
Why is on_event needed vs on_mouse_click and stuff in general.

Since you can't check the mouse button in interface_click (see above), we need to save the clicked mouse button in on_event first.

Quote from: Worm III on Wed 18/05/2005 01:16:44
(strazer, can you simplify this?)

Your code is fine. An alternative is this:

Code: ags

int ignore_interface_click = 0;

function on_event(int event, int data) {

  if (event == GUI_MDOWN) {

    if (IsButtonDown(RIGHT)) {
      ignore_interface_click = 1;
      SetNextCursorMode();   
    }
    else ignore_interface_click = 0;

  }

}


function interface_click(int interface, int button) {

  if (ignore_interface_click == 1) return;

  //  .... other stuff here.....

}


Here's basically how I do it in my game:

Code: ags

// main global script file

int GUIMouseButton; // stores mouse button clicked on gui

//on_mouse_click function here

function on_event(int event, int data) {
  //...

  if (event == GUI_MDOWN) { // if mouse clicked over a gui

    if (IsButtonDown(LEFT)) GUIMouseButton = LEFT; // if left mouse button pressed, store it in variable
    else if (IsButtonDown(RIGHT)) { // if right mouse button pressed
      GUIMouseButton = RIGHT; // store button in variable
      on_mouse_click(RIGHT); // call on_mouse_click function for default right mouse button action (SetNextCursorMode)
    }
    else GUIMouseButton = MIDDLE; // if any other mouse button pressed, store as middle mouse button

  }

  //...
}


function interface_click(int guiid, int controlid) {
  //...

  if (guiid == THEGUINAME_A) {
    if (controlid == THECONTROLNUMBER_A) {
      // do stuff
    }
  }

  if (GUIMouseButton != LEFT) return 0; // allow only left mouse button for the following GUIs

  if (guiid == THEGUINAME_B) {
    if (controlid == THECONTROLNUMBER_B) {
      // do stuff
    }
  }

  //...
}

Etcher Squared Games

Ok, I think I follow you....

So, when the mouse is RELEASED over a GUI element (not just anywhere on the GUI) the interface_click is triggered, regardless of the mouse button.

on_event with (event == GUI_MDOWN) is triggered ANY time you click on a GUI ANYWHERE....

on_mouse_click is triggered with RIGHTINV and LEFTINV anytime you click within an inventory window (or perhaps just when you actually click on an inventory item that's actually there)

on_mouse_click is triggered with RIGHT and LEFT any other mouse click scenario....

Does that sound like how it goes?
website: http://www.etcher2games.com/
email: etcher2games@yahoo.com
forum: http://www.etcher2games.com/forums

Anyone want to make my website for free?

strazer

#9
QuoteSo, when the mouse is RELEASED over a GUI element (not just anywhere on the GUI) the interface_click is triggered, regardless of the mouse button.

Yes, but the interface_click function is triggered regardless of whether the mouse is over a GUI control or not. That's why you use the
  if (interface == INVENTORY) {
and
  if (button == 0) {
parts to check for the GUI and GUI control that the mouse button has been clicked on.

Edit:
(Btw, the default parameter names of the interface_click function, "interface" and especially "button", are bit confusing I think, that's why I renamed them to "guiid" and "controlid" in my earlier example.)
-

Quoteon_mouse_click is triggered with RIGHTINV and LEFTINV anytime you click within an inventory window (or perhaps just when you actually click on an inventory item that's actually there)

The latter, yes.
Keep in mind that the on_event function is also run in this case (before the on_mouse_click function).

(Just for reference: "Handle inventory clicks in script" has to be checked in General settings for RIGHTINV/LEFTINV to work.)

Edit 2:

Another thing: In AGS v2.7, each GUI control (except inventory windows it seems) can have its own event handler function where you can check the mouse button:
  function MyButton_Click(GUIControl *control, MouseButton button) {
for example.

Etcher Squared Games

Hey all,

I just wanted to add to this thread something I just discovered...

3 messages up Strazer compares my code to his code saying either would work.Ã, 

Turns out something is a bit wrong with my version, so I would suggest to anyone finding this thread to use Strazer's suggestion.Ã,  I haven't investigated as to why yet, but with my code, if you were to right click on an inventory item (so the end result was just changing the cursor) and then click on one of the GUI buttons, the first click would NOT take....click again, all is good.


My initial guess is this...
Code: ags


#sectionstart interface_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button) {
Ã,  if (ignore_interface_click == 1)
Ã,  {
Ã,  Ã,  ignore_interface_click = 0;
Ã,  Ã,  return;
Ã,  }

Ã,  //Ã,  .... other stuff here.....

}


I'm guessing this function doesn't get run on right click on inventory.
Thus my ignore_interface_click would not get reset back to 0, and then clicking a GUI button would trigger this, but dump out due to ignore_interface_click being 1 still....

Sound right Strazer?

website: http://www.etcher2games.com/
email: etcher2games@yahoo.com
forum: http://www.etcher2games.com/forums

Anyone want to make my website for free?

strazer

Yeah, it would seem the interface_click function isn't triggered when you click on an inventory item.
So it's probably best to just capture the pressed mouse button in on_event and put the checks in interface_click like I did in my last example above.

SMF spam blocked by CleanTalk