Skip to content

Commit

Permalink
[#1797] Fixed out of bound exceptions when navigating with the mouse/…
Browse files Browse the repository at this point in the history
…controller in the item overflow screen (#1795)

* Fixed two out of bound exceptions when using the mouse/controller and hovering an empty slot when the max item amount is lower than 7

* Fixed overflow menu out of bounds when going up on controller and having less than 7 item limit

* Fixed out of bounds on cursor click on empty row in overflow menu

* Fixed more out of bounds exception in the overflow menu
  • Loading branch information
FrancisDionne authored Dec 6, 2024
1 parent e26710b commit 18fc90a
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ protected void render() {
this.invScroll--;
this.renderable_8011e204.y_44 = this.FUN_8010f178(this.invIndex);
} else if(this.invScroll == 0) {
this.invScroll = slotCount - 7;
this.invIndex = 6;
this.invScroll = Math.max(0, slotCount - 7);
this.invIndex = this.invScroll > 0 ? 6 : 0;
this.renderable_8011e204.y_44 = this.FUN_8010f178(this.invIndex);
}
}
Expand Down Expand Up @@ -209,7 +209,9 @@ private void FUN_8010fd80(final boolean allocate, final InventoryEntry inv, fina
}

if((a4 & 0x2) != 0) {
renderString(194, 164, I18n.translate(this.items.get(slotScroll + slotIndex).getDescriptionTranslationKey()), allocate);
if(slotScroll + slotIndex < this.items.size()) {
renderString(194, 164, I18n.translate(this.items.get(slotScroll + slotIndex).getDescriptionTranslationKey()), allocate);
}

final Renderable58 renderable = allocateOneFrameGlyph(137, 84, 140);
renderable.clut_30 = 0x7ceb;
Expand All @@ -223,7 +225,9 @@ private void FUN_8010fd80(final boolean allocate, final InventoryEntry inv, fina
}

if((a4 & 0x2) != 0) {
renderString(194, 164, I18n.translate(this.equipment.get(slotScroll + slotIndex).getDescriptionTranslationKey()), allocate);
if(slotScroll + slotIndex < this.equipment.size()) {
renderString(194, 164, I18n.translate(this.equipment.get(slotScroll + slotIndex).getDescriptionTranslationKey()), allocate);
}

final Renderable58 renderable = allocateOneFrameGlyph(137, 84, 140);
renderable.clut_30 = 0x7ceb;
Expand Down Expand Up @@ -255,7 +259,7 @@ protected InputPropagation mouseMove(final int x, final int y) {
}
}
} else if(this.menuState == MenuState._9) {
for(int i = 0; i < 7; i++) {
for(int i = 0; i < this.items.size(); i++) {
if(this.invIndex != i && MathHelper.inBox(x, y, 188, this.FUN_8010f178(i), 171, 17)) {
playMenuSound(1);
this.invIndex = i;
Expand Down Expand Up @@ -339,8 +343,8 @@ private void handleInventoryScrollUp() {
}

if(this.invIndex == 0 && this.invScroll == 0) {
this.invScroll = slotCount - 7;
this.invIndex = 7;
this.invScroll = Math.max(0, slotCount - 7);
this.invIndex = Math.min(slotCount, 7);
}
}

Expand All @@ -351,7 +355,7 @@ private void handleInventoryScrollDown() {
this.invScroll++;
}

if(this.invIndex == 6 && this.invScroll == slotCount - 7) {
if((this.invIndex == 6 && this.invScroll == slotCount - 7) || (this.invScroll < 1 && this.invIndex >= slotCount - 1)) {
this.invScroll = 0;
this.invIndex = -1;
}
Expand Down Expand Up @@ -442,6 +446,10 @@ private void selectMenuState9() {
final MenuEntryStruct04<InventoryEntry> newItem = this.droppedItems.get(this.dropIndex);
final boolean isItem = this.droppedItems.get(this.dropIndex).item_00 instanceof Item;

if(this.invIndex + this.invScroll > this.items.size() - 1) {
return;
}

if(((isItem ? this.items : this.equipment).get(this.invIndex + this.invScroll).flags_02 & 0x6000) != 0) {
playMenuSound(40);
} else {
Expand Down

0 comments on commit 18fc90a

Please sign in to comment.