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.
This commit is contained in:
Franck TROUILLEZ 2024-05-24 00:28:53 +02:00 committed by GitHub
parent c2bc94a5f3
commit 68e94845ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 0 deletions

View File

@ -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 {

View File

@ -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<void> {
@ -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 {

View File

@ -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() {