mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-03-30 06:29:16 +01:00
* Stop ShowAbilityPhase from ending until the bar has popped out * Remove ability bar hiding from messagePhase * Remove abilityBar reference from base Phase class * Add HideAbilityPhase to hide ability bar after effects * Add willSucceed to ability attrs * Update AbAttrs and PostInitAbAttrs * Update PreDefendAbAttrs * Update postDefend, postMoveUsed, StatStage, postSetStatus, and PostDamage * Update preAttack and fieldStat * Partially implement postAttack * Finish PostAttack * Update PostSummon * Update PreSwitchOut * Update preStatStageChange * Update PostStatStageChange, PreSetStatus, PreApplyBattlerTag * Update postTurn and preWeatherEffect * Update postWeatherChange * Update postWeatherChange * Update PostTerrainChange * Update CheckTrapped and PostBattle * Update postFaint * Update PostItemLost * Bug fixes from test cases * Fix intimidate display * Stop trace from displaying itself * Rename to canApply * Fix ability displays using getTriggerMessage * Ensure abilities which are mistakenly shown are still hidden * Fix ability bar showing the wrong ability with imposter * Add canApply for imposter * Update abilities using promises and `trySet...` functions * Committing overrides changes is bad * Document apply and canApply * Update PreLeaveFieldAbAttr * Remove boolean return type apply functions * Remove redundant assignment * Remove ability display from abilities that shouldn't have it * Move queueAbilityDisplay to battlescene * Remove unused shown variable * Minor changes * Fix using id instead of battlerindex in queueAbilityDisplay * Fix PostBattleInitFormChangeAbAttr displaying * Prevent crashes in case an ability for a pokemon not on the field is shown * Stop more abilities from displaying * Move enemy ability bar to the right side * Automatically reload bar if shown while already out, fix specific abilities * Remove duplicate call to clearPhaseQueueSplice * Remove ShowAbilityPhase import from ability.ts * Update PostDefendTypeChangeAbAttr to use PokemonType * Update PostSummonAddArenaTagAbAttr * Minor changes
115 lines
3.1 KiB
TypeScript
115 lines
3.1 KiB
TypeScript
import { globalScene } from "#app/global-scene";
|
|
import { TextStyle, addTextObject } from "./text";
|
|
import i18next from "i18next";
|
|
|
|
const barWidth = 118;
|
|
const screenLeft = 0;
|
|
const baseY = -116;
|
|
|
|
export default class AbilityBar extends Phaser.GameObjects.Container {
|
|
private abilityBars: Phaser.GameObjects.Image[];
|
|
private abilityBarText: Phaser.GameObjects.Text;
|
|
private player: boolean;
|
|
private screenRight: number; // hold screenRight in case size changes between show and hide
|
|
private shown: boolean;
|
|
|
|
constructor() {
|
|
super(globalScene, barWidth, baseY);
|
|
this.abilityBars = [];
|
|
this.player = true;
|
|
this.shown = false;
|
|
}
|
|
|
|
setup(): void {
|
|
for (const key of ["ability_bar_right", "ability_bar_left"]) {
|
|
const bar = globalScene.add.image(0, 0, key);
|
|
bar.setOrigin(0, 0);
|
|
bar.setVisible(false);
|
|
this.add(bar);
|
|
this.abilityBars.push(bar);
|
|
}
|
|
|
|
this.abilityBarText = addTextObject(15, 3, "", TextStyle.MESSAGE, {
|
|
fontSize: "72px",
|
|
});
|
|
this.abilityBarText.setOrigin(0, 0);
|
|
this.abilityBarText.setWordWrapWidth(600, true);
|
|
this.add(this.abilityBarText);
|
|
this.bringToTop(this.abilityBarText);
|
|
|
|
this.setVisible(false);
|
|
this.setX(-barWidth); // start hidden (right edge of bar at x=0)
|
|
}
|
|
|
|
public override setVisible(value: boolean): this {
|
|
this.abilityBars[+this.player].setVisible(value);
|
|
this.shown = value;
|
|
return this;
|
|
}
|
|
|
|
public async startTween(config: any, text?: string): Promise<void> {
|
|
this.setVisible(true);
|
|
if (text) {
|
|
this.abilityBarText.setText(text);
|
|
}
|
|
return new Promise(resolve => {
|
|
globalScene.tweens.add({
|
|
...config,
|
|
onComplete: () => {
|
|
if (config.onComplete) {
|
|
config.onComplete();
|
|
}
|
|
resolve();
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
public async showAbility(pokemonName: string, abilityName: string, passive = false, player = true): Promise<void> {
|
|
const text = `${i18next.t("fightUiHandler:abilityFlyInText", { pokemonName: pokemonName, passive: passive ? i18next.t("fightUiHandler:passive") : "", abilityName: abilityName })}`;
|
|
this.screenRight = globalScene.scaledCanvas.width;
|
|
if (player !== this.player) {
|
|
// Move the bar if it has changed from the player to enemy side (or vice versa)
|
|
this.setX(player ? -barWidth : this.screenRight);
|
|
this.player = player;
|
|
}
|
|
globalScene.fieldUI.bringToTop(this);
|
|
|
|
let y = baseY;
|
|
if (this.player) {
|
|
y += globalScene.currentBattle.double ? 14 : 0;
|
|
} else {
|
|
y -= globalScene.currentBattle.double ? 28 : 14;
|
|
}
|
|
|
|
this.setY(y);
|
|
|
|
return this.startTween(
|
|
{
|
|
targets: this,
|
|
x: this.player ? screenLeft : this.screenRight - barWidth,
|
|
duration: 500,
|
|
ease: "Sine.easeOut",
|
|
hold: 1000,
|
|
},
|
|
text,
|
|
);
|
|
}
|
|
|
|
public async hide(): Promise<void> {
|
|
return this.startTween({
|
|
targets: this,
|
|
x: this.player ? -barWidth : this.screenRight,
|
|
duration: 200,
|
|
ease: "Sine.easeIn",
|
|
onComplete: () => {
|
|
this.setVisible(false);
|
|
},
|
|
});
|
|
}
|
|
|
|
public isVisible(): boolean {
|
|
return this.shown;
|
|
}
|
|
}
|