pokerogue/src/ui/starter-container.ts
Leo Kim 62fd574ce5
[QoL] New Starter Select UI with Filter (#2916)
* update images for new UI

* add updated starter UI with filter code

* update starter-select test code

* update win filter condition to pass test

* remove unnecessary console log

* update test code to match current filter UI

* merge update

* apply bugfix & chrry-pick small issues fix which are handled beta branch

* resolve conflicts

* fix lint errors

* Fixed a bug where the target location for escaping using the left and right buttons on the starter button did not account for scrolling

* update filter bar label color change when activated

* fix lint error

* fix lint

* fix octolock.text.ts. it looks override import error. idk why it is happend in this PR. but it looks ok now

* add passive dropdown in unlocks filter

* fix lint

* fix double button sound bug. refactoring genSpecies -> allSpecies, starterContainers -> starterContainer which are remove unnecessary generation axis

* optimize updateStarterValueLabel function which is bottleneck of UI update latency

* apply translation of gen filter label. fix lint

* add # candies sort option

* merge beta

* resolve confilcts

* fix offset of starter and start cursor

* make compatible with starter UI

* add missing feature

* add images for legacy UI. adjust the position and size of the starterContainerWindow
2024-07-23 22:33:14 -05:00

102 lines
3.9 KiB
TypeScript

import BattleScene from "../battle-scene";
import PokemonSpecies from "../data/pokemon-species";
import { addTextObject, TextStyle } from "./text";
export class StarterContainer extends Phaser.GameObjects.Container {
public scene: BattleScene;
public species: PokemonSpecies;
public icon: Phaser.GameObjects.Sprite;
public shinyIcons: Phaser.GameObjects.Image[] = [];
public label: Phaser.GameObjects.Text;
public starterPassiveBgs: Phaser.GameObjects.Image;
public hiddenAbilityIcon: Phaser.GameObjects.Image;
public classicWinIcon: Phaser.GameObjects.Image;
public candyUpgradeIcon: Phaser.GameObjects.Image;
public candyUpgradeOverlayIcon: Phaser.GameObjects.Image;
public cost: number = 0;
constructor(scene: BattleScene, species: PokemonSpecies) {
super(scene, 0, 0);
this.species = species;
const defaultDexAttr = scene.gameData.getSpeciesDefaultDexAttr(species, false, true);
const defaultProps = scene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);
// starter passive bg
const starterPassiveBg = this.scene.add.image(2, 5, "passive_bg");
starterPassiveBg.setOrigin(0, 0);
starterPassiveBg.setScale(0.75);
starterPassiveBg.setVisible(false);
this.add(starterPassiveBg);
this.starterPassiveBgs = starterPassiveBg;
// icon
this.icon = this.scene.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 = this.scene.add.image(i * -3 + 12, 2, "shiny_star_small");
shinyIcon.setScale(0.5);
shinyIcon.setOrigin(0, 0);
shinyIcon.setVisible(false);
this.shinyIcons.push(shinyIcon);
}
this.add(this.shinyIcons);
// value label
const label = addTextObject(this.scene, 1, 2, "0", TextStyle.WINDOW, { fontSize: "32px" });
label.setShadowOffset(2, 2);
label.setOrigin(0, 0);
label.setVisible(false);
this.add(label);
this.label = label;
// hidden ability icon
const abilityIcon = this.scene.add.image(12, 7, "ha_capsule");
abilityIcon.setOrigin(0, 0);
abilityIcon.setScale(0.5);
abilityIcon.setVisible(false);
this.add(abilityIcon);
this.hiddenAbilityIcon = abilityIcon;
// classic win icon
const classicWinIcon = this.scene.add.image(2, 12, "champion_ribbon");
classicWinIcon.setOrigin(0, 0);
classicWinIcon.setScale(0.5);
classicWinIcon.setVisible(false);
this.add(classicWinIcon);
this.classicWinIcon = classicWinIcon;
// candy upgrade icon
const candyUpgradeIcon = this.scene.add.image(12, 12, "candy");
candyUpgradeIcon.setOrigin(0, 0);
candyUpgradeIcon.setScale(0.25);
candyUpgradeIcon.setVisible(false);
this.add(candyUpgradeIcon);
this.candyUpgradeIcon = candyUpgradeIcon;
// candy upgrade overlay icon
const candyUpgradeOverlayIcon = this.scene.add.image(12, 12, "candy_overlay");
candyUpgradeOverlayIcon.setOrigin(0, 0);
candyUpgradeOverlayIcon.setScale(0.25);
candyUpgradeOverlayIcon.setVisible(false);
this.add(candyUpgradeOverlayIcon);
this.candyUpgradeOverlayIcon = candyUpgradeOverlayIcon;
}
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.`);
this.icon.setTexture(this.species.getIconAtlasKey(formIndex, false, variant));
this.icon.setFrame(this.species.getIconId(female, formIndex, false, variant));
}
}
}