[SOLVED] About inventory window

Started by johanvepa, Fri 11/12/2015 23:03:56

Previous topic - Next topic

johanvepa

In the standard game template, the inventory GUI has an InventoryWindow. When selecting an item on this window, the cursor changes to that of the item, and that is well.

I want the GUI to disappear right when I select an item, not only when clicking the button btnInvOk. How can I change this?

Khris

You can only do this indirectly, try something like this:
Code: ags
  // in repeatedly_execute
  if (gInventory.Visible && mouse.Mode == eModeUseinv) gInventory.Visible = false;


Note that this solution requires you to change to another mode before displaying gInventory, should the cursor already be set to eModeUseinv (otherwise the GUI will immediately close again).

johanvepa

Thank you for this both usable and doable solution, Khris.


I am getting increasedly mystified about how the inventory window works, since I would have expected something like using "Interact inventory item" from the event handle panel to work, and have started a new thread on it. But this solution works for its purpose and thats the important thing!

Thank you again.

Khris

Unless you turn on the option to handle inv clicks in your script in General settings, the behavior of an inventory window is hard-coded. Clicking the default game's inventory's arrow button sets the mouse.Mode to eModeInteract and changes the cursor graphic to the pointer's mode sprite.
That's because selecting an item is done by interacting with it (or in other words, default inv handling does not permit the player to trigger the "interact with inv item" event). Right-clicking inv items will trigger "look at inv item".

If you want to change this, you have to handle eMouseLeftInv and eMouseRightInv in on_mouse_click(). There should be dozens of threads with examples, or just check the BASS template.

johanvepa

Still no success.

I turned to TRUE the "Override built-in inventory click handling".

In globalscript I have:
Code: ags

function on_mouse_click(MouseButton button)
{
  if (button == eMouseLeft) 
  {
    ProcessClick(mouse.x,mouse.y, mouse.Mode);
  }
  if (button == eMouseLeftInv)
  {
    ProcessClick(mouse.x,mouse.y, mouse.Mode);
  }
}


My inventory item Agern has this global script:
Code: ags
function iAgern_Interact()
{
Display("You picked up an acorn!");
}


But now nothing happens. Neither does the mouse cursor change into the eModeUseinv view, nor does my message display.

Crimson Wizard

#5
As being said in the manual (although maybe in a slightly vague way), ProcessClick works only on Room area and objects. It does not work on GUI (and, hence, inventory window).
Quote
ProcessClick
This function ignores all interfaces and acts as though the point is directly visible. In other words, if the co-ordinates you pass happen to lie on a button on an interface, what actually happens will be as if the user clicked behind the interface onto the actual screen.

You may try this instead:
Code: ags

InventoryItem *item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
if (item != null)
    item.RunInteraction(mouse.Mode);


There is this faster analogue, but I forgot if that works in all cases:
Code: ags

inventory[game.inv_activated].RunInteraction(mouse.Mode);

johanvepa

Thank you for all your help, both.

SMF spam blocked by CleanTalk