[UI] Add cyclic navigation in settings menu for LEFT/RIGHT buttons (#6404)

* feat: add cyclic navigation to settings menu

* review > refactor: use Phaser.Math.Wrap instead the ternary operator
This commit is contained in:
HeeMyung Kim 2025-09-07 08:16:43 +09:00 committed by GitHub
parent b5124ae3ce
commit 444080bb78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 12 deletions

View File

@ -544,8 +544,13 @@ export abstract class AbstractControlSettingsUiHandler extends UiHandler {
} }
if (this.settingBlacklisted.includes(setting) || setting.includes("BUTTON_")) { if (this.settingBlacklisted.includes(setting) || setting.includes("BUTTON_")) {
success = false; success = false;
} else if (this.optionCursors[cursor]) { } else {
success = this.setOptionCursor(cursor, this.optionCursors[cursor] - 1, true); // Cycle to the rightmost position when at the leftmost, otherwise move left
success = this.setOptionCursor(
cursor,
Phaser.Math.Wrap(this.optionCursors[cursor] - 1, 0, this.optionValueLabels[cursor].length),
true,
);
} }
break; break;
case Button.RIGHT: // Move selection right within the current option set. case Button.RIGHT: // Move selection right within the current option set.
@ -554,8 +559,13 @@ export abstract class AbstractControlSettingsUiHandler extends UiHandler {
} }
if (this.settingBlacklisted.includes(setting) || setting.includes("BUTTON_")) { if (this.settingBlacklisted.includes(setting) || setting.includes("BUTTON_")) {
success = false; success = false;
} else if (this.optionCursors[cursor] < this.optionValueLabels[cursor].length - 1) { } else {
success = this.setOptionCursor(cursor, this.optionCursors[cursor] + 1, true); // Cycle to the leftmost position when at the rightmost, otherwise move right
success = this.setOptionCursor(
cursor,
Phaser.Math.Wrap(this.optionCursors[cursor] + 1, 0, this.optionValueLabels[cursor].length),
true,
);
} }
break; break;
case Button.CYCLE_FORM: case Button.CYCLE_FORM:

View File

@ -318,16 +318,20 @@ export class AbstractSettingsUiHandler extends MessageUiHandler {
} }
break; break;
case Button.LEFT: case Button.LEFT:
if (this.optionCursors[cursor]) { // Cycle to the rightmost position when at the leftmost, otherwise move left
// Moves the option cursor left, if possible. success = this.setOptionCursor(
success = this.setOptionCursor(cursor, this.optionCursors[cursor] - 1, true); cursor,
} Phaser.Math.Wrap(this.optionCursors[cursor] - 1, 0, this.optionValueLabels[cursor].length),
true,
);
break; break;
case Button.RIGHT: case Button.RIGHT:
// Moves the option cursor right, if possible. // Cycle to the leftmost position when at the rightmost, otherwise move right
if (this.optionCursors[cursor] < this.optionValueLabels[cursor].length - 1) { success = this.setOptionCursor(
success = this.setOptionCursor(cursor, this.optionCursors[cursor] + 1, true); cursor,
} Phaser.Math.Wrap(this.optionCursors[cursor] + 1, 0, this.optionValueLabels[cursor].length),
true,
);
break; break;
case Button.CYCLE_FORM: case Button.CYCLE_FORM:
case Button.CYCLE_SHINY: case Button.CYCLE_SHINY: