gloot icon indicating copy to clipboard operation
gloot copied to clipboard

Overlapping items in InventoryGrid

Open peter-kish opened this issue 2 years ago • 4 comments

and also this one that items overlap:

image

This last one could be a problem if you remove the items in the scene or something like that?

Originally posted by @filipinyo in https://github.com/peter-kish/gloot/discussions/41#discussioncomment-3833107

peter-kish avatar Oct 09 '22 21:10 peter-kish

image

@peter-kish one weird thing I've noticed... When I hit play in the remote scene the inventory size is 10x10 but I've set it in all scenes for it to be 4x2... Could this be a reason for the bug that incorrect size is being set on runtime?

func reset() -> void:
	.reset()
	_set_size(DEFAULT_SIZE)

this DEFAULT_SIZE is 10x10... this should be size... Am I right?

filipinyo avatar Oct 14 '22 16:10 filipinyo

So other thing I've noticed is that when I set an inventory for the CtrlInventoryGridEx via script, unset it and set it again... the sort messes up... also if I use the item (potion) in the inventory and remove it, I believe the empty slot is still selected and sometimes happens that the items change positions an overlap. Try setting it up this way... You have 1 HUD for the inventory and many units with their inventory that have for example consumable items... on click of the unit you set the HUD's ctrl inventory to that units inventory and if you use the item for an example potion of that unit and remove it by using remove_item(item) function and select other unit, you'll get errors like Assertion failed: Item not found in the inventory! The sorting will be messed etc.

filipinyo avatar Oct 15 '22 05:10 filipinyo

@peter-kish one weird thing I've noticed... When I hit play in the remote scene the inventory size is 10x10 but I've set it in all scenes for it to be 4x2... Could this be a reason for the bug that incorrect size is being set on runtime?

func reset() -> void:
	.reset()
	_set_size(DEFAULT_SIZE)

this DEFAULT_SIZE is 10x10... this should be size... Am I right?

Yeah, the default InventoryGrid size is 10x10 (this is a const value), but the screenshot you provided shows that your inventory is 4x2: size Am I missing something here?

peter-kish avatar Oct 15 '22 18:10 peter-kish

So other thing I've noticed is that when I set an inventory for the CtrlInventoryGridEx via script, unset it and set it again... the sort messes up... also if I use the item (potion) in the inventory and remove it, I believe the empty slot is still selected and sometimes happens that the items change positions an overlap. Try setting it up this way... You have 1 HUD for the inventory and many units with their inventory that have for example consumable items... on click of the unit you set the HUD's ctrl inventory to that units inventory and if you use the item for an example potion of that unit and remove it by using remove_item(item) function and select other unit, you'll get errors like Assertion failed: Item not found in the inventory! The sorting will be messed etc.

Oh ok, I see a couple of issues here, as these are cases I haven't really tested thoroughly. The following method should take care of deselecting items when they are removed, but apparently it doesn't work right:

func _on_item_removed(_item: InventoryItem) -> void:
    if _item == _selected_item:
        _select(null)

I will create a couple of unit tests similar to how you described and hopefully I figure out what's going on.

peter-kish avatar Oct 15 '22 18:10 peter-kish