Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI/UX] Reducing number of containers in the Pokédex #5400

Merged
merged 5 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 37 additions & 29 deletions src/ui/pokedex-mon-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,7 @@ export class PokedexMonContainer extends Phaser.GameObjects.Container {
constructor(species: PokemonSpecies, options: SpeciesDetails = {}) {
super(globalScene, 0, 0);

this.species = species;

const { shiny, formIndex, female, variant } = options;

const defaultDexAttr = globalScene.gameData.getSpeciesDefaultDexAttr(species, false, true);
const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);

if (!isNullOrUndefined(formIndex)) {
defaultProps.formIndex = formIndex;
}
if (!isNullOrUndefined(shiny)) {
defaultProps.shiny = shiny;
}
if (!isNullOrUndefined(variant)) {
defaultProps.variant = variant;
}
if (!isNullOrUndefined(female)) {
defaultProps.female = female;
}

this.setSpecies(species, options);

// starter passive bg
const starterPassiveBg = globalScene.add.image(2, 5, "passive_bg");
Expand All @@ -65,15 +46,6 @@ export class PokedexMonContainer extends Phaser.GameObjects.Container {
this.add(starterPassiveBg);
this.starterPassiveBgs = starterPassiveBg;

// icon
this.icon = globalScene.add.sprite(-2, 2, species.getIconAtlasKey(defaultProps.formIndex, defaultProps.shiny, defaultProps.variant));
this.icon.setScale(0.5);
this.icon.setOrigin(0, 0);
this.icon.setFrame(species.getIconId(defaultProps.female, defaultProps.formIndex, defaultProps.shiny, defaultProps.variant));
this.checkIconId(defaultProps.female, defaultProps.formIndex, defaultProps.shiny, defaultProps.variant);
this.icon.setTint(0);
this.add(this.icon);

// shiny icons
for (let i = 0; i < 3; i++) {
const shinyIcon = globalScene.add.image(i * -3 + 12, 2, "shiny_star_small");
Expand Down Expand Up @@ -196,6 +168,42 @@ export class PokedexMonContainer extends Phaser.GameObjects.Container {
this.passive2OverlayIcon = passive2OverlayIcon;
}

setSpecies(species: PokemonSpecies, options: SpeciesDetails = {}) {

this.species = species;

const { shiny, formIndex, female, variant } = options;

const defaultDexAttr = globalScene.gameData.getSpeciesDefaultDexAttr(species, false, true);
const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);

if (!isNullOrUndefined(formIndex)) {
defaultProps.formIndex = formIndex;
}
if (!isNullOrUndefined(shiny)) {
defaultProps.shiny = shiny;
}
if (!isNullOrUndefined(variant)) {
defaultProps.variant = variant;
}
if (!isNullOrUndefined(female)) {
defaultProps.female = female;
}

if (this.icon) {
this.remove(this.icon);
this.icon.destroy(); // Properly removes the sprite from memory
}

// icon
this.icon = globalScene.add.sprite(-2, 2, species.getIconAtlasKey(defaultProps.formIndex, defaultProps.shiny, defaultProps.variant));
this.icon.setScale(0.5);
this.icon.setOrigin(0, 0);
this.icon.setFrame(species.getIconId(defaultProps.female, defaultProps.formIndex, defaultProps.shiny, defaultProps.variant));
this.checkIconId(defaultProps.female, defaultProps.formIndex, defaultProps.shiny, defaultProps.variant);
this.add(this.icon);
}

checkIconId(female, formIndex, shiny, variant) {
if (this.icon.frame.name !== this.species.getIconId(female, formIndex, shiny, variant)) {
console.log(`${this.species.name}'s variant icon does not exist. Replacing with default.`);
Expand Down
Loading