pokerogue/src/ui/saving-icon-handler.ts

81 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-04-04 15:16:29 +01:00
import BattleScene from "#app/battle-scene";
import * as Utils from "../utils";
export default class SavingIconHandler extends Phaser.GameObjects.Container {
private icon: Phaser.GameObjects.Sprite;
private animActive: boolean;
private shown: boolean;
constructor(scene: BattleScene) {
super(scene, scene.game.canvas.width / 6 - 4, scene.game.canvas.height / 6 - 4);
}
setup(): void {
this.icon = this.scene.add.sprite(0, 0, "saving_icon");
2024-04-04 15:16:29 +01:00
this.icon.setOrigin(1, 1);
this.add(this.icon);
this.animActive = false;
this.shown = false;
this.setAlpha(0);
this.setVisible(false);
}
show(): void {
this.shown = true;
if (this.animActive) {
2024-04-04 15:16:29 +01:00
return;
}
2024-04-04 15:16:29 +01:00
this.animActive = true;
this.scene.tweens.add({
targets: this,
alpha: 1,
duration: Utils.fixedInt(250),
ease: "Sine.easeInOut",
2024-04-04 15:16:29 +01:00
onComplete: () => {
this.scene.time.delayedCall(Utils.fixedInt(500), () => {
this.animActive = false;
if (!this.shown) {
2024-04-04 15:16:29 +01:00
this.hide();
}
2024-04-04 15:16:29 +01:00
});
}
});
2024-05-24 00:45:04 +01:00
2024-04-04 15:16:29 +01:00
this.setVisible(true);
this.shown = true;
}
hide(): void {
this.shown = false;
if (this.animActive) {
2024-04-04 15:16:29 +01:00
return;
}
2024-04-04 15:16:29 +01:00
this.animActive = true;
this.scene.tweens.add({
targets: this,
alpha: 0,
duration: Utils.fixedInt(250),
ease: "Sine.easeInOut",
2024-04-04 15:16:29 +01:00
onComplete: () => {
this.animActive = false;
this.setVisible(false);
if (this.shown) {
2024-04-04 15:16:29 +01:00
this.show();
}
2024-04-04 15:16:29 +01:00
}
});
2024-05-24 00:45:04 +01:00
2024-04-04 15:16:29 +01:00
this.shown = false;
}
}