Right click over GUIs (SOLVED)

Started by JpSoft, Tue 20/05/2008 18:43:46

Previous topic - Next topic

JpSoft

I checked the help file and searched here, but i dont found nothing about, so i guess my doubt is to simple, but i cant figure how i can fix it.

On section On_Click y added that when right buttons is clicked then do nothing. (on_click function works perfect, even the wheel support)

But right click still work on GUI´s buttons  ??? How i can solve this? I found a thread about something like this but was 3 years ago and reading the code i assume that it was in a old version (i begin with 2.72)

Thanks for any help

Jp

skuttleman

Can you post a sample of your code?

monkey0506

If you're using AGS 3.0 or higher then the GUI click handlers take a MouseButton parameter which will hold the button used when the function is called. So it should be as simple as adding a clause for the right button:

Code: ags
function gMygui_OnClick(GUI *theGui, MouseButton button) {
  if (button == eMouseRight) {
    // blah blah blah
  }
}

.M.M.

Yes, but (correct me if I am wrong) you must also define Right click in inventory because there is also eMouseRightInv . So just add this into the on_mouse_click.
Code: ags
 if (button==eMouseRightInv) {
 // this is nothing
}

monkey0506

Actually, now I see he said it wasn't working on the GUI's buttons. Most likely your GUI Buttons are set to Clickable, so their click handler function is intercepting it anyway. Basically the same code as I posted above, just for the Button's click handler instead of the GUI's. Or you could set the Button to non-clickable.

Mirez he never specifically mentioned inventory items, nor whether he was handling their clicks within the script. However if this is what he meant then yes, what you said. ;)

.M.M.

He don´t want to use right mouse button, so I think this is  important. ::)

monkey0506

I've been misreading this. You're right. :P

JpSoft

I dont have the source code with me (my PC is at home) but i just started the game with the empty template, then just leaved empty the sentences for right click in function on_click (remember that  it changes the mouse mode by default?)

Now, when i right-click in the map, characters or objects, it just dont do nothing; but right-click in any GUI works in the same way like left-clicks (the game is paused or not, i already checked that). Seems like AGS recognize (by default) anyclick over GUIs in the same way (but i guess there is a way to clarify which button you clicked scripting)

Until now, i did not use right clicks in the game, but now i want add special features using right click, but i cant, since when i click in the GUIs, i cant recognize whatever if it was a right or left button.

I hope i was enough clear. If not, i will post the source code tomorrow.

Thanks

Jp

.M.M.

Yes, you can do that only with scripting.
Code: ags
function btnYourButton_Click(GUIControl *control, MouseButton button) {
 if (Mouse.IsButtonDown(eMouseLeft)) {
   Display("You pressed left mouse button!");
  }
 else if (Mouse.IsButtonDown(eMouseRight)) {
   Display("You pressed right mouse button!");
  }
}

JpSoft

#9
Quote from: Mirek CZ on Wed 21/05/2008 12:10:21
Yes, you can do that only with scripting.
Code: ags
function btnYourButton_Click(GUIControl *control, MouseButton button) {
 if (Mouse.IsButtonDown(eMouseLeft)) {
   Display("You pressed left mouse button!");
  }
 else if (Mouse.IsButtonDown(eMouseRight)) {
   Display("You pressed right mouse button!");
  }
}


And i must add this function inside rep_exec? It makes no sense for me  ??? This code looks better to check if you are pressing any button(to drag functions, for example) but not to determine which button was clicked.

I added a code on_click when right buttons is pressed over a GUI(just display"right click pressed"), and AGS process the click as left and right (it minds, AGS first pushed the button GUI and then displayed the message  ??? ??? ??? ??? ??? ???

Im sure I'm missing something...

Jp

EDIT Here is the code from my game

in global script...

Code: ags

#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
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 if (button == eMouseRight)// right-click, dont do nothing
  {   
  }
else if (button == eMouseWheelNorth)
  {
  SetViewport (GetViewportX(), GetViewportY()-(scrollspeed*3)); 
  }
else if (button == eMouseWheelSouth)
  {
  SetViewport (GetViewportX(), GetViewportY()+(scrollspeed*3));
  }
}

#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE


as you can see, i keep the original coments and leave enough space to make it readable.

Now, what i did was add this single line...

Code: ags
else if (button == eMouseRight)// right-click, dont do nothing
  {   
 Display("Right Click Pressed");
  }


And the game process the click when the cursor is over a GUI and then displays the message. Can i fix this?


.M.M.

Quote from: JpSoft on Wed 21/05/2008 12:36:48
Code: ags
function btnYourButton_Click(GUIControl *control, MouseButton button) {
}

It is script for button with script name "btnYourButton". You have to add script for right mouse button click to every button in your game.

JpSoft

Quote from: Mirek CZ on Wed 21/05/2008 18:51:10
Quote from: JpSoft on Wed 21/05/2008 12:36:48
Code: ags
function btnYourButton_Click(GUIControl *control, MouseButton button) {
}

It is script for button with script name "btnYourButton". You have to add script for right mouse button click to every button in your game.

I added it and what i get is the same double result  ??? Looks like by design AGS  ALWAYS process right-clicks over GUIs.

Jp

RetroJay

Yes I found this as well.
Gui`s seem to respond to either (left and right) clicks and do the same thing.
Like on the load and save icons. If you left or right click they will both open up the load and save GUI.
I would like them only to respond to a left click of the mouse but can`t find a way to do this.

Jay.

P.S. Not that it is a huge problem for me. But I made a "start game", "Skip intro" and so on within my intro screen with hotspots and all of these work with just a left click of the mouse. Then I used GUI`s for "Exit" and "Load" and found that both left and right clicks of the mouse do the same thing.

monkey0506

The MouseButton parameter for the button click handler should contain which button was clicked. Are you saying it is always passed as eMouseLeft? You shouldn't need to use IsButtonDown, that's what the MouseButton parameter is for.

RetroJay

No.
I have found that if you right click on any of the GUI icons within the ICONBAR then the game treats the right click the same as a left click (walk, talk, look and interact).
However if you do right click on "save game icon" " Load game icon" and "Exit icon" when the next GUI appears (i.e.  Exit game "Yes" "No") then you can only use the left mouse button.
I have looked inside the GUI`s and all of the icons are set to "Left click - Run script" except for "Look, Talk, Walk and Interact" which have the
"Left click" option set to "Set Cursor Mode".

I think that the only way you will really understand is if you try to play a game yourself (written with 2.72) and see what I mean.

Jay.

JpSoft

Yes, Paul Quest was created using AGS 2.72 and i find the same you say. I really dont pay attention to that since i dont need right clicks in that game, but now i can check that this is a old trouble in the engine.

Jp

Maverick

#16
Hi,

If I understand the problem correctly then all you want to achieve is to stop the right click function when clicking on your buttons in the GUI? If this is the case the you have to run script in the button_click event or it will recognize any click (left or right).

To stop the right click do this:

1) In the GUI editor select the button and set the left click property to run script
2) In the click property >>double click and it will create the click event in global script so just OK.
3) Double click on the button and it will open the global script at the exact spot where you need to insert the code
4) Use this code and it should work (tested it in 2.72)

Code: ags

#sectionstart btnInvLook_Click  // DO NOT EDIT OR REMOVE THIS LINE
function btnInvLook_Click(GUIControl *control, MouseButton button) {
  
if (button==eMouseLeft) {
			mouse.Mode = eModeLookat;
			}
			
			
  
}
#sectionend btnInvLook_Click  // DO NOT EDIT OR REMOVE THIS LINE


In this case the script name for the control is btnInvLook so you will use whatever name you used for the control.

EDIT
Tested in 3.0.1 and it works fine

RetroJay

#17
Hi Maverick.

Yeah. That seems to work just fine Thankyou.
However I just took:-
Code: ags

if (button==eMouseLeft) {

and placed it within my code where I don't want both mouse buttons to work the same on GUI buttons (i.e. Intro screen).
You see most of my Intro buttons are Hotspots that all seem to work on (Only) a left click. The only GUI buttons I have are "Exit" and "Restore Game" within my Intro screen.
In saying that though I do like the fact that by using this piece of code I can now stop all GUI buttons from using the right click of a mouse.
So once again thankyou.

Jay.
P.S. I hope this has also helped JP. If so then we can call this (SOLVED). . . . for now. ;)

JpSoft

I will try with this and let you know. Thanks

Jp

JpSoft

It work perfects! I needed add the code in all the bAnyButton_on_click functions, but now it works fine.

Thanks a lot

Jp

SMF spam blocked by CleanTalk