mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-27 02:32:21 +02:00
Introducing tray to display form icons in the pokedex; displaying correct information for uncaught and seen forms in pokedex page; dexForDevs now unlocks everything in the main page
This commit is contained in:
parent
e6340de046
commit
d1ef1f34fb
@ -1,7 +1,16 @@
|
||||
import type { Variant } from "#app/data/variant";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
import { isNullOrUndefined } from "#app/utils";
|
||||
import type PokemonSpecies from "../data/pokemon-species";
|
||||
import { addTextObject, TextStyle } from "./text";
|
||||
|
||||
|
||||
interface SpeciesDetails {
|
||||
shiny?: boolean,
|
||||
formIndex?: number
|
||||
female?: boolean,
|
||||
variant?: Variant
|
||||
}
|
||||
export class PokedexMonContainer extends Phaser.GameObjects.Container {
|
||||
public species: PokemonSpecies;
|
||||
public icon: Phaser.GameObjects.Sprite;
|
||||
@ -21,14 +30,29 @@ export class PokedexMonContainer extends Phaser.GameObjects.Container {
|
||||
public passive2Icon: Phaser.GameObjects.Image;
|
||||
public cost: number = 0;
|
||||
|
||||
constructor(species: PokemonSpecies) {
|
||||
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;
|
||||
}
|
||||
|
||||
// starter passive bg
|
||||
const starterPassiveBg = globalScene.add.image(2, 5, "passive_bg");
|
||||
starterPassiveBg.setOrigin(0, 0);
|
||||
|
@ -43,7 +43,6 @@ import type { Moves } from "#enums/moves";
|
||||
import { Species } from "#enums/species";
|
||||
import { Button } from "#enums/buttons";
|
||||
import { EggSourceType } from "#enums/egg-source-types";
|
||||
import { StarterContainer } from "#app/ui/starter-container";
|
||||
import { getPassiveCandyCount, getValueReductionCandyCounts, getSameSpeciesEggCandyCounts } from "#app/data/balance/starters";
|
||||
import { BooleanHolder, capitalizeString, getLocalizedSpriteKey, isNullOrUndefined, NumberHolder, padInt, rgbHexToRgba, toReadableString } from "#app/utils";
|
||||
import type { Nature } from "#enums/nature";
|
||||
@ -127,8 +126,7 @@ interface SpeciesDetails {
|
||||
shiny?: boolean,
|
||||
formIndex?: number
|
||||
female?: boolean,
|
||||
variant?: number,
|
||||
forSeen?: boolean, // default = false
|
||||
variant?: number
|
||||
}
|
||||
|
||||
enum MenuOptions {
|
||||
@ -147,8 +145,6 @@ enum MenuOptions {
|
||||
export default class PokedexPageUiHandler extends MessageUiHandler {
|
||||
private starterSelectContainer: Phaser.GameObjects.Container;
|
||||
private shinyOverlay: Phaser.GameObjects.Image;
|
||||
private starterContainers: StarterContainer[] = [];
|
||||
private filteredStarterContainers: StarterContainer[] = [];
|
||||
private pokemonNumberText: Phaser.GameObjects.Text;
|
||||
private pokemonSprite: Phaser.GameObjects.Sprite;
|
||||
private pokemonNameText: Phaser.GameObjects.Text;
|
||||
@ -312,10 +308,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
|
||||
|
||||
this.speciesLoaded.set(species.speciesId, false);
|
||||
this.allSpecies.push(species);
|
||||
|
||||
const starterContainer = new StarterContainer(species).setVisible(false);
|
||||
this.starterContainers.push(starterContainer);
|
||||
starterBoxContainer.add(starterContainer);
|
||||
}
|
||||
|
||||
this.starterSelectContainer.add(starterBoxContainer);
|
||||
@ -799,39 +791,43 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
|
||||
|
||||
const hasShiny = caughtAttr & DexAttr.SHINY;
|
||||
const hasNonShiny = caughtAttr & DexAttr.NON_SHINY;
|
||||
if (starterAttributes.shiny && !hasShiny) {
|
||||
if (!hasShiny || (starterAttributes.shiny === undefined && hasNonShiny)) {
|
||||
// shiny form wasn't unlocked, purging shiny and variant setting
|
||||
starterAttributes.shiny = false;
|
||||
starterAttributes.variant = 0;
|
||||
} else if (starterAttributes.shiny === false && !hasNonShiny) {
|
||||
// non shiny form wasn't unlocked, purging shiny setting
|
||||
starterAttributes.shiny = false;
|
||||
} else if (!hasNonShiny || (starterAttributes.shiny === undefined && hasShiny)) {
|
||||
starterAttributes.shiny = true;
|
||||
starterAttributes.variant = 0;
|
||||
}
|
||||
|
||||
if (starterAttributes.variant !== undefined) {
|
||||
const unlockedVariants = [
|
||||
hasShiny && caughtAttr & DexAttr.DEFAULT_VARIANT,
|
||||
hasShiny && caughtAttr & DexAttr.VARIANT_2,
|
||||
hasShiny && caughtAttr & DexAttr.VARIANT_3
|
||||
];
|
||||
if (isNaN(starterAttributes.variant) || starterAttributes.variant < 0) {
|
||||
starterAttributes.variant = 0;
|
||||
} else if (!unlockedVariants[starterAttributes.variant]) {
|
||||
let highestValidIndex = -1;
|
||||
for (let i = 0; i <= starterAttributes.variant && i < unlockedVariants.length; i++) {
|
||||
if (unlockedVariants[i] !== 0n) {
|
||||
highestValidIndex = i;
|
||||
}
|
||||
const unlockedVariants = [
|
||||
hasShiny && caughtAttr & DexAttr.DEFAULT_VARIANT,
|
||||
hasShiny && caughtAttr & DexAttr.VARIANT_2,
|
||||
hasShiny && caughtAttr & DexAttr.VARIANT_3
|
||||
];
|
||||
if (starterAttributes.variant === undefined || isNaN(starterAttributes.variant) || starterAttributes.variant < 0) {
|
||||
starterAttributes.variant = 0;
|
||||
} else if (!unlockedVariants[starterAttributes.variant]) {
|
||||
let highestValidIndex = -1;
|
||||
for (let i = 0; i <= starterAttributes.variant && i < unlockedVariants.length; i++) {
|
||||
if (unlockedVariants[i] !== 0n) {
|
||||
highestValidIndex = i;
|
||||
}
|
||||
// Set to the highest valid index found or default to 0
|
||||
starterAttributes.variant = highestValidIndex !== -1 ? highestValidIndex : 0;
|
||||
}
|
||||
// Set to the highest valid index found or default to 0
|
||||
starterAttributes.variant = highestValidIndex !== -1 ? highestValidIndex : 0;
|
||||
}
|
||||
|
||||
if (starterAttributes.female !== undefined) {
|
||||
if ((starterAttributes.female && !(caughtAttr & DexAttr.FEMALE)) || (!starterAttributes.female && !(caughtAttr & DexAttr.MALE))) {
|
||||
starterAttributes.female = !starterAttributes.female;
|
||||
}
|
||||
} else {
|
||||
if (caughtAttr & DexAttr.FEMALE) {
|
||||
starterAttributes.female = true;
|
||||
} else if (caughtAttr & DexAttr.MALE) {
|
||||
starterAttributes.female = false;
|
||||
}
|
||||
}
|
||||
|
||||
return starterAttributes;
|
||||
@ -1967,88 +1963,10 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
|
||||
|
||||
if (species && (this.speciesStarterDexEntry?.seenAttr || this.isCaught())) {
|
||||
this.pokemonNumberText.setText(padInt(species.speciesId, 4));
|
||||
if (starterAttributes?.nickname) {
|
||||
const name = decodeURIComponent(escape(atob(starterAttributes.nickname)));
|
||||
this.pokemonNameText.setText(name);
|
||||
} else {
|
||||
this.pokemonNameText.setText(species.name);
|
||||
}
|
||||
|
||||
if (this.isCaught()) {
|
||||
const colorScheme = starterColors[species.speciesId];
|
||||
|
||||
const luck = globalScene.gameData.getDexAttrLuck(this.isCaught());
|
||||
this.pokemonLuckText.setVisible(!!luck);
|
||||
this.pokemonLuckText.setText(luck.toString());
|
||||
this.pokemonLuckText.setTint(getVariantTint(Math.min(luck - 1, 2) as Variant));
|
||||
this.pokemonLuckLabelText.setVisible(this.pokemonLuckText.visible);
|
||||
|
||||
//Growth translate
|
||||
let growthReadable = toReadableString(GrowthRate[species.growthRate]);
|
||||
const growthAux = growthReadable.replace(" ", "_");
|
||||
if (i18next.exists("growth:" + growthAux)) {
|
||||
growthReadable = i18next.t("growth:" + growthAux as any);
|
||||
}
|
||||
this.pokemonGrowthRateText.setText(growthReadable);
|
||||
|
||||
this.pokemonGrowthRateText.setColor(getGrowthRateColor(species.growthRate));
|
||||
this.pokemonGrowthRateText.setShadowColor(getGrowthRateColor(species.growthRate, true));
|
||||
this.pokemonGrowthRateLabelText.setVisible(true);
|
||||
this.pokemonUncaughtText.setVisible(false);
|
||||
this.pokemonCaughtCountText.setText(`${this.speciesStarterDexEntry?.caughtCount}`);
|
||||
if (species.speciesId === Species.MANAPHY || species.speciesId === Species.PHIONE) {
|
||||
this.pokemonHatchedIcon.setFrame("manaphy");
|
||||
} else {
|
||||
this.pokemonHatchedIcon.setFrame(getEggTierForSpecies(species));
|
||||
}
|
||||
this.pokemonHatchedCountText.setText(`${this.speciesStarterDexEntry?.hatchedCount}`);
|
||||
|
||||
const defaultDexAttr = this.getCurrentDexProps(species.speciesId);
|
||||
const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);
|
||||
const variant = defaultProps.variant;
|
||||
const tint = getVariantTint(variant);
|
||||
this.pokemonShinyIcon.setFrame(getVariantIcon(variant));
|
||||
this.pokemonShinyIcon.setTint(tint);
|
||||
this.pokemonShinyIcon.setVisible(defaultProps.shiny);
|
||||
this.pokemonCaughtHatchedContainer.setVisible(true);
|
||||
this.pokemonFormText.setVisible(true);
|
||||
|
||||
if (pokemonPrevolutions.hasOwnProperty(species.speciesId)) {
|
||||
this.pokemonCaughtHatchedContainer.setY(16);
|
||||
this.pokemonShinyIcon.setY(135);
|
||||
this.pokemonShinyIcon.setFrame(getVariantIcon(variant));
|
||||
[
|
||||
this.pokemonCandyContainer,
|
||||
this.pokemonHatchedIcon,
|
||||
this.pokemonHatchedCountText
|
||||
].map(c => c.setVisible(false));
|
||||
this.pokemonFormText.setY(25);
|
||||
} else {
|
||||
this.pokemonCaughtHatchedContainer.setY(25);
|
||||
this.pokemonShinyIcon.setY(117);
|
||||
this.pokemonCandyIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[0])));
|
||||
this.pokemonCandyOverlayIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[1])));
|
||||
this.pokemonCandyCountText.setText(`x${globalScene.gameData.starterData[this.getStarterSpeciesId(species.speciesId)].candyCount}`);
|
||||
this.pokemonCandyContainer.setVisible(true);
|
||||
this.pokemonFormText.setY(42);
|
||||
this.pokemonHatchedIcon.setVisible(true);
|
||||
this.pokemonHatchedCountText.setVisible(true);
|
||||
|
||||
const { currentFriendship, friendshipCap } = this.getFriendship(this.species.speciesId);
|
||||
const candyCropY = 16 - (16 * (currentFriendship / friendshipCap));
|
||||
this.pokemonCandyDarknessOverlay.setCrop(0, 0, 16, candyCropY);
|
||||
|
||||
this.pokemonCandyContainer.on("pointerover", () => {
|
||||
globalScene.ui.showTooltip("", `${currentFriendship}/${friendshipCap}`, true);
|
||||
this.activeTooltip = "CANDY";
|
||||
});
|
||||
this.pokemonCandyContainer.on("pointerout", () => {
|
||||
globalScene.ui.hideTooltip();
|
||||
this.activeTooltip = undefined;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Set default attributes if for some reason starterAttributes does not exist or attributes missing
|
||||
const props: StarterAttributes = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);
|
||||
if (starterAttributes?.variant && !isNaN(starterAttributes.variant)) {
|
||||
@ -2065,12 +1983,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
|
||||
female: props.female,
|
||||
variant: props.variant ?? 0,
|
||||
});
|
||||
|
||||
if (this.isFormCaught(this.species, props.form)) {
|
||||
const speciesForm = getPokemonSpeciesForm(species.speciesId, props.form ?? 0);
|
||||
this.setTypeIcons(speciesForm.type1, speciesForm.type2);
|
||||
this.pokemonSprite.clearTint();
|
||||
}
|
||||
} else {
|
||||
this.pokemonGrowthRateText.setText("");
|
||||
this.pokemonGrowthRateLabelText.setVisible(false);
|
||||
@ -2091,8 +2003,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
|
||||
shiny: props.shiny,
|
||||
formIndex: props.formIndex,
|
||||
female: props.female,
|
||||
variant: props.variant,
|
||||
forSeen: true
|
||||
variant: props.variant
|
||||
});
|
||||
this.pokemonSprite.setTint(0x808080);
|
||||
}
|
||||
@ -2123,7 +2034,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
|
||||
|
||||
setSpeciesDetails(species: PokemonSpecies, options: SpeciesDetails = {}, forceUpdate?: boolean): void {
|
||||
let { shiny, formIndex, female, variant } = options;
|
||||
const forSeen: boolean = options.forSeen ?? false;
|
||||
const oldProps = species ? this.starterAttributes : null;
|
||||
|
||||
// We will only update the sprite if there is a change to form, shiny/variant
|
||||
@ -2194,12 +2104,12 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
|
||||
}
|
||||
|
||||
const isFormCaught = this.isFormCaught();
|
||||
const isFormSeen = dexEntry ? (dexEntry.seenAttr & globalScene.gameData.getFormAttr(formIndex ?? 0)) > 0n : false;
|
||||
|
||||
this.shinyOverlay.setVisible(shiny ?? false); // TODO: is false the correct default?
|
||||
this.pokemonNumberText.setColor(this.getTextColor(shiny ? TextStyle.SUMMARY_GOLD : TextStyle.SUMMARY, false));
|
||||
this.pokemonNumberText.setShadowColor(this.getTextColor(shiny ? TextStyle.SUMMARY_GOLD : TextStyle.SUMMARY, true));
|
||||
|
||||
|
||||
const assetLoadCancelled = new BooleanHolder(false);
|
||||
this.assetLoadCancelled = assetLoadCancelled;
|
||||
|
||||
@ -2221,13 +2131,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
|
||||
this.pokemonSprite.setVisible(!this.statsMode);
|
||||
}
|
||||
|
||||
const currentFilteredContainer = this.filteredStarterContainers.find(p => p.species.speciesId === species.speciesId);
|
||||
if (currentFilteredContainer) {
|
||||
const starterSprite = currentFilteredContainer.icon as Phaser.GameObjects.Sprite;
|
||||
starterSprite.setTexture(species.getIconAtlasKey(formIndex, shiny, variant), species.getIconId(female!, formIndex, shiny, variant));
|
||||
currentFilteredContainer.checkIconId(female, formIndex, shiny, variant);
|
||||
}
|
||||
|
||||
const isNonShinyCaught = !!(caughtAttr & DexAttr.NON_SHINY);
|
||||
const isShinyCaught = !!(caughtAttr & DexAttr.SHINY);
|
||||
|
||||
@ -2250,24 +2153,127 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
|
||||
this.pokemonGenderText.setText("");
|
||||
}
|
||||
|
||||
if (caughtAttr) {
|
||||
if (isFormCaught) {
|
||||
this.species.loadAssets(female!, formIndex, shiny, variant as Variant, true).then(() => {
|
||||
const crier = (this.species.forms && this.species.forms.length > 0) ? this.species.forms[formIndex ?? this.formIndex] : this.species;
|
||||
crier.cry();
|
||||
});
|
||||
|
||||
this.pokemonSprite.clearTint();
|
||||
} else {
|
||||
this.pokemonSprite.setTint(0x000000);
|
||||
}
|
||||
// Setting tint of the sprite
|
||||
if (isFormCaught) {
|
||||
this.species.loadAssets(female!, formIndex, shiny, variant as Variant, true).then(() => {
|
||||
const crier = (this.species.forms && this.species.forms.length > 0) ? this.species.forms[formIndex ?? this.formIndex] : this.species;
|
||||
crier.cry();
|
||||
});
|
||||
this.pokemonSprite.clearTint();
|
||||
} else if (isFormSeen) {
|
||||
this.pokemonSprite.setTint(0x808080);
|
||||
} else {
|
||||
this.pokemonSprite.setTint(0);
|
||||
}
|
||||
|
||||
if (caughtAttr || forSeen) {
|
||||
// Setting luck text and sparks
|
||||
if (isFormCaught) {
|
||||
const luck = globalScene.gameData.getDexAttrLuck(this.isCaught());
|
||||
this.pokemonLuckText.setVisible(!!luck);
|
||||
this.pokemonLuckText.setText(luck.toString());
|
||||
this.pokemonLuckText.setTint(getVariantTint(Math.min(luck - 1, 2) as Variant));
|
||||
this.pokemonLuckLabelText.setVisible(this.pokemonLuckText.visible);
|
||||
} else {
|
||||
this.pokemonLuckText.setVisible(false);
|
||||
this.pokemonLuckLabelText.setVisible(false);
|
||||
}
|
||||
|
||||
// Setting growth rate text
|
||||
if (isFormCaught) {
|
||||
let growthReadable = toReadableString(GrowthRate[species.growthRate]);
|
||||
const growthAux = growthReadable.replace(" ", "_");
|
||||
if (i18next.exists("growth:" + growthAux)) {
|
||||
growthReadable = i18next.t("growth:" + growthAux as any);
|
||||
}
|
||||
this.pokemonGrowthRateText.setText(growthReadable);
|
||||
|
||||
this.pokemonGrowthRateText.setColor(getGrowthRateColor(species.growthRate));
|
||||
this.pokemonGrowthRateText.setShadowColor(getGrowthRateColor(species.growthRate, true));
|
||||
this.pokemonGrowthRateLabelText.setVisible(true);
|
||||
} else {
|
||||
this.pokemonGrowthRateText.setText("");
|
||||
this.pokemonGrowthRateLabelText.setVisible(false);
|
||||
}
|
||||
|
||||
// Caught and hatched
|
||||
if (isFormCaught) {
|
||||
const colorScheme = starterColors[species.speciesId];
|
||||
|
||||
this.pokemonUncaughtText.setVisible(false);
|
||||
this.pokemonCaughtCountText.setText(`${this.speciesStarterDexEntry?.caughtCount}`);
|
||||
if (species.speciesId === Species.MANAPHY || species.speciesId === Species.PHIONE) {
|
||||
this.pokemonHatchedIcon.setFrame("manaphy");
|
||||
} else {
|
||||
this.pokemonHatchedIcon.setFrame(getEggTierForSpecies(species));
|
||||
}
|
||||
this.pokemonHatchedCountText.setText(`${this.speciesStarterDexEntry?.hatchedCount}`);
|
||||
|
||||
const defaultDexAttr = this.getCurrentDexProps(species.speciesId);
|
||||
const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);
|
||||
const variant = defaultProps.variant;
|
||||
const tint = getVariantTint(variant);
|
||||
this.pokemonShinyIcon.setFrame(getVariantIcon(variant));
|
||||
this.pokemonShinyIcon.setTint(tint);
|
||||
this.pokemonShinyIcon.setVisible(defaultProps.shiny);
|
||||
this.pokemonCaughtHatchedContainer.setVisible(true);
|
||||
|
||||
if (pokemonPrevolutions.hasOwnProperty(species.speciesId)) {
|
||||
this.pokemonCaughtHatchedContainer.setY(16);
|
||||
this.pokemonShinyIcon.setY(135);
|
||||
this.pokemonShinyIcon.setFrame(getVariantIcon(variant));
|
||||
[
|
||||
this.pokemonCandyContainer,
|
||||
this.pokemonHatchedIcon,
|
||||
this.pokemonHatchedCountText
|
||||
].map(c => c.setVisible(false));
|
||||
this.pokemonFormText.setY(25);
|
||||
} else {
|
||||
this.pokemonCaughtHatchedContainer.setY(25);
|
||||
this.pokemonShinyIcon.setY(117);
|
||||
this.pokemonCandyIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[0])));
|
||||
this.pokemonCandyOverlayIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[1])));
|
||||
this.pokemonCandyCountText.setText(`x${globalScene.gameData.starterData[this.getStarterSpeciesId(species.speciesId)].candyCount}`);
|
||||
this.pokemonCandyContainer.setVisible(true);
|
||||
this.pokemonFormText.setY(42);
|
||||
this.pokemonHatchedIcon.setVisible(true);
|
||||
this.pokemonHatchedCountText.setVisible(true);
|
||||
|
||||
const { currentFriendship, friendshipCap } = this.getFriendship(this.species.speciesId);
|
||||
const candyCropY = 16 - (16 * (currentFriendship / friendshipCap));
|
||||
this.pokemonCandyDarknessOverlay.setCrop(0, 0, 16, candyCropY);
|
||||
|
||||
this.pokemonCandyContainer.on("pointerover", () => {
|
||||
globalScene.ui.showTooltip("", `${currentFriendship}/${friendshipCap}`, true);
|
||||
this.activeTooltip = "CANDY";
|
||||
});
|
||||
this.pokemonCandyContainer.on("pointerout", () => {
|
||||
globalScene.ui.hideTooltip();
|
||||
this.activeTooltip = undefined;
|
||||
});
|
||||
|
||||
}
|
||||
} else {
|
||||
this.pokemonUncaughtText.setVisible(true);
|
||||
this.pokemonCaughtHatchedContainer.setVisible(false);
|
||||
this.pokemonCandyContainer.setVisible(false);
|
||||
this.pokemonShinyIcon.setVisible(false);
|
||||
}
|
||||
|
||||
// Form text
|
||||
if (isFormCaught || isFormSeen) {
|
||||
this.pokemonFormText.setVisible(true);
|
||||
if (isFormSeen) {
|
||||
this.pokemonFormText.setY(18);
|
||||
}
|
||||
} else {
|
||||
this.pokemonFormText.setVisible(false);
|
||||
}
|
||||
|
||||
// Setting type icons
|
||||
if (isFormCaught || isFormSeen) {
|
||||
const speciesForm = getPokemonSpeciesForm(species.speciesId, formIndex!); // TODO: is the bang correct?
|
||||
this.setTypeIcons(speciesForm.type1, speciesForm.type2);
|
||||
this.pokemonFormText.setText(this.getFormString((speciesForm as PokemonForm).formKey, species));
|
||||
|
||||
} else {
|
||||
this.setTypeIcons(null, null);
|
||||
this.pokemonFormText.setText("");
|
||||
|
@ -42,7 +42,6 @@ import { pokemonStarters } from "#app/data/balance/pokemon-evolutions";
|
||||
import { Biome } from "#enums/biome";
|
||||
import { globalScene } from "#app/global-scene";
|
||||
|
||||
|
||||
interface LanguageSetting {
|
||||
starterInfoTextSize: string,
|
||||
instructionTextSize: string,
|
||||
@ -138,8 +137,7 @@ interface SpeciesDetails {
|
||||
female?: boolean,
|
||||
variant?: Variant,
|
||||
abilityIndex?: number,
|
||||
natureIndex?: number,
|
||||
forSeen?: boolean, // default = false
|
||||
natureIndex?: number
|
||||
}
|
||||
|
||||
export default class PokedexUiHandler extends MessageUiHandler {
|
||||
@ -206,6 +204,17 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
private toggleDecorationsIconElement: Phaser.GameObjects.Sprite;
|
||||
private toggleDecorationsLabel: Phaser.GameObjects.Text;
|
||||
|
||||
private formTrayContainer: Phaser.GameObjects.Container;
|
||||
private trayBg: Phaser.GameObjects.NineSlice;
|
||||
private trayForms: PokemonForm[];
|
||||
private trayContainers: PokedexMonContainer[] = [];
|
||||
private trayNumIcons: number;
|
||||
private trayRows: number;
|
||||
private trayColumns: number;
|
||||
private trayCursorObj: Phaser.GameObjects.Image;
|
||||
private trayCursor: number = 0;
|
||||
private showTray: boolean = false;
|
||||
|
||||
constructor() {
|
||||
super(Mode.POKEDEX);
|
||||
}
|
||||
@ -425,7 +434,6 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
|
||||
this.cursorObj = globalScene.add.image(0, 0, "select_cursor");
|
||||
this.cursorObj.setOrigin(0, 0);
|
||||
|
||||
starterBoxContainer.add(this.cursorObj);
|
||||
|
||||
for (const species of allSpecies) {
|
||||
@ -438,6 +446,20 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
starterBoxContainer.add(pokemonContainer);
|
||||
}
|
||||
|
||||
// Tray to display forms
|
||||
this.formTrayContainer = globalScene.add.container(0, 0);
|
||||
|
||||
this.trayBg = addWindow(0, 0, 0, 0);
|
||||
this.trayBg.setOrigin(0, 0);
|
||||
this.formTrayContainer.add(this.trayBg);
|
||||
|
||||
this.trayCursorObj = globalScene.add.image(0, 0, "select_cursor");
|
||||
this.trayCursorObj.setOrigin(0, 0);
|
||||
this.formTrayContainer.add(this.trayCursorObj);
|
||||
starterBoxContainer.add(this.formTrayContainer);
|
||||
starterBoxContainer.bringToTop(this.formTrayContainer);
|
||||
this.formTrayContainer.setVisible(false);
|
||||
|
||||
this.starterSelectContainer.add(starterBoxContainer);
|
||||
|
||||
this.pokemonSprite = globalScene.add.sprite(96, 143, "pkmn__sub");
|
||||
@ -449,7 +471,7 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
this.type1Icon.setOrigin(0, 0);
|
||||
this.starterSelectContainer.add(this.type1Icon);
|
||||
|
||||
this.type2Icon = globalScene.add.sprite(10, 166, getLocalizedSpriteKey("types"));
|
||||
this.type2Icon = globalScene.add.sprite(28, 158, getLocalizedSpriteKey("types"));
|
||||
this.type2Icon.setScale(0.5);
|
||||
this.type2Icon.setOrigin(0, 0);
|
||||
this.starterSelectContainer.add(this.type2Icon);
|
||||
@ -527,7 +549,7 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
|
||||
this.starterPreferences[species.speciesId] = this.initStarterPrefs(species);
|
||||
|
||||
if (dexEntry.caughtAttr) {
|
||||
if (dexEntry.caughtAttr || globalScene.dexForDevs) {
|
||||
icon.clearTint();
|
||||
} else if (dexEntry.seenAttr) {
|
||||
icon.setTint(0x808080);
|
||||
@ -860,32 +882,42 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
} else if (this.filterTextMode && !(this.filterText.getValue(this.filterTextCursor) === this.filterText.defaultText)) {
|
||||
this.filterText.resetSelection(this.filterTextCursor);
|
||||
success = true;
|
||||
} else if (this.showTray) {
|
||||
success = this.closeFormTray();
|
||||
} else {
|
||||
this.tryExit();
|
||||
success = true;
|
||||
}
|
||||
} else if (button === Button.STATS) {
|
||||
if (!this.filterMode) {
|
||||
if (!this.filterMode && !this.showTray) {
|
||||
this.cursorObj.setVisible(false);
|
||||
this.setSpecies(null);
|
||||
this.filterText.cursorObj.setVisible(false);
|
||||
this.filterTextMode = false;
|
||||
this.filterBarCursor = 0;
|
||||
this.setFilterMode(true);
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
} else if (button === Button.V) {
|
||||
if (!this.filterTextMode) {
|
||||
if (!this.filterTextMode && !this.showTray) {
|
||||
this.cursorObj.setVisible(false);
|
||||
this.setSpecies(null);
|
||||
this.filterBar.cursorObj.setVisible(false);
|
||||
this.filterMode = false;
|
||||
this.filterTextCursor = 0;
|
||||
this.setFilterTextMode(true);
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
} else if (button === Button.CYCLE_SHINY) {
|
||||
this.showDecorations = !this.showDecorations;
|
||||
this.updateScroll();
|
||||
success = true;
|
||||
if (!this.showTray) {
|
||||
this.showDecorations = !this.showDecorations;
|
||||
this.updateScroll();
|
||||
success = true;
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
} else if (this.filterMode) {
|
||||
switch (button) {
|
||||
case Button.LEFT:
|
||||
@ -982,8 +1014,55 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
} else if (this.showTray) {
|
||||
if (button === Button.ACTION) {
|
||||
const formIndex = this.trayForms[this.trayCursor].formIndex;
|
||||
ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, formIndex, { form: formIndex });
|
||||
success = true;
|
||||
} else {
|
||||
const numberOfForms = this.trayContainers.length;
|
||||
const numOfRows = Math.ceil(numberOfForms / maxColumns);
|
||||
const currentRow = Math.floor(this.trayCursor / maxColumns);
|
||||
switch (button) {
|
||||
case Button.UP:
|
||||
if (currentRow > 0) {
|
||||
success = this.setTrayCursor(this.trayCursor - 9);
|
||||
} else {
|
||||
const targetCol = this.trayCursor;
|
||||
if (numberOfForms % 9 > targetCol) {
|
||||
success = this.setTrayCursor(numberOfForms - (numberOfForms) % 9 + targetCol);
|
||||
} else {
|
||||
success = this.setTrayCursor(Math.max(numberOfForms - (numberOfForms) % 9 + targetCol - 9, 0));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Button.DOWN:
|
||||
if (currentRow < numOfRows - 1) {
|
||||
success = this.setTrayCursor(this.trayCursor + 9);
|
||||
} else {
|
||||
success = this.setTrayCursor(this.trayCursor % 9);
|
||||
}
|
||||
break;
|
||||
case Button.LEFT:
|
||||
if (this.trayCursor % 9 !== 0) {
|
||||
success = this.setTrayCursor(this.trayCursor - 1);
|
||||
} else {
|
||||
success = this.setTrayCursor(currentRow < numOfRows - 1 ? (currentRow + 1) * maxColumns - 1 : numberOfForms - 1);
|
||||
}
|
||||
break;
|
||||
case Button.RIGHT:
|
||||
if (this.trayCursor % 9 < (currentRow < numOfRows - 1 ? 8 : (numberOfForms - 1) % 9)) {
|
||||
success = this.setTrayCursor(this.trayCursor + 1);
|
||||
} else {
|
||||
success = this.setTrayCursor(currentRow * 9);
|
||||
}
|
||||
break;
|
||||
case Button.CYCLE_FORM:
|
||||
success = this.closeFormTray();
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
if (button === Button.ACTION) {
|
||||
ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, 0);
|
||||
success = true;
|
||||
@ -1042,6 +1121,12 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
success = true;
|
||||
}
|
||||
break;
|
||||
case Button.CYCLE_FORM:
|
||||
const species = this.filteredPokemonContainers[this.cursor].species;
|
||||
if (species.forms && species.forms.length > 1) {
|
||||
success = this.openFormTray(species);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1068,6 +1153,9 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
case SettingKeyboard.Button_Cycle_Variant:
|
||||
iconPath = "V.png";
|
||||
break;
|
||||
case SettingKeyboard.Button_Cycle_Form:
|
||||
iconPath = "F.png";
|
||||
break;
|
||||
case SettingKeyboard.Button_Stats:
|
||||
iconPath = "C.png";
|
||||
break;
|
||||
@ -1558,6 +1646,98 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
openFormTray(species: PokemonSpecies): boolean {
|
||||
|
||||
this.trayForms = species.forms;
|
||||
|
||||
this.trayNumIcons = this.trayForms.length;
|
||||
this.trayRows = Math.floor(this.trayNumIcons / 9) + (this.trayNumIcons % 9 === 0 ? 0 : 1);
|
||||
this.trayColumns = Math.min(this.trayNumIcons, 9);
|
||||
|
||||
const maxColumns = 9;
|
||||
const onScreenFirstIndex = this.scrollCursor * maxColumns;
|
||||
const boxCursor = this.cursor - onScreenFirstIndex;
|
||||
const boxCursorY = Math.floor(boxCursor / maxColumns);
|
||||
const boxCursorX = boxCursor - boxCursorY * 9;
|
||||
const spaceBelow = 9 - 1 - boxCursorY;
|
||||
const spaceRight = 9 - boxCursorX;
|
||||
const boxPos = calcStarterPosition(this.cursor, this.scrollCursor);
|
||||
const goUp = this.trayRows <= spaceBelow - 1 ? 0 : 1;
|
||||
const goLeft = this.trayColumns <= spaceRight ? 0 : 1;
|
||||
|
||||
this.trayBg.setSize(13 + this.trayColumns * 17, 8 + this.trayRows * 18);
|
||||
this.formTrayContainer.setX(
|
||||
(goLeft ? boxPos.x - 18 * (this.trayColumns - spaceRight) : boxPos.x) - 3
|
||||
);
|
||||
this.formTrayContainer.setY(
|
||||
goUp ? boxPos.y - this.trayBg.height : boxPos.y + 17
|
||||
);
|
||||
|
||||
const dexEntry = globalScene.gameData.dexData[species.speciesId];
|
||||
const dexAttr = this.getCurrentDexProps(species.speciesId);
|
||||
const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, dexAttr));
|
||||
|
||||
this.trayContainers = [];
|
||||
this.trayForms.map((f, index) => {
|
||||
const isFormCaught = dexEntry ? (dexEntry.caughtAttr & globalScene.gameData.getFormAttr(f.formIndex ?? 0)) > 0n : false;
|
||||
const isFormSeen = dexEntry ? (dexEntry.seenAttr & globalScene.gameData.getFormAttr(f.formIndex ?? 0)) > 0n : false;
|
||||
const formContainer = new PokedexMonContainer(species, { formIndex: f.formIndex, female: props.female, shiny: props.shiny, variant: props.variant });
|
||||
this.iconAnimHandler.addOrUpdate(formContainer.icon, PokemonIconAnimMode.NONE);
|
||||
// Setting tint, for all saves some caught forms may only show up as seen
|
||||
if (isFormCaught || globalScene.dexForDevs) {
|
||||
formContainer.icon.clearTint();
|
||||
} else if (isFormSeen) {
|
||||
formContainer.icon.setTint(0x808080);
|
||||
}
|
||||
formContainer.setPosition(5 + (index % 9) * 18, 4 + Math.floor(index / 9) * 17);
|
||||
this.formTrayContainer.add(formContainer);
|
||||
this.trayContainers.push(formContainer);
|
||||
});
|
||||
|
||||
this.showTray = true;
|
||||
|
||||
this.setTrayCursor(0);
|
||||
|
||||
this.formTrayContainer.setVisible(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
closeFormTray(): boolean {
|
||||
|
||||
this.trayContainers.forEach(obj => {
|
||||
this.formTrayContainer.remove(obj, true); // Removes from container and destroys it
|
||||
});
|
||||
|
||||
this.trayContainers = [];
|
||||
this.formTrayContainer.setVisible(false);
|
||||
this.showTray = false;
|
||||
|
||||
this.setSpeciesDetails(this.lastSpecies);
|
||||
return true;
|
||||
}
|
||||
|
||||
setTrayCursor(cursor: number): boolean {
|
||||
if (!this.showTray) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cursor = Math.max(Math.min(this.trayContainers.length - 1, cursor), 0);
|
||||
const changed = this.trayCursor !== cursor;
|
||||
if (changed) {
|
||||
this.trayCursor = cursor;
|
||||
}
|
||||
|
||||
this.trayCursorObj.setPosition(5 + (cursor % 9) * 18, 4 + Math.floor(cursor / 9) * 17);
|
||||
|
||||
const species = this.lastSpecies;
|
||||
const formIndex = this.trayForms[cursor].formIndex;
|
||||
|
||||
this.setSpeciesDetails(species, { formIndex: formIndex });
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
getFriendship(speciesId: number) {
|
||||
let currentFriendship = globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].friendship;
|
||||
if (!currentFriendship || currentFriendship === undefined) {
|
||||
@ -1592,13 +1772,13 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
|
||||
this.lastSpecies = species!; // TODO: is this bang correct?
|
||||
|
||||
if (species && (this.speciesStarterDexEntry?.seenAttr || this.speciesStarterDexEntry?.caughtAttr)) {
|
||||
if (species && (this.speciesStarterDexEntry?.seenAttr || this.speciesStarterDexEntry?.caughtAttr || globalScene.dexForDevs)) {
|
||||
|
||||
this.pokemonNumberText.setText(i18next.t("pokedexUiHandler:pokemonNumber") + padInt(species.speciesId, 4));
|
||||
|
||||
this.pokemonNameText.setText(species.name);
|
||||
|
||||
if (this.speciesStarterDexEntry?.caughtAttr) {
|
||||
if (this.speciesStarterDexEntry?.caughtAttr || globalScene.dexForDevs) {
|
||||
|
||||
// Pause the animation when the species is selected
|
||||
const speciesIndex = this.allSpecies.indexOf(species);
|
||||
@ -1627,9 +1807,7 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
this.type1Icon.setVisible(true);
|
||||
this.type2Icon.setVisible(true);
|
||||
|
||||
this.setSpeciesDetails(species, {
|
||||
forSeen: true
|
||||
});
|
||||
this.setSpeciesDetails(species);
|
||||
this.pokemonSprite.setTint(0x808080);
|
||||
}
|
||||
} else {
|
||||
@ -1646,7 +1824,6 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
|
||||
setSpeciesDetails(species: PokemonSpecies, options: SpeciesDetails = {}): void {
|
||||
let { shiny, formIndex, female, variant } = options;
|
||||
const forSeen: boolean = options.forSeen ?? false;
|
||||
|
||||
// We will only update the sprite if there is a change to form, shiny/variant
|
||||
// or gender for species with gender sprite differences
|
||||
@ -1676,25 +1853,27 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
if (!dexEntry.caughtAttr) {
|
||||
const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)));
|
||||
|
||||
if (shiny === undefined || shiny !== props.shiny) {
|
||||
if (shiny === undefined) {
|
||||
shiny = props.shiny;
|
||||
}
|
||||
if (formIndex === undefined || formIndex !== props.formIndex) {
|
||||
if (formIndex === undefined) {
|
||||
formIndex = props.formIndex;
|
||||
}
|
||||
if (female === undefined || female !== props.female) {
|
||||
if (female === undefined) {
|
||||
female = props.female;
|
||||
}
|
||||
if (variant === undefined || variant !== props.variant) {
|
||||
if (variant === undefined) {
|
||||
variant = props.variant;
|
||||
}
|
||||
}
|
||||
|
||||
const isFormCaught = dexEntry ? (dexEntry.caughtAttr & globalScene.gameData.getFormAttr(formIndex ?? 0)) > 0n : false;
|
||||
const isFormSeen = dexEntry ? (dexEntry.seenAttr & globalScene.gameData.getFormAttr(formIndex ?? 0)) > 0n : false;
|
||||
|
||||
const assetLoadCancelled = new BooleanHolder(false);
|
||||
this.assetLoadCancelled = assetLoadCancelled;
|
||||
|
||||
if (shouldUpdateSprite) {
|
||||
|
||||
species.loadAssets(female!, formIndex, shiny, variant, true).then(() => { // TODO: is this bang correct?
|
||||
if (assetLoadCancelled.value) {
|
||||
return;
|
||||
@ -1711,14 +1890,21 @@ export default class PokedexUiHandler extends MessageUiHandler {
|
||||
this.pokemonSprite.setVisible(!(this.filterMode || this.filterTextMode));
|
||||
}
|
||||
|
||||
if (dexEntry.caughtAttr || forSeen) {
|
||||
if (isFormCaught || globalScene.dexForDevs) {
|
||||
this.pokemonSprite.clearTint();
|
||||
} else if (isFormSeen) {
|
||||
this.pokemonSprite.setTint(0x808080);
|
||||
} else {
|
||||
this.pokemonSprite.setTint(0);
|
||||
}
|
||||
|
||||
if (isFormCaught || isFormSeen || globalScene.dexForDevs) {
|
||||
const speciesForm = getPokemonSpeciesForm(species.speciesId, 0); // TODO: always selecting the first form
|
||||
|
||||
this.setTypeIcons(speciesForm.type1, speciesForm.type2);
|
||||
} else {
|
||||
this.setTypeIcons(null, null);
|
||||
}
|
||||
|
||||
} else {
|
||||
this.setTypeIcons(null, null);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user