[Solved] inv control still shows item after selecting it

Started by arj0n, Wed 08/09/2021 14:16:57

Previous topic - Next topic

arj0n

When having a custom inv. window handling and I set an item as the player's active item, I expected the item to be 'auto-removed' from the inv.box but I can still click with the now active item on the same item in the inv. box
(e.g.: select key, can click with key on key in inv box).

When I currently select an inv. item via left-mouse click (see line 20 & 21 in code snippet below):
- the item is correctly set to the player's active item,
- the mouse-mode is correctly showing the item's mouse cursor image when in useinvmode
But:
- the item is still shown in the inventory item box

Am I overlooking something? Do I need to update the inv.box after setting an item to be the active item?

current settings & script:
In general setting 'Override build-in inventory window click handling' is set to True
And in the Global script I have this on_event function:

Code: ags

function on_event(EventType event, int data)
{
  if (event == eEventGUIMouseDown) 
  {
    if (mouse.IsButtonDown(eMouseLeft)) 
    {
      GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
      if (theControl==invCustom)
      {
        InventoryItem *item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
        if (item == null) {}
        else if (item != null)
        {
          if (mouse.Mode == eModeLookat) item.RunInteraction(eModeLookat);
          else if (mouse.Mode == eModeInteract)
          {
            if (player.ActiveInventory != null) {}
            else if (player.ActiveInventory == null)
            {
              player.ActiveInventory = item;
              mouse.Mode = eModeUseinv;
            }
          }
          else if (mouse.Mode == eModeUseinv) item.RunInteraction(eModeUseinv);
        }
      }
    }    
    else if (mouse.IsButtonDown(eMouseRight))
    {
      if (player.ActiveInventory != null)
      {
        player.ActiveInventory = null;
        mouse.Mode = eModeInteract;
      }
      else if (player.ActiveInventory == null)
      {
        if (mouse.Mode == eModeLookat) mouse.Mode = eModeInteract;
        else if (mouse.Mode == eModeInteract) mouse.Mode = eModeLookat;
      }
    }
  }
}


Crimson Wizard

#1
Quote from: arj0n on Wed 08/09/2021 14:16:57
When having a custom inv. window handling and I set an item as the player's active item, I expected the item to be 'auto-removed' from the inv.box

This is not how AGS works.
You have to script that yourself if you like, by calling LoseInventory and AddInventory if it has to be added back. Or scripting your custom inventory window with its own behavior if the above is not suitable.

arj0n

Well, I thought I had a working custom inv window script as shown in the first post.
All does work fine, except for removing the inv.item from the box after selecting it.

Adding LoseInventory after selecting an item (after line 20 and 21 in snipped in 1st post), does remove the item from the box (obviously) but also makes the player lose the selected item, which I don't want.

I'm doing something wrong or I'm missing something but i fail to see what...

Crimson Wizard

#3
By "custom inventory window" I meant fully custom one, that does not use default gui control and has its behavior fully scripted.

AGS default inventory window does not have this feature. You either have to work around temporarily removing an item from player's inventory, or script a fully custom inventory window: script it draw player's items and not draw selected item, respond to player's clicks and so on.

Crimson Wizard

Hmm, just a thought, one potential workaround could be to use a dummy character with a duplicate of player's inventory. Your inventory window would display that dummy character's inventory and you would add/remove items from there. This way player will keep items at all times, but visually they will dissapear when selected.

arj0n

The dummy char inventory sounds, as how you described it, indeed like a workaround for my issue.
Thanx, will look into that.

Khris

#6
You're expecting some sort of drag'n'drop behavior, but like CW says, this is not how AGS works and it never did. You cannot manually remove the item from the player's inventory either because you cannot have an  .ActiveInventory  that isn't also in the player's inventory.

However since you'll probably want an empty spot inside the inventory window anyway, you can simply set the InventoryItem's  .Graphic  to a transparent sprite while it's selected.
Store each item's graphic in an array in game_start so you can restore the original slot when the item is deselected.

Edit: this will also turn the cursor invisible, which means you also have to set the useinv cursor the item's original graphic.

arj0n

Yes, I wrongly assumed that ags had a sort of drag'n'drop behavior for the inv.items, my bad.

And yes, your workaround looks also interesting, using a transparent graphic for the active inv.window item.
Using an area is the way to go indeed, it will also store the 'previous' slot for all items before one becomes an active inv item,
so once one item becomes active, all others will be replaced. That way the active one (the transparent one) can be placed as last item.
Otherwise the top (1st) item will be the transparent one which just looks odd.

Thanx CW and Khris for the suggestions!  :-*

SMF spam blocked by CleanTalk