mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-15 06:15:20 +01:00
* Added `noBannedTypes` as a biome rule * Added `useShorthandAssign` rule * Added `useConsistentArrayType` * Update src/field/pokemon.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Update src/data/pokeball.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * Apply Biome after merge --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import type { PlayerPokemon } from "#field/pokemon";
|
|
import type { InputFieldConfig } from "#ui/form-modal-ui-handler";
|
|
import { FormModalUiHandler } from "#ui/form-modal-ui-handler";
|
|
import type { ModalConfig } from "#ui/modal-ui-handler";
|
|
import i18next from "i18next";
|
|
|
|
export class RenameFormUiHandler extends FormModalUiHandler {
|
|
getModalTitle(_config?: ModalConfig): string {
|
|
return i18next.t("menu:renamePokemon");
|
|
}
|
|
|
|
getWidth(_config?: ModalConfig): number {
|
|
return 160;
|
|
}
|
|
|
|
getMargin(_config?: ModalConfig): [number, number, number, number] {
|
|
return [0, 0, 48, 0];
|
|
}
|
|
|
|
getButtonLabels(_config?: ModalConfig): string[] {
|
|
return [i18next.t("menu:rename"), i18next.t("menu:cancel")];
|
|
}
|
|
|
|
getReadableErrorMessage(error: string): string {
|
|
const colonIndex = error?.indexOf(":");
|
|
if (colonIndex > 0) {
|
|
error = error.slice(0, colonIndex);
|
|
}
|
|
|
|
return super.getReadableErrorMessage(error);
|
|
}
|
|
|
|
override getInputFieldConfigs(): InputFieldConfig[] {
|
|
return [{ label: i18next.t("menu:nickname") }];
|
|
}
|
|
|
|
show(args: any[]): boolean {
|
|
if (super.show(args)) {
|
|
const config = args[0] as ModalConfig;
|
|
if (args[1] && typeof (args[1] as PlayerPokemon).getNameToRender === "function") {
|
|
this.inputs[0].text = (args[1] as PlayerPokemon).getNameToRender(false);
|
|
} else {
|
|
this.inputs[0].text = args[1];
|
|
}
|
|
this.submitAction = () => {
|
|
this.sanitizeInputs();
|
|
const sanitizedName = btoa(unescape(encodeURIComponent(this.inputs[0].text)));
|
|
config.buttonActions[0](sanitizedName);
|
|
return true;
|
|
};
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|