pinball/assets/_Game/Scripts/UI/UIController.ts

116 lines
4.0 KiB
TypeScript
Raw Normal View History

2024-04-03 20:20:56 -07:00
import { _decorator, Color, Component, Label, LabelOutline, Node, ParticleSystem, Tween, tween, Vec3 } from 'cc';
2024-03-10 20:46:50 -07:00
import { EventManger } from '../Manager/EventManger';
import GameEvent from '../Events/GameEvent';
import ScoreType from '../Enum/ScoreType';
import GameState from '../Enum/GameState';
2024-03-26 00:28:59 -07:00
import { GameManager } from '../Manager/GameManager';
import BEConnector from '../API/BEConnector';
2024-03-29 04:24:58 -07:00
import Utilities from '../Utilities';
import { StickerManager } from '../Manager/StickerManager';
2024-03-07 03:15:08 -08:00
const { ccclass, property } = _decorator;
@ccclass('UIController')
export class UIController extends Component {
2024-03-10 20:46:50 -07:00
@property({ type: Label, visible: true })
private _scoreLabel: Label;
@property({ type: Label, visible: true })
2024-03-29 04:24:58 -07:00
private _ticketLabel: Label;
2024-03-27 04:00:23 -07:00
2024-03-11 04:12:22 -07:00
@property({ type: ParticleSystem, visible: true })
private _buffFx: ParticleSystem;
2024-03-27 04:00:23 -07:00
@property({ type: Node, visible: true })
2024-04-04 04:27:04 -07:00
private _controlPanel: Node;
2024-03-10 20:46:50 -07:00
@property({ type: Node, visible: true })
private _startPanel: Node;
@property({ type: Node, visible: true })
private _overPanel: Node;
2024-03-07 03:15:08 -08:00
2024-03-22 03:27:52 -07:00
protected async onLoad() {
2024-03-10 20:46:50 -07:00
EventManger.instance.on(GameEvent.Score, this.onScore, this);
EventManger.instance.on(GameEvent.BallOut, this.onBallOut, this);
EventManger.instance.on(GameEvent.GameStateChange, this.onGameStateChange, this);
2024-03-11 04:12:22 -07:00
EventManger.instance.on(GameEvent.MultiBall, this.onMultiBall, this);
2024-03-28 20:35:44 -07:00
EventManger.instance.on(GameEvent.BoosterActive, this.onBoosterActive, this);
EventManger.instance.on(GameEvent.BoosterDisable, this.onBoosterDisable, this);
2024-03-07 03:15:08 -08:00
}
2024-03-28 20:35:44 -07:00
private async onScore(score: number, points: number, type: ScoreType) {
2024-03-29 04:24:58 -07:00
this._scoreLabel.string = score.toString();
2024-03-10 20:46:50 -07:00
if (type == ScoreType.Goal) {
2024-04-23 03:36:31 -07:00
StickerManager.instance.Show('Goal', new Vec3(0, 700));
2024-03-10 20:46:50 -07:00
}
}
2024-03-22 03:27:52 -07:00
private onBallOut() {
StickerManager.instance.Show('BallOut');
2024-03-22 03:27:52 -07:00
}
2024-03-29 04:24:58 -07:00
private async onGameStateChange(state: GameState) {
2024-03-10 20:46:50 -07:00
switch (state) {
case GameState.Init:
this._startPanel.active = true;
2024-03-29 04:24:58 -07:00
this._ticketLabel.string = BEConnector.instance.numberTicket.toString();
this._scoreLabel.string = '0';
2024-03-10 20:46:50 -07:00
break;
2024-04-03 02:43:18 -07:00
case GameState.Ready:
2024-04-04 04:27:04 -07:00
this._controlPanel.active = true;
2024-04-03 02:43:18 -07:00
this._startPanel.active = false;
break;
2024-03-10 20:46:50 -07:00
case GameState.Playing:
this._overPanel.active = false;
2024-04-03 02:43:18 -07:00
this._ticketLabel.string = BEConnector.instance.numberTicket.toString();
2024-03-10 20:46:50 -07:00
break;
case GameState.GameOver:
2024-03-12 21:36:19 -07:00
this._buffFx.stop();
await Utilities.waitUntil(() => !GameManager.instance.isWaitingUpdateScore);
await Utilities.delay(2);
2024-03-10 20:46:50 -07:00
this._overPanel.active = true;
2024-03-26 00:28:59 -07:00
break;
case GameState.End:
await Utilities.delay(2);
2024-03-29 04:24:58 -07:00
this._overPanel.active = true;
2024-03-26 00:28:59 -07:00
break;
case GameState.Relive:
this._overPanel.active = false;
2024-04-03 02:43:18 -07:00
this._ticketLabel.string = BEConnector.instance.numberTicket.toString();
2024-03-10 20:46:50 -07:00
break;
}
}
2024-03-11 04:12:22 -07:00
private onMultiBall(active: boolean) {
2024-03-22 03:27:52 -07:00
if (active) {
StickerManager.instance.showLabel('MULTI BALL!!!');
2024-03-22 03:27:52 -07:00
}
2024-03-11 04:12:22 -07:00
}
2024-03-28 20:35:44 -07:00
public onBoosterActive() {
this._buffFx.play();
StickerManager.instance.showLabel('CHEESE!!!', {
color: new Color('#ffb517'),
outLineColor: new Color('#ec830a'),
});
2024-03-28 20:35:44 -07:00
}
public onBoosterDisable() {
this._buffFx.stop();
}
2024-03-26 20:04:28 -07:00
public starGame() {
2024-04-03 02:43:18 -07:00
GameManager.instance.Ready();
2024-03-26 20:04:28 -07:00
}
2024-04-21 19:04:58 -07:00
// private secondsToTime(second: number) {
// const m = Math.floor((second - (second % 60)) / 60)
// .toString()
// .padStart(2, '0');
// const s = Math.floor(second % 60)
// .toString()
// .padStart(2, '0');
2024-03-11 04:12:22 -07:00
2024-04-21 19:04:58 -07:00
// return m + ':' + s;
// }
2024-03-10 20:46:50 -07:00
}