Skip to content

Inventory UI fixes - #712

Open
BenjaminAmos wants to merge 3 commits into
MovingBlocks:developfrom
BenjaminAmos:inventory-ui-fixes
Open

Inventory UI fixes#712
BenjaminAmos wants to merge 3 commits into
MovingBlocks:developfrom
BenjaminAmos:inventory-ui-fixes

Conversation

@BenjaminAmos

Copy link
Copy Markdown
Contributor

Description

This pull request fixes various issues encountered when testing the inventory UI a bit more thoroughly:

  • Fixes a crash when dropping the player's shield.
  • Fixes a crash when using keyboard navigation after all items are sold.
  • Changes highlight behaviour to target the nearest item after the currently highlighted item is removed.

Testing

  • Start a new game
  • Open the inventory screen and drop each of your items one-by-one.
  • When an item is dropped, the highlight cursor should move to the next item along (or the previous item, for the last item).
  • The game should not crash when you drop your shield.
  • Additionally, follow the instructions in list highlight crashing program #711 and ensure that the game does not crash.

Notes

This fixes #711.

@NicholasBatesNZ NicholasBatesNZ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging into these — the item == null guard in SolShip.maybeUnequip looks right and fixes a real latent NPE. I think the selection rework needs another pass, though.

In updateItemRows() the new fallback reads items.groupCount() < selectedIndex ? items.getGroup(selectedIndex) : null — the comparison looks inverted (it calls getGroup precisely when the index is out of range) and it's missing the page * Const.ITEM_GROUPS_PER_PAGE offset that every other lookup uses, so it can throw the very IndexOutOfBoundsException it's meant to prevent.

Relatedly, the items.groupCount() > 0 guards in onKeyEvent don't cover #711's actual trace (Index: 7, Size: 7 — the container wasn't empty, selectedIndex was just stale), and since setSelected no longer falls back to selectedIndex = 0, nothing clamps selectedIndex after a removal on page 0 any more; guarding on selectedIndex + page * Const.ITEM_GROUPS_PER_PAGE < items.groupCount() would handle both. That may be what @dreaddymck is still hitting on the PR build.

One smaller thing: in getSelectionAfterRemove, idx <= 0 now conflates "not found" (-1) with "the first group" (0), so removing the top item returns no selection instead of the next one — idx < 0 looks like what you want.

Good news is it still merges cleanly onto develop after the Gradle 9.6.1 / Java 17 bump, so no rebase needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

list highlight crashing program

2 participants