import Main from "./Main";
import ViewObject from "./ViewObject";

/**
 * 游戏主界面窗口管理
 */
const { ccclass, property } = cc._decorator;

export const GameViewType = cc.Enum({

    login: 'prefab/login/login',//登陆界面
    fqLogin: 'prefab/login/fqLogin',//凤起登陆

    historyArea: 'prefab/area/myzone',//历史登陆过的分区
    allArea: 'prefab/area/allzone',//所有分区

    area: 'prefab/area/area',//选区界面
    home: 'prefab/home/home',//主界面
    reward: 'prefab/common/award',//弹出奖励界面

    //引导界面
    plot_view: 'prefab/plot/plot_view',//插画引导界面

    //设置界面
    tap_role: 'prefab/setting/tap_role',//角色属性
    tap_role_name: 'prefab/setting/tap_role_name',//角色改名
    tap_shop: 'prefab/home/shop/shop',//商城
    tap_set: 'prefab/setting/tap_set',//设置
    tap_set_music: 'prefab/setting/tap_set_music',//声音
    tap_set_control: 'prefab/setting/tap_set_control',//按钮设置
    tap_set_Ann: 'prefab/setting/tap_set_Ann',//公告

    role_icon_view: 'prefab/setting/tap_role_head',//头像设置
    role_frame_view: 'prefab/setting/tap_role_headk',//头像框设置
    role_title_view: 'prefab/setting/tap_role_headtiezhi',//称号设置

    role_icon_info_view: 'prefab/setting/frame_icon/icon_info',//头像详细查看
    role_title_info_view: 'prefab/setting/frame_icon/title_info',//称号详细查看
    /**关卡 */
    stageView: 'prefab/home/stage/stage',//关卡选择界面
    stageInfo: 'prefab/home/stage/info/stageInfo',//关卡详情查看

    worldMap: 'prefab/home/stage/scene/wordMap',//关卡中选择世界地图
    wordTask: 'prefab/home/stage/scene/wordTask',//关卡中选择世界任务
    wordTaskItem: 'prefab/home/stage/scene/wordTaskItem',//世界任务说明奖励
    wordTaskItem_1: 'prefab/home/stage/scene/wordTaskItem_1',//众神事件
    dungeon: 'prefab/home/dungeon/dungeon',//关卡BOSS

    fight: 'prefab/fight/fight',//战斗界面
    fight_hd_zb: 'prefab/common/hd_zb',//战斗中获得装备
    fight_map_event_tips: 'prefab/map/element/map_event_tips',//战斗中机关提示
    fight_map_sjp_tips: 'prefab/map/element/shuijingping',//水晶瓶提示
    fight_dialog_box: 'prefab/fight/ff_dialog',//战斗中对话框
    fight_auto_equip: 'prefab/fight/ff_auto_equip',//战斗中获得装备自动使用
    fight_zsj_tips: 'prefab/fight/ff_tips',//获得紫水晶提示


    pack: 'prefab/home/pack/beibao',//背包界面
    god_card: 'prefab/home/godcard/god_card_view',//神庙界面
    god_card_info: 'prefab/home/godcard/card_about_view',//神卡说明
    god_card_star: 'prefab/home/godcard/card_star_view',//神卡升星
    god_card_star_success: 'prefab/home/godcard/card_star_success_view',//神卡进阶成功
    equip: 'prefab/home/equip/role_zb',//装备界面
    mohe: 'prefab/home/mohe/mohe',//魔盒界面
    moheInfo: 'prefab/home/mohe/magic_info_view',//魔盒详细查看
    moheReward: 'prefab/home/mohe/magic_reward_view',//魔盒奖励查看

    email: 'prefab/home/mail/mail',//邮箱
    emailInfo: 'prefab/home/mail/mail_info',//邮箱

    goodAbout: 'prefab/home/pack/good_Info',//道具说明
    // equipAbout: 'prefab/common/zbsx',//装备说明
    goodEat: 'prefab/home/pack/food_view',//道具说明

    changeEquip: 'prefab/home/equip/zb_gh',//换装备
    IntensifyEquip: 'prefab/home/equip/equi_pintensify',//装备强化

    petInfo: 'prefab/home/equip/pet_info',//宠物属性详细说明
    exchangeAmethyst: "prefab/home/shop/lottery_sj",//紫水晶兑换
    firstPay: "prefab/activity/1001_sc",//首冲
    wish: "prefab/activity/1002_mrlb",//每日祝福
    revenge: "prefab/activity/1003_fclb",//复仇礼包
});

export const AudioMgr = cc.Enum({
    homeMusic: "music/bgm/home",
    openDoor: "music/01_woodendoor",
    getCoin: "music/01_money",
    box: "music/01_treasure",
    amethyst: "music/01_crystal",
    star: "music/01_star",
    wooden: "music/01_wooden",
    qh: "music/01_intensify",
    qh2: "music/01_pack",
    click: "music/BT_common",
    equip: "music/01_clad",         //角色穿装备
    gift: "music/01_purchase",      //商店购买道具，礼包
    blood: "music/01_blood",        //关卡中补血的果子（摘果子就播放）
    award: "music/01_award",        //游戏奖励界面，通用的
})

@ccclass
export default class ViewManage extends cc.Component {

    public main: Main;

    @property(cc.Node)
    mLayer: cc.Node = null;//弹出层

    @property(cc.Node)
    mLayer1: cc.Node = null;//弹出层

    /**
     * 是否已经在执行中
     */
    private runclick = false;
    onLoad() {
        this.main = this.node.getComponent(Main);
    }
    /**
     * 
     * @param node 弹出窗口
     */
    public popView(node: cc.Node) {
        node.parent = this.mLayer;
        this.runclick = false;
    }
    /**
    * 
    * @param node 弹出窗口
    */
    public popView1(node: cc.Node) {
        node.parent = this.mLayer1;
        this.runclick = false;
    }
    /**
     * 载入功能界面
     */
    public loadFunc(func, callback: (viewObject: ViewObject) => void, prev?: cc.Node) {
        if (this.runclick) {
            return;
        }
        this.runclick = true;
        //开始加载
        this.main.startLoad();
        cc.resources.load(func, cc.Prefab, (err, prefab: cc.Prefab) => {
            if (err) {
                cc.error(err);
            } else {
                //加载结束
                let node: cc.Node = cc.instantiate(prefab);
                let viewObject = node.getComponent(ViewObject);
                viewObject.main = this.main;
                callback(viewObject);
            }
            this.main.stopLoad();
        });
    }
}
