Skip to content

Commit

Permalink
[Bug][UI/UX] Dex bug fixes 12 feb (#5307)
Browse files Browse the repository at this point in the history
* Fixed bug when setting tint of eggs for egg move filter

* Form text is properly hidden when going to filters

* Displaying level up moves of alternate forms

* Offsetting form cycle button when uncaught text is shown

* Pokedex buttons now appear on mobile touchpad

* Hotfix to prevent "Normal" form to showing the text

* Preventing filter texts from showing gibberish

* Moving cursor to input text when pressing on filter

* Introducing method to get full obtainable unlocks for a given species

* Filtering obtainable unlocks in dex

* Buying eggs in dex does not crash the game

* Shiny icon does not overlap with luck text for evolutions

* Shiny is maintained correctly when cycling through different pages

* Displacing text elements to avoid overlap for localized form names

* Checking starter caughtAttr in addition to pokemon caughtAttr
  • Loading branch information
Wlowscha authored Feb 13, 2025
1 parent 595413e commit be0f3b2
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 47 deletions.
12 changes: 6 additions & 6 deletions index.css
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ input:-internal-autofill-selected {
}

/* Show cycle buttons only on STARTER_SELECT and on touch configuration panel */
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT']) #apadOpenFilters,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT'], [data-ui-mode='RUN_INFO']) #apadCycleForm,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT'], [data-ui-mode='RUN_INFO']) #apadCycleShiny,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT'], [data-ui-mode='POKEDEX'], [data-ui-mode='POKEDEX_PAGE']) #apadOpenFilters,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT'], [data-ui-mode='POKEDEX'], [data-ui-mode='POKEDEX_PAGE'], [data-ui-mode='RUN_INFO']) #apadCycleForm,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT'], [data-ui-mode='POKEDEX'], [data-ui-mode='POKEDEX_PAGE'], [data-ui-mode='RUN_INFO']) #apadCycleShiny,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT']) #apadCycleNature,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT'], [data-ui-mode='RUN_INFO']) #apadCycleAbility,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT']) #apadCycleGender,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT']) #apadCycleVariant {
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT'], [data-ui-mode='POKEDEX_PAGE'], [data-ui-mode='RUN_INFO']) #apadCycleAbility,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT'], [data-ui-mode='POKEDEX_PAGE']) #apadCycleGender,
#touchControls:not(.config-mode):not([data-ui-mode='STARTER_SELECT'], [data-ui-mode='POKEDEX']) #apadCycleVariant {
display: none;
}

Expand Down
60 changes: 59 additions & 1 deletion src/data/pokemon-species.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import i18next from "i18next";
import type { AnySound } from "#app/battle-scene";
import { globalScene } from "#app/global-scene";
import type { GameMode } from "#app/game-mode";
import type { StarterMoveset } from "#app/system/game-data";
import { DexAttr, type StarterMoveset } from "#app/system/game-data";
import * as Utils from "#app/utils";
import { uncatchableSpecies } from "#app/data/balance/biomes";
import { speciesEggMoves } from "#app/data/balance/egg-moves";
Expand All @@ -32,6 +32,37 @@ export enum Region {
PALDEA
}

// TODO: this is horrible and will need to be removed once a refactor/cleanup of forms is executed.
export const normalForm: Species[] = [
Species.PIKACHU,
Species.RAICHU,
Species.EEVEE,
Species.JOLTEON,
Species.FLAREON,
Species.VAPOREON,
Species.ESPEON,
Species.UMBREON,
Species.LEAFEON,
Species.GLACEON,
Species.SYLVEON,
Species.PICHU,
Species.ROTOM,
Species.DIALGA,
Species.PALKIA,
Species.KYUREM,
Species.GENESECT,
Species.FROAKIE,
Species.FROGADIER,
Species.GRENINJA,
Species.ROCKRUFF,
Species.NECROZMA,
Species.MAGEARNA,
Species.MARSHADOW,
Species.CRAMORANT,
Species.ZARUDE,
Species.CALYREX
];

/**
* Gets the {@linkcode PokemonSpecies} object associated with the {@linkcode Species} enum given
* @param species The species to fetch
Expand Down Expand Up @@ -997,6 +1028,33 @@ export default class PokemonSpecies extends PokemonSpeciesForm implements Locali
? this.forms[formIndex || 0].getFormSpriteKey()
: "";
}

/**
* Generates a {@linkcode bigint} corresponding to the maximum unlocks possible for this species,
* taking into account if the species has a male/female gender, and which variants are implemented.
* @returns {@linkcode bigint} Maximum unlocks, can be compared with {@linkcode DexEntry.caughtAttr}.
*/
getFullUnlocksData(): bigint {
let caughtAttr: bigint = 0n;
caughtAttr += DexAttr.NON_SHINY;
caughtAttr += DexAttr.SHINY;
if (this.malePercent !== null) {
if (this.malePercent > 0) {
caughtAttr += DexAttr.MALE;
}
if (this.malePercent < 100) {
caughtAttr += DexAttr.FEMALE;
}
}
caughtAttr += DexAttr.DEFAULT_VARIANT;
if (this.hasVariants()) {
caughtAttr += DexAttr.VARIANT_2;
caughtAttr += DexAttr.VARIANT_3;
}
caughtAttr += DexAttr.DEFAULT_FORM;

return caughtAttr;
}
}

export class PokemonForm extends PokemonSpeciesForm {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/filter-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class FilterText extends Phaser.GameObjects.Container {
const handler = ui.getHandler() as AwaitableUiHandler;
handler.tutorialActive = true;
// Switch to the dialog test window
this.selections[index].setText(String(i18next.t(dialogueName)));
this.selections[index].setText( dialogueName === "" ? this.defaultText : String(i18next.t(dialogueName)));
ui.revertMode();
this.onChange();
},
Expand Down
48 changes: 27 additions & 21 deletions src/ui/pokedex-page-ui-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { pokemonFormChanges } from "#app/data/pokemon-forms";
import type { LevelMoves } from "#app/data/balance/pokemon-level-moves";
import { pokemonFormLevelMoves, pokemonSpeciesLevelMoves } from "#app/data/balance/pokemon-level-moves";
import type PokemonSpecies from "#app/data/pokemon-species";
import { allSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species";
import { allSpecies, getPokemonSpeciesForm, normalForm } from "#app/data/pokemon-species";
import { getStarterValueFriendshipCap, speciesStarterCosts } from "#app/data/balance/starters";
import { starterPassiveAbilities } from "#app/data/balance/passives";
import { Type } from "#enums/type";
Expand Down Expand Up @@ -383,7 +383,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.pokemonHatchedIcon.setScale(0.8);
this.pokemonCaughtHatchedContainer.add(this.pokemonHatchedIcon);

this.pokemonShinyIcon = globalScene.add.sprite(14, 76, "shiny_icons");
this.pokemonShinyIcon = globalScene.add.sprite(14, 117, "shiny_icons");
this.pokemonShinyIcon.setOrigin(0.15, 0.2);
this.pokemonShinyIcon.setScale(1);
this.pokemonCaughtHatchedContainer.add(this.pokemonShinyIcon);
Expand Down Expand Up @@ -601,7 +601,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
const form = species.forms[formIndex];

// If this form has a specific set of moves, we get them.
this.levelMoves = (formIndex > 0 && pokemonFormLevelMoves.hasOwnProperty(formIndex)) ? pokemonFormLevelMoves[species.speciesId][formIndex] : pokemonSpeciesLevelMoves[species.speciesId];
this.levelMoves = (formIndex > 0 && pokemonFormLevelMoves.hasOwnProperty(species.speciesId) && pokemonFormLevelMoves[species.speciesId].hasOwnProperty(formIndex)) ? pokemonFormLevelMoves[species.speciesId][formIndex] : pokemonSpeciesLevelMoves[species.speciesId];
this.ability1 = form.ability1;
this.ability2 = (form.ability2 === form.ability1) ? undefined : form.ability2;
this.abilityHidden = (form.abilityHidden === form.ability1) ? undefined : form.abilityHidden;
Expand Down Expand Up @@ -741,14 +741,16 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
return biomes;
}

isCaught(otherSpeciesDexEntry?: DexEntry): bigint {
isCaught(otherSpecies?: PokemonSpecies): bigint {
if (globalScene.dexForDevs) {
return 255n;
}

const dexEntry = otherSpeciesDexEntry ? otherSpeciesDexEntry : this.speciesStarterDexEntry;
const species = otherSpecies ? otherSpecies : this.species;
const dexEntry = globalScene.gameData.dexData[species.speciesId];
const starterDexEntry = globalScene.gameData.dexData[this.getStarterSpeciesId(species.speciesId)];

return dexEntry?.caughtAttr ?? 0n;
return (dexEntry?.caughtAttr ?? 0n) & (starterDexEntry?.caughtAttr ?? 0n) & species.getFullUnlocksData();
}
/**
* Check whether a given form is caught for a given species.
Expand All @@ -765,11 +767,9 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
}
const species = otherSpecies ? otherSpecies : this.species;
const formIndex = otherFormIndex !== undefined ? otherFormIndex : this.formIndex;
const dexEntry = globalScene.gameData.dexData[species.speciesId];
const caughtAttr = this.isCaught(species);

const isFormCaught = dexEntry ?
(dexEntry.caughtAttr & globalScene.gameData.getFormAttr(formIndex ?? 0)) > 0n
: false;
const isFormCaught = (caughtAttr & globalScene.gameData.getFormAttr(formIndex ?? 0)) > 0n;
return isFormCaught;
}

Expand All @@ -783,8 +783,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
*/
initStarterPrefs(): StarterAttributes {
const starterAttributes : StarterAttributes | null = this.species ? { ...this.savedStarterAttributes } : null;
const dexEntry = globalScene.gameData.dexData[this.species.speciesId];
const caughtAttr = this.isCaught(dexEntry);
const caughtAttr = this.isCaught();

// no preferences or Pokemon wasn't caught, return empty attribute
if (!starterAttributes || !caughtAttr) {
Expand Down Expand Up @@ -1235,7 +1234,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {

case MenuOptions.BIOMES:

if (!(this.isCaught() || this.speciesStarterDexEntry?.seenAttr)) {
if (!(isCaught || this.speciesStarterDexEntry?.seenAttr)) {
error = true;
} else {
this.blockInput = true;
Expand Down Expand Up @@ -1372,8 +1371,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
});
this.evolutions.map(evo => {
const evoSpecies = allSpecies.find(species => species.speciesId === evo.speciesId);
const evoSpeciesStarterDexEntry = evoSpecies ? globalScene.gameData.dexData[evoSpecies.speciesId] : undefined;
const isCaughtEvo = this.isCaught(evoSpeciesStarterDexEntry) ? true : false;
const isCaughtEvo = this.isCaught(evoSpecies) ? true : false;
// Attempts to find the formIndex of the evolved species
const newFormKey = evo.evoFormKey ? evo.evoFormKey : (this.species.forms.length > 0 ? this.species.forms[this.formIndex].formKey : "");
const matchingForm = evoSpecies?.forms.find(form => form.formKey === newFormKey);
Expand Down Expand Up @@ -1535,6 +1533,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.pokemonShinyIcon.setVisible(true);

starterAttributes.shiny = true;
this.savedStarterAttributes.shiny = starterAttributes.shiny;
} else {
let newVariant = props.variant;
do {
Expand Down Expand Up @@ -1688,7 +1687,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
}
this.pokemonCandyCountText.setText(`x${starterData.candyCount}`);

const egg = new Egg({ scene: globalScene, species: this.species.speciesId, sourceType: EggSourceType.SAME_SPECIES_EGG });
const egg = new Egg({ scene: globalScene, species: this.starterId, sourceType: EggSourceType.SAME_SPECIES_EGG });
egg.addEggToGameData();

globalScene.gameData.saveSystem().then(success => {
Expand Down Expand Up @@ -1856,6 +1855,9 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
if (this.canCycleGender) {
this.updateButtonIcon(SettingKeyboard.Button_Cycle_Gender, gamepadType, this.genderIconElement, this.genderLabel);
}
} else {
// Making space for "Uncaught" text
this.instructionRowY += 8;
}
if (this.canCycleForm) {
this.updateButtonIcon(SettingKeyboard.Button_Cycle_Form, gamepadType, this.formIconElement, this.formLabel);
Expand Down Expand Up @@ -2093,7 +2095,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
if (species) {
const dexEntry = globalScene.gameData.dexData[species.speciesId];

const caughtAttr = this.isCaught(dexEntry);
const caughtAttr = this.isCaught(species);

if (!caughtAttr) {
const props = this.starterAttributes;
Expand Down Expand Up @@ -2240,13 +2242,11 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.pokemonCandyContainer.setVisible(true);

if (pokemonPrevolutions.hasOwnProperty(species.speciesId)) {
this.pokemonShinyIcon.setY(135);
this.pokemonShinyIcon.setFrame(getVariantIcon(variant));
this.pokemonHatchedIcon.setVisible(false);
this.pokemonHatchedCountText.setVisible(false);
this.pokemonFormText.setY(36);
} else {
this.pokemonShinyIcon.setY(117);
this.pokemonHatchedIcon.setVisible(true);
this.pokemonHatchedCountText.setVisible(true);
this.pokemonFormText.setY(42);
Expand Down Expand Up @@ -2276,7 +2276,12 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
if (isFormCaught || isFormSeen) {
const speciesForm = getPokemonSpeciesForm(species.speciesId, formIndex!); // TODO: is the bang correct?
this.setTypeIcons(speciesForm.type1, speciesForm.type2);
this.pokemonFormText.setText(species.getFormNameToDisplay(formIndex));
// TODO: change this once forms are refactored
if (normalForm.includes(species.speciesId) && !formIndex) {
this.pokemonFormText.setText("");
} else {
this.pokemonFormText.setText(species.getFormNameToDisplay(formIndex));
}
this.pokemonFormText.setVisible(true);
if (!isFormCaught) {
this.pokemonFormText.setY(18);
Expand Down Expand Up @@ -2321,7 +2326,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
*/
getCurrentDexProps(speciesId: number): bigint {
let props = 0n;
const caughtAttr = globalScene.gameData.dexData[speciesId].caughtAttr;
const species = allSpecies.find(sp => sp.speciesId === speciesId);
const caughtAttr = globalScene.gameData.dexData[speciesId].caughtAttr & globalScene.gameData.dexData[this.getStarterSpeciesId(speciesId)].caughtAttr & (species?.getFullUnlocksData() ?? 0n);

/* this checks the gender of the pokemon; this works by checking a) that the starter preferences for the species exist, and if so, is it female. If so, it'll add DexAttr.FEMALE to our temp props
* It then checks b) if the caughtAttr for the pokemon is female and NOT male - this means that the ONLY gender we've gotten is female, and we need to add DexAttr.FEMALE to our temp props
Expand Down
7 changes: 6 additions & 1 deletion src/ui/pokedex-scan-ui-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export default class PokedexScanUiHandler extends FormModalUiHandler {

this.reduceKeys();

setTimeout(() => {
input.setFocus(); // Focus after a short delay to avoid unwanted input
}, 50);

input.on("keydown", (inputObject, evt: KeyboardEvent) => {
if ([ "escape", "space" ].some((v) => v === evt.key.toLowerCase() || v === evt.code.toLowerCase()) && ui.getMode() === Mode.AUTO_COMPLETE) {
// Delete autocomplete list and recovery focus.
Expand Down Expand Up @@ -169,7 +173,8 @@ export default class PokedexScanUiHandler extends FormModalUiHandler {
this.submitAction = (_) => {
if (ui.getMode() === Mode.POKEDEX_SCAN) {
this.sanitizeInputs();
const sanitizedName = btoa(unescape(encodeURIComponent(this.inputs[0].text)));
const outputName = this.reducedKeys.includes(this.inputs[0].text) ? this.inputs[0].text : "";
const sanitizedName = btoa(unescape(encodeURIComponent(outputName)));
config.buttonActions[0](sanitizedName);
return true;
}
Expand Down
Loading

0 comments on commit be0f3b2

Please sign in to comment.