pokerogue/src/ui/confirm-ui-handler.ts
Greenlamp2 d98f7733d4
Rework - Inputs management to include all gamepad mapping V2 (#429)
* rework of the input handling, including different gamepad and keyboard

* rework of the input handling, including different gamepad and keyboard

* first version of a too complex inputHandler based on phaser3-merged-input

* removed useless control management and kept it simple for our use case, investigating to put out button_XX()

* renamed inputHandler to inputController

* aggregate directions and some action into a same method + fix menu return value

* added back repeated input feature on keeping down a key

* cleanup + return type

* fix submit/action doing two things simultaneously, still same behaviour as before

* extracted UI inputs out of battle-scene

* tab -> spaces

* tab -> spaces what about now github ?

* tab -> spaces final (maybe)

* tried to fix the plugin loading issue on prod

* remove Plugins things as it's too uncertain how it works on prod

* seems old code source is indented with tab

* cleanup

* cleanup

* cleanup

* putting in an enum file the enum buttons

* fix repeating stats button + change message in event when the key is repeating

* added return type for ui-inputs

* added return type for inputs-controller

* adapted the code to integrate changes of bennybroseph
2024-05-05 10:30:00 -04:00

73 lines
2.0 KiB
TypeScript

import BattleScene from "../battle-scene";
import AbstractOptionSelectUiHandler, { OptionSelectConfig } from "./abstact-option-select-ui-handler";
import { Mode } from "./ui";
import i18next from "i18next";
import {Button} from "../enums/buttons";
export default class ConfirmUiHandler extends AbstractOptionSelectUiHandler {
private switchCheck: boolean;
private switchCheckCursor: integer;
constructor(scene: BattleScene) {
super(scene, Mode.CONFIRM);
}
getWindowWidth(): integer {
return 48;
}
show(args: any[]): boolean {
if (args.length >= 2 && args[0] instanceof Function && args[1] instanceof Function) {
const config: OptionSelectConfig = {
options: [
{
label: i18next.t("menu:yes"),
handler: () => {
args[0]();
return true;
}
},
{
label: i18next.t("menu:no"),
handler: () => {
args[1]();
return true;
}
}
],
delay: args.length >= 6 && args[5] !== null ? args[5] as integer : 0
};
super.show([ config ]);
this.switchCheck = args.length >= 3 && args[2] !== null && args[2] as boolean;
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);
this.optionSelectContainer.setPosition((this.scene.game.canvas.width / 6) - 1 + xOffset, -48 + yOffset);
this.setCursor(this.switchCheck ? this.switchCheckCursor : 0);
return true;
}
return false;
}
processInput(button: Button): boolean {
if (button === Button.CANCEL && this.blockInput)
this.unblockInput();
return super.processInput(button);
}
setCursor(cursor: integer): boolean {
const ret = super.setCursor(cursor);
if (ret && this.switchCheck)
this.switchCheckCursor = this.cursor;
return ret;
}
}