Right-click on GUI [SOLVED]

Started by Zoolander, Mon 06/03/2006 15:13:50

Previous topic - Next topic

Zoolander

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

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.

monkey0506

Try this.

Code: ags
function on_event(EventType event, int data) {
  if (event == eEventGUIMouseDown) {
    if (data == gInventory.ID) {
      if (mouse.IsButtonDown(eMouseRight))
        mouse.SelectNextMode();
    }
  }
}

Zoolander

Thanks, that works.  But I don't understand all of it.  What's "eEventGUIMouseDown" ?

Ashen

Check this manual entry 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).
I know what you're thinking ... Don't think that.

monkey0506

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.

Zoolander

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

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




Ashen

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).
I know what you're thinking ... Don't think that.

Zoolander

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.

monkey0506

Change that bit of code to this:

Code: ags
else if (button == eMouseRightInv) {
  mouse.SelectNextMode();
  }

Scorpiorus

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 );

Zoolander

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.

Scorpiorus

Hmm, it should work just like before.

Could you post your whole "on_mouse_click" function?

Zoolander

Here's everything:
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, 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 );
}
}


Khris

You need to change this:
Code: ags
Ã,  else {Ã,  Ã, // right-click, so cycle cursor
Ã,  Ã,  mouse.SelectNextMode();
}
if (button == eMouseLeftInv) // left click on inventory item


to look like this:

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

Zoolander

Thank you.  That did it.   :)

Khris

No prob.
Please modify your first post and put [SOLVED] behind the tread's title.

SMF spam blocked by CleanTalk