mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-16 13:22:18 +02:00
comment TSDOC both abstract class
This commit is contained in:
parent
2e00020457
commit
ed860167d0
@ -5,7 +5,9 @@ import {addWindow} from "../ui-theme";
|
|||||||
import {addTextObject, TextStyle} from "../text";
|
import {addTextObject, TextStyle} from "../text";
|
||||||
import {Button} from "../../enums/buttons";
|
import {Button} from "../../enums/buttons";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for handling UI elements related to button bindings.
|
||||||
|
*/
|
||||||
export default abstract class AbstractBindingUiHandler extends UiHandler {
|
export default abstract class AbstractBindingUiHandler extends UiHandler {
|
||||||
// Containers for different segments of the UI.
|
// Containers for different segments of the UI.
|
||||||
protected optionSelectContainer: Phaser.GameObjects.Container;
|
protected optionSelectContainer: Phaser.GameObjects.Container;
|
||||||
@ -22,6 +24,7 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
protected actionLabel: Phaser.GameObjects.Text;
|
protected actionLabel: Phaser.GameObjects.Text;
|
||||||
protected cancelLabel: Phaser.GameObjects.Text;
|
protected cancelLabel: Phaser.GameObjects.Text;
|
||||||
|
|
||||||
|
// State for listening and button pressed tracking.
|
||||||
protected listening: boolean = false;
|
protected listening: boolean = false;
|
||||||
protected buttonPressed: number | null = null;
|
protected buttonPressed: number | null = null;
|
||||||
|
|
||||||
@ -31,14 +34,24 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
|
|
||||||
// Function to call on cancel or completion of binding.
|
// Function to call on cancel or completion of binding.
|
||||||
protected cancelFn: (boolean?) => boolean;
|
protected cancelFn: (boolean?) => boolean;
|
||||||
|
protected swapAction: () => boolean;
|
||||||
|
|
||||||
// The specific setting being modified.
|
// The specific setting being modified.
|
||||||
protected target;
|
protected target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the AbstractBindingUiHandler.
|
||||||
|
*
|
||||||
|
* @param scene - The BattleScene instance.
|
||||||
|
* @param mode - The UI mode.
|
||||||
|
*/
|
||||||
constructor(scene: BattleScene, mode: Mode) {
|
constructor(scene: BattleScene, mode: Mode) {
|
||||||
super(scene, mode);
|
super(scene, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup UI elements.
|
||||||
|
*/
|
||||||
setup() {
|
setup() {
|
||||||
const ui = this.getUi();
|
const ui = this.getUi();
|
||||||
this.optionSelectContainer = this.scene.add.container(0, 0);
|
this.optionSelectContainer = this.scene.add.container(0, 0);
|
||||||
@ -104,6 +117,12 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
this.actionsContainer.add(this.cancelLabel);
|
this.actionsContainer.add(this.cancelLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the UI with the provided arguments.
|
||||||
|
*
|
||||||
|
* @param args - Arguments to be passed to the show method.
|
||||||
|
* @returns `true` if successful.
|
||||||
|
*/
|
||||||
show(args: any[]): boolean {
|
show(args: any[]): boolean {
|
||||||
super.show(args);
|
super.show(args);
|
||||||
this.buttonPressed = null;
|
this.buttonPressed = null;
|
||||||
@ -119,14 +138,30 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the width of the window.
|
||||||
|
*
|
||||||
|
* @returns The window width.
|
||||||
|
*/
|
||||||
getWindowWidth(): number {
|
getWindowWidth(): number {
|
||||||
return 160;
|
return 160;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the height of the window.
|
||||||
|
*
|
||||||
|
* @returns The window height.
|
||||||
|
*/
|
||||||
getWindowHeight(): number {
|
getWindowHeight(): number {
|
||||||
return 64;
|
return 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the input for the given button.
|
||||||
|
*
|
||||||
|
* @param button - The button to process.
|
||||||
|
* @returns `true` if the input was processed successfully.
|
||||||
|
*/
|
||||||
processInput(button: Button): boolean {
|
processInput(button: Button): boolean {
|
||||||
if (this.buttonPressed === null) return;
|
if (this.buttonPressed === null) return;
|
||||||
const ui = this.getUi();
|
const ui = this.getUi();
|
||||||
@ -158,6 +193,12 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the cursor to the specified position.
|
||||||
|
*
|
||||||
|
* @param cursor - The cursor position to set.
|
||||||
|
* @returns `true` if the cursor was set successfully.
|
||||||
|
*/
|
||||||
setCursor(cursor: integer): boolean {
|
setCursor(cursor: integer): boolean {
|
||||||
this.cursor = cursor;
|
this.cursor = cursor;
|
||||||
if (cursor === 1) {
|
if (cursor === 1) {
|
||||||
@ -174,6 +215,9 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the UI elements and state.
|
||||||
|
*/
|
||||||
clear() {
|
clear() {
|
||||||
super.clear();
|
super.clear();
|
||||||
this.listening = false;
|
this.listening = false;
|
||||||
@ -187,6 +231,13 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
this.buttonPressed = null;
|
this.buttonPressed = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle input down events.
|
||||||
|
*
|
||||||
|
* @param buttonIcon - The icon of the button that was pressed.
|
||||||
|
* @param assignedButtonIcon - The icon of the button that is assigned.
|
||||||
|
* @param type - The type of button press.
|
||||||
|
*/
|
||||||
onInputDown(buttonIcon: string, assignedButtonIcon: string, type: string): void {
|
onInputDown(buttonIcon: string, assignedButtonIcon: string, type: string): void {
|
||||||
this.newButtonIcon.setTexture(type);
|
this.newButtonIcon.setTexture(type);
|
||||||
this.newButtonIcon.setFrame(buttonIcon);
|
this.newButtonIcon.setFrame(buttonIcon);
|
||||||
|
@ -21,6 +21,9 @@ export interface LayoutConfig {
|
|||||||
bindingSettings: Array<String>;
|
bindingSettings: Array<String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for handling UI elements related to settings.
|
||||||
|
*/
|
||||||
export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
||||||
protected settingsContainer: Phaser.GameObjects.Container;
|
protected settingsContainer: Phaser.GameObjects.Container;
|
||||||
protected optionsContainer: Phaser.GameObjects.Container;
|
protected optionsContainer: Phaser.GameObjects.Container;
|
||||||
@ -59,10 +62,19 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
abstract saveSettingToLocalStorage(setting, cursor): void;
|
abstract saveSettingToLocalStorage(setting, cursor): void;
|
||||||
abstract getActiveConfig(): InterfaceConfig;
|
abstract getActiveConfig(): InterfaceConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the AbstractSettingsUiUiHandler.
|
||||||
|
*
|
||||||
|
* @param scene - The BattleScene instance.
|
||||||
|
* @param mode - The UI mode.
|
||||||
|
*/
|
||||||
constructor(scene: BattleScene, mode?: Mode) {
|
constructor(scene: BattleScene, mode?: Mode) {
|
||||||
super(scene, mode);
|
super(scene, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup UI elements.
|
||||||
|
*/
|
||||||
setup() {
|
setup() {
|
||||||
const ui = this.getUi();
|
const ui = this.getUi();
|
||||||
|
|
||||||
@ -103,7 +115,7 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
const optionsContainer = this.scene.add.container(0, 0);
|
const optionsContainer = this.scene.add.container(0, 0);
|
||||||
optionsContainer.setVisible(false);
|
optionsContainer.setVisible(false);
|
||||||
|
|
||||||
// Gather all gamepad binding settings from the configuration.
|
// Gather all binding settings from the configuration.
|
||||||
const bindingSettings = Object.keys(config.settings);
|
const bindingSettings = Object.keys(config.settings);
|
||||||
|
|
||||||
// Array to hold labels for different settings such as 'Default Controller', 'Gamepad Support', etc.
|
// Array to hold labels for different settings such as 'Default Controller', 'Gamepad Support', etc.
|
||||||
@ -139,9 +151,6 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
const valueLabels: Phaser.GameObjects.Text[] = []
|
const valueLabels: Phaser.GameObjects.Text[] = []
|
||||||
|
|
||||||
// Process each option for the current setting.
|
// Process each option for the current setting.
|
||||||
const aaa = this.settingDeviceOptions;
|
|
||||||
const bbb = this.settingDevice;
|
|
||||||
const ccc = this.settingDevice[setting];
|
|
||||||
for (const [o, option] of this.settingDeviceOptions[this.settingDevice[setting]].entries()) {
|
for (const [o, option] of this.settingDeviceOptions[this.settingDevice[setting]].entries()) {
|
||||||
// Check if the current setting is for binding keys.
|
// Check if the current setting is for binding keys.
|
||||||
if (bindingSettings.includes(this.settingDevice[setting])) {
|
if (bindingSettings.includes(this.settingDevice[setting])) {
|
||||||
@ -218,6 +227,9 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
this.settingsContainer.setVisible(false);
|
this.settingsContainer.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the bindings for the current active device configuration.
|
||||||
|
*/
|
||||||
updateBindings(): void {
|
updateBindings(): void {
|
||||||
// Hide the options container for all layouts to reset the UI visibility.
|
// Hide the options container for all layouts to reset the UI visibility.
|
||||||
Object.keys(this.layout).forEach((key) => this.layout[key].optionsContainer.setVisible(false));
|
Object.keys(this.layout).forEach((key) => this.layout[key].optionsContainer.setVisible(false));
|
||||||
@ -256,6 +268,12 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
this.setScrollCursor(0);
|
this.setScrollCursor(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the UI with the provided arguments.
|
||||||
|
*
|
||||||
|
* @param args - Arguments to be passed to the show method.
|
||||||
|
* @returns `true` if successful.
|
||||||
|
*/
|
||||||
show(args: any[]): boolean {
|
show(args: any[]): boolean {
|
||||||
super.show(args);
|
super.show(args);
|
||||||
|
|
||||||
@ -277,6 +295,12 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the UI layout for the active device configuration.
|
||||||
|
*
|
||||||
|
* @param activeConfig - The active device configuration.
|
||||||
|
* @returns `true` if the layout was successfully applied, otherwise `false`.
|
||||||
|
*/
|
||||||
setLayout(activeConfig: InterfaceConfig): boolean {
|
setLayout(activeConfig: InterfaceConfig): boolean {
|
||||||
// Check if there is no active configuration (e.g., no gamepad connected).
|
// Check if there is no active configuration (e.g., no gamepad connected).
|
||||||
if (!activeConfig) {
|
if (!activeConfig) {
|
||||||
@ -312,6 +336,12 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the input for the given button.
|
||||||
|
*
|
||||||
|
* @param button - The button to process.
|
||||||
|
* @returns `true` if the input was processed successfully.
|
||||||
|
*/
|
||||||
processInput(button: Button): boolean {
|
processInput(button: Button): boolean {
|
||||||
const ui = this.getUi();
|
const ui = this.getUi();
|
||||||
// Defines the maximum number of rows that can be displayed on the screen.
|
// Defines the maximum number of rows that can be displayed on the screen.
|
||||||
@ -385,6 +415,12 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
return success; // Return whether the input resulted in a successful action.
|
return success; // Return whether the input resulted in a successful action.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the cursor to the specified position.
|
||||||
|
*
|
||||||
|
* @param cursor - The cursor position to set.
|
||||||
|
* @returns `true` if the cursor was set successfully.
|
||||||
|
*/
|
||||||
setCursor(cursor: integer): boolean {
|
setCursor(cursor: integer): boolean {
|
||||||
const ret = super.setCursor(cursor);
|
const ret = super.setCursor(cursor);
|
||||||
// If the optionsContainer is not initialized, return the result from the parent class directly.
|
// If the optionsContainer is not initialized, return the result from the parent class directly.
|
||||||
@ -403,6 +439,12 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
return ret; // Return the result from the parent class's setCursor method.
|
return ret; // Return the result from the parent class's setCursor method.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the scroll cursor to the specified position.
|
||||||
|
*
|
||||||
|
* @param scrollCursor - The scroll cursor position to set.
|
||||||
|
* @returns `true` if the scroll cursor was set successfully.
|
||||||
|
*/
|
||||||
setScrollCursor(scrollCursor: integer): boolean {
|
setScrollCursor(scrollCursor: integer): boolean {
|
||||||
// Check if the new scroll position is the same as the current one; if so, do not update.
|
// Check if the new scroll position is the same as the current one; if so, do not update.
|
||||||
if (scrollCursor === this.scrollCursor)
|
if (scrollCursor === this.scrollCursor)
|
||||||
@ -420,6 +462,14 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
return true; // Return true to indicate the scroll cursor was successfully updated.
|
return true; // Return true to indicate the scroll cursor was successfully updated.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the option cursor to the specified position.
|
||||||
|
*
|
||||||
|
* @param settingIndex - The index of the setting.
|
||||||
|
* @param cursor - The cursor position to set.
|
||||||
|
* @param save - Whether to save the setting to local storage.
|
||||||
|
* @returns `true` if the option cursor was set successfully.
|
||||||
|
*/
|
||||||
setOptionCursor(settingIndex: integer, cursor: integer, save?: boolean): boolean {
|
setOptionCursor(settingIndex: integer, cursor: integer, save?: boolean): boolean {
|
||||||
// Retrieve the specific setting using the settingIndex from the settingDevice enumeration.
|
// Retrieve the specific setting using the settingIndex from the settingDevice enumeration.
|
||||||
const setting = this.settingDevice[Object.keys(this.settingDevice)[settingIndex]];
|
const setting = this.settingDevice[Object.keys(this.settingDevice)[settingIndex]];
|
||||||
@ -451,6 +501,9 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
return true; // Return true to indicate the cursor was successfully updated.
|
return true; // Return true to indicate the cursor was successfully updated.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the scroll position of the settings UI.
|
||||||
|
*/
|
||||||
updateSettingsScroll(): void {
|
updateSettingsScroll(): void {
|
||||||
// Return immediately if the options container is not initialized.
|
// Return immediately if the options container is not initialized.
|
||||||
if (!this.optionsContainer) return;
|
if (!this.optionsContainer) return;
|
||||||
@ -470,6 +523,9 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the UI elements and state.
|
||||||
|
*/
|
||||||
clear(): void {
|
clear(): void {
|
||||||
super.clear();
|
super.clear();
|
||||||
|
|
||||||
@ -480,6 +536,9 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
this.eraseCursor();
|
this.eraseCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erase the cursor from the UI.
|
||||||
|
*/
|
||||||
eraseCursor(): void {
|
eraseCursor(): void {
|
||||||
// Check if a cursor object exists.
|
// Check if a cursor object exists.
|
||||||
if (this.cursorObj)
|
if (this.cursorObj)
|
||||||
|
@ -32,7 +32,7 @@ export default class GamepadBindingUiHandler extends AbstractBindingUiHandler {
|
|||||||
this.onInputDown(buttonIcon, specialCaseIcon || assignedButtonIcon, type);
|
this.onInputDown(buttonIcon, specialCaseIcon || assignedButtonIcon, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
swapAction() {
|
swapAction(): boolean {
|
||||||
const activeConfig = this.scene.inputController.getActiveConfig(Device.GAMEPAD);
|
const activeConfig = this.scene.inputController.getActiveConfig(Device.GAMEPAD);
|
||||||
this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed)
|
this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed)
|
||||||
this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig);
|
this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig);
|
||||||
|
@ -31,7 +31,7 @@ export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler {
|
|||||||
this.onInputDown(buttonIcon, specialCaseIcon || assignedButtonIcon, 'keyboard');
|
this.onInputDown(buttonIcon, specialCaseIcon || assignedButtonIcon, 'keyboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
swapAction() {
|
swapAction(): boolean {
|
||||||
const activeConfig = this.scene.inputController.getActiveConfig(Device.KEYBOARD);
|
const activeConfig = this.scene.inputController.getActiveConfig(Device.KEYBOARD);
|
||||||
this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed)
|
this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed)
|
||||||
this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig);
|
this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig);
|
||||||
|
Loading…
Reference in New Issue
Block a user