[beta][ui] fix scrolling issue in Load Game menu

This commit is contained in:
MokaStitcher 2024-10-11 13:17:53 +02:00
parent 334962ee2d
commit c79c9113f7

View File

@ -13,6 +13,7 @@ import { addWindow } from "./ui-theme";
import { RunDisplayMode } from "#app/ui/run-info-ui-handler"; import { RunDisplayMode } from "#app/ui/run-info-ui-handler";
const SESSION_SLOTS_COUNT = 5; const SESSION_SLOTS_COUNT = 5;
const SLOTS_ON_SCREEN = 3;
export enum SaveSlotUiMode { export enum SaveSlotUiMode {
LOAD, LOAD,
@ -159,9 +160,9 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
} }
break; break;
case Button.DOWN: case Button.DOWN:
if (this.cursor < 2) { if (this.cursor < (SLOTS_ON_SCREEN - 1)) {
success = this.setCursor(this.cursor + 1, this.cursor); success = this.setCursor(this.cursor + 1, cursorPosition);
} else if (this.scrollCursor < SESSION_SLOTS_COUNT - 3) { } else if (this.scrollCursor < SESSION_SLOTS_COUNT - SLOTS_ON_SCREEN) {
success = this.setScrollCursor(this.scrollCursor + 1, cursorPosition); success = this.setScrollCursor(this.scrollCursor + 1, cursorPosition);
} }
break; break;
@ -213,12 +214,12 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
} }
/** /**
* setCursor takes user navigation as an input and positions the cursor accordingly * Move the cursor to a new position and update the view accordingly
* @param cursor the index provided to the cursor * @param cursor the new cursor position, between `0` and `SLOTS_ON_SCREEN - 1`
* @param prevCursor the previous index occupied by the cursor - optional * @param prevSlotIndex index of the previous session occupied by the cursor, between `0` and `SESSION_SLOTS_COUNT - 1` - optional
* @returns `true` if the cursor position has changed | `false` if it has not * @returns `true` if the cursor position has changed | `false` if it has not
*/ */
override setCursor(cursor: integer, prevCursor?: integer): boolean { override setCursor(cursor: integer, prevSlotIndex?: integer): boolean {
const changed = super.setCursor(cursor); const changed = super.setCursor(cursor);
if (!this.cursorObj) { if (!this.cursorObj) {
@ -245,21 +246,20 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
} }
this.setArrowVisibility(hasData); this.setArrowVisibility(hasData);
} }
if (!Utils.isNullOrUndefined(prevCursor)) { if (!Utils.isNullOrUndefined(prevSlotIndex)) {
this.revertSessionSlot(prevCursor); this.revertSessionSlot(prevSlotIndex);
} }
return changed; return changed;
} }
/** /**
* Helper function that resets the session slot position to its default central position * Helper function that resets the given session slot to its default central position
* @param prevCursor the previous location of the cursor
*/ */
revertSessionSlot(prevCursor: integer): void { revertSessionSlot(slotIndex: integer): void {
const sessionSlot = this.sessionSlots[prevCursor]; const sessionSlot = this.sessionSlots[slotIndex];
if (sessionSlot) { if (sessionSlot) {
sessionSlot.setPosition(0, prevCursor * 56); sessionSlot.setPosition(0, slotIndex * 56);
} }
} }
@ -274,12 +274,18 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
} }
} }
setScrollCursor(scrollCursor: integer, priorCursor?: integer): boolean { /**
* Move the scrolling cursor to a new position and update the view accordingly
* @param scrollCursor the new cursor position, between `0` and `SESSION_SLOTS_COUNT - SLOTS_ON_SCREEN`
* @param prevSlotIndex index of the previous slot occupied by the cursor, between `0` and `SESSION_SLOTS_COUNT-1` - optional
* @returns `true` if the cursor position has changed | `false` if it has not
*/
setScrollCursor(scrollCursor: integer, prevSlotIndex?: integer): boolean {
const changed = scrollCursor !== this.scrollCursor; const changed = scrollCursor !== this.scrollCursor;
if (changed) { if (changed) {
this.scrollCursor = scrollCursor; this.scrollCursor = scrollCursor;
this.setCursor(this.cursor, priorCursor); this.setCursor(this.cursor, prevSlotIndex);
this.scene.tweens.add({ this.scene.tweens.add({
targets: this.sessionSlotsContainer, targets: this.sessionSlotsContainer,
y: this.sessionSlotsContainerInitialY - 56 * scrollCursor, y: this.sessionSlotsContainerInitialY - 56 * scrollCursor,
@ -294,6 +300,7 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
clear() { clear() {
super.clear(); super.clear();
this.saveSlotSelectContainer.setVisible(false); this.saveSlotSelectContainer.setVisible(false);
this.setScrollCursor(0);
this.eraseCursor(); this.eraseCursor();
this.saveSlotSelectCallback = null; this.saveSlotSelectCallback = null;
this.clearSessionSlots(); this.clearSessionSlots();