import { _decorator, Component, Node, loader, Prefab, find } from 'cc';
import { LoadingView } from '../../engines/loadingView/LoadingView';
import { GUIManager } from '../../engines/gui/GUIManager';
import { UIConst } from '../ui/UIConst';
import { GameModel } from '../models/GameModel';
import GameConfigManager from '../models/GameConfigManager';
import { LayerManager } from '../../engines/gui/LayerManager';
import { NoticeManager } from '../../engines/notices/NoticeManager';
import BufferManager from '../../engines/buffers/BufferManager';
import { PlatformManager } from '../../Platform/PlatformManager';
import { WeChatPlatform } from '../../Platform/WeChat/WeChatPlatform';
import { branchIdType } from '../../Platform/WeChat/branchIdType';
const { ccclass, property } = _decorator;

@ccclass('PrepareScene')
export class PrepareScene extends Component {

    public static Inited:boolean=false;
    
    @property({
        type:Prefab
    })
    TextNoticeView:Prefab=null;

    start () {
        console.log("进入Prepare场景");
        if(PrepareScene.Inited==false){
            PrepareScene.Inited=true;
            let canvas:Node=find("Canvas");
            //UI全局节点
            let uiRoot:Node=canvas.getChildByName("UIRoot");
            let layerRoot:Node=uiRoot.getChildByName("LayerRoot");
            let NoticeLayer:Node=uiRoot.getChildByName("NoticeLayer");
            LayerManager.single.Init(layerRoot);

            //提示
            let noticeMap:Map<string,Prefab>=new Map<string,Prefab>();
            noticeMap.set("Text",this.TextNoticeView);
            NoticeManager.Init(NoticeLayer,noticeMap);

            UIConst.RegisterGUI();
        }
        
        GUIManager.single.Show(UIConst.PREPARE_UI);

        let weChat = PlatformManager.impl as WeChatPlatform;
            if(weChat instanceof WeChatPlatform){
                weChat.branchAnalytics(branchIdType.EnterHall)
            }

    }
    
    update (deltaTime: number) {
        GameModel.single.CheckEarnings();
        BufferManager.Tick(deltaTime);
    }
}
