From 1a4420853e9fc9ed56869dd624924ede6d1c7aa3 Mon Sep 17 00:00:00 2001 From: frutescens Date: Fri, 18 Oct 2024 15:09:50 -0700 Subject: [PATCH] fix in! --- src/phases/command-phase.ts | 23 ++++++++++++++--------- src/ui/command-ui-handler.ts | 11 +++++++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/phases/command-phase.ts b/src/phases/command-phase.ts index cb56012ce82..6e89987d4af 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 { Command } from "#app/ui/command-ui-handler"; +import CommandUiHandler, { Command } from "#app/ui/command-ui-handler"; import { Mode } from "#app/ui/ui"; import i18next from "i18next"; import { FieldPhase } from "./field-phase"; @@ -30,14 +30,7 @@ export class CommandPhase extends FieldPhase { start() { super.start(); - 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() !== 0 ? commandUiHandler.getCursor() : Command.FIGHT); - } - } + this.repositionCursor(); if (this.fieldIndex) { // If we somehow are attempting to check the right pokemon but there's only one pokemon out @@ -266,6 +259,18 @@ 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 a5eeb95c48d..922b929ff2f 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 { - private commandsContainer: Phaser.GameObjects.Container; - private cursorObj: Phaser.GameObjects.Image | null; + public commandsContainer: Phaser.GameObjects.Container; + public cursorObj: Phaser.GameObjects.Image | null; protected fieldIndex: integer = 0; protected cursor2: integer = 0; @@ -69,6 +69,13 @@ export default class CommandUiHandler extends UiHandler { 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); + } + + 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; }