Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Zoolander on Mon 06/03/2006 15:13:50

Title: Right-click on GUI [SOLVED]
Post by: Zoolander on Mon 06/03/2006 15:13:50
I'm trying to have it so that a right click on my inventory GUI will result in switching to the next mode and cursor.

I tried:

function on_event (int event, int data) {
Ã,  if (event==2) { //The number of the inventory GUI
Ã,  if (mouse.IsButtonDown(eMouseRight)) {
Ã,  Ã,  Mouse.SelectNextMode();
}
}
}


I've also tried the GUI name instead of number: if (event==gInventory) {
but either way, nothing happens when I right click.
Title: Re: Right-click on GUI
Post by: monkey0506 on Mon 06/03/2006 15:20:54
Try this.

function on_event(EventType event, int data) {
  if (event == eEventGUIMouseDown) {
    if (data == gInventory.ID) {
      if (mouse.IsButtonDown(eMouseRight))
        mouse.SelectNextMode();
    }
  }
}
Title: Re: Right-click on GUI
Post by: Zoolander on Mon 06/03/2006 15:27:30
Thanks, that works.  But I don't understand all of it.  What's "eEventGUIMouseDown" ?
Title: Re: Right-click on GUI
Post by: Ashen on Mon 06/03/2006 15:34:09
Check this manual entry (http://www.adventuregamestudio.co.uk/manual/TextScriptEvents.htm) for a full list of the on_event events.

The event parameter will always be one of those events (eEventGUIMouseDown is the event that's called when a mouse button is pressed over a GUI), while data changes depending on the event (in this case, it's the number of the GUI the button was pressed over).
Title: Re: Right-click on GUI
Post by: monkey0506 on Mon 06/03/2006 16:00:18
Sorry about the brevity...I had to go.  In fact, I have to go now...just I had a few more minutes after my shower while I wait for my ride.

Thanks for explaining it Ashen.
Title: Re: Right-click on GUI
Post by: Zoolander on Tue 07/03/2006 16:11:09
Thanks for the reply.

One more thing.Ã,  While I have the mouse mode change with a right click, I'd like it so that the right click doesn't result in the "look" action, or any other action.Ã,  I found a thread that asks this:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=21419.0
But I don't know what to put so that no action occurs at this point:

else if (button == eMouseRightInv) { // if right mouse button clicked on an inv item
Ã,  Ã,  inventory[game.inv_activated].RunInteraction(eModeLookAt);
}



Title: Re: Right-click on GUI
Post by: Ashen on Tue 07/03/2006 18:12:02
Just delete the inventory[game.inv_activated].RunInteraction(eModeLookAt); line, or even the whole else if (button == eMouseRightInv) condition.

But, that will only work when right-clicking an Inventory Item, and only if you've got 'Handel inventory clicks in script' selected. To make no right-click anywhere on any GUI have an effect is possible, but more complicated (not sure if that's what you want).
Title: Re: Right-click on GUI
Post by: Zoolander on Tue 07/03/2006 18:49:13
Deleting that line doesn't do it.Ã, 

All I want is for the right click in the inventory to just go to the next mode.Ã,  Right now it does that but also causes the look action (no matter which mode is showing) which I don't want to happen.
Title: Re: Right-click on GUI
Post by: monkey0506 on Tue 07/03/2006 19:39:14
Change that bit of code to this:

else if (button == eMouseRightInv) {
  mouse.SelectNextMode();
  }
Title: Re: Right-click on GUI
Post by: Scorpiorus on Tue 07/03/2006 21:33:18
The reason for this to happen is because, as strazer said in the thread you gave a link to, by default, AGS itself handles inventory clicks.

To override this behaviour tick Handle inventory clicks in script in the General settings pane.

Next modify your on_mouse_click() function as follows:

...
else if (button == eMouseLeftInv) // left click on inventory item
{
   if (mouse.Mode == eModeInteract)
   {
      // select inventory item on eModeInteract:
      player.ActiveInventory = inventory[ game.inv_activated ];
   }
   else
   {
      // run interaction if the cursor mode isn't eModeInteract:
      inventory[ game.inv_activated ].RunInteraction( mouse.Mode );
   }
}
else if (button == eMouseRightInv) // right click on inventory item
{
   // always run look interaction on right click:
   inventory[ game.inv_activated ].RunInteraction( eModeLookat );
}
...


The above script code replicates AGS default behaviour. So, in order to disable the "LookAt" interaction on right click just comment out the relevant line of code:

// always run look interaction on right click:
// inventory[ game.inv_activated ].RunInteraction( eModeLookat );
Title: Re: Right-click on GUI
Post by: Zoolander on Tue 07/03/2006 23:03:13
Okay, I've done what you've said and commented out the last part.  It works fine - right-clicking in the inventory GUI now just changes to the next mode and cursor. 

But I still wanted to be able to left-click on inventory with a "look" or "talk' cursor and get a display message or something.  Right now when I left-click on an inventory item  with the "look" cursor or any other, it just changes the cursor to that item.
Title: Re: Right-click on GUI
Post by: Scorpiorus on Wed 08/03/2006 01:03:24
Hmm, it should work just like before.

Could you post your whole "on_mouse_click" function?
Title: Re: Right-click on GUI
Post by: Zoolander on Wed 08/03/2006 02:20:39
Here's everything:

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();
}
if (button == eMouseLeftInv) // left click on inventory item
{
   if (mouse.Mode == eModeInteract)
   {
      // select inventory item on eModeInteract:
      player.ActiveInventory = inventory[ game.inv_activated ];
   }
   else
   {
      // run interaction if the cursor mode isn't eModeInteract:
      inventory[ game.inv_activated ].RunInteraction( mouse.Mode );
   }
}
else if (button == eMouseRightInv) // right click on inventory item
{
   // always run look interaction on right click:
   //inventory[ game.inv_activated ].RunInteraction( eModeLookat );
}
}

Title: Re: Right-click on GUI
Post by: Khris on Wed 08/03/2006 08:26:59
You need to change this:
Ã,  else {Ã,  Ã, // right-click, so cycle cursor
Ã,  Ã,  mouse.SelectNextMode();
}
if (button == eMouseLeftInv) // left click on inventory item


to look like this:

Ã,  else if (button == eMouseRight) {Ã,  Ã, // right-click, so cycle cursor
Ã,  Ã,  mouse.SelectNextMode();
}
else if (button == eMouseLeftInv) // left click on inventory item


Otherwise, the "else" will catch every click other than eMouseLeft and change the Mouse.Mode even before Inv-clicks are handled.
Title: Re: Right-click on GUI
Post by: Zoolander on Wed 08/03/2006 12:48:46
Thank you.  That did it.   :)
Title: Re: Right-click on GUI
Post by: Khris on Wed 08/03/2006 14:48:17
No prob.
Please modify your first post and put [SOLVED] behind the tread's title.