2023-04-11 05:24:55 +01:00
|
|
|
import { Button, default as BattleScene } from '../battle-scene';
|
2023-03-28 19:54:52 +01:00
|
|
|
import UiHandler from './uiHandler';
|
|
|
|
import BattleMessageUiHandler from './battle-message-ui-handler';
|
|
|
|
import CommandUiHandler from './command-ui-handler';
|
|
|
|
import PartyUiHandler from './party-ui-handler';
|
|
|
|
import FightUiHandler from './fight-ui-handler';
|
|
|
|
import MessageUiHandler from './message-ui-handler';
|
2023-04-07 03:24:13 +01:00
|
|
|
import ConfirmUiHandler from './confirm-ui-handler';
|
2023-03-28 19:54:52 +01:00
|
|
|
import ModifierSelectUiHandler from './modifier-select-ui-handler';
|
2023-04-02 03:59:07 +01:00
|
|
|
import BallUiHandler from './ball-ui-handler';
|
2023-04-05 13:35:15 +01:00
|
|
|
import SummaryUiHandler from './summary-ui-handler';
|
2023-04-10 00:15:21 +01:00
|
|
|
import StarterSelectUiHandler from './starter-select-ui-handler';
|
2023-04-10 18:54:06 +01:00
|
|
|
import EvolutionSceneHandler from './evolution-scene-handler';
|
2023-04-12 05:37:56 +01:00
|
|
|
import BiomeSelectUiHandler from './biome-select-ui-handler';
|
2023-03-28 19:54:52 +01:00
|
|
|
|
|
|
|
export enum Mode {
|
|
|
|
MESSAGE = 0,
|
|
|
|
COMMAND,
|
|
|
|
FIGHT,
|
2023-04-02 03:59:07 +01:00
|
|
|
BALL,
|
2023-03-28 19:54:52 +01:00
|
|
|
MODIFIER_SELECT,
|
2023-04-05 13:35:15 +01:00
|
|
|
PARTY,
|
2023-04-10 00:15:21 +01:00
|
|
|
SUMMARY,
|
2023-04-12 05:37:56 +01:00
|
|
|
BIOME_SELECT,
|
2023-04-10 18:54:06 +01:00
|
|
|
STARTER_SELECT,
|
2023-04-13 00:09:15 +01:00
|
|
|
EVOLUTION_SCENE,
|
|
|
|
CONFIRM
|
2023-03-28 19:54:52 +01:00
|
|
|
};
|
|
|
|
|
2023-04-07 03:24:13 +01:00
|
|
|
const transitionModes = [
|
|
|
|
Mode.PARTY,
|
2023-04-10 00:15:21 +01:00
|
|
|
Mode.SUMMARY,
|
|
|
|
Mode.STARTER_SELECT,
|
2023-04-10 18:54:06 +01:00
|
|
|
Mode.EVOLUTION_SCENE
|
|
|
|
];
|
|
|
|
|
|
|
|
const noTransitionModes = [
|
|
|
|
Mode.CONFIRM
|
2023-04-07 03:24:13 +01:00
|
|
|
];
|
|
|
|
|
2023-03-28 19:54:52 +01:00
|
|
|
export default class UI extends Phaser.GameObjects.Container {
|
|
|
|
private mode: Mode;
|
|
|
|
private handlers: UiHandler[];
|
2023-04-07 03:24:13 +01:00
|
|
|
private overlay: Phaser.GameObjects.Rectangle;
|
2023-04-07 05:17:55 +01:00
|
|
|
|
|
|
|
private transitioning: boolean;
|
2023-03-28 19:54:52 +01:00
|
|
|
|
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, 0, scene.game.canvas.height / 6);
|
|
|
|
|
|
|
|
this.mode = Mode.MESSAGE;
|
|
|
|
this.handlers = [
|
|
|
|
new BattleMessageUiHandler(scene),
|
|
|
|
new CommandUiHandler(scene),
|
|
|
|
new FightUiHandler(scene),
|
2023-04-02 03:59:07 +01:00
|
|
|
new BallUiHandler(scene),
|
2023-03-28 19:54:52 +01:00
|
|
|
new ModifierSelectUiHandler(scene),
|
2023-04-05 13:35:15 +01:00
|
|
|
new PartyUiHandler(scene),
|
2023-04-10 00:15:21 +01:00
|
|
|
new SummaryUiHandler(scene),
|
2023-04-12 05:37:56 +01:00
|
|
|
new BiomeSelectUiHandler(scene),
|
2023-04-10 18:54:06 +01:00
|
|
|
new StarterSelectUiHandler(scene),
|
2023-04-13 00:09:15 +01:00
|
|
|
new EvolutionSceneHandler(scene),
|
|
|
|
new ConfirmUiHandler(scene)
|
2023-03-28 19:54:52 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-04-07 05:17:55 +01:00
|
|
|
setup(): void {
|
2023-03-28 19:54:52 +01:00
|
|
|
for (let handler of this.handlers) {
|
|
|
|
handler.setup();
|
|
|
|
}
|
2023-04-07 03:24:13 +01:00
|
|
|
this.overlay = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0);
|
|
|
|
this.overlay.setOrigin(0, 0);
|
|
|
|
(this.scene as BattleScene).uiContainer.add(this.overlay);
|
|
|
|
this.overlay.setVisible(false);
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-07 05:17:55 +01:00
|
|
|
getHandler(): UiHandler {
|
2023-03-28 19:54:52 +01:00
|
|
|
return this.handlers[this.mode];
|
|
|
|
}
|
|
|
|
|
2023-04-07 05:17:55 +01:00
|
|
|
getMessageHandler(): BattleMessageUiHandler {
|
2023-03-28 19:54:52 +01:00
|
|
|
return this.handlers[Mode.MESSAGE] as BattleMessageUiHandler;
|
|
|
|
}
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
processInput(button: Button): void {
|
2023-04-07 05:17:55 +01:00
|
|
|
if (this.transitioning)
|
|
|
|
return;
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
this.getHandler().processInput(button);
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-10 18:54:06 +01:00
|
|
|
showText(text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean, promptDelay?: integer): void {
|
2023-03-28 19:54:52 +01:00
|
|
|
const handler = this.getHandler();
|
|
|
|
if (handler instanceof MessageUiHandler)
|
2023-04-10 18:54:06 +01:00
|
|
|
(handler as MessageUiHandler).showText(text, delay, callback, callbackDelay, prompt, promptDelay);
|
2023-03-28 19:54:52 +01:00
|
|
|
else
|
2023-04-10 18:54:06 +01:00
|
|
|
this.getMessageHandler().showText(text, delay, callback, callbackDelay, prompt, promptDelay);
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-07 05:17:55 +01:00
|
|
|
clearText(): void {
|
2023-03-28 19:54:52 +01:00
|
|
|
const handler = this.getHandler();
|
|
|
|
if (handler instanceof MessageUiHandler)
|
|
|
|
(handler as MessageUiHandler).clearText();
|
|
|
|
else
|
|
|
|
this.getMessageHandler().clearText();
|
|
|
|
}
|
|
|
|
|
|
|
|
setCursor(cursor: integer): boolean {
|
|
|
|
const changed = this.getHandler().setCursor(cursor);
|
|
|
|
if (changed)
|
|
|
|
this.playSelect();
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2023-04-07 05:17:55 +01:00
|
|
|
playSelect(): void {
|
2023-03-28 19:54:52 +01:00
|
|
|
this.scene.sound.play('select');
|
|
|
|
}
|
|
|
|
|
2023-04-07 05:17:55 +01:00
|
|
|
playError(): void {
|
2023-03-28 19:54:52 +01:00
|
|
|
this.scene.sound.play('error');
|
|
|
|
}
|
|
|
|
|
2023-04-10 18:54:06 +01:00
|
|
|
private setModeInternal(mode: Mode, clear: boolean, forceTransition: boolean, args: any[]): Promise<void> {
|
2023-04-07 03:24:13 +01:00
|
|
|
return new Promise(resolve => {
|
2023-04-10 18:54:06 +01:00
|
|
|
if (this.mode === mode && !forceTransition) {
|
2023-04-07 03:24:13 +01:00
|
|
|
resolve();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const doSetMode = () => {
|
2023-04-10 18:54:06 +01:00
|
|
|
if (this.mode !== mode) {
|
|
|
|
if (clear)
|
|
|
|
this.getHandler().clear();
|
|
|
|
this.mode = mode;
|
|
|
|
this.getHandler().show(args);
|
|
|
|
}
|
2023-04-07 03:24:13 +01:00
|
|
|
resolve();
|
|
|
|
};
|
2023-04-10 18:54:06 +01:00
|
|
|
if ((transitionModes.indexOf(this.mode) > -1 || transitionModes.indexOf(mode) > -1)
|
|
|
|
&& (noTransitionModes.indexOf(this.mode) === -1 && noTransitionModes.indexOf(mode) === -1) && !(this.scene as BattleScene).auto) {
|
2023-04-07 05:17:55 +01:00
|
|
|
this.transitioning = true;
|
2023-04-07 03:24:13 +01:00
|
|
|
this.overlay.setAlpha(0);
|
|
|
|
this.overlay.setVisible(true);
|
|
|
|
this.scene.tweens.add({
|
|
|
|
targets: this.overlay,
|
|
|
|
alpha: 1,
|
|
|
|
duration: 250,
|
2023-04-07 05:17:55 +01:00
|
|
|
ease: 'Sine.easeOut',
|
2023-04-07 03:24:13 +01:00
|
|
|
onComplete: () => {
|
2023-04-07 05:17:55 +01:00
|
|
|
this.scene.time.delayedCall(100, () => {
|
2023-04-07 03:24:13 +01:00
|
|
|
doSetMode();
|
|
|
|
this.scene.tweens.add({
|
|
|
|
targets: this.overlay,
|
|
|
|
alpha: 0,
|
|
|
|
duration: 250,
|
2023-04-07 05:17:55 +01:00
|
|
|
ease: 'Sine.easeIn',
|
2023-04-07 03:24:13 +01:00
|
|
|
onComplete: () => this.overlay.setVisible(false)
|
|
|
|
});
|
2023-04-07 05:17:55 +01:00
|
|
|
this.transitioning = false;
|
2023-04-07 03:24:13 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
doSetMode();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setMode(mode: Mode, ...args: any[]): Promise<void> {
|
2023-04-10 18:54:06 +01:00
|
|
|
return this.setModeInternal(mode, true, false, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
setModeForceTransition(mode: Mode, ...args: any[]): Promise<void> {
|
|
|
|
return this.setModeInternal(mode, true, true, args);
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
|
2023-04-07 03:24:13 +01:00
|
|
|
setModeWithoutClear(mode: Mode, ...args: any[]): Promise<void> {
|
2023-04-10 18:54:06 +01:00
|
|
|
return this.setModeInternal(mode, false, false, args);
|
2023-03-28 19:54:52 +01:00
|
|
|
}
|
|
|
|
}
|