move getGamepadType function to ui.ts

This commit is contained in:
KimJeongSun 2024-09-06 10:32:38 +09:00
parent f1bb5fbce8
commit c8331d1225
2 changed files with 19 additions and 18 deletions

View File

@ -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;
}
}
}

View File

@ -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;
}
}
}