[Enhancement] Target Selection also highlights target's held items (#3448)

* Target Pokemon's held items flash with the Pokemon during target selection

* Fixed typedocs issues and adjusted animation

* removed .js from imports

* removed .js from imports

* Slowed down animation + fixed bug

* Implemented Torranx's fixes + slightly widened the range for alpha values

* Apply suggestions from code review

Co-authored-by: Amani H. <109637146+xsn34kzx@users.noreply.github.com>

* Additional suggestions from code review

* Update src/battle-scene.ts

Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com>

---------

Co-authored-by: Frutescens <info@laptop>
Co-authored-by: Amani H. <109637146+xsn34kzx@users.noreply.github.com>
Co-authored-by: Adrian T. <68144167+torranx@users.noreply.github.com>
This commit is contained in:
Mumble 2024-08-13 13:30:01 -07:00 committed by GitHub
parent 513adf779f
commit e9c89b437b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 9 deletions

View File

@ -791,10 +791,11 @@ export default class BattleScene extends SceneBase {
/** /**
* Returns the ModifierBar of this scene, which is declared private and therefore not accessible elsewhere * Returns the ModifierBar of this scene, which is declared private and therefore not accessible elsewhere
* @param isEnemy Whether to return the enemy's modifier bar
* @returns {ModifierBar} * @returns {ModifierBar}
*/ */
getModifierBar(): ModifierBar { getModifierBar(isEnemy?: boolean): ModifierBar {
return this.modifierBar; return isEnemy ? this.enemyModifierBar : this.modifierBar;
} }
// store info toggles to be accessible by the ui // store info toggles to be accessible by the ui

View File

@ -22,12 +22,12 @@ import { FormChangeItem, SpeciesFormChangeItemTrigger } from "../data/pokemon-fo
import { Nature } from "#app/data/nature"; import { Nature } from "#app/data/nature";
import Overrides from "#app/overrides"; import Overrides from "#app/overrides";
import { ModifierType, modifierTypes } from "./modifier-type"; import { ModifierType, modifierTypes } from "./modifier-type";
import { Command } from "#app/ui/command-ui-handler.js"; import { Command } from "#app/ui/command-ui-handler";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import i18next from "i18next"; import i18next from "i18next";
import { allMoves } from "#app/data/move.js"; import { allMoves } from "#app/data/move";
import { Abilities } from "#app/enums/abilities.js"; import { Abilities } from "#app/enums/abilities";
export type ModifierPredicate = (modifier: Modifier) => boolean; export type ModifierPredicate = (modifier: Modifier) => boolean;
@ -506,6 +506,7 @@ export abstract class PokemonHeldItemModifier extends PersistentModifier {
if (pokemon) { if (pokemon) {
const pokemonIcon = scene.addPokemonIcon(pokemon, -2, 10, 0, 0.5); const pokemonIcon = scene.addPokemonIcon(pokemon, -2, 10, 0, 0.5);
container.add(pokemonIcon); container.add(pokemonIcon);
container.setName(pokemon.id.toString());
} }
const item = scene.add.sprite(16, this.virtualStackCount ? 8 : 16, "items"); const item = scene.add.sprite(16, this.virtualStackCount ? 8 : 16, "items");

View File

@ -6,7 +6,8 @@ import * as Utils from "../utils";
import { getMoveTargets } from "../data/move"; import { getMoveTargets } from "../data/move";
import {Button} from "#enums/buttons"; import {Button} from "#enums/buttons";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import Pokemon from "#app/field/pokemon.js"; import Pokemon from "#app/field/pokemon";
import { ModifierBar } from "#app/modifier/modifier";
export type TargetSelectCallback = (targets: BattlerIndex[]) => void; export type TargetSelectCallback = (targets: BattlerIndex[]) => void;
@ -19,6 +20,7 @@ export default class TargetSelectUiHandler extends UiHandler {
private targets: BattlerIndex[]; private targets: BattlerIndex[];
private targetsHighlighted: Pokemon[]; private targetsHighlighted: Pokemon[];
private targetFlashTween: Phaser.Tweens.Tween | null; private targetFlashTween: Phaser.Tweens.Tween | null;
private enemyModifiers: ModifierBar;
private targetBattleInfoMoveTween: Phaser.Tweens.Tween[] = []; private targetBattleInfoMoveTween: Phaser.Tweens.Tween[] = [];
constructor(scene: BattleScene) { constructor(scene: BattleScene) {
@ -48,6 +50,8 @@ export default class TargetSelectUiHandler extends UiHandler {
return false; return false;
} }
this.enemyModifiers = this.scene.getModifierBar(true);
this.setCursor(this.targets.includes(this.cursor) ? this.cursor : this.targets[0]); this.setCursor(this.targets.includes(this.cursor) ? this.cursor : this.targets[0]);
return true; return true;
@ -108,22 +112,26 @@ export default class TargetSelectUiHandler extends UiHandler {
this.targetFlashTween.stop(); this.targetFlashTween.stop();
for (const pokemon of multipleTargets) { for (const pokemon of multipleTargets) {
pokemon.setAlpha(1); pokemon.setAlpha(1);
this.highlightItems(pokemon.id, 1);
} }
} }
this.targetFlashTween = this.scene.tweens.add({ this.targetFlashTween = this.scene.tweens.add({
targets: this.targetsHighlighted, targets: this.targetsHighlighted,
alpha: 0, key: { start: 0.55, to: 1 },
loop: -1, loop: -1,
duration: Utils.fixedInt(250), loopDelay: 150,
ease: "Sine.easeIn", duration: Utils.fixedInt(450),
ease: "Sine.easeInOut",
yoyo: true, yoyo: true,
onUpdate: t => { onUpdate: t => {
for (const target of this.targetsHighlighted) { for (const target of this.targetsHighlighted) {
target.setAlpha(t.getValue()); target.setAlpha(t.getValue());
this.highlightItems(target.id, t.getValue());
} }
} }
}); });
if (this.targetBattleInfoMoveTween.length >= 1) { if (this.targetBattleInfoMoveTween.length >= 1) {
this.targetBattleInfoMoveTween.filter(t => t !== undefined).forEach(tween => tween.stop()); this.targetBattleInfoMoveTween.filter(t => t !== undefined).forEach(tween => tween.stop());
for (const pokemon of multipleTargets) { for (const pokemon of multipleTargets) {
@ -152,8 +160,10 @@ export default class TargetSelectUiHandler extends UiHandler {
this.targetFlashTween.stop(); this.targetFlashTween.stop();
this.targetFlashTween = null; this.targetFlashTween = null;
} }
for (const pokemon of this.targetsHighlighted) { for (const pokemon of this.targetsHighlighted) {
pokemon.setAlpha(1); pokemon.setAlpha(1);
this.highlightItems(pokemon.id, 1);
} }
if (this.targetBattleInfoMoveTween.length >= 1) { if (this.targetBattleInfoMoveTween.length >= 1) {
@ -165,6 +175,13 @@ export default class TargetSelectUiHandler extends UiHandler {
} }
} }
private highlightItems(targetId: number, val: number) : void {
const targetItems = this.enemyModifiers.getAll("name", targetId.toString());
for (const item of targetItems as Phaser.GameObjects.Container[]) {
item.setAlpha(val);
}
}
clear() { clear() {
super.clear(); super.clear();
this.eraseCursor(); this.eraseCursor();