import { _decorator, Component, Node, Prefab, director, instantiate } from 'cc';
import { GameNode } from './GameNode';
import { GameUI } from './GameUI';
import { HallUI } from './HallUI';
import WindowManager from '../core/manager/WindowManager';
import platformSystem from '../platform/platformSystem';
import { bundleMgr } from '../core/manager/BundleManager';
import { GameConst } from '../core/common/GameConst';
const { ccclass, property } = _decorator;

@ccclass('Main')
export class Main extends Component {
    public static I: Main;
    _HallUI: HallUI = null;
    _GameUI: GameUI = null;
    _GameNode: GameNode = null;
    start() {
        Main.I = this;
        WindowManager.ins.register(this.node)
        WindowManager.ins.open("HallUI").then(panle => {
            this._HallUI = panle
        })
        WindowManager.ins.open("GameUI").then(panle => {
            this._GameUI = panle;
            this._GameUI.node.active = false;
            bundleMgr.loadAsset(GameConst.bundleName.resources,"prefabs/GameNode",Prefab, (err, res) => {
                this._GameNode = (instantiate(res) as Node).getComponent(GameNode);
                director.getScene().addChild(this._GameNode.node);
            })
        })
    }

    play() {
        this._HallUI.node.active = false;
        this._GameUI.node.active = true;
        this._GameUI.restart();
        this._GameNode.node.active = true;
        this._GameNode.restart();
        platformSystem.platform.hideBannerAd();
    }

    backHall() {
        
        platformSystem.platform.showBannerAd();
        this._GameNode.node.active = false;
        this._HallUI.node.active = true;
        this._GameUI.node.active = false;
    }
}

