Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Grid Inventory that can be enabled or disabled #194

Merged
merged 6 commits into from
Jun 1, 2024

Conversation

PeterD23
Copy link
Contributor

  • Added Grid bool so grids can be turned on or off at the designers
    convenience
  • Hotbar is chosen by item order from top left to bottom right
  • Quantity, Ammo and item textures scale based on the grid size of the
    item
  • Green highlights if an object can be placed, yellow if it will swap
    out a colliding object, or red if it collides with multiple objects
    or doesn't fit
  • Should work with controller as well, but not fully tested

PeterD23 added 3 commits May 3, 2024 15:38
- Added size to InventoryItemPD
- Added origin_index to InventorySlotPD to indicate reference point for
  where the item starts
- Able to move a 2x2 battery around the grid so far
- Added Grid bool so grids can be turned on or off at the designers
  convenience
- Hotbar is chosen by item order from top left to bottom right
- Quantity, Ammo and item textures scale based on the grid size of the
  item
- Green highlights if an object can be placed, yellow if it will swap
  out a colliding object, or red if it collides with multiple objects
  or doesn't fit
- Should work with controller as well, but not fully tested
@Phazorknight
Copy link
Owner

This is mighty impressive! Great job! Especially cool that it can really be toggled on/off with relative ease.

  • Bug: Items that are bigger in the inventory can "override" existing items. I had a health potion in the 3rd slot, then picked up the LaserRifle and it placed it self "on top" of it, basically deleting the health potion from my inventory.

  • Bug: While the items themselves show up on the Hotbar, activating them doesn't seem to work quite as expected. Sometimes I was able to trigger an item with a different Hotbar key than what it is assigned in the UI.
    To be fair, the Hotbar system should be revamped, so items can just directly get a button assigned instead of assuming the first 4 slots.

  • Would love to see some tool tips in the exposed inspector settings, especially that when grid is enabled that the number of inventory slots needs to match the total of the inventory size for this to properly work as expected.
    (eg. when the inventory size is 8x4, there needs to be 32 inventory slots in the inventory slot array).

@PeterD23
Copy link
Contributor Author

PeterD23 commented May 16, 2024

This is mighty impressive! Great job! Especially cool that it can really be toggled on/off with relative ease.

  • Bug: Items that are bigger in the inventory can "override" existing items. I had a health potion in the 3rd slot, then picked up the LaserRifle and it placed it self "on top" of it, basically deleting the health potion from my inventory.
  • Bug: While the items themselves show up on the Hotbar, activating them doesn't seem to work quite as expected. Sometimes I was able to trigger an item with a different Hotbar key than what it is assigned in the UI.
    To be fair, the Hotbar system should be revamped, so items can just directly get a button assigned instead of assuming the first 4 slots.
  • Would love to see some tool tips in the exposed inspector settings, especially that when grid is enabled that the number of inventory slots needs to match the total of the inventory size for this to properly work as expected.
    (eg. when the inventory size is 8x4, there needs to be 32 inventory slots in the inventory slot array).

Thanks for the feedback! I'll take a look and investigate the items getting overriden issue and the hotbar slots. I'll also look into adding tooltips, although the inventory slots array should automatically get resized to fit the X and Y dimensions specified. I was meaning to hide that from the inspector since the starter inventory array would be the grid-agnostic replacement.

@Phazorknight
Copy link
Owner

The more I think about it, the more I feel like this could potentially be a permanent replacement of the "legacy" inventory system. I'd have to dive a bit deeper into the code and would like to give polishing the UI a shot, but here are my thoughts:

  • If devs want to stick to the legacy system, they can by just keeping all items to 1x1 size.
  • I wanted to rework the hot bar slots to work that they can be manually assigned, decoupling them from the main inventory resource.
  • The only thing that's a bit trickier would be filling containers with items, would have to implement a check that would make sure the items defined in the inventory slots of a container don't overflow the container's defined inventory size.

Let me know if and when you'll work on certain parts on this, 'cause I might want to push an update to this PR myself next week. 😇

- Hotbar should now work correctly in grid mode, added an array to keep
  track of which hotbar is assigned to which origin index
- Added tooltips to grid bool and starter inventory to make it clear
  that interactables and player should both have enabled
- Fixed larger items overriding bigger items by adding a pickup check to
  the is_enough_space() function which was unintentionally swapping the
  smaller item out into nothingness
- Fixed an issue where "Take All" was throwing an index bounds error due
  to the source slot having its origin index changed. Made the parameter
  a duplicate to keep the original source index (darn pass-by-ref :|)
@PeterD23
Copy link
Contributor Author

The more I think about it, the more I feel like this could potentially be a permanent replacement of the "legacy" inventory system. I'd have to dive a bit deeper into the code and would like to give polishing the UI a shot, but here are my thoughts:

  • If devs want to stick to the legacy system, they can by just keeping all items to 1x1 size.
  • I wanted to rework the hot bar slots to work that they can be manually assigned, decoupling them from the main inventory resource.
  • The only thing that's a bit trickier would be filling containers with items, would have to implement a check that would make sure the items defined in the inventory slots of a container don't overflow the container's defined inventory size.

Let me know if and when you'll work on certain parts on this, 'cause I might want to push an update to this PR myself next week. 😇

Hey, I've fixed the issues you mentioned, details of what broke and how I fixed it are in the commit details. I'll be away to London next week so any other feedback I can look into after I get back!

- Updated inventory grid margins to 0 to make it look less "chopped up"
- Updated some variable names to be more explicit (so many variables were just called size, I tried to differentiate them a bit more)
- Added some input device checks to offer some QoL features like smoother grabbed items and info panel.
- Made it so mouse ignores the grabbed item panel, making it feel nicer when moving items around.

ISSUES:
- Inventory Slot navigation with gamepad is borked. I'll have to look into exactly what causes this, as this seems new. Should be fixable though. Worst case we have to overwrite the focus navigation on runtime.
@Phazorknight
Copy link
Owner

Phazorknight commented May 24, 2024

Hey y'all, I've taken a small dive into this and made some changes/updates. Mostly cleaned up some variable naming and added some QoL stuff.

Overall I think it's shaping up really well and I'm confident we can put this into main soon.
@PeterD23 thanks again for all the work you put into this, it's gonna be a great new feature.

@Phazorknight Phazorknight added the enhancement New feature or request label May 24, 2024
@ac-arcana
Copy link
Collaborator

I'm still working on getting Read The Docs to build, so for now please ignore any errors that the check has failed from Read the Docs for the purpose of merging.

Fixed the gamepad navigation for the grid inventory by manually setting the focus neighbors on instantiation of slots.

One remaining cosmetic issue:
When an item is being moved with the gamepad, the grabbed item icon always first moves to the center of the first slot (instead of the currently focused slot). As soon as the focus is moved the grabbed item positions correctly, so it is updated correctly, just that initial "pick up" seems off.
@Phazorknight
Copy link
Owner

Pushed some updates and will now try to merge this into main.
Since I've made a few structural changes on main, this might take a few updates after the initial merge to fix what will inevitably break on the merge, so stay with me.

@Phazorknight Phazorknight merged commit 2dee164 into Phazorknight:main Jun 1, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants