From c8331d12256ef289ae86c7d6f9fb5090b681ec44 Mon Sep 17 00:00:00 2001 From: KimJeongSun Date: Fri, 6 Sep 2024 10:32:38 +0900 Subject: [PATCH] move getGamepadType function to ui.ts --- src/ui/run-info-ui-handler.ts | 20 ++------------------ src/ui/ui.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/ui/run-info-ui-handler.ts b/src/ui/run-info-ui-handler.ts index c89b02d4510..7dac9acaf67 100644 --- a/src/ui/run-info-ui-handler.ts +++ b/src/ui/run-info-ui-handler.ts @@ -23,7 +23,6 @@ import {modifierSortFunc} from "../modifier/modifier"; import { Species } from "#enums/species"; import { PlayerGender } from "#enums/player-gender"; import { SettingKeyboard } from "#app/system/settings/settings-keyboard"; -import { Device } from "#enums/devices"; /** * RunInfoUiMode indicates possible overlays of RunInfoUiHandler. @@ -154,7 +153,7 @@ export default class RunInfoUiHandler extends UiHandler { const headerBgCoords = headerBg.getTopRight(); const abilityButtonContainer = this.scene.add.container(0, 0); const abilityButtonText = addTextObject(this.scene, 8, 0, i18next.t("runHistory:viewHeldItems"), TextStyle.WINDOW, {fontSize:"34px"}); - const gamepadType = this.getGamepadType(); + const gamepadType = this.getUi().getGamepadType(); let abilityButtonElement: Phaser.GameObjects.Sprite; if (gamepadType === "touch") { abilityButtonElement = new Phaser.GameObjects.Sprite(this.scene, 0, 2, "keyboard", "E.png"); @@ -190,7 +189,7 @@ export default class RunInfoUiHandler extends UiHandler { const hallofFameInstructionContainer = this.scene.add.container(0, 0); const shinyButtonText = addTextObject(this.scene, 8, 0, i18next.t("runHistory:viewHallOfFame"), TextStyle.WINDOW, {fontSize:"65px"}); const formButtonText = addTextObject(this.scene, 8, 12, i18next.t("runHistory:viewEndingSplash"), TextStyle.WINDOW, {fontSize:"65px"}); - const gamepadType = this.getGamepadType(); + const gamepadType = this.getUi().getGamepadType(); let shinyButtonElement: Phaser.GameObjects.Sprite; let formButtonElement: Phaser.GameObjects.Sprite; if (gamepadType === "touch") { @@ -899,20 +898,5 @@ export default class RunInfoUiHandler extends UiHandler { break; } } - - /** - * getGamepadType - returns the type of gamepad being used - * inputMethod could be "keyboard" or "touch" or "gamepad" - * if inputMethod is "keyboard" or "touch", then the inputMethod is returned - * if inputMethod is "gamepad", then the gamepad type is returned it could be "xbox" or "duelshock" - * @returns gamepad type - */ - private getGamepadType(): string { - if (this.scene.inputMethod === "gamepad") { - return this.scene.inputController.getConfig(this.scene.inputController.selectedDevice[Device.GAMEPAD]).padType; - } else { - return this.scene.inputMethod; - } - } } diff --git a/src/ui/ui.ts b/src/ui/ui.ts index 6c988b43043..cc0fc4ca3db 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -52,6 +52,7 @@ import RunInfoUiHandler from "./run-info-ui-handler"; import EggSummaryUiHandler from "./egg-summary-ui-handler"; import TestDialogueUiHandler from "#app/ui/test-dialogue-ui-handler"; import AutoCompleteUiHandler from "./autocomplete-ui-handler"; +import { Device } from "#enums/devices"; export enum Mode { MESSAGE, @@ -560,4 +561,20 @@ export default class UI extends Phaser.GameObjects.Container { public getModeChain(): Mode[] { return this.modeChain; } + + /** + * getGamepadType - returns the type of gamepad being used + * inputMethod could be "keyboard" or "touch" or "gamepad" + * if inputMethod is "keyboard" or "touch", then the inputMethod is returned + * if inputMethod is "gamepad", then the gamepad type is returned it could be "xbox" or "duelshock" + * @returns gamepad type + */ + public getGamepadType(): string { + const scene = this.scene as BattleScene; + if (scene.inputMethod === "gamepad") { + return scene.inputController.getConfig(scene.inputController.selectedDevice[Device.GAMEPAD]).padType; + } else { + return scene.inputMethod; + } + } }