From 2687ce25354ac3e3f00e098daba304c8e8637c59 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Wed, 23 Apr 2025 10:55:03 -0500 Subject: [PATCH] Make flyout exclusive to EnemyBattleInfo --- src/field/pokemon.ts | 26 +++++++------- src/ui-inputs.ts | 2 +- src/ui/battle-flyout.ts | 4 +-- src/ui/battle-info/battle-info.ts | 45 ------------------------- src/ui/battle-info/enemy-battle-info.ts | 38 ++++++++++++++++++++- src/ui/fight-ui-handler.ts | 6 ++-- 6 files changed, 57 insertions(+), 64 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 08ad0f22caf..ce26979c990 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -3349,22 +3349,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return this.battleInfo.updateInfo(this, instant); } - /** - * Show or hide the type effectiveness multiplier window - * Passing undefined will hide the window - */ - updateEffectiveness(effectiveness?: string) { - this.battleInfo.updateEffectiveness(effectiveness); - } - toggleStats(visible: boolean): void { this.battleInfo.toggleStats(visible); } - toggleFlyout(visible: boolean): void { - this.battleInfo.toggleFlyout(visible); - } - /** * Adds experience to this PlayerPokemon, subject to wave based level caps. * @param exp The amount of experience to add @@ -6040,6 +6028,7 @@ export class PlayerPokemon extends Pokemon { } export class EnemyPokemon extends Pokemon { + protected battleInfo: EnemyBattleInfo; public trainerSlot: TrainerSlot; public aiType: AiType; public bossSegments: number; @@ -6711,6 +6700,19 @@ export class EnemyPokemon extends Pokemon { return ret; } + + + /** + * Show or hide the type effectiveness multiplier window + * Passing undefined will hide the window + */ + updateEffectiveness(effectiveness?: string) { + this.battleInfo.updateEffectiveness(effectiveness); + } + + toggleFlyout(visible: boolean): void { + this.battleInfo.toggleFlyout(visible); + } } /** diff --git a/src/ui-inputs.ts b/src/ui-inputs.ts index 0c13cdb9512..e4f11e1c93c 100644 --- a/src/ui-inputs.ts +++ b/src/ui-inputs.ts @@ -161,7 +161,7 @@ export class UiInputs { buttonInfo(pressed = true): void { if (globalScene.showMovesetFlyout) { - for (const p of globalScene.getField().filter(p => p?.isActive(true))) { + for (const p of globalScene.getEnemyField().filter(p => p?.isActive(true))) { p.toggleFlyout(pressed); } } diff --git a/src/ui/battle-flyout.ts b/src/ui/battle-flyout.ts index e590bebcf5a..f8ef5fc1ec4 100644 --- a/src/ui/battle-flyout.ts +++ b/src/ui/battle-flyout.ts @@ -1,4 +1,4 @@ -import type { default as Pokemon } from "../field/pokemon"; +import type { EnemyPokemon, default as Pokemon } from "../field/pokemon"; import { addTextObject, TextStyle } from "./text"; import { fixedInt } from "#app/utils/common"; import { globalScene } from "#app/global-scene"; @@ -126,7 +126,7 @@ export default class BattleFlyout extends Phaser.GameObjects.Container { * Links the given {@linkcode Pokemon} and subscribes to the {@linkcode BattleSceneEventType.MOVE_USED} event * @param pokemon {@linkcode Pokemon} to link to this flyout */ - initInfo(pokemon: Pokemon) { + initInfo(pokemon: EnemyPokemon) { this.pokemon = pokemon; this.name = `Flyout ${getPokemonNameWithAffix(this.pokemon)}`; diff --git a/src/ui/battle-info/battle-info.ts b/src/ui/battle-info/battle-info.ts index e0746f86d27..522eff874f5 100644 --- a/src/ui/battle-info/battle-info.ts +++ b/src/ui/battle-info/battle-info.ts @@ -9,7 +9,6 @@ import { getTypeRgb } from "#app/data/type"; import { PokemonType } from "#enums/pokemon-type"; import { getVariantTint } from "#app/sprites/variant"; import { Stat } from "#enums/stat"; -import type BattleFlyout from "../battle-flyout"; import i18next from "i18next"; import { ExpGainsSpeed } from "#app/enums/exp-gains-speed"; @@ -55,13 +54,6 @@ export default abstract class BattleInfo extends Phaser.GameObjects.Container { protected type3Icon: Phaser.GameObjects.Sprite; protected expBar: Phaser.GameObjects.Image; - // #region Type effectiveness hint objects - protected effectivenessContainer: Phaser.GameObjects.Container; - protected effectivenessWindow: Phaser.GameObjects.NineSlice; - protected effectivenessText: Phaser.GameObjects.Text; - protected currentEffectiveness?: string; - // #endregion - public expMaskRect: Phaser.GameObjects.Graphics; protected statsContainer: Phaser.GameObjects.Container; @@ -69,8 +61,6 @@ export default abstract class BattleInfo extends Phaser.GameObjects.Container { protected statValuesContainer: Phaser.GameObjects.Container; protected statNumbers: Phaser.GameObjects.Sprite[]; - public flyoutMenu?: BattleFlyout; - get statOrder(): Stat[] { return []; } @@ -282,8 +272,6 @@ export default abstract class BattleInfo extends Phaser.GameObjects.Container { this.name = pokemon.getNameToRender(); this.box.name = pokemon.getNameToRender(); - this.flyoutMenu?.initInfo(pokemon); - this.genderText.setText(getGenderSymbol(pokemon.gender)); this.genderText.setColor(getGenderColor(pokemon.gender)); this.genderText.setPositionRelative(this.nameText, nameTextWidth, 0); @@ -877,39 +865,6 @@ export default abstract class BattleInfo extends Phaser.GameObjects.Container { }); } - /** - * Request the flyoutMenu to toggle if available and hides or shows the effectiveness window where necessary - */ - toggleFlyout(visible: boolean): void { - this.flyoutMenu?.toggleFlyout(visible); - - if (visible) { - this.effectivenessContainer?.setVisible(false); - } else { - this.updateEffectiveness(this.currentEffectiveness); - } - } - - /** - * Show or hide the type effectiveness multiplier window - * Passing undefined will hide the window - */ - updateEffectiveness(effectiveness?: string) { - if (this.player) { - return; - } - this.currentEffectiveness = effectiveness; - - if (!globalScene.typeHints || effectiveness === undefined || this.flyoutMenu?.flyoutVisible) { - this.effectivenessContainer.setVisible(false); - return; - } - - this.effectivenessText.setText(effectiveness); - this.effectivenessWindow.width = 10 + this.effectivenessText.displayWidth; - this.effectivenessContainer.setVisible(true); - } - getBaseY(): number { return this.baseY; } diff --git a/src/ui/battle-info/enemy-battle-info.ts b/src/ui/battle-info/enemy-battle-info.ts index 7df93bf35c5..b7e149621d6 100644 --- a/src/ui/battle-info/enemy-battle-info.ts +++ b/src/ui/battle-info/enemy-battle-info.ts @@ -4,12 +4,13 @@ import BattleFlyout from "../battle-flyout"; import { addTextObject, TextStyle } from "#app/ui/text"; import { addWindow, WindowVariant } from "#app/ui/ui-theme"; import { Stat } from "#enums/stat"; +import type { EnemyPokemon } from "#app/field/pokemon"; export class EnemyBattleInfo extends BattleInfo { protected player: false = false; protected championRibbon: Phaser.GameObjects.Sprite; protected ownedIcon: Phaser.GameObjects.Sprite; - public flyoutMenu: BattleFlyout; + protected flyoutMenu: BattleFlyout; // #region Type effectiveness hint objects protected effectivenessContainer: Phaser.GameObjects.Container; @@ -52,5 +53,40 @@ export class EnemyBattleInfo extends BattleInfo { this.effectivenessContainer.add([this.effectivenessWindow, this.effectivenessText]); } + override initInfo(pokemon: EnemyPokemon): void { + this.flyoutMenu.initInfo(pokemon); + super.initInfo(pokemon); + } + + /** + * Show or hide the type effectiveness multiplier window + * Passing undefined will hide the window + */ + updateEffectiveness(effectiveness?: string) { + this.currentEffectiveness = effectiveness; + + if (!globalScene.typeHints || effectiveness === undefined || this.flyoutMenu.flyoutVisible) { + this.effectivenessContainer.setVisible(false); + return; + } + + this.effectivenessText.setText(effectiveness); + this.effectivenessWindow.width = 10 + this.effectivenessText.displayWidth; + this.effectivenessContainer.setVisible(true); + } + + /** + * Request the flyoutMenu to toggle if available and hides or shows the effectiveness window where necessary + */ + toggleFlyout(visible: boolean): void { + this.flyoutMenu.toggleFlyout(visible); + + if (visible) { + this.effectivenessContainer?.setVisible(false); + } else { + this.updateEffectiveness(this.currentEffectiveness); + } + } + setMini(_mini: boolean): void {} // Always mini } diff --git a/src/ui/fight-ui-handler.ts b/src/ui/fight-ui-handler.ts index 5a0978a934d..ccb16c68541 100644 --- a/src/ui/fight-ui-handler.ts +++ b/src/ui/fight-ui-handler.ts @@ -10,7 +10,7 @@ import { getLocalizedSpriteKey, fixedInt, padInt } from "#app/utils/common"; import { MoveCategory } from "#enums/MoveCategory"; import i18next from "i18next"; import { Button } from "#enums/buttons"; -import type { PokemonMove } from "#app/field/pokemon"; +import type { EnemyPokemon, PokemonMove } from "#app/field/pokemon"; import type Pokemon from "#app/field/pokemon"; import type { CommandPhase } from "#app/phases/command-phase"; import MoveInfoOverlay from "./move-info-overlay"; @@ -279,7 +279,7 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { this.moveInfoOverlay.show(pokemonMove.getMove()); pokemon.getOpponents().forEach(opponent => { - opponent.updateEffectiveness(this.getEffectivenessText(pokemon, opponent, pokemonMove)); + (opponent as EnemyPokemon).updateEffectiveness(this.getEffectivenessText(pokemon, opponent, pokemonMove)); }); } @@ -391,7 +391,7 @@ export default class FightUiHandler extends UiHandler implements InfoToggle { const opponents = (globalScene.getCurrentPhase() as CommandPhase).getPokemon().getOpponents(); opponents.forEach(opponent => { - opponent.updateEffectiveness(undefined); + (opponent as EnemyPokemon).updateEffectiveness(undefined); }); }