42 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-12-13 18:21:04 +01:00
import { Component, Label, ProgressBar, _decorator } from "cc";
2022-12-21 14:08:49 +01:00
import { UIButton } from "../../Services/UI/Button/UIButton";
import { GameModalLauncher } from "../ModalWIndows/GameModalLauncher";
2022-11-28 11:49:16 +01:00
import { Player } from "../Unit/Player/Player";
2022-11-28 12:19:04 +01:00
import { UnitLevel } from "../Unit/UnitLevel";
2022-11-16 14:04:23 +01:00
const { ccclass, property } = _decorator;
@ccclass("GameUI")
export class GameUI extends Component {
@property(ProgressBar) private xpBar: ProgressBar;
2022-12-13 18:21:04 +01:00
@property(Label) private timeAliveText: Label;
2022-12-21 14:08:49 +01:00
@property(UIButton) private pauseBtn: UIButton;
2022-11-16 14:04:23 +01:00
private playerLevel: UnitLevel;
2022-12-21 14:08:49 +01:00
private modalLauncher: GameModalLauncher;
2022-11-16 14:04:23 +01:00
2022-12-21 14:08:49 +01:00
public init(player: Player, modalLauncher: GameModalLauncher): void {
2022-11-16 14:04:23 +01:00
this.playerLevel = player.Level;
2022-12-21 14:08:49 +01:00
this.modalLauncher = modalLauncher;
2022-11-16 14:04:23 +01:00
this.playerLevel.XpAddedEvent.on(this.updateProgressBar, this);
this.playerLevel.LevelUpEvent.on(this.updateProgressBar, this);
this.xpBar.progress = 0;
2022-12-21 14:08:49 +01:00
this.pauseBtn.InteractedEvent.on(this.showPauseWindow, this);
2022-11-16 14:04:23 +01:00
}
private updateProgressBar(): void {
this.xpBar.progress = this.playerLevel.XP / this.playerLevel.RequiredXP;
}
2022-12-13 18:21:04 +01:00
2022-12-21 14:08:49 +01:00
private showPauseWindow(): void {
console.log("Show pause window");
this.modalLauncher.showPauseModal();
}
2022-12-13 18:21:04 +01:00
public updateTimeAlive(timeAlive: number): void {
this.timeAliveText.string = `${Math.floor(timeAlive)}`;
}
2022-11-16 14:04:23 +01:00
}