2024-05-05 15:30:00 +01:00
|
|
|
import BattleScene from "../battle-scene";
|
2023-04-20 20:46:05 +01:00
|
|
|
import { addTextObject, TextStyle } from "./text";
|
|
|
|
import { Type } from "../data/type";
|
2023-03-28 19:54:52 +01:00
|
|
|
import { Command } from "./command-ui-handler";
|
2023-04-01 01:19:57 +01:00
|
|
|
import { Mode } from "./ui";
|
2023-12-21 00:19:23 +00:00
|
|
|
import UiHandler from "./ui-handler";
|
2023-04-01 01:19:57 +01:00
|
|
|
import * as Utils from "../utils";
|
2024-02-22 04:57:49 +00:00
|
|
|
import { CommandPhase } from "../phases";
|
2024-04-25 01:49:39 +01:00
|
|
|
import { MoveCategory } from "#app/data/move.js";
|
2024-04-25 23:54:56 +01:00
|
|
|
import i18next from '../plugins/i18n';
|
2024-05-05 15:30:00 +01:00
|
|
|
import {Button} from "../enums/buttons";
|
2023-03-28 19:54:52 +01:00
|
|
|
|
|
|
|
export default class FightUiHandler extends UiHandler {
|
|
|
|
private movesContainer: Phaser.GameObjects.Container;
|
2023-04-01 01:19:57 +01:00
|
|
|
private typeIcon: Phaser.GameObjects.Sprite;
|
2024-04-25 23:54:56 +01:00
|
|
|
private ppLabel: Phaser.GameObjects.Text;
|
2023-04-01 01:19:57 +01:00
|
|
|
private ppText: Phaser.GameObjects.Text;
|
2024-04-25 23:54:56 +01:00
|
|
|
private powerLabel: Phaser.GameObjects.Text;
|
|
|
|
private powerText: Phaser.GameObjects.Text;
|
2024-05-10 04:30:24 +01:00
|
|
|
private accuracyLabel: Phaser.GameObjects.Text;
|
|
|
|
private accuracyText: Phaser.GameObjects.Text;
|
2023-03-28 19:54:52 +01:00
|
|
|
private cursorObj: Phaser.GameObjects.Image;
|
2024-04-25 01:49:39 +01:00
|
|
|
private moveCategoryIcon: Phaser.GameObjects.Sprite;
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2023-10-19 04:16:38 +01:00
|
|
|
protected fieldIndex: integer = 0;
|
|
|
|
protected cursor2: integer = 0;
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, Mode.FIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
const ui = this.getUi();
|
2024-04-25 23:54:56 +01:00
|
|
|
|
2023-04-01 01:19:57 +01:00
|
|
|
this.movesContainer = this.scene.add.container(18, -38.7);
|
|
|
|
ui.add(this.movesContainer);
|
2023-03-28 19:54:52 +01:00
|
|
|
|
2024-05-10 04:30:24 +01:00
|
|
|
this.typeIcon = this.scene.add.sprite((this.scene.game.canvas.width / 6) - 57, -36, 'types', 'unknown');
|
2023-04-01 01:19:57 +01:00
|
|
|
this.typeIcon.setVisible(false);
|
|
|
|
ui.add(this.typeIcon);
|
|
|
|
|
2024-05-10 04:30:24 +01:00
|
|
|
this.moveCategoryIcon = this.scene.add.sprite((this.scene.game.canvas.width / 6) - 25, -36, 'categories', 'physical');
|
2024-04-25 01:49:39 +01:00
|
|
|
this.moveCategoryIcon.setVisible(false);
|
|
|
|
ui.add(this.moveCategoryIcon);
|
|
|
|
|
2024-05-10 04:30:24 +01:00
|
|
|
this.ppLabel = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 70, -26, 'PP', TextStyle.MOVE_INFO_CONTENT);
|
2024-04-25 23:54:56 +01:00
|
|
|
this.ppLabel.setOrigin(0.0, 0.5);
|
|
|
|
this.ppLabel.setVisible(false);
|
|
|
|
this.ppLabel.setText(i18next.t('fightUiHandler:pp'));
|
|
|
|
ui.add(this.ppLabel);
|
|
|
|
|
2024-05-10 04:30:24 +01:00
|
|
|
this.ppText = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 12, -26, '--/--', TextStyle.MOVE_INFO_CONTENT);
|
2023-04-01 01:19:57 +01:00
|
|
|
this.ppText.setOrigin(1, 0.5);
|
|
|
|
this.ppText.setVisible(false);
|
|
|
|
ui.add(this.ppText);
|
2024-04-25 23:54:56 +01:00
|
|
|
|
2024-05-10 04:30:24 +01:00
|
|
|
this.powerLabel = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 70, -18, 'POWER', TextStyle.MOVE_INFO_CONTENT);
|
2024-04-25 23:54:56 +01:00
|
|
|
this.powerLabel.setOrigin(0.0, 0.5);
|
|
|
|
this.powerLabel.setVisible(false);
|
|
|
|
this.powerLabel.setText(i18next.t('fightUiHandler:power'));
|
|
|
|
ui.add(this.powerLabel);
|
|
|
|
|
2024-05-10 04:30:24 +01:00
|
|
|
this.powerText = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 12, -18, '---', TextStyle.MOVE_INFO_CONTENT);
|
2024-04-25 23:54:56 +01:00
|
|
|
this.powerText.setOrigin(1, 0.5);
|
|
|
|
this.powerText.setVisible(false);
|
|
|
|
ui.add(this.powerText);
|
2024-05-10 04:30:24 +01:00
|
|
|
|
|
|
|
this.accuracyLabel = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 70, -10, 'ACC', TextStyle.MOVE_INFO_CONTENT);
|
|
|
|
this.accuracyLabel.setOrigin(0.0, 0.5);
|
|
|
|
this.accuracyLabel.setVisible(false);
|
|
|
|
this.accuracyLabel.setText(i18next.t('fightUiHandler:accuracy'))
|
|
|
|
ui.add(this.accuracyLabel);
|
|
|
|
|
|
|
|
this.accuracyText = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 12, -10, '---', TextStyle.MOVE_INFO_CONTENT);
|
|
|
|
this.accuracyText.setOrigin(1, 0.5);
|
|
|
|
this.accuracyText.setVisible(false);
|
|
|
|
ui.add(this.accuracyText);
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-12-30 23:41:25 +00:00
|
|
|
show(args: any[]): boolean {
|
2023-03-28 19:54:52 +01:00
|
|
|
super.show(args);
|
|
|
|
|
2023-10-19 04:16:38 +01:00
|
|
|
this.fieldIndex = args.length ? args[0] as integer : 0;
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
const messageHandler = this.getUi().getMessageHandler();
|
2023-12-21 03:22:15 +00:00
|
|
|
messageHandler.commandWindow.setVisible(false);
|
|
|
|
messageHandler.movesWindowContainer.setVisible(true);
|
2023-10-19 04:16:38 +01:00
|
|
|
this.setCursor(this.getCursor());
|
2023-03-28 19:54:52 +01:00
|
|
|
this.displayMoves();
|
2023-12-30 23:41:25 +00:00
|
|
|
|
|
|
|
return true;
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-11-12 05:31:40 +00:00
|
|
|
processInput(button: Button): boolean {
|
2023-03-28 19:54:52 +01:00
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
let success = false;
|
|
|
|
|
2023-10-19 04:16:38 +01:00
|
|
|
const cursor = this.getCursor();
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
if (button === Button.CANCEL || button === Button.ACTION) {
|
|
|
|
if (button === Button.ACTION) {
|
2023-10-19 04:16:38 +01:00
|
|
|
if ((this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, cursor, false))
|
2023-03-28 19:54:52 +01:00
|
|
|
success = true;
|
2023-04-13 02:44:12 +01:00
|
|
|
else
|
|
|
|
ui.playError();
|
2023-03-28 19:54:52 +01:00
|
|
|
} else {
|
2023-10-20 16:38:41 +01:00
|
|
|
ui.setMode(Mode.COMMAND, this.fieldIndex);
|
2023-03-28 19:54:52 +01:00
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
} else {
|
2023-04-11 05:24:55 +01:00
|
|
|
switch (button) {
|
|
|
|
case Button.UP:
|
2023-10-19 04:16:38 +01:00
|
|
|
if (cursor >= 2)
|
|
|
|
success = this.setCursor(cursor - 2);
|
2023-03-28 19:54:52 +01:00
|
|
|
break;
|
2023-04-11 05:24:55 +01:00
|
|
|
case Button.DOWN:
|
2023-10-19 04:16:38 +01:00
|
|
|
if (cursor < 2)
|
|
|
|
success = this.setCursor(cursor + 2);
|
2023-03-28 19:54:52 +01:00
|
|
|
break;
|
2023-04-11 05:24:55 +01:00
|
|
|
case Button.LEFT:
|
2023-10-19 04:16:38 +01:00
|
|
|
if (cursor % 2 === 1)
|
|
|
|
success = this.setCursor(cursor - 1);
|
2023-03-28 19:54:52 +01:00
|
|
|
break;
|
2023-04-11 05:24:55 +01:00
|
|
|
case Button.RIGHT:
|
2023-10-19 04:16:38 +01:00
|
|
|
if (cursor % 2 === 0)
|
|
|
|
success = this.setCursor(cursor + 1);
|
2023-03-28 19:54:52 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
ui.playSelect();
|
2023-11-12 05:31:40 +00:00
|
|
|
|
|
|
|
return success;
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-10-19 04:16:38 +01:00
|
|
|
getCursor(): integer {
|
|
|
|
return !this.fieldIndex ? this.cursor : this.cursor2;
|
|
|
|
}
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
setCursor(cursor: integer): boolean {
|
|
|
|
const ui = this.getUi();
|
2023-10-19 04:16:38 +01:00
|
|
|
|
|
|
|
const changed = this.getCursor() !== cursor;
|
|
|
|
if (changed) {
|
|
|
|
if (!this.fieldIndex)
|
|
|
|
this.cursor = cursor;
|
|
|
|
else
|
|
|
|
this.cursor2 = cursor;
|
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
|
|
|
|
if (!this.cursorObj) {
|
|
|
|
this.cursorObj = this.scene.add.image(0, 0, 'cursor');
|
|
|
|
ui.add(this.cursorObj);
|
|
|
|
}
|
|
|
|
|
2023-05-18 16:11:06 +01:00
|
|
|
const moveset = (this.scene.getCurrentPhase() as CommandPhase).getPokemon().getMoveset();
|
2023-04-04 04:38:31 +01:00
|
|
|
|
|
|
|
const hasMove = cursor < moveset.length;
|
|
|
|
|
|
|
|
if (hasMove) {
|
|
|
|
const pokemonMove = moveset[cursor];
|
2024-04-25 23:54:56 +01:00
|
|
|
this.typeIcon.setTexture('types', Type[pokemonMove.getMove().type].toLowerCase()).setScale(0.8);
|
|
|
|
this.moveCategoryIcon.setTexture('categories', MoveCategory[pokemonMove.getMove().category].toLowerCase()).setScale(1.0);
|
2023-04-01 01:19:57 +01:00
|
|
|
|
2024-04-25 23:54:56 +01:00
|
|
|
const power = pokemonMove.getMove().power;
|
2024-05-10 04:30:24 +01:00
|
|
|
const accuracy = pokemonMove.getMove().accuracy;
|
2024-01-13 15:56:20 +00:00
|
|
|
const maxPP = pokemonMove.getMovePp();
|
2023-04-04 04:38:31 +01:00
|
|
|
const pp = maxPP - pokemonMove.ppUsed;
|
|
|
|
|
|
|
|
this.ppText.setText(`${Utils.padInt(pp, 2, ' ')}/${Utils.padInt(maxPP, 2, ' ')}`);
|
2024-04-25 23:54:56 +01:00
|
|
|
this.powerText.setText(`${power >= 0 ? power : '---'}`);
|
2024-05-10 04:30:24 +01:00
|
|
|
this.accuracyText.setText(`${accuracy >= 0 ? accuracy : '---'}`);
|
2023-04-04 04:38:31 +01:00
|
|
|
}
|
2023-04-01 01:19:57 +01:00
|
|
|
|
2023-04-04 04:38:31 +01:00
|
|
|
this.typeIcon.setVisible(hasMove);
|
2024-04-25 23:54:56 +01:00
|
|
|
this.ppLabel.setVisible(hasMove);
|
2023-04-04 04:38:31 +01:00
|
|
|
this.ppText.setVisible(hasMove);
|
2024-04-25 23:54:56 +01:00
|
|
|
this.powerLabel.setVisible(hasMove);
|
|
|
|
this.powerText.setVisible(hasMove);
|
2024-05-10 04:30:24 +01:00
|
|
|
this.accuracyLabel.setVisible(hasMove);
|
|
|
|
this.accuracyText.setVisible(hasMove);
|
2024-04-25 01:49:39 +01:00
|
|
|
this.moveCategoryIcon.setVisible(hasMove);
|
2023-04-01 01:19:57 +01:00
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
this.cursorObj.setPosition(13 + (cursor % 2 === 1 ? 100 : 0), -31 + (cursor >= 2 ? 15 : 0));
|
|
|
|
|
2023-10-19 04:16:38 +01:00
|
|
|
return changed;
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
displayMoves() {
|
2023-05-18 16:11:06 +01:00
|
|
|
const moveset = (this.scene.getCurrentPhase() as CommandPhase).getPokemon().getMoveset();
|
2023-03-28 19:54:52 +01:00
|
|
|
for (let m = 0; m < 4; m++) {
|
|
|
|
const moveText = addTextObject(this.scene, m % 2 === 0 ? 0 : 100, m < 2 ? 0 : 16, '-', TextStyle.WINDOW);
|
|
|
|
if (m < moveset.length)
|
|
|
|
moveText.setText(moveset[m].getName());
|
|
|
|
this.movesContainer.add(moveText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
super.clear();
|
|
|
|
this.clearMoves();
|
2023-04-01 01:19:57 +01:00
|
|
|
this.typeIcon.setVisible(false);
|
2024-04-25 23:54:56 +01:00
|
|
|
this.ppLabel.setVisible(false);
|
2023-04-01 01:19:57 +01:00
|
|
|
this.ppText.setVisible(false);
|
2024-04-25 23:54:56 +01:00
|
|
|
this.powerLabel.setVisible(false);
|
|
|
|
this.powerText.setVisible(false);
|
2024-05-10 04:30:24 +01:00
|
|
|
this.accuracyLabel.setVisible(false);
|
|
|
|
this.accuracyText.setVisible(false);
|
2024-04-25 01:49:39 +01:00
|
|
|
this.moveCategoryIcon.setVisible(false);
|
2023-03-28 19:54:52 +01:00
|
|
|
this.eraseCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
clearMoves() {
|
|
|
|
this.movesContainer.removeAll(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
eraseCursor() {
|
|
|
|
if (this.cursorObj)
|
|
|
|
this.cursorObj.destroy();
|
|
|
|
this.cursorObj = null;
|
|
|
|
}
|
|
|
|
}
|