From 444080bb78294465686d48b52d8af1e7710b3aa0 Mon Sep 17 00:00:00 2001 From: HeeMyung Kim Date: Sun, 7 Sep 2025 08:16:43 +0900 Subject: [PATCH] [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 --- .../abstract-control-settings-ui-handler.ts | 18 +++++++++++++---- .../settings/abstract-settings-ui-handler.ts | 20 +++++++++++-------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/ui/settings/abstract-control-settings-ui-handler.ts b/src/ui/settings/abstract-control-settings-ui-handler.ts index c08f1570b75..17812785d1e 100644 --- a/src/ui/settings/abstract-control-settings-ui-handler.ts +++ b/src/ui/settings/abstract-control-settings-ui-handler.ts @@ -544,8 +544,13 @@ export abstract class AbstractControlSettingsUiHandler extends UiHandler { } if (this.settingBlacklisted.includes(setting) || setting.includes("BUTTON_")) { success = false; - } else if (this.optionCursors[cursor]) { - success = this.setOptionCursor(cursor, this.optionCursors[cursor] - 1, true); + } else { + // 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; 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_")) { success = false; - } else if (this.optionCursors[cursor] < this.optionValueLabels[cursor].length - 1) { - success = this.setOptionCursor(cursor, this.optionCursors[cursor] + 1, true); + } else { + // 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; case Button.CYCLE_FORM: diff --git a/src/ui/settings/abstract-settings-ui-handler.ts b/src/ui/settings/abstract-settings-ui-handler.ts index ae1bb40dbeb..85e93bd8e2e 100644 --- a/src/ui/settings/abstract-settings-ui-handler.ts +++ b/src/ui/settings/abstract-settings-ui-handler.ts @@ -318,16 +318,20 @@ export class AbstractSettingsUiHandler extends MessageUiHandler { } break; case Button.LEFT: - if (this.optionCursors[cursor]) { - // Moves the option cursor left, if possible. - 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; case Button.RIGHT: - // Moves the option cursor right, if possible. - if (this.optionCursors[cursor] < this.optionValueLabels[cursor].length - 1) { - 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; case Button.CYCLE_FORM: case Button.CYCLE_SHINY: