From d1b058fe3e4224343283a74e44d98589d6702a20 Mon Sep 17 00:00:00 2001 From: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com> Date: Tue, 10 Sep 2024 20:00:50 +0200 Subject: [PATCH] [UI] fix candy upgrade icon not updating after purchasing eggs (#4153) --- src/ui/starter-select-ui-handler.ts | 53 +++++++++++++++++------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index 89f1b87bcf4..0c3d8de61b0 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -1220,6 +1220,19 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } } + /** + * Update the display of candy upgrade icons or animations for the given StarterContainer + * @param starterContainer the container for the Pokemon to update + */ + updateCandyUpgradeDisplay(starterContainer: StarterContainer) { + if (this.isUpgradeIconEnabled() ) { + this.setUpgradeIcon(starterContainer); + } + if (this.isUpgradeAnimationEnabled()) { + this.setUpgradeAnimation(starterContainer.icon, this.lastSpecies, true); + } + } + /** * Processes an {@linkcode CandyUpgradeNotificationChangedEvent} sent when the corresponding setting changes * @param event {@linkcode Event} sent by the callback @@ -1624,7 +1637,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { } }); } - const candyCount = starterData.candyCount; + const passiveAttr = starterData.passiveAttr; if (passiveAttr & PassiveAttr.UNLOCKED) { // this is for enabling and disabling the passive if (!(passiveAttr & PassiveAttr.ENABLED)) { @@ -1705,8 +1718,13 @@ export default class StarterSelectUiHandler extends MessageUiHandler { return true; } }); - const showUseCandies = () => { // this lets you use your candies + + // Purchases with Candy + const candyCount = starterData.candyCount; + const showUseCandies = () => { const options: any[] = []; // TODO: add proper type + + // Unlock passive option if (!(passiveAttr & PassiveAttr.UNLOCKED)) { const passiveCost = getPassiveCandyCount(speciesStarters[this.lastSpecies.speciesId]); options.push({ @@ -1727,16 +1745,9 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.setSpeciesDetails(this.lastSpecies); this.scene.playSound("se/buy"); - // if starterContainer exists, update the passive background + // update the passive background and icon/animation for available upgrade if (starterContainer) { - // Update the candy upgrade display - if (this.isUpgradeIconEnabled() ) { - this.setUpgradeIcon(starterContainer); - } - if (this.isUpgradeAnimationEnabled()) { - this.setUpgradeAnimation(starterContainer.icon, this.lastSpecies, true); - } - + this.updateCandyUpgradeDisplay(starterContainer); starterContainer.starterPassiveBgs.setVisible(!!this.scene.gameData.starterData[this.lastSpecies.speciesId].passiveAttr); } return true; @@ -1747,6 +1758,8 @@ export default class StarterSelectUiHandler extends MessageUiHandler { itemArgs: starterColors[this.lastSpecies.speciesId] }); } + + // Reduce cost option const valueReduction = starterData.valueReduction; if (valueReduction < valueReductionMax) { const reductionCost = getValueReductionCandyCounts(speciesStarters[this.lastSpecies.speciesId])[valueReduction]; @@ -1768,19 +1781,10 @@ export default class StarterSelectUiHandler extends MessageUiHandler { ui.setMode(Mode.STARTER_SELECT); this.scene.playSound("se/buy"); - // if starterContainer exists, update the value reduction background + // update the value label and icon/animation for available upgrade if (starterContainer) { this.updateStarterValueLabel(starterContainer); - - // If the notification setting is set to 'On', update the candy upgrade display - if (this.scene.candyUpgradeNotification === 2) { - if (this.isUpgradeIconEnabled() ) { - this.setUpgradeIcon(starterContainer); - } - if (this.isUpgradeAnimationEnabled()) { - this.setUpgradeAnimation(starterContainer.icon, this.lastSpecies, true); - } - } + this.updateCandyUpgradeDisplay(starterContainer); } return true; } @@ -1813,6 +1817,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler { ui.setMode(Mode.STARTER_SELECT); this.scene.playSound("se/buy"); + // update the icon/animation for available upgrade + if (starterContainer) { + this.updateCandyUpgradeDisplay(starterContainer); + } + return true; } return false;