2023-04-05 13:35:15 +01:00
|
|
|
import BattleScene from "../battle-scene";
|
|
|
|
import { Mode } from "./ui";
|
|
|
|
import UiHandler from "./uiHandler";
|
2023-04-06 16:30:22 +01:00
|
|
|
import * as Utils from "../utils";
|
2023-04-05 13:35:15 +01:00
|
|
|
|
2023-04-06 15:05:12 +01:00
|
|
|
enum Page {
|
|
|
|
PROFILE,
|
|
|
|
MOVES
|
|
|
|
}
|
|
|
|
|
2023-04-05 13:35:15 +01:00
|
|
|
export default class SummaryUiHandler extends UiHandler {
|
|
|
|
private summaryContainer: Phaser.GameObjects.Container;
|
2023-04-06 16:30:22 +01:00
|
|
|
private summaryPageContainer: Phaser.GameObjects.Container;
|
|
|
|
private summaryPageBg: Phaser.GameObjects.Sprite;
|
|
|
|
private summaryPageTransitionContainer: Phaser.GameObjects.Container;
|
|
|
|
private summaryPageTransitionBg: Phaser.GameObjects.Sprite;
|
2023-04-06 15:05:12 +01:00
|
|
|
|
2023-04-06 16:30:22 +01:00
|
|
|
private transitioning: boolean;
|
2023-04-05 13:35:15 +01:00
|
|
|
|
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, Mode.SUMMARY);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
this.summaryContainer = this.scene.add.container(0, 0);
|
|
|
|
this.summaryContainer.setVisible(false);
|
|
|
|
ui.add(this.summaryContainer);
|
|
|
|
|
|
|
|
const summaryBg = this.scene.add.image(0, 0, 'summary_bg');
|
2023-04-06 15:05:12 +01:00
|
|
|
summaryBg.setOrigin(0, 1);
|
2023-04-05 13:35:15 +01:00
|
|
|
this.summaryContainer.add(summaryBg);
|
|
|
|
|
2023-04-06 16:30:22 +01:00
|
|
|
const getSummaryPageBg = () => {
|
|
|
|
const ret = this.scene.add.sprite(0, 0, this.getPageKey(0));
|
|
|
|
ret.setOrigin(0, 1);
|
|
|
|
ret.setVisible(false);
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.summaryPageContainer = this.scene.add.container(106, 0);
|
|
|
|
this.summaryPageContainer.add((this.summaryPageBg = getSummaryPageBg()));
|
|
|
|
this.summaryPageTransitionContainer = this.scene.add.container(106, 0);
|
|
|
|
this.summaryPageTransitionContainer.add((this.summaryPageTransitionBg = getSummaryPageBg()));
|
2023-04-06 15:05:12 +01:00
|
|
|
}
|
|
|
|
|
2023-04-06 16:30:22 +01:00
|
|
|
getPageKey(page?: integer) {
|
|
|
|
if (page === undefined)
|
|
|
|
page = this.cursor;
|
|
|
|
return `summary_${Page[page].toLowerCase()}`;
|
2023-04-05 13:35:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
show(args: any[]) {
|
|
|
|
super.show(args);
|
|
|
|
|
|
|
|
this.summaryContainer.setVisible(true);
|
2023-04-06 16:30:22 +01:00
|
|
|
this.cursor = -1;
|
|
|
|
this.setCursor(args.length ? args[0] as Page : 0);
|
2023-04-05 13:35:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
processInput(keyCode: integer) {
|
2023-04-06 16:30:22 +01:00
|
|
|
if (this.transitioning)
|
|
|
|
return;
|
|
|
|
|
2023-04-05 13:35:15 +01:00
|
|
|
const ui = this.getUi();
|
|
|
|
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
|
2023-04-06 15:05:12 +01:00
|
|
|
|
2023-04-06 16:30:22 +01:00
|
|
|
let success = false;
|
|
|
|
|
2023-04-06 15:05:12 +01:00
|
|
|
if (keyCode === keyCodes.X) {
|
|
|
|
ui.setMode(Mode.PARTY);
|
2023-04-06 16:30:22 +01:00
|
|
|
success = true;
|
|
|
|
} else {
|
|
|
|
const pages = Utils.getEnumValues(Page);
|
|
|
|
switch (keyCode) {
|
|
|
|
case keyCodes.LEFT:
|
|
|
|
if (this.cursor)
|
|
|
|
success = this.setCursor(this.cursor - 1);
|
|
|
|
break;
|
|
|
|
case keyCodes.RIGHT:
|
|
|
|
if (this.cursor < pages.length - 1)
|
|
|
|
success = this.setCursor(this.cursor + 1);
|
|
|
|
break;
|
|
|
|
}
|
2023-04-06 15:05:12 +01:00
|
|
|
}
|
2023-04-06 16:30:22 +01:00
|
|
|
|
|
|
|
if (success)
|
|
|
|
ui.playSelect();
|
2023-04-05 13:35:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setCursor(cursor: integer): boolean {
|
|
|
|
const changed = this.cursor !== cursor;
|
|
|
|
if (changed) {
|
2023-04-06 16:30:22 +01:00
|
|
|
const forward = this.cursor < cursor;
|
|
|
|
this.cursor = cursor;
|
|
|
|
|
|
|
|
if (this.summaryPageContainer.visible) {
|
|
|
|
this.transitioning = true;
|
|
|
|
this.populatePageContainer(this.summaryPageTransitionContainer, forward ? cursor : cursor + 1);
|
|
|
|
if (forward)
|
|
|
|
this.summaryPageTransitionContainer.x += 214;
|
|
|
|
else
|
|
|
|
this.populatePageContainer(this.summaryPageContainer);
|
|
|
|
this.scene.tweens.add({
|
|
|
|
targets: this.summaryPageTransitionContainer,
|
|
|
|
x: forward ? '-=214' : '+=214',
|
|
|
|
duration: 250,
|
|
|
|
onComplete: () => {
|
|
|
|
if (forward)
|
|
|
|
this.populatePageContainer(this.summaryPageContainer);
|
|
|
|
else
|
|
|
|
this.summaryPageTransitionContainer.x -= 214;
|
|
|
|
this.summaryPageTransitionContainer.setVisible(false);
|
|
|
|
this.transitioning = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.summaryPageTransitionContainer.setVisible(true);
|
|
|
|
} else {
|
|
|
|
this.populatePageContainer(this.summaryPageContainer);
|
|
|
|
this.summaryPageContainer.setVisible(true);
|
|
|
|
}
|
2023-04-05 13:35:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2023-04-06 16:30:22 +01:00
|
|
|
populatePageContainer(pageContainer: Phaser.GameObjects.Container, page?: Page) {
|
|
|
|
if (page === undefined)
|
|
|
|
page = this.cursor;
|
|
|
|
|
|
|
|
if (pageContainer.getAll().length > 1)
|
|
|
|
pageContainer.removeBetween(1, undefined, true);
|
|
|
|
(pageContainer.getAt(0) as Phaser.GameObjects.Sprite).setTexture(this.getPageKey(page));
|
|
|
|
|
|
|
|
switch (page) {
|
|
|
|
case Page.MOVES:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-05 13:35:15 +01:00
|
|
|
clear() {
|
|
|
|
super.clear();
|
2023-04-06 16:30:22 +01:00
|
|
|
this.cursor = -1;
|
2023-04-05 13:35:15 +01:00
|
|
|
this.summaryContainer.setVisible(false);
|
2023-04-06 16:30:22 +01:00
|
|
|
this.summaryPageContainer.setVisible(false);
|
2023-04-05 13:35:15 +01:00
|
|
|
}
|
|
|
|
}
|