Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Joacim Andersson on Sun 22/01/2023 09:59:28

Title: [RESOLVED] Can't select Inventory Item in custom GUI
Post by: Joacim Andersson on Sun 22/01/2023 09:59:28
Hi,

I haven't used AGS for almost 20 years, so many things have changed.
I started a new project from an empty game template, and I've added a GUI that will be the toolbar which is displayed when the mouse moves to the top of the screen. I've added an Inventory Window to this. This works, so that when the mouse moves to the top, the GUI is displayed and the Inventory Window shows my Inventory list.

However, I didn't want to cycle through different mouse pointers for different actions, so I only have one Walk mouse pointer, which is animated (it flashes) when over a hotspot or other character. I also have a Pointer mouse cursor, which is correctly shown when over a GUI.

I have written the following code for the mouse:
function on_mouse_click(MouseButton button)
{
  if (IsGamePaused())
  {
    return;
  }
 
  if (button == eMouseLeftInv)
  {
    player.Say("Inventory Item");
    player.ActiveInventory = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
    mouse.Mode = eModeUseinv;
  }
  else if (button == eMouseLeft)
  {
    if (Game.GetLocationName(mouse.x, mouse.y) != "")
    {
      Room.ProcessClick(mouse.x, mouse.y, eModeInteract);
    }
    else
    {
      Room.ProcessClick(mouse.x, mouse.y, eModeWalkto);
    }
  }
  else if (button == eMouseRight)
  {
    Room.ProcessClick(mouse.x, mouse.y, eModeLookat);
  }

}
The problem is that when I click on an Inventory item it doesn't get selected and the GUI just closes, I've added the line player.Say(...) if the button is eMouseLeftInv just to debug the code, but the character never says anything. What am I doing wrong here?
 
Title: Re: Can't select Inventory Item in custom GUI
Post by: Khris on Sun 22/01/2023 23:51:57
My guess is you need to turn on custom inventory click handling in the General Settings.
Title: Re: Can't select Inventory Item in custom GUI
Post by: Joacim Andersson on Mon 23/01/2023 08:55:43
Thank you, yes that triggered the click event, but it still just closes the GUI and the cursor doesn't change to reflect the inventory item I've selected.
Title: Re: Can't select Inventory Item in custom GUI
Post by: Khris on Mon 23/01/2023 09:18:46
Ok, try
  player.ActiveInventory = inventory[game.inv_activated];
instead. Also, why is the GUI closing at all? I don't see anything that would cause this in your code.
Title: Re: Can't select Inventory Item in custom GUI
Post by: Crimson Wizard on Mon 23/01/2023 09:28:56
Quote from: Khris on Mon 23/01/2023 09:18:46Also, why is the GUI closing at all? I don't see anything that would cause this in your code.

Could be the gui has a "Popup when mouse is at Y" style?
Title: Re: Can't select Inventory Item in custom GUI
Post by: Joacim Andersson on Mon 23/01/2023 12:17:55
Thank you, Khris, that solved the issue with the cursor. However, the GUI is still closing, and yes I have it set to pop up when the mouse moves to the top of the screen. But how do I prevent it from closing if the mouse is still at the top of the screen?
Title: Re: Can't select Inventory Item in custom GUI
Post by: Crimson Wizard on Mon 23/01/2023 12:24:00
Quote from: Joacim Andersson on Mon 23/01/2023 12:17:55However, the GUI is still closing, and yes I have it set to pop up when the mouse moves to the top of the screen. But how do I prevent it from closing if the mouse is still at the top of the screen?

IIRC that's the built-in behavior for these popup guis. If you want a different behavior, you will have to script it instead of using a "popup" style.
Use a "normal" gui, and script it appearing and disappearing depending on the mouse position.
Title: Re: Can't select Inventory Item in custom GUI
Post by: Joacim Andersson on Mon 23/01/2023 12:54:12
Thank you, I did that, and that obviously worked fine.