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";
|
2023-04-07 03:24:13 +01:00
|
|
|
import { Mode } from "./ui";
|
|
|
|
import UiHandler from "./uiHandler";
|
|
|
|
|
|
|
|
export default class ConfirmUiHandler extends UiHandler {
|
|
|
|
private yesHandler: Function;
|
|
|
|
private noHander: Function;
|
|
|
|
|
|
|
|
private confirmContainer: Phaser.GameObjects.Container;
|
|
|
|
private confirmBg: Phaser.GameObjects.Image;
|
|
|
|
|
|
|
|
private cursorObj: Phaser.GameObjects.Image;
|
|
|
|
|
|
|
|
private switchCheck: boolean;
|
|
|
|
private switchCheckCursor: integer;
|
|
|
|
|
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, Mode.CONFIRM);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
this.confirmContainer = this.scene.add.container((this.scene.game.canvas.width / 6) - 49, -49);
|
|
|
|
this.confirmContainer.setVisible(false);
|
|
|
|
ui.add(this.confirmContainer);
|
|
|
|
|
|
|
|
this.confirmBg = this.scene.add.image(0, 0, 'boolean_window');
|
|
|
|
this.confirmBg.setOrigin(0, 1);
|
|
|
|
this.confirmContainer.add(this.confirmBg);
|
|
|
|
|
|
|
|
const confirmText = addTextObject(this.scene, 0, 0, 'Yes\nNo', TextStyle.WINDOW, { maxLines: 2 });
|
|
|
|
confirmText.setPositionRelative(this.confirmBg, 16, 9);
|
|
|
|
confirmText.setLineSpacing(12);
|
|
|
|
this.confirmContainer.add(confirmText);
|
|
|
|
|
|
|
|
this.setCursor(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
show(args: any[]) {
|
|
|
|
if (args.length >= 2 && args[0] instanceof Function && args[1] instanceof Function) {
|
|
|
|
super.show(args);
|
|
|
|
|
|
|
|
this.yesHandler = args[0] as Function;
|
|
|
|
this.noHander = args[1] as Function;
|
|
|
|
this.switchCheck = args.length >= 3 && args[2] as boolean;
|
|
|
|
|
|
|
|
this.confirmContainer.setVisible(true);
|
|
|
|
this.setCursor(this.switchCheck ? this.switchCheckCursor : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
processInput(button: Button) {
|
2023-04-07 03:24:13 +01:00
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
let success = false;
|
|
|
|
|
2023-04-11 05:24:55 +01:00
|
|
|
if (button === Button.ACTION || button === Button.CANCEL) {
|
2023-04-07 03:24:13 +01:00
|
|
|
success = true;
|
2023-04-11 05:24:55 +01:00
|
|
|
if (button === Button.CANCEL)
|
2023-04-07 03:24:13 +01:00
|
|
|
this.setCursor(1);
|
|
|
|
const handler = this.cursor ? this.noHander : this.yesHandler;
|
|
|
|
handler();
|
|
|
|
this.clear();
|
|
|
|
} else {
|
2023-04-11 05:24:55 +01:00
|
|
|
switch (button) {
|
|
|
|
case Button.UP:
|
2023-04-07 03:24:13 +01:00
|
|
|
if (this.cursor)
|
|
|
|
success = this.setCursor(0);
|
|
|
|
break;
|
2023-04-11 05:24:55 +01:00
|
|
|
case Button.DOWN:
|
2023-04-07 03:24:13 +01:00
|
|
|
if (!this.cursor)
|
|
|
|
success = this.setCursor(1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
ui.playSelect();
|
|
|
|
}
|
|
|
|
|
|
|
|
setCursor(cursor: integer): boolean {
|
|
|
|
const ret = super.setCursor(cursor);
|
|
|
|
|
|
|
|
if (ret && this.switchCheck)
|
|
|
|
this.switchCheckCursor = this.cursor;
|
|
|
|
|
|
|
|
if (!this.cursorObj) {
|
|
|
|
this.cursorObj = this.scene.add.image(0, 0, 'cursor');
|
|
|
|
this.confirmContainer.add(this.cursorObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.cursorObj.setPositionRelative(this.confirmBg, 12, this.cursor ? 33 : 17);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
super.clear();
|
|
|
|
this.yesHandler = null;
|
|
|
|
this.noHander = null;
|
|
|
|
this.confirmContainer.setVisible(false);
|
|
|
|
this.eraseCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
eraseCursor() {
|
|
|
|
if (this.cursorObj)
|
|
|
|
this.cursorObj.destroy();
|
|
|
|
this.cursorObj = null;
|
|
|
|
}
|
|
|
|
}
|