diff --git a/src/phases/show-ability-phase.ts b/src/phases/show-ability-phase.ts index a0db660ded5..1e45818af1d 100644 --- a/src/phases/show-ability-phase.ts +++ b/src/phases/show-ability-phase.ts @@ -17,13 +17,15 @@ export class ShowAbilityPhase extends PokemonPhase { const pokemon = this.getPokemon(); if (pokemon) { - globalScene.abilityBar.showAbility(pokemon, this.passive); + globalScene.abilityBar.showAbility(pokemon, this.passive).then(() => { + if (pokemon?.battleData) { + pokemon.battleData.abilityRevealed = true; + } - if (pokemon?.battleData) { - pokemon.battleData.abilityRevealed = true; - } + this.end(); + }); + } else { + this.end(); } - - this.end(); } } diff --git a/src/ui/ability-bar.ts b/src/ui/ability-bar.ts index 8335f7b517c..2c62ab36d1e 100644 --- a/src/ui/ability-bar.ts +++ b/src/ui/ability-bar.ts @@ -12,9 +12,6 @@ export default class AbilityBar extends Phaser.GameObjects.Container { private bg: Phaser.GameObjects.Image; private abilityBarText: Phaser.GameObjects.Text; - private tween: Phaser.Tweens.Tween | null; - private autoHideTimer: NodeJS.Timeout | null; - public shown: boolean; constructor() { @@ -36,66 +33,55 @@ export default class AbilityBar extends Phaser.GameObjects.Container { this.shown = false; } - showAbility(pokemon: Pokemon, passive: boolean = false): void { - this.abilityBarText.setText(`${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: getPokemonNameWithAffix(pokemon), passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: !passive ? pokemon.getAbility().name : pokemon.getPassiveAbility().name })}`); + override setVisible(shown: boolean): this { + this.shown = shown; + super.setVisible(shown); + return this; + } - if (this.shown) { - return; + startTween(config: any, text?: string): Promise { + this.setVisible(true); + this.shown = true; + if (text) { + this.abilityBarText.setText(text); } + return new Promise((resolve) => { + globalScene.tweens.add({ + ...config, + onComplete: () => { + if (config.onComplete) { + config.onComplete(); + } + resolve(); + } + }); + }); + } + + showAbility(pokemon: Pokemon, passive: boolean = false): Promise { + const text = (`${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: getPokemonNameWithAffix(pokemon), passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: !passive ? pokemon.getAbility().name : pokemon.getPassiveAbility().name })}`); globalScene.fieldUI.bringToTop(this); - this.y = baseY + (globalScene.currentBattle.double ? 14 : 0); - this.tween = globalScene.tweens.add({ + return this.startTween({ targets: this, x: shownX, duration: 500, ease: "Sine.easeOut", - onComplete: () => { - this.tween = null; - this.resetAutoHideTimer(); - } - }); - - this.setVisible(true); - this.shown = true; + hold: 1000, + }, text); } hide(): void { - if (!this.shown) { - return; - } - - if (this.autoHideTimer) { - clearInterval(this.autoHideTimer); - } - - if (this.tween) { - this.tween.stop(); - } - - this.tween = globalScene.tweens.add({ + this.startTween({ targets: this, x: -91, duration: 500, ease: "Sine.easeIn", onComplete: () => { - this.tween = null; this.setVisible(false); } }); - - this.shown = false; - } - - resetAutoHideTimer(): void { - if (this.autoHideTimer) { - clearInterval(this.autoHideTimer); - } - this.autoHideTimer = setTimeout(() => { - this.hide(); - this.autoHideTimer = null; - }, 2500); } }