This commit is contained in:
fabske0 2025-06-20 08:31:34 +02:00 committed by GitHub
commit 52d83c75f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 40 deletions

View File

@ -71,6 +71,10 @@ export abstract class FormModalUiHandler extends ModalUiHandler {
(hasTitle ? 31 : 5) + 20 * (config.length - 1) + 16 + this.getButtonTopMargin(), (hasTitle ? 31 : 5) + 20 * (config.length - 1) + 16 + this.getButtonTopMargin(),
"", "",
TextStyle.TOOLTIP_CONTENT, TextStyle.TOOLTIP_CONTENT,
{
fontSize: "42px",
wordWrap: { width: 850 },
},
); );
this.errorMessage.setColor(this.getTextColor(TextStyle.SUMMARY_PINK)); this.errorMessage.setColor(this.getTextColor(TextStyle.SUMMARY_PINK));
this.errorMessage.setShadowColor(this.getTextColor(TextStyle.SUMMARY_PINK, true)); this.errorMessage.setShadowColor(this.getTextColor(TextStyle.SUMMARY_PINK, true));
@ -83,20 +87,29 @@ export abstract class FormModalUiHandler extends ModalUiHandler {
this.inputs = []; this.inputs = [];
this.formLabels = []; this.formLabels = [];
fieldsConfig.forEach((config, f) => { fieldsConfig.forEach((config, f) => {
const label = addTextObject(10, (hasTitle ? 31 : 5) + 20 * f, config.label, TextStyle.TOOLTIP_CONTENT); // The Pokédex Scan Window has a much bigger width, so there is currently no need to shorten the label
const label = addTextObject(
10,
(hasTitle ? 31 : 5) + 20 * f,
config.label.length > 25 && this.constructor.name !== "PokedexScanUiHandler"
? config.label.slice(0, 20) + "..."
: config.label,
TextStyle.TOOLTIP_CONTENT,
);
label.name = "formLabel" + f; label.name = "formLabel" + f;
this.formLabels.push(label); this.formLabels.push(label);
this.modalContainer.add(this.formLabels[this.formLabels.length - 1]); this.modalContainer.add(this.formLabels[this.formLabels.length - 1]);
const inputContainer = globalScene.add.container(70, (hasTitle ? 28 : 2) + 20 * f); const inputWidth = label.width < 320 ? 80 : 80 - (label.width - 320) / 5.5;
const inputContainer = globalScene.add.container(70 + (80 - inputWidth), (hasTitle ? 28 : 2) + 20 * f);
inputContainer.setVisible(false); inputContainer.setVisible(false);
const inputBg = addWindow(0, 0, 80, 16, false, false, 0, 0, WindowVariant.XTHIN); const inputBg = addWindow(0, 0, inputWidth, 16, false, false, 0, 0, WindowVariant.XTHIN);
const isPassword = config?.isPassword; const isPassword = config?.isPassword;
const isReadOnly = config?.isReadOnly; const isReadOnly = config?.isReadOnly;
const input = addTextInputObject(4, -2, 440, 116, TextStyle.TOOLTIP_CONTENT, { const input = addTextInputObject(4, -2, inputWidth * 5.5, 116, TextStyle.TOOLTIP_CONTENT, {
type: isPassword ? "password" : "text", type: isPassword ? "password" : "text",
maxLength: isPassword ? 64 : 20, maxLength: isPassword ? 64 : 20,
readOnly: isReadOnly, readOnly: isReadOnly,

View File

@ -151,7 +151,12 @@ export abstract class ModalUiHandler extends UiHandler {
updateContainer(config?: ModalConfig): void { updateContainer(config?: ModalConfig): void {
const [marginTop, marginRight, marginBottom, marginLeft] = this.getMargin(config); const [marginTop, marginRight, marginBottom, marginLeft] = this.getMargin(config);
const [width, height] = [this.getWidth(config), this.getHeight(config)]; /**
* If the total amount of characters for the 2 buttons exceeds ~30 characters,
* the width in `registration-form-ui-handler.ts` and `login-form-ui-handler.ts` needs to be increased.
*/
const width = this.getWidth(config);
const height = this.getHeight(config);
this.modalContainer.setPosition( this.modalContainer.setPosition(
(globalScene.game.canvas.width / 6 - (width + (marginRight - marginLeft))) / 2, (globalScene.game.canvas.width / 6 - (width + (marginRight - marginLeft))) / 2,
(-globalScene.game.canvas.height / 6 - (height + (marginBottom - marginTop))) / 2, (-globalScene.game.canvas.height / 6 - (height + (marginBottom - marginTop))) / 2,
@ -165,10 +170,14 @@ export abstract class ModalUiHandler extends UiHandler {
this.titleText.setX(width / 2); this.titleText.setX(width / 2);
this.titleText.setVisible(!!title); this.titleText.setVisible(!!title);
for (let b = 0; b < this.buttonContainers.length; b++) { if (this.buttonContainers.length > 0) {
const sliceWidth = width / (this.buttonContainers.length + 1); const spacing = 12;
const totalWidth = this.buttonBgs.reduce((sum, bg) => sum + bg.width, 0) + spacing * (this.buttonBgs.length - 1);
this.buttonContainers[b].setPosition(sliceWidth * (b + 1), this.modalBg.height - (this.buttonBgs[b].height + 8)); let x = (this.modalBg.width - totalWidth) / 2;
this.buttonContainers.forEach((container, i) => {
container.setPosition(x + this.buttonBgs[i].width / 2, this.modalBg.height - (this.buttonBgs[i].height + 8));
x += this.buttonBgs[i].width + spacing;
});
} }
} }

View File

@ -160,8 +160,11 @@ export default class PokedexScanUiHandler extends FormModalUiHandler {
if (super.show(args)) { if (super.show(args)) {
const config = args[0] as ModalConfig; const config = args[0] as ModalConfig;
this.inputs[0].resize(1150, 116); const label = this.formLabels[0];
this.inputContainers[0].list[0].width = 200;
const inputWidth = label.width < 420 ? 200 : 200 - (label.width - 420) / 5.75;
this.inputs[0].resize(inputWidth * 5.75, 116);
this.inputContainers[0].list[0].width = inputWidth;
if (args[1] && typeof (args[1] as PlayerPokemon).getNameToRender === "function") { if (args[1] && typeof (args[1] as PlayerPokemon).getNameToRender === "function") {
this.inputs[0].text = (args[1] as PlayerPokemon).getNameToRender(); this.inputs[0].text = (args[1] as PlayerPokemon).getNameToRender();
} else { } else {

View File

@ -7,19 +7,6 @@ import i18next from "i18next";
import { pokerogueApi } from "#app/plugins/api/pokerogue-api"; import { pokerogueApi } from "#app/plugins/api/pokerogue-api";
import { globalScene } from "#app/global-scene"; import { globalScene } from "#app/global-scene";
interface LanguageSetting {
inputFieldFontSize?: string;
warningMessageFontSize?: string;
errorMessageFontSize?: string;
}
const languageSettings: { [key: string]: LanguageSetting } = {
"es-ES": {
inputFieldFontSize: "50px",
errorMessageFontSize: "40px",
},
};
export default class RegistrationFormUiHandler extends FormModalUiHandler { export default class RegistrationFormUiHandler extends FormModalUiHandler {
getModalTitle(_config?: ModalConfig): string { getModalTitle(_config?: ModalConfig): string {
return i18next.t("menu:register"); return i18next.t("menu:register");
@ -34,7 +21,7 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler {
} }
getButtonTopMargin(): number { getButtonTopMargin(): number {
return 8; return 12;
} }
getButtonLabels(_config?: ModalConfig): string[] { getButtonLabels(_config?: ModalConfig): string[] {
@ -75,18 +62,9 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler {
setup(): void { setup(): void {
super.setup(); super.setup();
this.modalContainer.list.forEach((child: Phaser.GameObjects.GameObject) => {
if (child instanceof Phaser.GameObjects.Text && child !== this.titleText) {
const inputFieldFontSize = languageSettings[i18next.resolvedLanguage!]?.inputFieldFontSize;
if (inputFieldFontSize) {
child.setFontSize(inputFieldFontSize);
}
}
});
const warningMessageFontSize = languageSettings[i18next.resolvedLanguage!]?.warningMessageFontSize ?? "42px";
const label = addTextObject(10, 87, i18next.t("menu:registrationAgeWarning"), TextStyle.TOOLTIP_CONTENT, { const label = addTextObject(10, 87, i18next.t("menu:registrationAgeWarning"), TextStyle.TOOLTIP_CONTENT, {
fontSize: warningMessageFontSize, fontSize: "42px",
wordWrap: { width: 850 },
}); });
this.modalContainer.add(label); this.modalContainer.add(label);
@ -106,10 +84,6 @@ export default class RegistrationFormUiHandler extends FormModalUiHandler {
const onFail = error => { const onFail = error => {
globalScene.ui.setMode(UiMode.REGISTRATION_FORM, Object.assign(config, { errorMessage: error?.trim() })); globalScene.ui.setMode(UiMode.REGISTRATION_FORM, Object.assign(config, { errorMessage: error?.trim() }));
globalScene.ui.playError(); globalScene.ui.playError();
const errorMessageFontSize = languageSettings[i18next.resolvedLanguage!]?.errorMessageFontSize;
if (errorMessageFontSize) {
this.errorMessage.setFontSize(errorMessageFontSize);
}
}; };
if (!this.inputs[0].text) { if (!this.inputs[0].text) {
return onFail(i18next.t("menu:emptyUsername")); return onFail(i18next.t("menu:emptyUsername"));