This commit is contained in:
frutescens 2024-10-18 15:09:50 -07:00
parent 01a9e8c2e6
commit 1a4420853e
2 changed files with 23 additions and 11 deletions

View File

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

View File

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