2024-05-05 15:30:00 +01:00
|
|
|
import BattleScene from "../battle-scene";
|
2024-01-11 17:26:32 +00:00
|
|
|
import AbstractOptionSelectUiHandler, { OptionSelectConfig } from "./abstact-option-select-ui-handler";
|
2023-04-07 03:24:13 +01:00
|
|
|
import { Mode } from "./ui";
|
2024-05-03 22:52:09 +01:00
|
|
|
import i18next from "i18next";
|
2024-05-05 15:30:00 +01:00
|
|
|
import {Button} from "../enums/buttons";
|
2023-04-07 03:24:13 +01:00
|
|
|
|
2023-11-14 03:29:03 +00:00
|
|
|
export default class ConfirmUiHandler extends AbstractOptionSelectUiHandler {
|
2023-04-07 03:24:13 +01:00
|
|
|
private switchCheck: boolean;
|
|
|
|
private switchCheckCursor: integer;
|
|
|
|
|
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, Mode.CONFIRM);
|
|
|
|
}
|
|
|
|
|
2023-06-16 17:13:52 +01:00
|
|
|
getWindowWidth(): integer {
|
|
|
|
return 48;
|
2023-06-01 00:54:57 +01:00
|
|
|
}
|
2023-04-07 03:24:13 +01:00
|
|
|
|
2023-12-30 23:41:25 +00:00
|
|
|
show(args: any[]): boolean {
|
2023-04-07 03:24:13 +01:00
|
|
|
if (args.length >= 2 && args[0] instanceof Function && args[1] instanceof Function) {
|
2024-01-11 17:26:32 +00:00
|
|
|
const config: OptionSelectConfig = {
|
|
|
|
options: [
|
|
|
|
{
|
2024-05-03 22:52:09 +01:00
|
|
|
label: i18next.t("menu:yes"),
|
2024-04-13 23:59:58 +01:00
|
|
|
handler: () => {
|
|
|
|
args[0]();
|
|
|
|
return true;
|
|
|
|
}
|
2024-01-11 17:26:32 +00:00
|
|
|
},
|
|
|
|
{
|
2024-05-03 22:52:09 +01:00
|
|
|
label: i18next.t("menu:no"),
|
2024-04-13 23:59:58 +01:00
|
|
|
handler: () => {
|
|
|
|
args[1]();
|
|
|
|
return true;
|
|
|
|
}
|
2024-01-11 17:26:32 +00:00
|
|
|
}
|
2024-04-04 20:22:05 +01:00
|
|
|
],
|
|
|
|
delay: args.length >= 6 && args[5] !== null ? args[5] as integer : 0
|
2024-01-11 17:26:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
super.show([ config ]);
|
2023-04-07 03:24:13 +01:00
|
|
|
|
2024-02-07 04:11:00 +00:00
|
|
|
this.switchCheck = args.length >= 3 && args[2] !== null && args[2] as boolean;
|
2023-04-07 03:24:13 +01:00
|
|
|
|
2024-02-07 04:11:00 +00:00
|
|
|
const xOffset = (args.length >= 4 && args[3] !== null ? args[3] as number : 0);
|
|
|
|
const yOffset = (args.length >= 5 && args[4] !== null ? args[4] as number : 0);
|
2023-12-26 19:49:23 +00:00
|
|
|
|
2024-02-07 04:11:00 +00:00
|
|
|
this.optionSelectContainer.setPosition((this.scene.game.canvas.width / 6) - 1 + xOffset, -48 + yOffset);
|
2023-12-26 19:49:23 +00:00
|
|
|
|
2023-04-07 03:24:13 +01:00
|
|
|
this.setCursor(this.switchCheck ? this.switchCheckCursor : 0);
|
2023-12-30 23:41:25 +00:00
|
|
|
|
|
|
|
return true;
|
2023-04-07 03:24:13 +01:00
|
|
|
}
|
2023-12-30 23:41:25 +00:00
|
|
|
|
|
|
|
return false;
|
2023-04-07 03:24:13 +01:00
|
|
|
}
|
|
|
|
|
2024-04-07 15:28:23 +01:00
|
|
|
processInput(button: Button): boolean {
|
|
|
|
if (button === Button.CANCEL && this.blockInput)
|
|
|
|
this.unblockInput();
|
|
|
|
|
|
|
|
return super.processInput(button);
|
|
|
|
}
|
|
|
|
|
2023-04-07 03:24:13 +01:00
|
|
|
setCursor(cursor: integer): boolean {
|
|
|
|
const ret = super.setCursor(cursor);
|
|
|
|
|
|
|
|
if (ret && this.switchCheck)
|
|
|
|
this.switchCheckCursor = this.cursor;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|