diff --git a/src/ui/fight-ui-handler.ts b/src/ui/fight-ui-handler.ts index 60db9d19eef..4e5b0394428 100644 --- a/src/ui/fight-ui-handler.ts +++ b/src/ui/fight-ui-handler.ts @@ -1,4 +1,4 @@ -import BattleScene from "../battle-scene"; +import BattleScene, { InfoToggle } from "../battle-scene"; import { addTextObject, TextStyle } from "./text"; import { getTypeDamageMultiplierColor, Type } from "../data/type"; import { Command } from "./command-ui-handler"; @@ -10,8 +10,9 @@ import i18next from "i18next"; import {Button} from "#enums/buttons"; import Pokemon, { PokemonMove } from "#app/field/pokemon"; import { CommandPhase } from "#app/phases/command-phase"; +import MoveInfoOverlay from "./move-info-overlay"; -export default class FightUiHandler extends UiHandler { +export default class FightUiHandler extends UiHandler implements InfoToggle { public static readonly MOVES_CONTAINER_NAME = "moves"; private movesContainer: Phaser.GameObjects.Container; @@ -25,6 +26,7 @@ export default class FightUiHandler extends UiHandler { private accuracyText: Phaser.GameObjects.Text; private cursorObj: Phaser.GameObjects.Image | null; private moveCategoryIcon: Phaser.GameObjects.Sprite; + private moveInfoOverlay : MoveInfoOverlay; protected fieldIndex: integer = 0; protected cursor2: integer = 0; @@ -84,6 +86,24 @@ export default class FightUiHandler extends UiHandler { this.accuracyText.setOrigin(1, 0.5); this.accuracyText.setVisible(false); this.moveInfoContainer.add(this.accuracyText); + + // prepare move overlay + const overlayScale = 1; + this.moveInfoOverlay = new MoveInfoOverlay(this.scene, { + delayVisibility: true, + scale: overlayScale, + onSide: true, + right: true, + x: 0, + y: -MoveInfoOverlay.getHeight(overlayScale, true), + width: (this.scene.game.canvas.width / 6) + 4, + hideEffectBox: true, + hideBg: true + }); + ui.add(this.moveInfoOverlay); + // register the overlay to receive toggle events + this.scene.addInfoToggle(this.moveInfoOverlay); + this.scene.addInfoToggle(this); } show(args: any[]): boolean { @@ -102,6 +122,8 @@ export default class FightUiHandler extends UiHandler { this.setCursor(this.getCursor()); } this.displayMoves(); + this.toggleInfo(false); // in case cancel was pressed while info toggle is active + this.active = true; return true; } @@ -155,6 +177,27 @@ export default class FightUiHandler extends UiHandler { return success; } + toggleInfo(visible: boolean): void { + if (visible) { + this.movesContainer.setVisible(false); + this.cursorObj?.setVisible(false); + } + this.scene.tweens.add({ + targets: [this.movesContainer, this.cursorObj], + duration: Utils.fixedInt(125), + ease: "Sine.easeInOut", + alpha: visible ? 0 : 1 + }); + if (!visible) { + this.movesContainer.setVisible(true); + this.cursorObj?.setVisible(true); + } + } + + isActive(): boolean { + return this.active; + } + getCursor(): integer { return !this.fieldIndex ? this.cursor : this.cursor2; } @@ -162,6 +205,7 @@ export default class FightUiHandler extends UiHandler { setCursor(cursor: integer): boolean { const ui = this.getUi(); + this.moveInfoOverlay.clear(); const changed = this.getCursor() !== cursor; if (changed) { if (!this.fieldIndex) { @@ -215,6 +259,7 @@ export default class FightUiHandler extends UiHandler { //** Changes the text color and shadow according to the determined TextStyle */ this.ppText.setColor(this.getTextColor(ppColorStyle, false)); this.ppText.setShadowColor(this.getTextColor(ppColorStyle, true)); + this.moveInfoOverlay.show(pokemonMove.getMove()); pokemon.getOpponents().forEach((opponent) => { opponent.updateEffectiveness(this.getEffectivenessText(pokemon, opponent, pokemonMove)); @@ -302,8 +347,10 @@ export default class FightUiHandler extends UiHandler { this.accuracyLabel.setVisible(false); this.accuracyText.setVisible(false); this.moveCategoryIcon.setVisible(false); + this.moveInfoOverlay.clear(); messageHandler.bg.setVisible(true); this.eraseCursor(); + this.active = false; } clearMoves() { diff --git a/src/ui/move-info-overlay.ts b/src/ui/move-info-overlay.ts index 77010f84528..598e57ba209 100644 --- a/src/ui/move-info-overlay.ts +++ b/src/ui/move-info-overlay.ts @@ -16,11 +16,13 @@ export interface MoveInfoOverlaySettings { x?: number; y?: number; width?: number; // default is always half the screen, regardless of scale + hideEffectBox?: boolean; // whether or not the small secondary box should be shown + hideBg?: boolean; // whether to hide the window background } -const EFF_HEIGHT = 46; +const EFF_HEIGHT = 48; const EFF_WIDTH = 82; -const DESC_HEIGHT = 46; +const DESC_HEIGHT = 48; const BORDER = 8; const GLOBAL_SCALE = 6; @@ -38,6 +40,7 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem private acc: Phaser.GameObjects.Text; private typ: Phaser.GameObjects.Sprite; private cat: Phaser.GameObjects.Sprite; + private descBg: Phaser.GameObjects.NineSlice; private options : MoveInfoOverlaySettings; @@ -52,9 +55,9 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem // prepare the description box const width = (options?.width || MoveInfoOverlay.getWidth(scale, scene)) / scale; // divide by scale as we always want this to be half a window wide - const descBg = addWindow(scene, (options?.onSide && !options?.right ? EFF_WIDTH : 0), options?.top ? EFF_HEIGHT : 0, width - (options?.onSide ? EFF_WIDTH : 0), DESC_HEIGHT); - descBg.setOrigin(0, 0); - this.add(descBg); + this.descBg = addWindow(scene, (options?.onSide && !options?.right ? EFF_WIDTH : 0), options?.top ? EFF_HEIGHT : 0, width - (options?.onSide ? EFF_WIDTH : 0), DESC_HEIGHT); + this.descBg.setOrigin(0, 0); + this.add(this.descBg); // set up the description; wordWrap uses true pixels, unaffected by any scaling, while other values are affected this.desc = addTextObject(scene, (options?.onSide && !options?.right ? EFF_WIDTH : 0) + BORDER, (options?.top ? EFF_HEIGHT : 0) + BORDER - 2, "", TextStyle.BATTLE_INFO, { wordWrap: { width: (width - (BORDER - 2) * 2 - (options?.onSide ? EFF_WIDTH : 0)) * GLOBAL_SCALE } }); @@ -125,6 +128,14 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem this.acc.setOrigin(1, 0.5); this.val.add(this.acc); + if (options?.hideEffectBox) { + this.val.setVisible(false); + } + + if (options?.hideBg) { + this.descBg.setVisible(false); + } + // hide this component for now this.setVisible(false); } @@ -176,8 +187,19 @@ export default class MoveInfoOverlay extends Phaser.GameObjects.Container implem this.active = false; } - toggleInfo(force?: boolean): void { - this.setVisible(force ?? !this.visible); + toggleInfo(visible: boolean): void { + if (visible) { + this.setVisible(true); + } + this.scene.tweens.add({ + targets: this.desc, + duration: Utils.fixedInt(125), + ease: "Sine.easeInOut", + alpha: visible ? 1 : 0 + }); + if (!visible) { + this.setVisible(false); + } } isActive(): boolean {