From 7e1b383be21a14a5f897ea5e3a4ec22fd0a12a84 Mon Sep 17 00:00:00 2001 From: Adrian T <68144167+torranx@users.noreply.github.com> Date: Thu, 30 May 2024 06:17:41 +0800 Subject: [PATCH] Add window showing number of eggs hatching during hatch phase (#1421) * add window showing count of eggs hatching * adjust property naming --- src/egg-hatch-phase.ts | 23 ++++++++++- src/phases.ts | 9 ++++- src/ui/eggs-to-hatch-count-container.ts | 54 +++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 src/ui/eggs-to-hatch-count-container.ts diff --git a/src/egg-hatch-phase.ts b/src/egg-hatch-phase.ts index cf67e5a7566..11b71d8fbb5 100644 --- a/src/egg-hatch-phase.ts +++ b/src/egg-hatch-phase.ts @@ -12,10 +12,14 @@ import { achvs } from "./system/achv"; import { pokemonPrevolutions } from "./data/pokemon-evolutions"; import { EggTier } from "./data/enums/egg-type"; import PokemonInfoContainer from "./ui/pokemon-info-container"; +import EggsToHatchCountContainer from "./ui/eggs-to-hatch-count-container"; export class EggHatchPhase extends Phase { private egg: Egg; + private eggsToHatchCount: integer; + private eggsToHatchCountContainer: EggsToHatchCountContainer; + private eggHatchHandler: EggHatchSceneHandler; private eggHatchContainer: Phaser.GameObjects.Container; private eggHatchBg: Phaser.GameObjects.Image; @@ -36,10 +40,11 @@ export class EggHatchPhase extends Phase { private skipped: boolean; private evolutionBgm: AnySound; - constructor(scene: BattleScene, egg: Egg) { + constructor(scene: BattleScene, egg: Egg, eggsToHatchCount: integer) { super(scene); this.egg = egg; + this.eggsToHatchCount = eggsToHatchCount; } start() { @@ -84,6 +89,11 @@ export class EggHatchPhase extends Phase { this.eggContainer.add(this.eggLightraysOverlay); this.eggHatchContainer.add(this.eggContainer); + this.eggsToHatchCountContainer = new EggsToHatchCountContainer(this.scene, this.eggsToHatchCount); + this.eggsToHatchCountContainer.setup(); + + this.eggHatchContainer.add(this.eggsToHatchCountContainer); + const getPokemonSprite = () => { const ret = this.scene.add.sprite(this.eggHatchBg.displayWidth / 2, this.eggHatchBg.displayHeight / 2, "pkmn__sub"); ret.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); @@ -259,6 +269,13 @@ export class EggHatchPhase extends Phase { } doReveal(): void { + // Update/reduce count of hatching eggs when revealed if count is at least 1 + // If count is 0, hide eggsToHatchCountContainer instead + if (this.eggsToHatchCount > 1) { + this.eggsToHatchCount -= 1; + } else { + this.eggsToHatchCountContainer.setVisible(false); + } const isShiny = this.pokemon.isShiny(); if (this.pokemon.species.subLegendary) { this.scene.validateAchv(achvs.HATCH_SUB_LEGENDARY); @@ -280,6 +297,10 @@ export class EggHatchPhase extends Phase { this.pokemonSprite.setPipelineData("variant", this.pokemon.variant); this.pokemonSprite.setVisible(true); this.scene.time.delayedCall(Utils.fixedInt(250), () => { + if (this.eggsToHatchCount < 10) { + this.eggsToHatchCountContainer.setWindowToDefaultSize(); + } + this.eggsToHatchCountContainer.eggCountText.setText(`${this.eggsToHatchCount}`); this.pokemon.cry(); if (isShiny) { this.scene.time.delayedCall(Utils.fixedInt(500), () => { diff --git a/src/phases.ts b/src/phases.ts index b6d03561993..53e150b888e 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -5036,11 +5036,16 @@ export class EggLapsePhase extends Phase { return Overrides.IMMEDIATE_HATCH_EGGS_OVERRIDE ? true : --egg.hatchWaves < 1; }); - if (eggsToHatch.length) { + let eggsToHatchCount: integer = eggsToHatch.length; + + if (eggsToHatchCount) { this.scene.queueMessage(i18next.t("battle:eggHatching")); for (const egg of eggsToHatch) { - this.scene.unshiftPhase(new EggHatchPhase(this.scene, egg)); + this.scene.unshiftPhase(new EggHatchPhase(this.scene, egg, eggsToHatchCount)); + if (eggsToHatchCount > 0) { + eggsToHatchCount--; + } } } diff --git a/src/ui/eggs-to-hatch-count-container.ts b/src/ui/eggs-to-hatch-count-container.ts new file mode 100644 index 00000000000..693e4666220 --- /dev/null +++ b/src/ui/eggs-to-hatch-count-container.ts @@ -0,0 +1,54 @@ +import BattleScene from "#app/battle-scene.js"; +import { addWindow } from "./ui-theme"; +import { addTextObject, TextStyle } from "./text"; + +/** + * A container that displays the count of hatching eggs. + * Extends Phaser.GameObjects.Container. + */ +export default class EggsToHatchCountContainer extends Phaser.GameObjects.Container { + private readonly WINDOW_DEFAULT_WIDTH = 37; + private readonly WINDOW_MEDIUM_WIDTH = 42; + private readonly WINDOW_HEIGHT = 26; + + private eggsToHatchCount: integer; + private eggsToHatchCountWindow: Phaser.GameObjects.NineSlice; + + public eggCountText: Phaser.GameObjects.Text; + + /** + * @param {BattleScene} scene - The scene to which this container belongs. + * @param {number} eggsToHatchCount - The number of eggs to hatch. + */ + constructor(scene: BattleScene, eggsToHatchCount: integer) { + super(scene, 0, 0); + this.eggsToHatchCount = eggsToHatchCount; + } + + /** + * Sets up the container, creating the window, egg sprite, and egg count text. + */ + setup(): void { + const windowWidth = this.eggsToHatchCount > 9 ? this.WINDOW_MEDIUM_WIDTH : this.WINDOW_DEFAULT_WIDTH; + + this.eggsToHatchCountWindow = addWindow(this.scene as BattleScene, 5, 5, windowWidth, this.WINDOW_HEIGHT); + this.setVisible(this.eggsToHatchCount > 1); + + this.add(this.eggsToHatchCountWindow); + + const eggSprite = this.scene.add.sprite(19, 18, "egg", "egg_0"); + eggSprite.setScale(0.32); + + this.eggCountText = addTextObject(this.scene, 28, 13, `${this.eggsToHatchCount}`, TextStyle.MESSAGE, { fontSize: "66px" }); + + this.add(eggSprite); + this.add(this.eggCountText); + } + + /** + * Resets the window size to the default width and height. + */ + setWindowToDefaultSize(): void { + this.eggsToHatchCountWindow.setSize(this.WINDOW_DEFAULT_WIDTH, this.WINDOW_HEIGHT); + } +}