added top/down support from legacy settings

pull/685/head
Greenlamp 2024-05-12 01:31:57 +02:00
parent d80c0e3d34
commit 4c39fd068c
1 changed files with 25 additions and 10 deletions

View File

@ -1,5 +1,4 @@
import BattleScene from "../battle-scene";
import { hasTouchscreen, isMobile } from "../touch-controls";
import {TextStyle, addTextObject} from "./text";
import {Mode} from "./ui";
import UiHandler from "./ui-handler";
@ -227,6 +226,8 @@ export default class SettingsGamepadUiHandler extends UiHandler {
processInput(button: Button): boolean {
const ui = this.getUi();
// Defines the maximum number of rows that can be displayed on the screen.
const rowsToDisplay = 9;
let success = false;
@ -242,14 +243,28 @@ export default class SettingsGamepadUiHandler extends UiHandler {
success = this.setCursor(this.cursor - 1);
else
success = this.setScrollCursor(this.scrollCursor - 1);
} else {
// When at the top of the menu and pressing UP, move to the bottommost item.
// First, set the cursor to the last visible element, preparing for the scroll to the end.
const successA = this.setCursor(rowsToDisplay - 1);
// Then, adjust the scroll to display the bottommost elements of the menu.
const successB = this.setScrollCursor(this.optionValueLabels.length - rowsToDisplay);
success = successA && successB; // success is just there to play the little validation sound effect
}
break;
case Button.DOWN:
if (cursor < this.optionValueLabels.length) {
if (this.cursor < 8)
if (cursor < this.optionValueLabels.length - 1) {
if (this.cursor < rowsToDisplay - 1)
success = this.setCursor(this.cursor + 1);
else if (this.scrollCursor < this.optionValueLabels.length - 9)
else if (this.scrollCursor < this.optionValueLabels.length - rowsToDisplay)
success = this.setScrollCursor(this.scrollCursor + 1);
} else {
// When at the bottom of the menu and pressing DOWN, move to the topmost item.
// First, set the cursor to the first visible element, resetting the scroll to the top.
const successA = this.setCursor(0);
// Then, reset the scroll to start from the first element of the menu.
const successB = this.setScrollCursor(0);
success = successA && successB; // Indicates a successful cursor and scroll adjustment.
}
break;
case Button.LEFT: