Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Technocrat on Wed 08/12/2010 13:12:30

Title: Right-clicking to deselect items in an inventory window...
Post by: Technocrat on Wed 08/12/2010 13:12:30
At the moment, in-game, right-clicking will deselect an inventory item (player.activeitem=null). However, I'm having difficulty replicating this while the inventory window is open. Is it likely to be something to do with the way the game pauses when the invent?  It will deselect as long as my mouse isn't over the GUI itself, though. I'm sure I'm missing something...

So, here's my on_mouse_click.


function on_mouse_click(MouseButton button) {

       if(button == eMouseLeft){  if(gInventory.Visible==true && GUI.GetAtScreenXY(mouse.x, mouse.y)!=gInventory){gInventory.Visible=false;return;}}
       if(button == eMouseRight){player.ActiveInventory=null;mouse.Mode=2;return;}

  if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)
 }
 else if (button == eMouseLeft) {
         if(gInventory.Visible==true && GUI.GetAtScreenXY(mouse.x, mouse.y)!=gInventory){gInventory.Visible=false;return;}
     if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) ProcessClick(mouse.x, mouse.y, eModeWalkto);
     else {
       if (player.ActiveInventory != null) ProcessClick(mouse.x, mouse.y, eModeUseinv);
       else ProcessClick(mouse.x, mouse.y, eModeInteract);
     }
 
 }

 else if (button == eMouseRight){
       if(player.ActiveInventory!=null){player.ActiveInventory=null;mouse.Mode=2;return;}
       ProcessClick(mouse.x, mouse.y, eModeLookat);
 }

}


Also, I had to move the " if(button == eMouseLeft){  if(gInventory.Visible==true && GUI.GetAtScreenXY" part to the top of the mouse clicking script, otherwise it didn't seem to work.
Title: Re: Right-clicking to deselect items in an inventory window...
Post by: Khris on Wed 08/12/2010 14:15:57
Try
if(button == eMouseRight || button == eMouseRightInv) ...
Title: Re: Right-clicking to deselect items in an inventory window...
Post by: Technocrat on Thu 09/12/2010 12:54:06
No success with that, I'm afraid. I've been able to make it so that it will deselect if I right-click while it's over the GUI (by putting a bit in the OnClick for the GUI), but it still won't deselect if it's over the inv part of the inventory window.
Title: Re: Right-clicking to deselect items in an inventory window...
Post by: Khris on Thu 09/12/2010 13:09:52
You have to set an option in General settings/inventory: Set "Override built-in inv window click handling" to true.
Title: Re: Right-clicking to deselect items in an inventory window...
Post by: Ryan Timothy B on Thu 09/12/2010 16:04:54
While clicking on the invWindow itself (the GUI component that has the actual inventory icon grid), it will steal clicks.

What you need to do is find out if they've pressed down on the mouse over a GUI through the on_event.
You then have to check if it's the GUI that contains the InvWindow and then if the mouse is actually over the InvWindow.
And then you have to check if there isn't an inventory item there (unless you have no use for right clicking over an inventory item itself while holding an inventory item).

Something like this:

function on_event(EventType event, int data)
{
  if (event == eEventGUIMouseDown && mouse.IsButtonDown(eMouseRight) && player.ActiveInventory != null && data == gInventory.ID)
  {
    GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    if (theControl==InventoryWindow1) //the InvWindow
    {
      InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
      if (i == null)
      {
        player.ActiveInventory = null;   // loose active inv
        mouse.Mode=eModeInteract;
      }
    }
  }
}


Only reason why I've narrowed it down to only the empty space on the InvWindow is because I don't know what kind of a GUI you have. If you have have buttons on it that require clicking, or if you don't want right click on that button or the GUI background to deselect the inventory item.


I actually just noticed that you've already mentioned that you've done the on_event business. I've tried it with Khris' suggestion of turning on and off the 'Override built-in inv window click handling' and it works either way. You sure you haven't missed something?