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';
|
2024-04-22 04:12:57 -07:00
|
|
|
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-10 20:46:50 -07:00
|
|
|
@property({ type: Label, visible: true })
|
2024-03-29 04:24:58 -07:00
|
|
|
private _eventLabel: 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-22 03:27:52 -07:00
|
|
|
this._eventLabel.string = '';
|
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() {
|
2024-04-22 04:12:57 -07:00
|
|
|
StickerManager.instance.Show('BallOut');
|
2024-03-22 03:27:52 -07:00
|
|
|
}
|
|
|
|
|
2024-04-03 20:20:56 -07:00
|
|
|
private showEventLabel(string: string, color?: Color, outLineColor?: Color) {
|
2024-03-22 03:27:52 -07:00
|
|
|
this._eventLabel.string = string;
|
2024-04-03 20:20:56 -07:00
|
|
|
this._eventLabel.color = color || new Color('#FFFF00');
|
|
|
|
|
|
|
|
this._eventLabel.getComponent(LabelOutline).color = outLineColor || new Color('#FF6600');
|
|
|
|
|
2024-03-22 03:27:52 -07:00
|
|
|
Tween.stopAllByTarget(this._eventLabel.node);
|
|
|
|
tween(this._eventLabel.node)
|
2024-04-03 20:20:56 -07:00
|
|
|
.set({ scale: Vec3.ZERO })
|
2024-03-22 03:27:52 -07:00
|
|
|
.to(0.2, { scale: Vec3.ONE }, { easing: 'backOut' })
|
|
|
|
.delay(1)
|
|
|
|
.to(
|
|
|
|
0.1,
|
|
|
|
{ scale: Vec3.ZERO },
|
|
|
|
{
|
|
|
|
onComplete: () => {
|
|
|
|
this._eventLabel.string = '';
|
|
|
|
},
|
|
|
|
easing: 'backIn',
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.start();
|
2024-03-07 03:15:08 -08: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-04-04 04:27:04 -07:00
|
|
|
this.showEventLabel('TIME UP!!!', new Color('#ed3a18'), Color.WHITE);
|
2024-03-29 04:24:58 -07:00
|
|
|
await Utilities.delay(1.2);
|
2024-03-12 21:36:19 -07:00
|
|
|
this._buffFx.stop();
|
2024-03-10 20:46:50 -07:00
|
|
|
this._overPanel.active = true;
|
2024-03-26 00:28:59 -07:00
|
|
|
break;
|
|
|
|
case GameState.End:
|
2024-04-04 04:27:04 -07:00
|
|
|
this.showEventLabel('TIME UP!!!', new Color('#ed3a18'), Color.WHITE);
|
2024-03-29 04:24:58 -07:00
|
|
|
await Utilities.delay(1.2);
|
|
|
|
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) {
|
|
|
|
this.showEventLabel('MULTI BALL!!!');
|
|
|
|
}
|
2024-03-11 04:12:22 -07:00
|
|
|
}
|
|
|
|
|
2024-03-28 20:35:44 -07:00
|
|
|
public onBoosterActive() {
|
|
|
|
this._buffFx.play();
|
2024-04-03 20:20:56 -07:00
|
|
|
this.showEventLabel('CHEESE!!!', new Color('#ffb517'), 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
|
|
|
}
|