Add window showing number of eggs hatching during hatch phase (#1421)

* add window showing count of eggs hatching

* adjust property naming
This commit is contained in:
Adrian T 2024-05-30 06:17:41 +08:00 committed by GitHub
parent dcd7a11b01
commit 7e1b383be2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 83 additions and 3 deletions

View File

@ -12,10 +12,14 @@ import { achvs } from "./system/achv";
import { pokemonPrevolutions } from "./data/pokemon-evolutions"; import { pokemonPrevolutions } from "./data/pokemon-evolutions";
import { EggTier } from "./data/enums/egg-type"; import { EggTier } from "./data/enums/egg-type";
import PokemonInfoContainer from "./ui/pokemon-info-container"; import PokemonInfoContainer from "./ui/pokemon-info-container";
import EggsToHatchCountContainer from "./ui/eggs-to-hatch-count-container";
export class EggHatchPhase extends Phase { export class EggHatchPhase extends Phase {
private egg: Egg; private egg: Egg;
private eggsToHatchCount: integer;
private eggsToHatchCountContainer: EggsToHatchCountContainer;
private eggHatchHandler: EggHatchSceneHandler; private eggHatchHandler: EggHatchSceneHandler;
private eggHatchContainer: Phaser.GameObjects.Container; private eggHatchContainer: Phaser.GameObjects.Container;
private eggHatchBg: Phaser.GameObjects.Image; private eggHatchBg: Phaser.GameObjects.Image;
@ -36,10 +40,11 @@ export class EggHatchPhase extends Phase {
private skipped: boolean; private skipped: boolean;
private evolutionBgm: AnySound; private evolutionBgm: AnySound;
constructor(scene: BattleScene, egg: Egg) { constructor(scene: BattleScene, egg: Egg, eggsToHatchCount: integer) {
super(scene); super(scene);
this.egg = egg; this.egg = egg;
this.eggsToHatchCount = eggsToHatchCount;
} }
start() { start() {
@ -84,6 +89,11 @@ export class EggHatchPhase extends Phase {
this.eggContainer.add(this.eggLightraysOverlay); this.eggContainer.add(this.eggLightraysOverlay);
this.eggHatchContainer.add(this.eggContainer); this.eggHatchContainer.add(this.eggContainer);
this.eggsToHatchCountContainer = new EggsToHatchCountContainer(this.scene, this.eggsToHatchCount);
this.eggsToHatchCountContainer.setup();
this.eggHatchContainer.add(this.eggsToHatchCountContainer);
const getPokemonSprite = () => { const getPokemonSprite = () => {
const ret = this.scene.add.sprite(this.eggHatchBg.displayWidth / 2, this.eggHatchBg.displayHeight / 2, "pkmn__sub"); 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 }); 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 { 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(); const isShiny = this.pokemon.isShiny();
if (this.pokemon.species.subLegendary) { if (this.pokemon.species.subLegendary) {
this.scene.validateAchv(achvs.HATCH_SUB_LEGENDARY); 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.setPipelineData("variant", this.pokemon.variant);
this.pokemonSprite.setVisible(true); this.pokemonSprite.setVisible(true);
this.scene.time.delayedCall(Utils.fixedInt(250), () => { this.scene.time.delayedCall(Utils.fixedInt(250), () => {
if (this.eggsToHatchCount < 10) {
this.eggsToHatchCountContainer.setWindowToDefaultSize();
}
this.eggsToHatchCountContainer.eggCountText.setText(`${this.eggsToHatchCount}`);
this.pokemon.cry(); this.pokemon.cry();
if (isShiny) { if (isShiny) {
this.scene.time.delayedCall(Utils.fixedInt(500), () => { this.scene.time.delayedCall(Utils.fixedInt(500), () => {

View File

@ -5036,11 +5036,16 @@ export class EggLapsePhase extends Phase {
return Overrides.IMMEDIATE_HATCH_EGGS_OVERRIDE ? true : --egg.hatchWaves < 1; 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")); this.scene.queueMessage(i18next.t("battle:eggHatching"));
for (const egg of eggsToHatch) { 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--;
}
} }
} }

View File

@ -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);
}
}