From 553a2e7ba806f7142b5c36a2788f805e86410d9e Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Sun, 16 Feb 2025 22:16:13 +0100 Subject: [PATCH] =?UTF-8?q?Moving=20creation=20of=20pok=C3=A9mon=20icon=20?= =?UTF-8?q?containers=20from=20setup()=20to=20view();=20clearing=20contain?= =?UTF-8?q?ers=20on=20clear().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/pokedex-ui-handler.ts | 35 +++++++++++++++++--------- src/ui/starter-select-ui-handler.ts | 39 ++++++++++++++++++----------- 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/ui/pokedex-ui-handler.ts b/src/ui/pokedex-ui-handler.ts index 5180d7bd956..d776bed7b93 100644 --- a/src/ui/pokedex-ui-handler.ts +++ b/src/ui/pokedex-ui-handler.ts @@ -141,6 +141,7 @@ interface SpeciesDetails { export default class PokedexUiHandler extends MessageUiHandler { private starterSelectContainer: Phaser.GameObjects.Container; + private starterBoxContainer: Phaser.GameObjects.Container; private starterSelectScrollBar: ScrollBar; private filterBarContainer: Phaser.GameObjects.Container; private filterBar: FilterBar; @@ -425,32 +426,27 @@ export default class PokedexUiHandler extends MessageUiHandler { this.pokemonFormText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonFormText); - const starterBoxContainer = globalScene.add.container(speciesContainerX + 6, 9); //115 + this.starterBoxContainer = globalScene.add.container(speciesContainerX + 6, 9); //115 this.starterSelectScrollBar = new ScrollBar(161, 12, 5, pokemonContainerWindow.height - 6, 9); - starterBoxContainer.add(this.starterSelectScrollBar); + this.starterBoxContainer.add(this.starterSelectScrollBar); this.pokerusCursorObjs = new Array(POKERUS_STARTER_COUNT).fill(null).map(() => { const cursorObj = globalScene.add.image(0, 0, "select_cursor_pokerus"); cursorObj.setVisible(false); cursorObj.setOrigin(0, 0); - starterBoxContainer.add(cursorObj); + this.starterBoxContainer.add(cursorObj); return cursorObj; }); this.cursorObj = globalScene.add.image(0, 0, "select_cursor"); this.cursorObj.setOrigin(0, 0); - starterBoxContainer.add(this.cursorObj); + this.starterBoxContainer.add(this.cursorObj); for (const species of allSpecies) { this.speciesLoaded.set(species.speciesId, false); this.allSpecies.push(species); - - const pokemonContainer = new PokedexMonContainer(species).setVisible(false); - this.iconAnimHandler.addOrUpdate(pokemonContainer.icon, PokemonIconAnimMode.NONE); - this.pokemonContainers.push(pokemonContainer); - starterBoxContainer.add(pokemonContainer); } // Tray to display forms @@ -463,11 +459,11 @@ export default class PokedexUiHandler extends MessageUiHandler { 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.starterBoxContainer.add(this.formTrayContainer); + this.starterBoxContainer.bringToTop(this.formTrayContainer); this.formTrayContainer.setVisible(false); - this.starterSelectContainer.add(starterBoxContainer); + this.starterSelectContainer.add(this.starterBoxContainer); this.pokemonSprite = globalScene.add.sprite(96, 143, "pkmn__sub"); this.pokemonSprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); @@ -545,6 +541,13 @@ export default class PokedexUiHandler extends MessageUiHandler { show(args: any[]): boolean { + for (const species of this.allSpecies) { + const pokemonContainer = new PokedexMonContainer(species).setVisible(false); + this.iconAnimHandler.addOrUpdate(pokemonContainer.icon, PokemonIconAnimMode.NONE); + this.pokemonContainers.push(pokemonContainer); + this.starterBoxContainer.add(pokemonContainer); + } + if (!this.starterPreferences) { this.starterPreferences = StarterPrefs.load(); } @@ -2125,6 +2128,14 @@ export default class PokedexUiHandler extends MessageUiHandler { clear(): void { super.clear(); + this.pokemonContainers.forEach(obj => { + this.starterBoxContainer.remove(obj, true); // Removes from container and destroys it + }); + this.pokemonContainers = []; + // These arrays must be emptied too, or garbage is not collected properly + this.validPokemonContainers = []; + this.filteredPokemonContainers = []; + this.cursor = -1; globalScene.ui.hideTooltip(); diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index 65c159c62a8..fd777811a92 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -216,6 +216,7 @@ interface SpeciesDetails { export default class StarterSelectUiHandler extends MessageUiHandler { private starterSelectContainer: Phaser.GameObjects.Container; + private starterBoxContainer: Phaser.GameObjects.Container; private starterSelectScrollBar: ScrollBar; private filterBarContainer: Phaser.GameObjects.Container; private filterBar: FilterBar; @@ -623,19 +624,17 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.randomCursorObj.setOrigin(0, 0); this.starterSelectContainer.add(this.randomCursorObj); - const starterSpecies: Species[] = []; - - const starterBoxContainer = globalScene.add.container(speciesContainerX + 6, 9); //115 + this.starterBoxContainer = globalScene.add.container(speciesContainerX + 6, 9); //115 this.starterSelectScrollBar = new ScrollBar(161, 12, 5, starterContainerWindow.height - 6, 9); - starterBoxContainer.add(this.starterSelectScrollBar); + this.starterBoxContainer.add(this.starterSelectScrollBar); this.pokerusCursorObjs = new Array(POKERUS_STARTER_COUNT).fill(null).map(() => { const cursorObj = globalScene.add.image(0, 0, "select_cursor_pokerus"); cursorObj.setVisible(false); cursorObj.setOrigin(0, 0); - starterBoxContainer.add(cursorObj); + this.starterBoxContainer.add(cursorObj); return cursorObj; }); @@ -643,7 +642,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { const cursorObj = globalScene.add.image(0, 0, "select_cursor_highlight"); cursorObj.setVisible(false); cursorObj.setOrigin(0, 0); - starterBoxContainer.add(cursorObj); + this.starterBoxContainer.add(cursorObj); return cursorObj; }); @@ -655,25 +654,19 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.starterIconsCursorObj.setOrigin(0, 0); this.starterSelectContainer.add(this.starterIconsCursorObj); - starterBoxContainer.add(this.cursorObj); + this.starterBoxContainer.add(this.cursorObj); + + this.starterSelectContainer.add(this.starterBoxContainer); for (const species of allSpecies) { if (!speciesStarterCosts.hasOwnProperty(species.speciesId) || !species.isObtainable()) { continue; } - starterSpecies.push(species.speciesId); this.speciesLoaded.set(species.speciesId, false); this.allSpecies.push(species); - - const starterContainer = new StarterContainer(species).setVisible(false); - this.iconAnimHandler.addOrUpdate(starterContainer.icon, PokemonIconAnimMode.NONE); - this.starterContainers.push(starterContainer); - starterBoxContainer.add(starterContainer); } - this.starterSelectContainer.add(starterBoxContainer); - this.starterIcons = new Array(6).fill(null).map((_, i) => { const icon = globalScene.add.sprite(teamWindowX + 7, calcStarterIconY(i), "pokemon_icons_0"); icon.setScale(0.5); @@ -924,6 +917,14 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } show(args: any[]): boolean { + + for (const species of this.allSpecies) { + const starterContainer = new StarterContainer(species).setVisible(false); + this.iconAnimHandler.addOrUpdate(starterContainer.icon, PokemonIconAnimMode.NONE); + this.starterContainers.push(starterContainer); + this.starterBoxContainer.add(starterContainer); + } + if (!this.starterPreferences) { // starterPreferences haven't been loaded yet this.starterPreferences = StarterPrefs.load(); @@ -3829,6 +3830,14 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.activeTooltip = undefined; globalScene.ui.hideTooltip(); + this.starterContainers.forEach(obj => { + this.starterBoxContainer.remove(obj, true); // Removes from container and destroys it + }); + this.starterContainers = []; + // These arrays must be emptied too, or garbage is not collected properly + this.validStarterContainers = []; + this.filteredStarterContainers = []; + this.starterSelectContainer.setVisible(false); this.blockInput = false;