2023-12-20 04:51:48 +00:00
|
|
|
import BattleScene, { Button } from "../battle-scene";
|
|
|
|
import { Mode } from "./ui";
|
2024-03-01 01:08:50 +00:00
|
|
|
import PokemonIconAnimHandler, { PokemonIconAnimMode } from "./pokemon-icon-anim-handler";
|
2023-12-20 04:51:48 +00:00
|
|
|
import { TextStyle, addTextObject } from "./text";
|
|
|
|
import MessageUiHandler from "./message-ui-handler";
|
|
|
|
import { EGG_SEED, Egg, GachaType, getEggGachaTypeDescriptor, getEggHatchWavesMessage, getEggDescriptor } from "../data/egg";
|
|
|
|
import * as Utils from "../utils";
|
2023-12-21 03:22:15 +00:00
|
|
|
import { addWindow } from "./window";
|
2023-12-20 04:51:48 +00:00
|
|
|
|
|
|
|
export default class EggListUiHandler extends MessageUiHandler {
|
|
|
|
private eggListContainer: Phaser.GameObjects.Container;
|
|
|
|
private eggListIconContainer: Phaser.GameObjects.Container;
|
|
|
|
private eggSprite: Phaser.GameObjects.Sprite;
|
|
|
|
private eggNameText: Phaser.GameObjects.Text;
|
|
|
|
private eggDateText: Phaser.GameObjects.Text;
|
|
|
|
private eggHatchWavesText: Phaser.GameObjects.Text;
|
|
|
|
private eggGachaInfoText: Phaser.GameObjects.Text;
|
|
|
|
private eggListMessageBoxContainer: Phaser.GameObjects.Container;
|
|
|
|
|
|
|
|
private cursorObj: Phaser.GameObjects.Image;
|
|
|
|
|
|
|
|
private iconAnimHandler: PokemonIconAnimHandler;
|
|
|
|
|
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, Mode.EGG_LIST);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
this.eggListContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6);
|
|
|
|
this.eggListContainer.setVisible(false);
|
|
|
|
ui.add(this.eggListContainer);
|
|
|
|
|
|
|
|
const bgColor = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0x006860);
|
|
|
|
bgColor.setOrigin(0, 0);
|
|
|
|
this.eggListContainer.add(bgColor);
|
|
|
|
|
2024-03-31 21:49:53 +01:00
|
|
|
const eggListBg = this.scene.add.image(0, 0, 'egg_list_bg');
|
2023-12-22 04:57:11 +00:00
|
|
|
eggListBg.setOrigin(0, 0);
|
|
|
|
this.eggListContainer.add(eggListBg);
|
2023-12-20 04:51:48 +00:00
|
|
|
|
2023-12-21 03:22:15 +00:00
|
|
|
this.eggListContainer.add(addWindow(this.scene, 1, 85, 106, 22));
|
|
|
|
this.eggListContainer.add(addWindow(this.scene, 1, 102, 106, 50, true));
|
|
|
|
this.eggListContainer.add(addWindow(this.scene, 1, 147, 106, 32, true));
|
|
|
|
this.eggListContainer.add(addWindow(this.scene, 107, 1, 212, 178));
|
|
|
|
|
2023-12-20 04:51:48 +00:00
|
|
|
this.iconAnimHandler = new PokemonIconAnimHandler();
|
|
|
|
this.iconAnimHandler.setup(this.scene);
|
|
|
|
|
2024-03-31 21:49:53 +01:00
|
|
|
this.eggNameText = addTextObject(this.scene, 8, 66, '', TextStyle.SUMMARY);
|
2023-12-20 04:51:48 +00:00
|
|
|
this.eggNameText.setOrigin(0, 0);
|
|
|
|
this.eggListContainer.add(this.eggNameText);
|
|
|
|
|
|
|
|
this.eggDateText = addTextObject(this.scene, 8, 91, '', TextStyle.TOOLTIP_CONTENT);
|
|
|
|
this.eggListContainer.add(this.eggDateText);
|
|
|
|
|
|
|
|
this.eggHatchWavesText = addTextObject(this.scene, 8, 108, '', TextStyle.TOOLTIP_CONTENT);
|
|
|
|
this.eggHatchWavesText.setWordWrapWidth(540);
|
|
|
|
this.eggListContainer.add(this.eggHatchWavesText);
|
|
|
|
|
|
|
|
this.eggGachaInfoText = addTextObject(this.scene, 8, 152, '', TextStyle.TOOLTIP_CONTENT);
|
|
|
|
this.eggGachaInfoText.setWordWrapWidth(540);
|
|
|
|
this.eggListContainer.add(this.eggGachaInfoText);
|
|
|
|
|
|
|
|
this.eggListIconContainer = this.scene.add.container(115, 9);
|
|
|
|
this.eggListContainer.add(this.eggListIconContainer);
|
|
|
|
|
2024-03-16 01:59:34 +00:00
|
|
|
this.cursorObj = this.scene.add.image(0, 0, 'select_cursor');
|
2023-12-20 04:51:48 +00:00
|
|
|
this.cursorObj.setOrigin(0, 0);
|
|
|
|
this.eggListContainer.add(this.cursorObj);
|
|
|
|
|
|
|
|
this.eggSprite = this.scene.add.sprite(54, 37, `egg`);
|
|
|
|
this.eggListContainer.add(this.eggSprite);
|
|
|
|
|
|
|
|
this.eggListMessageBoxContainer = this.scene.add.container(0, this.scene.game.canvas.height / 6);
|
|
|
|
this.eggListMessageBoxContainer.setVisible(false);
|
|
|
|
this.eggListContainer.add(this.eggListMessageBoxContainer);
|
|
|
|
|
2023-12-22 04:57:11 +00:00
|
|
|
const eggListMessageBox = addWindow(this.scene, 1, -1, 318, 28);
|
|
|
|
eggListMessageBox.setOrigin(0, 1);
|
|
|
|
this.eggListMessageBoxContainer.add(eggListMessageBox);
|
2023-12-20 04:51:48 +00:00
|
|
|
|
|
|
|
this.message = addTextObject(this.scene, 8, -8, '', TextStyle.WINDOW, { maxLines: 1 });
|
|
|
|
this.message.setOrigin(0, 1);
|
|
|
|
this.eggListMessageBoxContainer.add(this.message);
|
|
|
|
|
|
|
|
this.cursor = -1;
|
|
|
|
}
|
|
|
|
|
2023-12-30 23:41:25 +00:00
|
|
|
show(args: any[]): boolean {
|
2023-12-20 04:51:48 +00:00
|
|
|
super.show(args);
|
|
|
|
|
2024-01-12 05:09:11 +00:00
|
|
|
this.getUi().bringToTop(this.eggListContainer);
|
|
|
|
|
2023-12-20 04:51:48 +00:00
|
|
|
this.eggListContainer.setVisible(true);
|
|
|
|
|
|
|
|
let e = 0;
|
|
|
|
|
|
|
|
/*this.scene.gameData.eggs = [
|
|
|
|
new Egg(1, 1, 5, new Date().getTime()),
|
|
|
|
new Egg(1 + EGG_SEED, 1, 15, new Date().getTime()),
|
|
|
|
new Egg(1 + EGG_SEED * 2, 1, 50, new Date().getTime()),
|
|
|
|
new Egg(1 + EGG_SEED * 3, GachaType.LEGENDARY, 100, new Date().getTime())
|
|
|
|
];*/
|
|
|
|
|
|
|
|
for (let egg of this.scene.gameData.eggs) {
|
|
|
|
const x = (e % 11) * 18;
|
|
|
|
const y = Math.floor(e / 11) * 18;
|
|
|
|
const icon = this.scene.add.sprite(x - 2, y + 2, 'egg_icons');
|
|
|
|
icon.setScale(0.5);
|
|
|
|
icon.setOrigin(0, 0);
|
|
|
|
icon.setFrame(egg.getKey());
|
|
|
|
this.eggListIconContainer.add(icon);
|
|
|
|
this.iconAnimHandler.addOrUpdate(icon, PokemonIconAnimMode.NONE);
|
|
|
|
e++;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setCursor(0);
|
2023-12-30 23:41:25 +00:00
|
|
|
|
|
|
|
return true;
|
2023-12-20 04:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processInput(button: Button): boolean {
|
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
let success = false;
|
|
|
|
let error = false;
|
|
|
|
|
|
|
|
if (button === Button.CANCEL) {
|
|
|
|
ui.revertMode();
|
|
|
|
success = true;
|
|
|
|
} else {
|
|
|
|
const eggCount = this.eggListIconContainer.getAll().length;
|
|
|
|
const rows = Math.ceil(eggCount / 11);
|
|
|
|
const row = Math.floor(this.cursor / 11);
|
|
|
|
switch (button) {
|
|
|
|
case Button.UP:
|
|
|
|
if (row)
|
|
|
|
success = this.setCursor(this.cursor - 11);
|
|
|
|
break;
|
|
|
|
case Button.DOWN:
|
|
|
|
if (row < rows - 2 || (row < rows - 1 && this.cursor % 11 <= (eggCount - 1) % 11))
|
|
|
|
success = this.setCursor(this.cursor + 11);
|
|
|
|
break;
|
|
|
|
case Button.LEFT:
|
|
|
|
if (this.cursor % 11)
|
|
|
|
success = this.setCursor(this.cursor - 1);
|
|
|
|
break;
|
|
|
|
case Button.RIGHT:
|
|
|
|
if (this.cursor % 11 < (row < rows - 1 ? 10 : (eggCount - 1) % 11))
|
|
|
|
success = this.setCursor(this.cursor + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
ui.playSelect();
|
|
|
|
else if (error)
|
|
|
|
ui.playError();
|
|
|
|
|
|
|
|
return success || error;
|
|
|
|
}
|
|
|
|
|
|
|
|
setEggDetails(egg: Egg): void {
|
|
|
|
this.eggSprite.setFrame(`egg_${egg.getKey()}`);
|
|
|
|
this.eggNameText.setText(`Egg (${getEggDescriptor(egg)})`);
|
|
|
|
this.eggDateText.setText(
|
|
|
|
new Date(egg.timestamp).toLocaleString(undefined, {
|
|
|
|
weekday: 'short',
|
|
|
|
year: 'numeric',
|
|
|
|
month: '2-digit',
|
|
|
|
day: 'numeric'
|
|
|
|
})
|
|
|
|
);
|
|
|
|
this.eggHatchWavesText.setText(getEggHatchWavesMessage(egg.hatchWaves));
|
|
|
|
this.eggGachaInfoText.setText(getEggGachaTypeDescriptor(this.scene, egg));
|
|
|
|
}
|
|
|
|
|
|
|
|
setCursor(cursor: integer): boolean {
|
|
|
|
let changed = false;
|
|
|
|
|
|
|
|
let lastCursor = this.cursor;
|
|
|
|
|
|
|
|
changed = super.setCursor(cursor);
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
this.cursorObj.setPosition(114 + 18 * (cursor % 11), 10 + 18 * Math.floor(cursor / 11));
|
|
|
|
|
|
|
|
if (lastCursor > -1)
|
|
|
|
this.iconAnimHandler.addOrUpdate(this.eggListIconContainer.getAt(lastCursor) as Phaser.GameObjects.Sprite, PokemonIconAnimMode.NONE);
|
|
|
|
this.iconAnimHandler.addOrUpdate(this.eggListIconContainer.getAt(cursor) as Phaser.GameObjects.Sprite, PokemonIconAnimMode.ACTIVE);
|
|
|
|
|
|
|
|
this.setEggDetails(this.scene.gameData.eggs[cursor]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear(): void {
|
|
|
|
super.clear();
|
|
|
|
this.cursor = -1;
|
|
|
|
this.eggListContainer.setVisible(false);
|
|
|
|
this.iconAnimHandler.removeAll();
|
|
|
|
this.eggListIconContainer.removeAll(true);
|
|
|
|
}
|
|
|
|
}
|