pokerogue/src/ui/autocomplete-ui-handler.ts
Sirz Benjie 5854b21da0
[Refactor] Remove circular imports part 1 (#5663)
* Extract Mode enum out of UI and into its own file

Reduces circular imports from 909 to 773

* Move around utility files

Reduces cyclical dependencies from 773 to 765

* Remove starterColors and bypassLogin from battle-scene

Reduces cyclical dependencies from 765 to 623

* Fix test runner error

* Update import for bypassLogin in test

* Update mocks for utils in tests

* Fix broken tests

* Update selectWithTera override

* Update path for utils in ab-attr.ts

* Update path for utils in ability-class.ts

* Fix utils import path in healer.test.ts
2025-04-19 11:57:03 +00:00

52 lines
1.7 KiB
TypeScript

import { Button } from "#enums/buttons";
import AbstractOptionSelectUiHandler from "./abstact-option-select-ui-handler";
import { UiMode } from "#enums/ui-mode";
export default class AutoCompleteUiHandler extends AbstractOptionSelectUiHandler {
modalContainer: Phaser.GameObjects.Container;
constructor(mode: UiMode = UiMode.OPTION_SELECT) {
super(mode);
}
getWindowWidth(): number {
return 64;
}
show(args: any[]): boolean {
if (args[0].modalContainer) {
const { modalContainer } = args[0];
const show = super.show(args);
this.modalContainer = modalContainer;
this.setupOptions();
return show;
}
return false;
}
protected setupOptions() {
super.setupOptions();
if (this.modalContainer) {
this.optionSelectContainer.setSize(
this.optionSelectContainer.height,
Math.max(this.optionSelectText.displayWidth + 24, this.getWindowWidth()),
);
this.optionSelectContainer.setPositionRelative(
this.modalContainer,
this.optionSelectBg.width,
this.optionSelectBg.height + 50,
);
}
}
processInput(button: Button): boolean {
// the cancel and action button are here because if you're typing, x and z are used for cancel/action. This means you could be typing something and accidentally cancel/select when you don't mean to
// the submit button is therefore used to select a choice (the enter button), though this does not work on my local dev testing for phones, as for my phone/keyboard combo, the enter and z key are both
// bound to Button.ACTION, which makes this not work on mobile
if (button !== Button.CANCEL && button !== Button.ACTION) {
return super.processInput(button);
}
return false;
}
}