pokerogue/src/ui/ability-bar.ts
Jannik Tappert 8099f02306
[Enhancement] Added a bgmBar to show the name of the track once music is played (#2457)
* Added a bgmBar to show the name of the track once music is played

* Even more close to ability bar

* It now shows. And also shows already for a couple of them a readable name

* Now the queue actually works

* Create locales for bgmName (bgm-bar ui)

  + Most of the music has only Japanese and English names
    But there are a number of tracks with official translations following OST commercialization

* Add i18n and use it to retrieve OST names (avoids a giga switch case)

  + A fallback key is implemented in the case of adding tracks not referenced in the translation files, its value being just the name of the bgm itself

* FormatText is now in Utils and not arena-flyout

BGM Names for non-localized music will be formatted to have capitalized letters and no _

* It is now a setting. It can be even changed mid fight

* Update src/ui/ability-bar.ts

* Apply suggestions from code review

Co-authored-by: Lugiad' <adrien.grivel@hotmail.fr>

* Update src/locales/de/bgm-name.ts

* Apply suggestions from code review

Co-authored-by: sodam <66295123+sodaMelon@users.noreply.github.com>

* Added the rest of the music names

* Changed PMD EoS to PMD ETH in german (Pokemon Mystery Dungeon Erkundungsteam Himmel)

* Due to feedback it is now "PMD ET-Himmel"

* Corrected the encounter theme names (and some missed trainer class names)

* Background is now a nicneslice. And it is at the top of the screen and above everything else

* The bar now scales with the text.

* Revert override

* Update src/locales/fr/bgm-name.ts

Co-authored-by: Lugiad' <adrien.grivel@hotmail.fr>

* It now only appears when V is pressed (in all but starter select)

* Cleared the cod eup

* Update src/locales/zh_CN/bgm-name.ts

Co-authored-by: Yonmaru40 <47717431+40chyan@users.noreply.github.com>

* Update src/locales/zh_CN/settings.ts

Co-authored-by: Yonmaru40 <47717431+40chyan@users.noreply.github.com>

* Update src/locales/ko/bgm-name.ts

Co-authored-by: sodam <66295123+sodaMelon@users.noreply.github.com>

* The bgmBar now appears in the pause menu instead.

* Should react better on settings change

* To be safe this required a reload now

* Update src/locales/fr/bgm-name.ts

Co-authored-by: Lugiad' <adrien.grivel@hotmail.fr>

* Update src/locales/fr/bgm-name.ts

Co-authored-by: Lugiad' <adrien.grivel@hotmail.fr>

* Write out pokemon mystery dungeon names in german

* Update src/locales/es/bgm-name.ts

Co-authored-by: GoldTra <162721984+GoldTra@users.noreply.github.com>

* Update src/locales/zh_CN/bgm-name.ts

Co-authored-by: Yonmaru40 <47717431+40chyan@users.noreply.github.com>

* Update src/battle-scene.ts

---------

Co-authored-by: Dakurei <maxime.palanchini@gmail.com>
Co-authored-by: Lugiad' <adrien.grivel@hotmail.fr>
Co-authored-by: sodam <66295123+sodaMelon@users.noreply.github.com>
Co-authored-by: Yonmaru40 <47717431+40chyan@users.noreply.github.com>
Co-authored-by: GoldTra <162721984+GoldTra@users.noreply.github.com>
2024-06-24 16:31:38 +01:00

101 lines
2.4 KiB
TypeScript

import BattleScene from "../battle-scene";
import Pokemon from "../field/pokemon";
import { TextStyle, addTextObject } from "./text";
import i18next from "i18next";
const hiddenX = -118;
const shownX = 0;
const baseY = -116;
export default class AbilityBar extends Phaser.GameObjects.Container {
private bg: Phaser.GameObjects.Image;
private abilityBarText: Phaser.GameObjects.Text;
private tween: Phaser.Tweens.Tween;
private autoHideTimer: NodeJS.Timeout;
public shown: boolean;
constructor(scene: BattleScene) {
super(scene, hiddenX, baseY);
}
setup(): void {
this.bg = this.scene.add.image(0, 0, "ability_bar_left");
this.bg.setOrigin(0, 0);
this.add(this.bg);
this.abilityBarText = addTextObject(this.scene, 15, 3, "", TextStyle.MESSAGE, { fontSize: "72px" });
this.abilityBarText.setOrigin(0, 0);
this.abilityBarText.setWordWrapWidth(600, true);
this.add(this.abilityBarText);
this.setVisible(false);
this.shown = false;
}
showAbility(pokemon: Pokemon, passive: boolean = false): void {
this.abilityBarText.setText(`${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: pokemon.name, passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: !passive ? pokemon.getAbility().name : pokemon.getPassiveAbility().name })}`);
if (this.shown) {
return;
}
(this.scene as BattleScene).fieldUI.bringToTop(this);
this.y = baseY + ((this.scene as BattleScene).currentBattle.double ? 14 : 0);
this.tween = this.scene.tweens.add({
targets: this,
x: shownX,
duration: 500,
ease: "Sine.easeOut",
onComplete: () => {
this.tween = null;
this.resetAutoHideTimer();
}
});
this.setVisible(true);
this.shown = true;
}
hide(): void {
if (!this.shown) {
return;
}
if (this.autoHideTimer) {
clearInterval(this.autoHideTimer);
}
if (this.tween) {
this.tween.stop();
}
this.tween = this.scene.tweens.add({
targets: this,
x: -91,
duration: 500,
ease: "Sine.easeIn",
onComplete: () => {
this.tween = null;
this.setVisible(false);
}
});
this.shown = false;
}
resetAutoHideTimer(): void {
if (this.autoHideTimer) {
clearInterval(this.autoHideTimer);
}
this.autoHideTimer = setTimeout(() => {
this.hide();
this.autoHideTimer = null;
}, 2500);
}
}