From dd893785b5ab655efc41060f472f5a2d8c6445dd Mon Sep 17 00:00:00 2001 From: Opaque02 <66582645+Opaque02@users.noreply.github.com> Date: Sat, 19 Oct 2024 19:32:41 +1000 Subject: [PATCH] Possible cursor fixes --- src/phases/command-phase.ts | 23 +++++++++-------------- src/ui/command-ui-handler.ts | 14 ++++++-------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/phases/command-phase.ts b/src/phases/command-phase.ts index 6e89987d4af..214494cb94f 100644 --- a/src/phases/command-phase.ts +++ b/src/phases/command-phase.ts @@ -10,7 +10,7 @@ import { Moves } from "#app/enums/moves"; import { PokeballType } from "#app/enums/pokeball"; import { FieldPosition, PlayerPokemon } from "#app/field/pokemon"; import { getPokemonNameWithAffix } from "#app/messages"; -import CommandUiHandler, { Command } from "#app/ui/command-ui-handler"; +import { Command } from "#app/ui/command-ui-handler"; import { Mode } from "#app/ui/ui"; import i18next from "i18next"; import { FieldPhase } from "./field-phase"; @@ -30,7 +30,14 @@ export class CommandPhase extends FieldPhase { start() { super.start(); - this.repositionCursor(); + const commandUiHandler = this.scene.ui.handlers[Mode.COMMAND]; + if (commandUiHandler) { + if (this.scene.currentBattle.turn === 1 || commandUiHandler.getCursor() === Command.POKEMON) { + commandUiHandler.setCursor(Command.FIGHT); + } else { + commandUiHandler.setCursor(commandUiHandler.getCursor()); + } + } if (this.fieldIndex) { // If we somehow are attempting to check the right pokemon but there's only one pokemon out @@ -259,18 +266,6 @@ export class CommandPhase extends FieldPhase { return success!; // TODO: is the bang correct? } - repositionCursor() { - const commandUiHandler = this.scene.ui.handlers[Mode.COMMAND] as CommandUiHandler; - if (commandUiHandler) { - if (this.scene.currentBattle.turn === 1 || commandUiHandler.getCursor() === Command.POKEMON) { - commandUiHandler.setCursor(Command.FIGHT); - } else { - commandUiHandler.setCursor(commandUiHandler.getCursor()); - } - - } - } - cancel() { if (this.fieldIndex) { this.scene.unshiftPhase(new CommandPhase(this.scene, 0)); diff --git a/src/ui/command-ui-handler.ts b/src/ui/command-ui-handler.ts index 922b929ff2f..2f65fa0b457 100644 --- a/src/ui/command-ui-handler.ts +++ b/src/ui/command-ui-handler.ts @@ -16,8 +16,8 @@ export enum Command { } export default class CommandUiHandler extends UiHandler { - public commandsContainer: Phaser.GameObjects.Container; - public cursorObj: Phaser.GameObjects.Image | null; + private commandsContainer: Phaser.GameObjects.Container; + private cursorObj: Phaser.GameObjects.Image | null; protected fieldIndex: integer = 0; protected cursor2: integer = 0; @@ -68,14 +68,12 @@ export default class CommandUiHandler extends UiHandler { messageHandler.movesWindowContainer.setVisible(false); messageHandler.message.setWordWrapWidth(1110); messageHandler.showText(i18next.t("commandUiHandler:actionMessage", { pokemonName: getPokemonNameWithAffix(commandPhase.getPokemon()) }), 0); - - if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, "cursor"); - this.commandsContainer.add(this.cursorObj); + if (this.getCursor() === Command.POKEMON) { + this.setCursor(Command.FIGHT); + } else { + this.setCursor(this.getCursor()); } - const cursorPosition = this.getCursor() === Command.POKEMON ? Command.FIGHT : this.getCursor(); - this.cursorObj.setPosition(-5 + (cursorPosition % 2 === 1 ? 56 : 0), 8 + (cursorPosition >= 2 ? 16 : 0)); return true; }