2024-02-21 23:57:49 -05:00
|
|
|
import { CommandPhase } from "../phases";
|
2024-05-05 16:30:00 +02:00
|
|
|
import BattleScene from "../battle-scene";
|
2023-04-20 15:46:05 -04:00
|
|
|
import { addTextObject, TextStyle } from "./text";
|
2023-05-31 12:38:55 -04:00
|
|
|
import PartyUiHandler, { PartyUiMode } from "./party-ui-handler";
|
2023-10-18 23:16:38 -04:00
|
|
|
import { Mode } from "./ui";
|
2023-12-20 19:19:23 -05:00
|
|
|
import UiHandler from "./ui-handler";
|
2024-05-23 17:03:10 +02:00
|
|
|
import i18next from "../plugins/i18n";
|
2024-05-05 16:30:00 +02:00
|
|
|
import {Button} from "../enums/buttons";
|
2023-03-28 14:54:52 -04:00
|
|
|
|
|
|
|
export enum Command {
|
|
|
|
FIGHT = 0,
|
|
|
|
BALL,
|
|
|
|
POKEMON,
|
|
|
|
RUN
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-03-28 14:54:52 -04:00
|
|
|
|
|
|
|
export default class CommandUiHandler extends UiHandler {
|
|
|
|
private commandsContainer: Phaser.GameObjects.Container;
|
|
|
|
private cursorObj: Phaser.GameObjects.Image;
|
|
|
|
|
2023-10-20 11:38:41 -04:00
|
|
|
protected fieldIndex: integer = 0;
|
|
|
|
protected cursor2: integer = 0;
|
|
|
|
|
2023-03-28 14:54:52 -04:00
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, Mode.COMMAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
const ui = this.getUi();
|
2024-05-24 01:45:04 +02:00
|
|
|
const commands = [
|
|
|
|
i18next.t("commandUiHandler:fight"),
|
|
|
|
i18next.t("commandUiHandler:ball"),
|
|
|
|
i18next.t("commandUiHandler:pokemon"),
|
|
|
|
i18next.t("commandUiHandler:run")
|
2024-04-24 06:36:07 +02:00
|
|
|
];
|
2023-03-28 14:54:52 -04:00
|
|
|
|
|
|
|
this.commandsContainer = this.scene.add.container(216, -38.7);
|
|
|
|
this.commandsContainer.setVisible(false);
|
|
|
|
ui.add(this.commandsContainer);
|
|
|
|
|
|
|
|
for (let c = 0; c < commands.length; c++) {
|
|
|
|
const commandText = addTextObject(this.scene, c % 2 === 0 ? 0 : 55.8, c < 2 ? 0 : 16, commands[c], TextStyle.WINDOW);
|
|
|
|
this.commandsContainer.add(commandText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-30 18:41:25 -05:00
|
|
|
show(args: any[]): boolean {
|
2023-03-28 14:54:52 -04:00
|
|
|
super.show(args);
|
|
|
|
|
2023-10-20 11:38:41 -04:00
|
|
|
this.fieldIndex = args.length ? args[0] as integer : 0;
|
|
|
|
|
2023-03-28 14:54:52 -04:00
|
|
|
this.commandsContainer.setVisible(true);
|
|
|
|
|
2024-01-09 23:34:43 -05:00
|
|
|
let commandPhase: CommandPhase;
|
2024-05-23 17:03:10 +02:00
|
|
|
const currentPhase = this.scene.getCurrentPhase();
|
|
|
|
if (currentPhase instanceof CommandPhase) {
|
2024-01-09 23:34:43 -05:00
|
|
|
commandPhase = currentPhase;
|
2024-05-23 17:03:10 +02:00
|
|
|
} else {
|
2024-01-09 23:34:43 -05:00
|
|
|
commandPhase = this.scene.getStandbyPhase() as CommandPhase;
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2024-01-09 23:34:43 -05:00
|
|
|
|
2023-03-28 14:54:52 -04:00
|
|
|
const messageHandler = this.getUi().getMessageHandler();
|
2023-12-20 22:22:15 -05:00
|
|
|
messageHandler.commandWindow.setVisible(true);
|
|
|
|
messageHandler.movesWindowContainer.setVisible(false);
|
2023-03-28 14:54:52 -04:00
|
|
|
messageHandler.message.setWordWrapWidth(1110);
|
2024-05-23 17:03:10 +02:00
|
|
|
messageHandler.showText(i18next.t("commandUiHandler:actionMessage", {pokemonName: commandPhase.getPokemon().name}), 0);
|
2023-10-20 11:38:41 -04:00
|
|
|
this.setCursor(this.getCursor());
|
2023-12-30 18:41:25 -05:00
|
|
|
|
|
|
|
return true;
|
2023-03-28 14:54:52 -04:00
|
|
|
}
|
|
|
|
|
2023-11-12 00:31:40 -05:00
|
|
|
processInput(button: Button): boolean {
|
2023-03-28 14:54:52 -04:00
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
let success = false;
|
|
|
|
|
2023-10-20 11:38:41 -04:00
|
|
|
const cursor = this.getCursor();
|
|
|
|
|
2023-04-11 00:24:55 -04:00
|
|
|
if (button === Button.CANCEL || button === Button.ACTION) {
|
2024-05-24 01:45:04 +02:00
|
|
|
|
2023-04-11 00:24:55 -04:00
|
|
|
if (button === Button.ACTION) {
|
2023-10-20 11:38:41 -04:00
|
|
|
switch (cursor) {
|
2024-05-23 17:03:10 +02:00
|
|
|
// Fight
|
|
|
|
case 0:
|
|
|
|
if ((this.scene.getCurrentPhase() as CommandPhase).checkFightOverride()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ui.setMode(Mode.FIGHT, (this.scene.getCurrentPhase() as CommandPhase).getFieldIndex());
|
|
|
|
success = true;
|
|
|
|
break;
|
2024-03-30 15:34:00 -04:00
|
|
|
// Ball
|
2024-05-23 17:03:10 +02:00
|
|
|
case 1:
|
|
|
|
ui.setModeWithoutClear(Mode.BALL);
|
|
|
|
success = true;
|
|
|
|
break;
|
2024-03-30 15:34:00 -04:00
|
|
|
// Pokemon
|
2024-05-23 17:03:10 +02:00
|
|
|
case 2:
|
|
|
|
ui.setMode(Mode.PARTY, PartyUiMode.SWITCH, (this.scene.getCurrentPhase() as CommandPhase).getPokemon().getFieldIndex(), null, PartyUiHandler.FilterNonFainted);
|
|
|
|
success = true;
|
|
|
|
break;
|
2024-03-30 15:34:00 -04:00
|
|
|
// Run
|
2024-05-23 17:03:10 +02:00
|
|
|
case 3:
|
|
|
|
(this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.RUN, 0);
|
|
|
|
success = true;
|
|
|
|
break;
|
2023-03-28 14:54:52 -04:00
|
|
|
}
|
2024-05-23 17:03:10 +02:00
|
|
|
} else {
|
2023-10-18 23:16:38 -04:00
|
|
|
(this.scene.getCurrentPhase() as CommandPhase).cancel();
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-03-28 14:54:52 -04:00
|
|
|
} else {
|
2023-04-11 00:24:55 -04:00
|
|
|
switch (button) {
|
2024-05-23 17:03:10 +02:00
|
|
|
case Button.UP:
|
|
|
|
if (cursor >= 2) {
|
|
|
|
success = this.setCursor(cursor - 2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Button.DOWN:
|
|
|
|
if (cursor < 2) {
|
|
|
|
success = this.setCursor(cursor + 2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Button.LEFT:
|
|
|
|
if (cursor % 2 === 1) {
|
|
|
|
success = this.setCursor(cursor - 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Button.RIGHT:
|
|
|
|
if (cursor % 2 === 0) {
|
|
|
|
success = this.setCursor(cursor + 1);
|
|
|
|
}
|
|
|
|
break;
|
2023-03-28 14:54:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
if (success) {
|
2023-03-28 14:54:52 -04:00
|
|
|
ui.playSelect();
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-11-12 00:31:40 -05:00
|
|
|
|
|
|
|
return success;
|
2023-03-28 14:54:52 -04:00
|
|
|
}
|
|
|
|
|
2023-10-20 11:38:41 -04:00
|
|
|
getCursor(): integer {
|
|
|
|
return !this.fieldIndex ? this.cursor : this.cursor2;
|
|
|
|
}
|
|
|
|
|
2023-03-28 14:54:52 -04:00
|
|
|
setCursor(cursor: integer): boolean {
|
2023-10-20 11:38:41 -04:00
|
|
|
const changed = this.getCursor() !== cursor;
|
|
|
|
if (changed) {
|
2024-05-23 17:03:10 +02:00
|
|
|
if (!this.fieldIndex) {
|
2023-10-20 11:38:41 -04:00
|
|
|
this.cursor = cursor;
|
2024-05-23 17:03:10 +02:00
|
|
|
} else {
|
2023-10-20 11:38:41 -04:00
|
|
|
this.cursor2 = cursor;
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-10-20 11:38:41 -04:00
|
|
|
}
|
2023-03-28 14:54:52 -04:00
|
|
|
|
|
|
|
if (!this.cursorObj) {
|
2024-05-23 17:03:10 +02:00
|
|
|
this.cursorObj = this.scene.add.image(0, 0, "cursor");
|
2023-12-19 23:51:48 -05:00
|
|
|
this.commandsContainer.add(this.cursorObj);
|
2023-03-28 14:54:52 -04:00
|
|
|
}
|
|
|
|
|
2023-12-19 23:51:48 -05:00
|
|
|
this.cursorObj.setPosition(-5 + (cursor % 2 === 1 ? 56 : 0), 8 + (cursor >= 2 ? 16 : 0));
|
2023-03-28 14:54:52 -04:00
|
|
|
|
2023-10-20 11:38:41 -04:00
|
|
|
return changed;
|
2023-03-28 14:54:52 -04:00
|
|
|
}
|
|
|
|
|
2023-04-30 00:51:33 -04:00
|
|
|
clear(): void {
|
2023-03-28 14:54:52 -04:00
|
|
|
super.clear();
|
2024-01-09 23:34:43 -05:00
|
|
|
this.getUi().getMessageHandler().commandWindow.setVisible(false);
|
2023-03-28 14:54:52 -04:00
|
|
|
this.commandsContainer.setVisible(false);
|
|
|
|
this.getUi().getMessageHandler().clearText();
|
|
|
|
this.eraseCursor();
|
|
|
|
}
|
|
|
|
|
2023-04-30 00:51:33 -04:00
|
|
|
eraseCursor(): void {
|
2024-05-23 17:03:10 +02:00
|
|
|
if (this.cursorObj) {
|
2023-03-28 14:54:52 -04:00
|
|
|
this.cursorObj.destroy();
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-03-28 14:54:52 -04:00
|
|
|
this.cursorObj = null;
|
|
|
|
}
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|