84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import { _decorator, Component, Node } from 'cc';
|
|
import { SingletonBase } from './framework/SingletonBase';
|
|
import { BattleLevel } from './BattleLevel';
|
|
import { UIManager } from './framework/ui/UIManager';
|
|
import { PlayPanel } from './ui/PlayPanel';
|
|
import { MainPanel } from './ui/MainPanel';
|
|
import { LoadingPanel } from './ui/LoadingPanel';
|
|
import { WinPanel } from './ui/WinPanel';
|
|
import { FPSCameraController } from './FPSCameraController';
|
|
import { LocalSaveMgr } from './framework/data/LocalSaveMgr';
|
|
import { AddHeartPanel } from './ui/AddHeartPanel';
|
|
import { SettingPanel } from './ui/SettingPanel';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('GameController')
|
|
export class GameController extends SingletonBase<GameController> {
|
|
|
|
@property(BattleLevel)
|
|
curLevel: BattleLevel = null
|
|
|
|
@property
|
|
forceLevelIndex: number = 1
|
|
|
|
protected onLoad(): void {
|
|
super.onLoad()
|
|
}
|
|
|
|
protected start(): void {
|
|
// this.gameStart()
|
|
UIManager.instance.openPanel(MainPanel)
|
|
}
|
|
|
|
judgePower() {
|
|
if (LocalSaveMgr.instance.playerData.power > 0) {
|
|
LocalSaveMgr.instance.usePower()
|
|
return true
|
|
} else {
|
|
UIManager.instance.openPanel(AddHeartPanel)
|
|
}
|
|
return false
|
|
}
|
|
|
|
gameStart() {
|
|
if (!this.judgePower()) {
|
|
return
|
|
}
|
|
UIManager.instance.closePanel(MainPanel)
|
|
UIManager.instance.openPanel(LoadingPanel)
|
|
this.scheduleOnce(() => {
|
|
console.log("gameStart openPanel")
|
|
this.curLevel.loadLevel()
|
|
}, 0.5)
|
|
}
|
|
|
|
gameRestart() {
|
|
if (!this.judgePower()) {
|
|
return
|
|
}
|
|
UIManager.instance.closeAllPanels()
|
|
UIManager.instance.openPanel(LoadingPanel)
|
|
this.scheduleOnce(() => {
|
|
console.log("gameStart openPanel")
|
|
this.curLevel.loadLevel()
|
|
}, 0.5)
|
|
}
|
|
|
|
backMain() {
|
|
UIManager.instance.closeAllPanels()
|
|
UIManager.instance.openPanel(MainPanel)
|
|
this.curLevel.unLoadLevel()
|
|
FPSCameraController.getInstance().clear()
|
|
}
|
|
|
|
onLoadComplete() {
|
|
let self = this
|
|
LoadingPanel.instance.onLoadingComplete(() => {
|
|
UIManager.instance.openPanel(PlayPanel)
|
|
self.curLevel.startLevel()
|
|
})
|
|
}
|
|
}
|
|
|
|
|