[Enhancement] Allow nickname assignment in the starter select UI. (#3456)

* add rename nickname in starter UI

* update requested changes
This commit is contained in:
Leo Kim 2024-08-09 23:17:18 +09:00 committed by GitHub
parent 57a4e1cc47
commit d2eea96777
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 11 deletions

View File

@ -622,6 +622,11 @@ export class SelectStarterPhase extends Phase {
if (starter.pokerus) {
starterPokemon.pokerus = true;
}
if (starter.nickname) {
starterPokemon.nickname = starter.nickname;
}
if (this.scene.gameMode.isSplicedOnly) {
starterPokemon.generateFusionSpecies(true);
}

View File

@ -198,6 +198,7 @@ export interface StarterAttributes {
form?: integer;
female?: boolean;
shiny?: boolean;
nickname?: string;
}
export interface StarterPreferences {

View File

@ -36,17 +36,13 @@ export default class RenameFormUiHandler extends FormModalUiHandler {
show(args: any[]): boolean {
if (super.show(args)) {
const config = args[0] as ModalConfig;
this.inputs[0].text = (args[1] as PlayerPokemon).getNameToRender();
if (args[1] && typeof (args[1] as PlayerPokemon).getNameToRender === "function") {
this.inputs[0].text = (args[1] as PlayerPokemon).getNameToRender();
} else {
this.inputs[0].text = args[1];
}
this.submitAction = (_) => {
this.sanitizeInputs();
// const onFail = () => {
// this.scene.ui.setModeWithoutClear(Mode.RENAME_POKEMON, Object.assign(config));
// this.scene.ui.playError();
// };
// if (!this.inputs[0].text) {
// return onFail();
// }
const sanitizedName = btoa(unescape(encodeURIComponent(this.inputs[0].text)));
config.buttonActions[0](sanitizedName);
return true;

View File

@ -55,6 +55,7 @@ export interface Starter {
nature: Nature;
moveset?: StarterMoveset;
pokerus: boolean;
nickname?: string;
}
interface LanguageSetting {
@ -1542,6 +1543,33 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
});
}
}
options.push({
label: i18next.t("menu:rename"),
handler: () => {
ui.playSelect();
let nickname = starterAttributes.nickname ? String(starterAttributes.nickname) : "";
nickname = decodeURIComponent(escape(atob(nickname)));
ui.setModeWithoutClear(Mode.RENAME_POKEMON, {
buttonActions: [
(sanitizedName: string) => {
ui.playSelect();
starterAttributes.nickname = sanitizedName;
const name = decodeURIComponent(escape(atob(starterAttributes.nickname)));
if (name.length > 0) {
this.pokemonNameText.setText(name);
} else {
this.pokemonNameText.setText(species.name);
}
ui.setMode(Mode.STARTER_SELECT);
},
() => {
ui.setMode(Mode.STARTER_SELECT);
}
]
}, nickname);
return true;
}
});
const showUseCandies = () => { // this lets you use your candies
const options: any[] = []; // TODO: add proper type
if (!(passiveAttr & PassiveAttr.UNLOCKED)) {
@ -2573,7 +2601,12 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
if (species && (this.speciesStarterDexEntry?.seenAttr || this.speciesStarterDexEntry?.caughtAttr)) {
this.pokemonNumberText.setText(Utils.padInt(species.speciesId, 4));
this.pokemonNameText.setText(species.name);
if (starterAttributes?.nickname) {
const name = decodeURIComponent(escape(atob(starterAttributes.nickname)));
this.pokemonNameText.setText(name);
} else {
this.pokemonNameText.setText(species.name);
}
if (this.speciesStarterDexEntry?.caughtAttr) {
const colorScheme = starterColors[species.speciesId];
@ -3215,7 +3248,8 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
passive: !(thisObj.scene.gameData.starterData[starterSpecies.speciesId].passiveAttr ^ (PassiveAttr.ENABLED | PassiveAttr.UNLOCKED)),
nature: thisObj.starterNatures[i] as Nature,
moveset: thisObj.starterMovesets[i],
pokerus: thisObj.pokerusSpecies.includes(starterSpecies)
pokerus: thisObj.pokerusSpecies.includes(starterSpecies),
nickname: thisObj.starterPreferences[starterSpecies.speciesId]?.nickname,
};
}));
};