2023-11-12 00:31:40 -05:00
|
|
|
import BattleScene from "../battle-scene";
|
|
|
|
import { Achv } from "../system/achv";
|
2023-12-19 23:51:48 -05:00
|
|
|
import { Voucher } from "../system/voucher";
|
2023-11-12 00:31:40 -05:00
|
|
|
import { TextStyle, addTextObject } from "./text";
|
|
|
|
|
|
|
|
export default class AchvBar extends Phaser.GameObjects.Container {
|
2024-05-29 10:02:41 +02:00
|
|
|
private defaultWidth: number;
|
|
|
|
private defaultHeight: number;
|
|
|
|
|
2023-11-12 00:31:40 -05:00
|
|
|
private bg: Phaser.GameObjects.NineSlice;
|
|
|
|
private icon: Phaser.GameObjects.Sprite;
|
|
|
|
private titleText: Phaser.GameObjects.Text;
|
|
|
|
private scoreText: Phaser.GameObjects.Text;
|
|
|
|
private descriptionText: Phaser.GameObjects.Text;
|
|
|
|
|
2023-12-19 23:51:48 -05:00
|
|
|
private queue: (Achv | Voucher)[] = [];
|
2023-11-12 00:31:40 -05:00
|
|
|
|
|
|
|
public shown: boolean;
|
|
|
|
|
|
|
|
constructor(scene: BattleScene) {
|
|
|
|
super(scene, scene.game.canvas.width / 6, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
setup(): void {
|
2024-05-29 10:02:41 +02:00
|
|
|
this.defaultWidth = 160;
|
|
|
|
this.defaultHeight = 40;
|
|
|
|
|
|
|
|
this.bg = this.scene.add.nineslice(0, 0, "achv_bar", null, this.defaultWidth, this.defaultHeight, 41, 6, 16, 4);
|
2023-11-12 00:31:40 -05:00
|
|
|
this.bg.setOrigin(0, 0);
|
|
|
|
|
|
|
|
this.add(this.bg);
|
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
this.icon = this.scene.add.sprite(4, 4, "items");
|
2023-11-12 00:31:40 -05:00
|
|
|
this.icon.setOrigin(0, 0);
|
|
|
|
this.add(this.icon);
|
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
this.titleText = addTextObject(this.scene, 40, 3, "", TextStyle.MESSAGE, { fontSize: "72px" });
|
2023-11-12 00:31:40 -05:00
|
|
|
this.titleText.setOrigin(0, 0);
|
|
|
|
this.add(this.titleText);
|
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
this.scoreText = addTextObject(this.scene, 150, 3, "", TextStyle.MESSAGE, { fontSize: "72px" });
|
2023-11-12 00:31:40 -05:00
|
|
|
this.scoreText.setOrigin(1, 0);
|
|
|
|
this.add(this.scoreText);
|
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
this.descriptionText = addTextObject(this.scene, 43, 16, "", TextStyle.WINDOW_ALT, { fontSize: "72px" });
|
2023-11-12 00:31:40 -05:00
|
|
|
this.descriptionText.setOrigin(0, 0);
|
|
|
|
this.add(this.descriptionText);
|
|
|
|
|
|
|
|
this.descriptionText.setWordWrapWidth(664);
|
|
|
|
this.descriptionText.setLineSpacing(-5);
|
|
|
|
|
|
|
|
this.setScale(0.5);
|
|
|
|
|
|
|
|
this.shown = false;
|
|
|
|
}
|
|
|
|
|
2023-12-19 23:51:48 -05:00
|
|
|
showAchv(achv: Achv | Voucher): void {
|
2023-11-12 00:31:40 -05:00
|
|
|
if (this.shown) {
|
|
|
|
this.queue.push(achv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tier = achv.getTier();
|
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
this.bg.setTexture(`achv_bar${tier ? `_${tier + 1}` : ""}`);
|
2023-12-19 23:51:48 -05:00
|
|
|
this.icon.setFrame(achv.getIconImage());
|
|
|
|
this.titleText.setText(achv.getName());
|
2024-03-28 14:36:39 -04:00
|
|
|
this.scoreText.setVisible(achv instanceof Achv);
|
2023-11-12 00:31:40 -05:00
|
|
|
this.descriptionText.setText(achv.description);
|
2023-12-19 23:51:48 -05:00
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
if (achv instanceof Achv) {
|
2023-12-19 23:51:48 -05:00
|
|
|
this.scoreText.setText(`+${(achv as Achv).score}pt`);
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-11-12 00:31:40 -05:00
|
|
|
|
2024-05-29 10:02:41 +02:00
|
|
|
// Take the width of the default interface or the title if longest
|
|
|
|
this.bg.width = Math.max(this.defaultWidth, this.icon.displayWidth + this.titleText.displayWidth + this.scoreText.displayWidth + 16);
|
|
|
|
|
|
|
|
this.scoreText.x = this.bg.width - 2;
|
|
|
|
this.descriptionText.width = this.bg.width - this.icon.displayWidth - 16;
|
|
|
|
this.descriptionText.setWordWrapWidth(this.descriptionText.width * 6);
|
|
|
|
|
|
|
|
// Take the height of the default interface or the description if longest
|
|
|
|
this.bg.height = Math.max(this.defaultHeight, this.titleText.displayHeight + this.descriptionText.displayHeight + 8);
|
|
|
|
this.icon.y = (this.bg.height / 2) - (this.icon.height / 2);
|
|
|
|
|
2024-05-23 17:03:10 +02:00
|
|
|
(this.scene as BattleScene).playSound("achv");
|
2023-11-12 00:31:40 -05:00
|
|
|
|
|
|
|
this.scene.tweens.add({
|
|
|
|
targets: this,
|
2024-05-29 10:02:41 +02:00
|
|
|
x: (this.scene.game.canvas.width / 6) - (this.bg.width / 2),
|
2023-11-12 00:31:40 -05:00
|
|
|
duration: 500,
|
2024-05-23 17:03:10 +02:00
|
|
|
ease: "Sine.easeOut"
|
2023-11-12 00:31:40 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
this.scene.time.delayedCall(10000, () => this.hide());
|
2024-05-24 01:45:04 +02:00
|
|
|
|
2023-11-12 00:31:40 -05:00
|
|
|
this.setVisible(true);
|
|
|
|
this.shown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected hide(): void {
|
2024-05-23 17:03:10 +02:00
|
|
|
if (!this.shown) {
|
2023-11-12 00:31:40 -05:00
|
|
|
return;
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-11-12 00:31:40 -05:00
|
|
|
|
|
|
|
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-11-12 00:31:40 -05:00
|
|
|
onComplete: () => {
|
|
|
|
this.shown = false;
|
|
|
|
this.setVisible(false);
|
2024-05-23 17:03:10 +02:00
|
|
|
if (this.queue.length) {
|
2023-11-12 00:31:40 -05:00
|
|
|
this.showAchv(this.queue.shift());
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|
2023-11-12 00:31:40 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2024-05-23 17:03:10 +02:00
|
|
|
}
|