2023-04-14 04:04:51 +01:00
|
|
|
import { CommandPhase } from "../battle-phases";
|
2023-04-11 05:24:55 +01:00
|
|
|
import BattleScene, { Button } from "../battle-scene";
|
2023-04-20 20:46:05 +01:00
|
|
|
import { addTextObject, TextStyle } from "./text";
|
2023-03-28 19:54:52 +01:00
|
|
|
import { toPokemonUpperCase } from "../utils";
|
2023-05-31 17:38:55 +01:00
|
|
|
import PartyUiHandler, { PartyUiMode } from "./party-ui-handler";
|
2023-03-28 19:54:52 +01:00
|
|
|
import UI, { Mode } from "./ui";
|
|
|
|
import UiHandler from "./uiHandler";
|
|
|
|
|
|
|
|
export enum Command {
|
|
|
|
FIGHT = 0,
|
|
|
|
BALL,
|
|
|
|
POKEMON,
|
|
|
|
RUN
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class CommandUiHandler extends UiHandler {
|
|
|
|
private commandsContainer: Phaser.GameObjects.Container;
|
|
|
|
private cursorObj: Phaser.GameObjects.Image;
|
|
|
|
|
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, Mode.COMMAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
const ui = this.getUi();
|
|
|
|
const commands = [ 'Fight', 'Ball', 'Pokémon', 'Run' ].map(s => toPokemonUpperCase(s));
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
show(args: any[]) {
|
|
|
|
super.show(args);
|
|
|
|
|
|
|
|
this.commandsContainer.setVisible(true);
|
|
|
|
|
|
|
|
const messageHandler = this.getUi().getMessageHandler();
|
|
|
|
messageHandler.bg.setTexture('bg_command');
|
|
|
|
messageHandler.message.setWordWrapWidth(1110);
|
2023-05-18 16:11:06 +01:00
|
|
|
messageHandler.showText(`What will\n${(this.scene.getCurrentPhase() as CommandPhase).getPokemon().name} do?`, 0);
|
2023-03-28 19:54:52 +01:00
|
|
|
this.setCursor(this.cursor);
|
|
|
|
}
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
processInput(button: Button) {
|
2023-03-28 19:54:52 +01:00
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
let success = false;
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
if (button === Button.CANCEL || button === Button.ACTION) {
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
if (button === Button.ACTION) {
|
2023-03-28 19:54:52 +01:00
|
|
|
switch (this.cursor) {
|
|
|
|
case 0:
|
|
|
|
ui.setMode(Mode.FIGHT);
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
case 1:
|
2023-04-02 03:59:07 +01:00
|
|
|
ui.setModeWithoutClear(Mode.BALL);
|
2023-03-28 19:54:52 +01:00
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
case 2:
|
2023-05-31 17:38:55 +01:00
|
|
|
ui.setMode(Mode.PARTY, PartyUiMode.SWITCH, (this.scene.getCurrentPhase() as CommandPhase).getPokemon().getFieldIndex(), null, PartyUiHandler.FilterNonFainted);
|
2023-03-28 19:54:52 +01:00
|
|
|
success = true;
|
|
|
|
break;
|
2023-04-14 04:04:51 +01:00
|
|
|
case 3:
|
|
|
|
(this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.RUN, 0);
|
|
|
|
success = true;
|
|
|
|
break;
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2023-04-11 05:24:55 +01:00
|
|
|
switch (button) {
|
|
|
|
case Button.UP:
|
2023-03-28 19:54:52 +01:00
|
|
|
if (this.cursor >= 2)
|
|
|
|
success = this.setCursor(this.cursor - 2);
|
|
|
|
break;
|
2023-04-11 05:24:55 +01:00
|
|
|
case Button.DOWN:
|
2023-03-28 19:54:52 +01:00
|
|
|
if (this.cursor < 2)
|
|
|
|
success = this.setCursor(this.cursor + 2);
|
|
|
|
break;
|
2023-04-11 05:24:55 +01:00
|
|
|
case Button.LEFT:
|
2023-03-28 19:54:52 +01:00
|
|
|
if (this.cursor % 2 === 1)
|
|
|
|
success = this.setCursor(this.cursor - 1);
|
|
|
|
break;
|
2023-04-11 05:24:55 +01:00
|
|
|
case Button.RIGHT:
|
2023-03-28 19:54:52 +01:00
|
|
|
if (this.cursor % 2 === 0)
|
|
|
|
success = this.setCursor(this.cursor + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
ui.playSelect();
|
|
|
|
}
|
|
|
|
|
|
|
|
setCursor(cursor: integer): boolean {
|
|
|
|
const ui = this.getUi();
|
|
|
|
const ret = super.setCursor(cursor);
|
|
|
|
|
|
|
|
if (!this.cursorObj) {
|
|
|
|
this.cursorObj = this.scene.add.image(0, 0, 'cursor');
|
|
|
|
ui.add(this.cursorObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.cursorObj.setPosition(211 + (cursor % 2 === 1 ? 56 : 0), -31 + (cursor >= 2 ? 16 : 0));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-04-30 05:51:33 +01:00
|
|
|
clear(): void {
|
2023-03-28 19:54:52 +01:00
|
|
|
super.clear();
|
|
|
|
this.commandsContainer.setVisible(false);
|
|
|
|
this.getUi().getMessageHandler().clearText();
|
|
|
|
this.eraseCursor();
|
|
|
|
}
|
|
|
|
|
2023-04-30 05:51:33 +01:00
|
|
|
eraseCursor(): void {
|
2023-03-28 19:54:52 +01:00
|
|
|
if (this.cursorObj)
|
|
|
|
this.cursorObj.destroy();
|
|
|
|
this.cursorObj = null;
|
|
|
|
}
|
|
|
|
}
|