From 68e94845aba489e075ced91688df69c387341f49 Mon Sep 17 00:00:00 2001 From: Franck TROUILLEZ <57403591+francktrouillez@users.noreply.github.com> Date: Fri, 24 May 2024 00:28:53 +0200 Subject: [PATCH] Add BattleInfo to TargetSelectUiHandler to move when target selected (#1255) This change allows to move the box containing the battle info of the ennemy pokemons during double battle when the user has to choose a target. In addition to the pokemon opacity constantly changing, the battle info will also move up and down to indicate which Pokemon is targeted. It exposes the BattleInfo object from the Pokemon object through an accessor method. --- src/field/pokemon.ts | 4 ++++ src/ui/battle-info.ts | 12 ++++++++++++ src/ui/target-select-ui-handler.ts | 29 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index b565c3b8ae2..e7a91832c59 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -2765,6 +2765,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.battleInfo?.destroy(); super.destroy(); } + + getBattleInfo(): BattleInfo { + return this.battleInfo; + } } export default interface Pokemon { diff --git a/src/ui/battle-info.ts b/src/ui/battle-info.ts index 35db5edf4b8..a6444a7bc63 100644 --- a/src/ui/battle-info.ts +++ b/src/ui/battle-info.ts @@ -12,6 +12,8 @@ import { BattleStat } from "#app/data/battle-stat"; const battleStatOrder = [ BattleStat.ATK, BattleStat.DEF, BattleStat.SPATK, BattleStat.SPDEF, BattleStat.ACC, BattleStat.EVA, BattleStat.SPD ]; export default class BattleInfo extends Phaser.GameObjects.Container { + private baseY: number; + private player: boolean; private mini: boolean; private boss: boolean; @@ -57,6 +59,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { constructor(scene: Phaser.Scene, x: number, y: number, player: boolean) { super(scene, x, y); + this.baseY = y; this.player = player; this.mini = !player; this.boss = false; @@ -417,6 +420,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.x += 10 * (offset === this.player ? 1 : -1); this.y += 27 * (offset ? 1 : -1); + this.baseY = this.y; } updateInfo(pokemon: Pokemon, instant?: boolean): Promise { @@ -655,6 +659,14 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.statNumbers[i].setFrame(battleStats[s].toString()); }); } + + getBaseY(): number { + return this.baseY; + } + + resetY(): void { + this.y = this.baseY; + } } export class PlayerBattleInfo extends BattleInfo { diff --git a/src/ui/target-select-ui-handler.ts b/src/ui/target-select-ui-handler.ts index 0f6fce3b274..c69284fe64e 100644 --- a/src/ui/target-select-ui-handler.ts +++ b/src/ui/target-select-ui-handler.ts @@ -16,6 +16,7 @@ export default class TargetSelectUiHandler extends UiHandler { private targets: BattlerIndex[]; private targetFlashTween: Phaser.Tweens.Tween; + private targetBattleInfoMoveTween: Phaser.Tweens.Tween; constructor(scene: BattleScene) { super(scene, Mode.TARGET_SELECT); @@ -116,6 +117,25 @@ export default class TargetSelectUiHandler extends UiHandler { } }); + if (this.targetBattleInfoMoveTween) { + this.targetBattleInfoMoveTween.stop(); + const lastTarget = this.scene.getField()[lastCursor]; + if (lastTarget) { + lastTarget.getBattleInfo().resetY(); + } + } + + const targetBattleInfo = target.getBattleInfo(); + + this.targetBattleInfoMoveTween = this.scene.tweens.add({ + targets: [ targetBattleInfo ], + y: { start: targetBattleInfo.getBaseY(), to: targetBattleInfo.getBaseY() + 1 }, + loop: -1, + duration: Utils.fixedInt(250), + ease: "Linear", + yoyo: true + }); + return ret; } @@ -128,6 +148,15 @@ export default class TargetSelectUiHandler extends UiHandler { if (target) { target.setAlpha(1); } + + const targetBattleInfo = target.getBattleInfo(); + if (this.targetBattleInfoMoveTween) { + this.targetBattleInfoMoveTween.stop(); + this.targetBattleInfoMoveTween = null; + } + if (targetBattleInfo) { + targetBattleInfo.resetY(); + } } clear() {