"use strict"; cc._RF.push(module, '4563bUxnZ9LUqQGqxUPsQJ1', 'cmp.main.ui'); // Scripts/mod/mainui/cmp/cmp.main.ui.js "use strict"; /****************************************************************** * Copyright(C) 2019 - 2020 Nx Studio * * 主界面 * * ******************************************************************/ var BridgeWindow = require("bridge.window"); var RoleController = require("role_controller"); var DramaConst = require("battle_drama_event"); var PartnerBody = require("cmp.partner.body.show"); var BattleController = require("battle_controller"); var BattleConst = require("battle_const"); var ArenaConst = require("arena_const"); var _require = require("bridge.conditions"), CKeys = _require.CKeys; var FID = require("bridge.function.ids"); var PLOT_DELAY = 0.02; var SEC_DELAY = 2.5; cc.Class({ "extends": BridgeWindow, properties: { imgDesktop: { "default": null, type: cc.Node }, cmpBody: { "default": null, type: PartnerBody }, nodPush: { "default": null, type: cc.Node } }, // 显示 onLoad: function onLoad() { var _this = this; // 角色属性监听 this.role = RoleController.getInstance().getRoleVo(); this.handler = this.role.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (_key, _val) { _this.onRoleAttrChanged(_key, _val); }); // 关卡更新 this.bindGEvent(DramaConst.BattleDrama_Top_Update_Data, function () { _this.onDramaLevelChanged(); }); this.racewnd = null; this.isracing = false; // 视图监听 this.vbind([["PPushGifts", this.onFreshGifts.bind(this)], ["clerkShowId", this.onActiveClerkChanged.bind(this)], ["matVersion", this.onMatchVersion.bind(this)], ["DailyPop", this.onShowPop.bind(this)], ["CChampionPro", this.onShowTips.bind(this)], ["CampfightTop", this.showCampTopThree.bind(this)]]); // 桌面更新 this.updateDesktop(this.role.theme_id); // 其他常驻界面 this.createPanels(); // 调试接口 this.dbgOpen(); // 全局 nx.bridge.mainui = this; // 战斗单例 this.battleC = BattleController.getInstance(); if (nx.storage.get("battleArena") != "null") { nx.bridge.jumper.jump2Window(nx.storage.get("battleArena")); } // console.log( nx. ); }, // 销毁 onDestroy: function onDestroy() { // 战斗单例 this.battleC = null; // 角色属性监听解除 if (this.role && this.handler) { this.role.unbind(this.handler); this.handler = null; this.role = null; } // 监听事件释放 this.unbindGEvents(); // 战斗实例销毁 if (this.battleC) { BattleController.instance.onDestroy(); delete BattleController.instance; BattleController.instance = null; this.battleC = null; } this.racewnd = null; }, // 帧更新 update: function update(dt) { if (this.battleC) { this.battleC.update(dt); } }, // 主场景显隐 show: function show(_show, _force) { // let cur = ( this.node.opacity > 0 ); // if( cur == _show ) { // return; // } // // this.node.opacity = _show ? 255 : 0; // 激活剧情辅助器 if (_show) { this.tryPlot(); this.onDramaLevelChanged(); } }, // 剧情触发 tryPlot: function tryPlot(_key) { if (_key === void 0) { _key = "main"; } var cmp = nx.gui.getComponent(this, "pres/plot", "cmp.main.ui.plot"); if (!cmp) { return; } // 战斗剧情触发 -- 挂机界面 if (_key == "drama") { this.scheduleOnce(function () { cmp.backDramaHook(); }, PLOT_DELAY); return; } // 战斗剧情触发 -- 编队界面 if (_key == "drama_team") { this.scheduleOnce(function () { cmp.backDramaTeamHook(); }, PLOT_DELAY); return; } // 战斗剧情触发 -- 编队界面 if (_key == "drama_team") { this.scheduleOnce(function () { cmp.backDramaTeamHook(); }, PLOT_DELAY); return; } // 主界面触发 if (this.node.opacity > 0) { this.scheduleOnce(function () { cmp.backMainScene(); }, PLOT_DELAY); return; } }, // 设置桌面 updateDesktop: function updateDesktop(_id) { var id = _id || 1; var path = cc.path.join("resDB/desktop", "" + id); nx.gui.setSpriteFrame(this.imgDesktop, "", path); }, // 角色属性改变 onRoleAttrChanged: function onRoleAttrChanged(_key, _val) { // 设置桌面 if (_key == "theme_id") { this.updateDesktop(_val); return; } if (!nx.dt.arrMember(CKeys, _key)) { return; } // 功能解锁检查 nx.bridge.mods.checkUnLock(); nx.bridge.acts.freshForeshow(); // 解锁条件更新 var cmps = game.node.getComponentsInChildren("bridge.condition.locker"); if (nx.dt.arrNEmpty(cmps)) { for (var i in cmps) { cmps[i].updateLocker(_key, _val); } } }, // 关卡更新 onDramaLevelChanged: function onDramaLevelChanged() { // 功能解锁检查 nx.bridge.mods.checkUnLock(); // 解锁条件更新 var cmps = game.node.getComponentsInChildren("bridge.condition.locker"); if (nx.dt.arrNEmpty(cmps)) { for (var i in cmps) { cmps[i].updateLocker("max_dun_id"); } } nx.gui.setActive(this, "ui/kfyg", RoleController.getInstance().dealOpenServer()); }, onTouchTrainCamp: function onTouchTrainCamp() { this.battleC.requestOpenBattleRelevanceWindow(BattleConst.Fight_Type.Training_Camp); }, // 其他常驻界面 createPanels: function createPanels() { nx.bridge.createPanel("WndHoverdLayer"); nx.bridge.createPanel("WndSummonAnimation"); }, onShowPop: function onShowPop(_pop) { if (_pop == 1) { var showDaily = nx.bridge.vget("DailyLimit"); if (showDaily) { switch (showDaily) { case 1: { nx.bridge.jumper.jump2Window(FID.ActFirst); nx.bridge.vset("DailyLimit", null); } ; break; case 2: { nx.bridge.jumper.jump2Window(FID.ActMySteryGift); nx.bridge.vset("DailyLimit", null); } ; break; case 3: { nx.bridge.jumper.jump2Window(FID.ActOptional); nx.bridge.vset("DailyLimit", null); } ; } } } }, showCampTopThree: function showCampTopThree(_data) { this.unscheduleAllCallbacks(); var show = nx.storage.get("WndCampfightFinal"); if (!_data || show && show == 1) { return; } if (!nx.bridge.getBridgeWindow("WndCampfightFinal")) { this.scheduleOnce(function () { nx.bridge.createPanel("WndCampfightFinal", { show: 100 }); nx.bridge.vset("CampfightTop", null); }, SEC_DELAY); } }, onShowTips: function onShowTips(_data) { if (!_data || this.racewnd || this.isracing) { return; } this.unscheduleAllCallbacks(); // console.log( "當前的跨服冠軍賽數據相關" + JSON.stringify( _data ) ); var self = this; var data = _data; if (data.showlist) { var crosscc = nx.storage.get("CChampionPro"); if (!crosscc || crosscc && crosscc == 0) { this.scheduleOnce(function () { nx.bridge.createPanel("WndCChampionFinal", { show: 99 }); nx.bridge.vset("CChampionPro", null); }, SEC_DELAY + 2); this.racewnd = data; } } else { if (data.round_status == ArenaConst.champion_round_status.guess) { // 每次競猜都要彈提示 var info = { type: BattleConst.Fight_Type.CrossChampion, raceinfo: 3, cb: function cb() { nx.bridge.jumper.jump2Window(FID.CrossChampion); self.isracing = true; } }; if (!this.racewnd) { nx.bridge.createPanel("WndPvpRaceTip", info); this.racewnd = data; } // nx.bridge.vset( "CChampionPro", null ); } else { if (data.step != ArenaConst.champion_step.unopened && data.step_status == ArenaConst.champion_step_status.opened && data.round == 1 && data.round_status == 0) { var _info = { type: BattleConst.Fight_Type.CrossChampion, raceinfo: 1, cb: function cb() { nx.bridge.jumper.jump2Window(FID.CrossChampion); self.isracing = true; } }; if (!this.racewnd) { // nx.bridge.createPanel( "WndPvpRaceTip", info ); nx.bridge.createPanel("WndPvpRaceTip", _info); // nx.bridge.vset( "CChampionPro", null ); this.racewnd = data; } } } } // nx.bridge.vset( "DailyLimit", null ); }, // ======================================================================== // 秘书相关 // ======================================================================== // 点击切换秘书 onTouchSwap: function onTouchSwap() { // 未解锁 var lst = nx.bridge.vget("clerkList"); if (nx.dt.arrEmpty(lst)) { nx.tbox("NeedUnlock"); return; } // 只有一个 if (lst.length == 1) { nx.bridge.createPanel("WndPersonalClerk"); return; } // 切换 nx.bridge.clerks.reqActiveShow(); }, // 当前秘书改变 onActiveClerkChanged: function onActiveClerkChanged(_id) { var _nx$bridge$partner; // 空 if (!this.cmpBody || nx.dt.strEmpty(_id)) { if (this.cmpBody) this.cmpBody.setEmpty(); return; } var arr = _id.split("_"); var info = (_nx$bridge$partner = nx.bridge.partner).parseShowInfo.apply(_nx$bridge$partner, arr); if (nx.dt.objNEmpty(info)) { this.cmpBody.setModel(info.sp_show, info.voice, info.phonetic_text || "", "main"); } }, // ======================================================================== // 个推相关 // ======================================================================== // 个人推送 onFreshGifts: function onFreshGifts(_list) { var _this2 = this; if (!this.nodPush || this.nodPush.childrenCount > 0 || nx.dt.arrEmpty(_list)) { return; } var path = cc.path.join("prefab/push/fab_personal_push_entry"); nx.res.loadPrefab(path, function (_err, _data) { if (_err) { return; } var node = cc.instantiate(_data); node.parent = _this2.nodPush; node.position = cc.Vec2.ZERO; }); }, // ======================================================================== // 版本验证 // ======================================================================== onMatchVersion: function onMatchVersion(_ver) { if (nx.dt.strEmpty(_ver)) { return; } // 验证热更版本是否与服务器匹配 var cur = nx.frame.vget("HotVersion"); // let v1 = _ver.split( '.' ); // let v2 = cur.split( '.' ); // if( v1[ 0 ] != v2[ 0 ] || v1[ 1 ] != v2[ 1 ] ) { if (cur != _ver) { nx.mbox("检测到新版本", ['confirm'], function (_key, _box) { _box.close(); nx.restart(); }); } }, // ======================================================================== // 调试相关 // ======================================================================== // 调试接口 dbgOpen: function dbgOpen() { if (!CC_DEBUG) { return; } nx.bridge = nx.bridge || {}; // 接口装载 var inst = function inst(_key, _fs) { var Mod = require(_fs); var Ins = Mod.getInstance(); nx.bridge[_key] = Ins; if (Ins && nx.dt.fnGood(Ins.getModel)) { nx.bridge[_key + "_mod"] = Ins.getModel(); } }; inst("bag", "backpack_controller"); // 背包 inst("hero", "hero_controller"); // 伙伴 inst("role", "role_controller"); // 自己 inst("arena", "arena_controller"); // 竞技 inst("mu", "mainui_controller"); // 奖励测试 inst("sum", "summon.mod"); // 召唤测试 inst("bat", "battle_controller"); // 战斗 inst("task", "task_controller"); // 任务 inst("dispatch", "dispatch.mod"); // 任务派遣 inst("guild", "guild_controller"); // 工会 inst("drama", "battle_drama_controller"); // 剧情 inst("pvp", "pvp.mod"); // STEP-UP inst("crystal", "summon.crystal.mod"); // STEP-UP inst("home", "home.mod"); // Home inst("vip", "vip_controller"); // VIP nx.bridge.timetool = require("timetool"); } }); cc._RF.pop();