From 28c04877db56ec389f82a25c2541d39410601313 Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Sat, 31 May 2025 01:16:15 +0200 Subject: [PATCH] Held items now show up in summary --- src/field/pokemon-held-item-manager.ts | 8 ++++++++ src/modifier/all-held-items.ts | 25 ++++++++++++++++++++++++- src/ui/summary-ui-handler.ts | 21 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/field/pokemon-held-item-manager.ts b/src/field/pokemon-held-item-manager.ts index 08f8416861c..ac3fe1f0afc 100644 --- a/src/field/pokemon-held-item-manager.ts +++ b/src/field/pokemon-held-item-manager.ts @@ -22,6 +22,10 @@ export class PokemonItemManager { return this.heldItems; } + getHeldItemKeys(): number[] { + return Object.keys(this.heldItems).map(k => Number(k)); + } + hasItem(itemType: HeldItems): boolean { return itemType in this.getHeldItems(); } @@ -31,6 +35,10 @@ export class PokemonItemManager { return this.heldItems[itemType]; } + getStack(itemType: HeldItems): number { + return itemType in this.getHeldItems() ? this.heldItems[itemType].stack : 0; + } + addHeldItem(itemType: HeldItems, addStack = 1) { const maxStack = allHeldItems[itemType].getMaxStackCount(); diff --git a/src/modifier/all-held-items.ts b/src/modifier/all-held-items.ts index 8417c97a581..5144e326182 100644 --- a/src/modifier/all-held-items.ts +++ b/src/modifier/all-held-items.ts @@ -66,7 +66,7 @@ export class HeldItem implements Localizable { return this.maxStackCount; } - createIcon(stackCount: number, _forSummary?: boolean): Phaser.GameObjects.Container { + createSummaryIcon(stackCount: number): Phaser.GameObjects.Container { const container = globalScene.add.container(0, 0); const item = globalScene.add.sprite(0, 12, "items"); @@ -79,6 +79,29 @@ export class HeldItem implements Localizable { container.add(stackText); } + container.setScale(0.5); + + return container; + } + + createPokemonIcon(stackCount: number, pokemon: Pokemon): Phaser.GameObjects.Container { + const container = globalScene.add.container(0, 0); + + const pokemonIcon = globalScene.addPokemonIcon(pokemon, -2, 10, 0, 0.5, undefined, true); + container.add(pokemonIcon); + container.setName(pokemon.id.toString()); + + const item = globalScene.add.sprite(16, 16, "items"); + item.setScale(0.5); + item.setOrigin(0, 0.5); + item.setTexture("items", this.getIcon()); + container.add(item); + + const stackText = this.getIconStackText(stackCount); + if (stackText) { + container.add(stackText); + } + return container; } diff --git a/src/ui/summary-ui-handler.ts b/src/ui/summary-ui-handler.ts index 3f1e726ca0c..2b19e9c9561 100644 --- a/src/ui/summary-ui-handler.ts +++ b/src/ui/summary-ui-handler.ts @@ -38,6 +38,7 @@ import { PlayerGender } from "#enums/player-gender"; import { Stat, PERMANENT_STATS, getStatKey } from "#enums/stat"; import { Nature } from "#enums/nature"; import { achvs } from "#app/system/achv"; +import { allHeldItems } from "#app/modifier/all-held-items"; enum Page { PROFILE, @@ -1047,6 +1048,26 @@ export default class SummaryUiHandler extends UiHandler { icon.on("pointerout", () => globalScene.ui.hideTooltip()); }); + const heldItemKeys = this.pokemon?.heldItemManager.getHeldItemKeys(); + // TODO: Sort them + //.sort(heldItemSortFunc); + + console.log(heldItemKeys); + + heldItemKeys?.forEach((itemKey, i) => { + const stack = this.pokemon?.heldItemManager.getStack(itemKey); + const heldItem = allHeldItems[itemKey]; + const icon = heldItem.createSummaryIcon(stack); + + console.log(icon); + icon.setPosition((i % 17) * 12 + 3, 14 * Math.floor(i / 17) + 15); + this.statsContainer.add(icon); + + icon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 32, 32), Phaser.Geom.Rectangle.Contains); + icon.on("pointerover", () => globalScene.ui.showTooltip(heldItem.getName(), heldItem.getDescription(), true)); + icon.on("pointerout", () => globalScene.ui.hideTooltip()); + }); + const pkmLvl = this.pokemon?.level!; // TODO: is this bang correct? const pkmLvlExp = this.pokemon?.levelExp!; // TODO: is this bang correct? const pkmExp = this.pokemon?.exp!; // TODO: is this bang correct?