2023-10-04 17:24:28 -04:00
|
|
|
import BattleScene from "../battle-scene";
|
2024-02-29 20:08:50 -05:00
|
|
|
import Pokemon from "../field/pokemon";
|
2023-10-04 17:24:28 -04:00
|
|
|
import { TextStyle, addTextObject } from "./text";
|
|
|
|
|
|
|
|
export default class PartyExpBar extends Phaser.GameObjects.Container {
|
|
|
|
private bg: Phaser.GameObjects.NineSlice;
|
2024-04-10 10:57:06 -04:00
|
|
|
private pokemonIcon: Phaser.GameObjects.Container;
|
2023-10-04 17:24:28 -04:00
|
|
|
private expText: Phaser.GameObjects.Text;
|
|
|
|
|
|
|
|
private tween: Phaser.Tweens.Tween;
|
|
|
|
|
|
|
|
public shown: boolean;
|
|
|
|
|
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, (scene.game.canvas.width / 6), -((scene.game.canvas.height) / 6) + 15);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup(): void {
|
2024-05-23 17:03:10 +02:00
|
|
|
this.bg = this.scene.add.nineslice(0, 0, "party_exp_bar", null, 8, 18, 21, 5, 6, 4);
|
2023-10-04 17:24:28 -04:00
|
|
|
this.bg.setOrigin(0, 0);
|
|
|
|
|
|
|
|
this.add(this.bg);
|
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
this.expText = addTextObject(this.scene, 22, 4, "", TextStyle.BATTLE_INFO);
|
2023-10-04 17:24:28 -04:00
|
|
|
this.expText.setOrigin(0, 0);
|
|
|
|
this.add(this.expText);
|
|
|
|
|
|
|
|
this.setVisible(false);
|
|
|
|
this.shown = false;
|
|
|
|
}
|
|
|
|
|
2024-05-10 15:54:14 +02:00
|
|
|
showPokemonExp(pokemon: Pokemon, expValue: integer, showOnlyLevelUp: boolean, newLevel: number): Promise<void> {
|
2023-10-04 17:24:28 -04:00
|
|
|
return new Promise<void>(resolve => {
|
2024-05-23 17:03:10 +02:00
|
|
|
if (this.shown) {
|
2023-10-04 17:24:28 -04:00
|
|
|
return resolve();
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-10-04 17:24:28 -04:00
|
|
|
|
2024-04-10 10:57:06 -04:00
|
|
|
this.pokemonIcon = (this.scene as BattleScene).addPokemonIcon(pokemon, -8, 15, 0, 0.5);
|
|
|
|
this.pokemonIcon.setScale(0.5);
|
2024-05-24 01:45:04 +02:00
|
|
|
|
2024-04-10 10:57:06 -04:00
|
|
|
this.add(this.pokemonIcon);
|
|
|
|
|
2024-05-10 15:54:14 +02:00
|
|
|
// if we want to only display the level in the small frame
|
|
|
|
if (showOnlyLevelUp) {
|
|
|
|
if (newLevel > 200) { // if the level is greater than 200, we only display Lv. UP
|
2024-05-23 17:03:10 +02:00
|
|
|
this.expText.setText("Lv. UP");
|
2024-05-10 15:54:14 +02:00
|
|
|
} else { // otherwise we display Lv. Up and the new level
|
|
|
|
this.expText.setText(`Lv. UP: ${newLevel.toString()}`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// if we want to display the exp
|
|
|
|
this.expText.setText(`+${expValue.toString()}`);
|
|
|
|
}
|
2023-10-04 17:24:28 -04:00
|
|
|
|
|
|
|
this.bg.width = this.expText.displayWidth + 28;
|
|
|
|
|
|
|
|
(this.scene as BattleScene).fieldUI.bringToTop(this);
|
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
if (this.tween) {
|
2023-10-04 17:24:28 -04:00
|
|
|
this.tween.stop();
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-10-04 17:24:28 -04:00
|
|
|
|
|
|
|
this.tween = this.scene.tweens.add({
|
|
|
|
targets: this,
|
|
|
|
x: (this.scene.game.canvas.width / 6) - (this.bg.width - 5),
|
2024-04-18 00:49:44 -04:00
|
|
|
duration: 500 / Math.pow(2, pokemon.scene.expGainsSpeed),
|
2024-05-23 17:03:10 +02:00
|
|
|
ease: "Sine.easeOut",
|
2023-10-04 17:24:28 -04:00
|
|
|
onComplete: () => {
|
|
|
|
this.tween = null;
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
2024-05-24 01:45:04 +02:00
|
|
|
|
2023-10-04 17:24:28 -04:00
|
|
|
this.setVisible(true);
|
|
|
|
this.shown = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
hide(): Promise<void> {
|
|
|
|
return new Promise<void>(resolve => {
|
2024-05-23 17:03:10 +02:00
|
|
|
if (!this.shown) {
|
2023-10-04 17:24:28 -04:00
|
|
|
return resolve();
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-10-04 17:24:28 -04:00
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
if (this.tween) {
|
2023-10-04 17:24:28 -04:00
|
|
|
this.tween.stop();
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-10-04 17:24:28 -04:00
|
|
|
|
|
|
|
this.tween = this.scene.tweens.add({
|
|
|
|
targets: this,
|
|
|
|
x: (this.scene.game.canvas.width / 6),
|
|
|
|
duration: 500,
|
2024-05-23 17:03:10 +02:00
|
|
|
ease: "Sine.easeIn",
|
2023-10-04 17:24:28 -04:00
|
|
|
onComplete: () => {
|
|
|
|
this.tween = null;
|
|
|
|
this.shown = false;
|
|
|
|
this.setVisible(false);
|
2024-04-10 10:57:06 -04:00
|
|
|
this.pokemonIcon?.destroy();
|
2023-10-04 17:24:28 -04:00
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|