Inventory UI fixes - #712
Conversation
NicholasBatesNZ
left a comment
There was a problem hiding this comment.
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.
Description
This pull request fixes various issues encountered when testing the inventory UI a bit more thoroughly:
Testing
Notes
This fixes #711.