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";
|
2024-01-10 04:34:43 +00:00
|
|
|
import { Mode } from "./ui";
|
2023-03-28 19:54:52 +01:00
|
|
|
import * as Utils from "../utils";
|
|
|
|
import MessageUiHandler from "./message-ui-handler";
|
2023-04-20 20:46:05 +01:00
|
|
|
import { getStatName, Stat } from "../data/pokemon-stat";
|
2024-04-01 02:14:35 +01:00
|
|
|
import { addWindow } from "./ui-theme";
|
2023-03-28 19:54:52 +01:00
|
|
|
|
|
|
|
export default class BattleMessageUiHandler extends MessageUiHandler {
|
|
|
|
private levelUpStatsContainer: Phaser.GameObjects.Container;
|
|
|
|
private levelUpStatsIncrContent: Phaser.GameObjects.Text;
|
|
|
|
private levelUpStatsValuesContent: Phaser.GameObjects.Text;
|
2024-03-21 04:57:28 +00:00
|
|
|
private nameBox: Phaser.GameObjects.NineSlice;
|
2023-10-18 23:01:15 +01:00
|
|
|
private nameText: Phaser.GameObjects.Text;
|
2023-03-28 19:54:52 +01:00
|
|
|
|
|
|
|
public bg: Phaser.GameObjects.Image;
|
2023-12-21 03:22:15 +00:00
|
|
|
public commandWindow: Phaser.GameObjects.NineSlice;
|
|
|
|
public movesWindowContainer: Phaser.GameObjects.Container;
|
2023-10-18 23:01:15 +01:00
|
|
|
public nameBoxContainer: Phaser.GameObjects.Container;
|
2023-03-28 19:54:52 +01:00
|
|
|
|
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, Mode.MESSAGE);
|
|
|
|
}
|
|
|
|
|
2023-10-18 23:01:15 +01:00
|
|
|
setup(): void {
|
2023-03-28 19:54:52 +01:00
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
this.textTimer = null;
|
|
|
|
this.textCallbackTimer = null;
|
|
|
|
|
2024-04-01 02:23:27 +01:00
|
|
|
const bg = this.scene.add.sprite(0, 0, 'bg', this.scene.windowType);
|
2023-03-28 19:54:52 +01:00
|
|
|
bg.setOrigin(0, 1);
|
|
|
|
ui.add(bg);
|
|
|
|
|
|
|
|
this.bg = bg;
|
|
|
|
|
2023-12-21 03:22:15 +00:00
|
|
|
this.commandWindow = addWindow(this.scene, 201, -1, 118, 46);
|
|
|
|
this.commandWindow.setOrigin(0, 1);
|
|
|
|
this.commandWindow.setVisible(false);
|
|
|
|
ui.add(this.commandWindow);
|
|
|
|
|
|
|
|
this.movesWindowContainer = this.scene.add.container(1, -1);
|
|
|
|
this.movesWindowContainer.setVisible(false);
|
|
|
|
|
|
|
|
const movesWindow = addWindow(this.scene, 0, 0, 243, 46);
|
|
|
|
movesWindow.setOrigin(0, 1);
|
|
|
|
this.movesWindowContainer.add(movesWindow);
|
|
|
|
|
|
|
|
const moveDetailsWindow = addWindow(this.scene, 238, 0, 80, 46, false, true, 2, 133);
|
|
|
|
moveDetailsWindow.setOrigin(0, 1);
|
|
|
|
this.movesWindowContainer.add(moveDetailsWindow);
|
|
|
|
|
|
|
|
const commandFightLabels = this.scene.add.image(246, -10, 'command_fight_labels');
|
|
|
|
commandFightLabels.setOrigin(0, 1);
|
|
|
|
this.movesWindowContainer.add(commandFightLabels);
|
|
|
|
|
|
|
|
ui.add(this.movesWindowContainer);
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
const messageContainer = this.scene.add.container(12, -39);
|
|
|
|
ui.add(messageContainer);
|
|
|
|
|
|
|
|
const message = addTextObject(this.scene, 0, 0, '', TextStyle.MESSAGE, {
|
|
|
|
maxLines: 2,
|
|
|
|
wordWrap: {
|
|
|
|
width: 1780
|
|
|
|
}
|
|
|
|
});
|
|
|
|
messageContainer.add(message);
|
|
|
|
|
|
|
|
this.message = message;
|
|
|
|
|
2023-10-18 23:01:15 +01:00
|
|
|
this.nameBoxContainer = this.scene.add.container(0, -16);
|
|
|
|
this.nameBoxContainer.setVisible(false);
|
|
|
|
|
2024-04-01 15:06:28 +01:00
|
|
|
this.nameBox = this.scene.add.nineslice(0, 0, 'namebox', this.scene.windowType, 72, 16, 8, 8, 5, 5);
|
2024-03-21 04:57:28 +00:00
|
|
|
this.nameBox.setOrigin(0, 0);
|
2023-10-18 23:01:15 +01:00
|
|
|
|
|
|
|
this.nameText = addTextObject(this.scene, 8, 0, 'Rival', TextStyle.MESSAGE, { maxLines: 1 });
|
|
|
|
|
2024-03-21 04:57:28 +00:00
|
|
|
this.nameBoxContainer.add(this.nameBox);
|
2023-10-18 23:01:15 +01:00
|
|
|
this.nameBoxContainer.add(this.nameText);
|
|
|
|
messageContainer.add(this.nameBoxContainer);
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
const prompt = this.scene.add.sprite(0, 0, 'prompt');
|
|
|
|
prompt.setVisible(false);
|
|
|
|
prompt.setOrigin(0, 0);
|
|
|
|
messageContainer.add(prompt);
|
|
|
|
|
|
|
|
this.prompt = prompt;
|
|
|
|
|
|
|
|
const levelUpStatsContainer = this.scene.add.container(0, 0);
|
|
|
|
levelUpStatsContainer.setVisible(false);
|
|
|
|
ui.add(levelUpStatsContainer);
|
|
|
|
|
|
|
|
this.levelUpStatsContainer = levelUpStatsContainer;
|
|
|
|
|
2023-12-21 03:22:15 +00:00
|
|
|
const levelUpStatsBg = addWindow(this.scene, (this.scene.game.canvas.width / 6), -100, 128, 100);
|
2023-03-28 19:54:52 +01:00
|
|
|
levelUpStatsBg.setOrigin(1, 0);
|
|
|
|
levelUpStatsContainer.add(levelUpStatsBg);
|
|
|
|
|
2023-11-12 17:49:06 +00:00
|
|
|
const levelUpStatsLabelsContent = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 121, -94, '', TextStyle.WINDOW, { maxLines: 6 });
|
2023-03-28 19:54:52 +01:00
|
|
|
let levelUpStatsLabelText = '';
|
|
|
|
|
|
|
|
const stats = Utils.getEnumValues(Stat);
|
|
|
|
for (let s of stats)
|
|
|
|
levelUpStatsLabelText += `${getStatName(s)}\n`;
|
|
|
|
|
|
|
|
levelUpStatsLabelsContent.text = levelUpStatsLabelText;
|
|
|
|
levelUpStatsContainer.add(levelUpStatsLabelsContent);
|
|
|
|
|
|
|
|
const levelUpStatsIncrContent = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 50, -94, '+\n+\n+\n+\n+\n+', TextStyle.WINDOW, { maxLines: 6 });
|
|
|
|
levelUpStatsContainer.add(levelUpStatsIncrContent);
|
|
|
|
|
|
|
|
this.levelUpStatsIncrContent = levelUpStatsIncrContent;
|
|
|
|
|
|
|
|
const levelUpStatsValuesContent = addTextObject(this.scene, (this.scene.game.canvas.width / 6) - 7, -94, '', TextStyle.WINDOW, { maxLines: 6 });
|
|
|
|
levelUpStatsValuesContent.setOrigin(1, 0);
|
2023-06-16 17:13:52 +01:00
|
|
|
levelUpStatsValuesContent.setAlign('right');
|
2023-03-28 19:54:52 +01:00
|
|
|
levelUpStatsContainer.add(levelUpStatsValuesContent);
|
|
|
|
|
|
|
|
this.levelUpStatsValuesContent = levelUpStatsValuesContent;
|
|
|
|
}
|
|
|
|
|
2023-12-30 23:41:25 +00:00
|
|
|
show(args: any[]): boolean {
|
2023-03-28 19:54:52 +01:00
|
|
|
super.show(args);
|
|
|
|
|
2023-12-21 03:22:15 +00:00
|
|
|
this.commandWindow.setVisible(false);
|
|
|
|
this.movesWindowContainer.setVisible(false);
|
2023-03-28 19:54:52 +01:00
|
|
|
this.message.setWordWrapWidth(1780);
|
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();
|
|
|
|
if (this.awaitingActionInput) {
|
2023-04-11 05:24:55 +01:00
|
|
|
if (button === Button.CANCEL || button === Button.ACTION) {
|
2023-03-28 19:54:52 +01:00
|
|
|
if (this.onActionInput) {
|
|
|
|
ui.playSelect();
|
|
|
|
const originalOnActionInput = this.onActionInput;
|
|
|
|
this.onActionInput = null;
|
|
|
|
originalOnActionInput();
|
2023-11-12 05:31:40 +00:00
|
|
|
return true;
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-29 20:05:17 +00:00
|
|
|
clear() {
|
2023-03-28 19:54:52 +01:00
|
|
|
super.clear();
|
|
|
|
}
|
|
|
|
|
2023-10-18 23:01:15 +01:00
|
|
|
showText(text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean, promptDelay?: integer) {
|
|
|
|
this.hideNameText();
|
|
|
|
super.showText(text, delay, callback, callbackDelay, prompt, promptDelay);
|
|
|
|
}
|
|
|
|
|
|
|
|
showDialogue(text: string, name: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean, promptDelay?: integer) {
|
|
|
|
this.showNameText(name);
|
|
|
|
super.showDialogue(text, name, delay, callback, callbackDelay, prompt, promptDelay);
|
|
|
|
}
|
|
|
|
|
2023-11-12 17:49:06 +00:00
|
|
|
promptLevelUpStats(partyMemberIndex: integer, prevStats: integer[], showTotals: boolean): Promise<void> {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
if (!this.scene.showLevelUpStats)
|
|
|
|
return resolve();
|
|
|
|
const newStats = (this.scene as BattleScene).getParty()[partyMemberIndex].stats;
|
|
|
|
let levelUpStatsValuesText = '';
|
|
|
|
const stats = Utils.getEnumValues(Stat);
|
|
|
|
for (let s of stats)
|
|
|
|
levelUpStatsValuesText += `${showTotals ? newStats[s] : newStats[s] - prevStats[s]}\n`;
|
|
|
|
this.levelUpStatsValuesContent.text = levelUpStatsValuesText;
|
|
|
|
this.levelUpStatsIncrContent.setVisible(!showTotals);
|
|
|
|
this.levelUpStatsContainer.setVisible(true);
|
|
|
|
this.awaitingActionInput = true;
|
|
|
|
this.onActionInput = () => {
|
|
|
|
if (!showTotals)
|
|
|
|
return this.promptLevelUpStats(partyMemberIndex, null, true).then(() => resolve());
|
|
|
|
else {
|
|
|
|
this.levelUpStatsContainer.setVisible(false);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
promptIvs(pokemonId: integer, ivs: integer[], shownIvsCount: integer): Promise<void> {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
this.scene.executeWithSeedOffset(() => {
|
|
|
|
let levelUpStatsValuesText = '';
|
|
|
|
const stats = Utils.getEnumValues(Stat);
|
|
|
|
let shownStats: Stat[] = [];
|
|
|
|
if (shownIvsCount < 6) {
|
|
|
|
let statsPool = stats.slice(0);
|
|
|
|
for (let i = 0; i < shownIvsCount; i++) {
|
2024-02-17 05:40:03 +00:00
|
|
|
const shownStat = Utils.randSeedItem(statsPool);
|
2023-11-12 17:49:06 +00:00
|
|
|
shownStats.push(shownStat);
|
|
|
|
statsPool.splice(statsPool.indexOf(shownStat), 1);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
shownStats = stats;
|
|
|
|
for (let s of stats)
|
|
|
|
levelUpStatsValuesText += `${shownStats.indexOf(s) > -1 ? this.getIvDescriptor(ivs[s]) : '???'}\n`;
|
|
|
|
this.levelUpStatsValuesContent.text = levelUpStatsValuesText;
|
|
|
|
this.levelUpStatsIncrContent.setVisible(false);
|
|
|
|
this.levelUpStatsContainer.setVisible(true);
|
|
|
|
this.awaitingActionInput = true;
|
|
|
|
this.onActionInput = () => {
|
|
|
|
this.levelUpStatsContainer.setVisible(false);
|
|
|
|
resolve();
|
|
|
|
};
|
|
|
|
}, pokemonId);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getIvDescriptor(value: integer): string {
|
|
|
|
if (value > 30)
|
2023-11-13 04:47:04 +00:00
|
|
|
return 'Best';
|
2023-11-12 17:49:06 +00:00
|
|
|
if (value === 30)
|
|
|
|
return 'Fantastic';
|
|
|
|
if (value > 20)
|
|
|
|
return 'Very Good';
|
|
|
|
if (value > 10)
|
|
|
|
return 'Pretty Good';
|
|
|
|
if (value)
|
|
|
|
return 'Decent';
|
|
|
|
return 'No Good';
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
2023-10-18 23:01:15 +01:00
|
|
|
|
|
|
|
showNameText(name: string): void {
|
|
|
|
this.nameBoxContainer.setVisible(true);
|
|
|
|
this.nameText.setText(name);
|
2024-03-21 04:57:28 +00:00
|
|
|
this.nameBox.width = this.nameText.displayWidth + 16;
|
2023-10-18 23:01:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hideNameText(): void {
|
|
|
|
this.nameBoxContainer.setVisible(false);
|
|
|
|
}
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|