[RESOLVED] Can't select Inventory Item in custom GUI

Started by Joacim Andersson, Sun 22/01/2023 09:59:28

Previous topic - Next topic

Joacim Andersson

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

Khris

My guess is you need to turn on custom inventory click handling in the General Settings.

Joacim Andersson

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.

Khris

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

Crimson Wizard

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?

Joacim Andersson

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?

Crimson Wizard

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.

Joacim Andersson

Thank you, I did that, and that obviously worked fine.

SMF spam blocked by CleanTalk