"use strict"; cc._RF.push(module, '11e35uft+xPA6bZL2ABe2o7', 'nx.bridge'); // Scripts/zbridge/nx.bridge.js "use strict"; /******************************************************************************* * * Nx老项目桥接 * * * 2021.12.10 ******************************************************************************/ var CFG = require("config"); var NxMod = require("nx.mod"); var BDef = require("bridge.define"); var PathTool = require("pathtool"); var FFSDK = require("ff_sdk"); var FFMisc = require("misc_help"); var _require = require("bridge.conditions"), CFMap = _require.CFMap; var NxBridge = cc.Class({ "extends": NxMod, name: "NxBridge", // 初始化 initialize: function initialize(_args) { // 初始化 if (!this._super(_args)) { cc.error("初始化NX框架失败!"); return false; } // 视图创建 nx.plugin.add(this, ["view"]); this.vbuild(BDef.ViewBridge); // 界面集合 this.panels = {}; // tag2回溯界面 this.setTag2Infos = []; // 初始参数解析 this.sdkConfigs(); return true; }, // 销毁 uninitialize: function uninitialize() { // USPER return this._super(); }, // 初始参数解析 sdkConfigs: function sdkConfigs() { var info = FFSDK.getInstance().init() || {}; nx.frame.vset("DebugOpen", CC_DEBUG); nx.frame.vset("Platform", FFMisc.getInstance().getPlatformName()); nx.frame.vset("DeviceID", info.deviceId || nx.sdk.getDeviceID()); nx.frame.vset("ApkName", info.appName || ""); nx.frame.vset("ApkVersion", info.appVersion || nx.sdk.getPackVersion()); nx.frame.vset("LocalLanguage", info.lang || CFG.DesignLanguage); nx.frame.vset("IDFA", info.idfa || ""); nx.frame.vset("NetType", info.netType || "4g"); nx.frame.vset("Simulator", info.simulator == "1"); nx.frame.vset("Host", info.ip || "0.0.0.0"); nx.frame.vset("hMode", info.hMode == "1"); nx.frame.vset("GUUID", info.gUUID || CFG.GName); console.log("APK:" + JSON.stringify(info)); // 日志 var llv = parseInt(info.logLv || "2"); if (CC_DEBUG) { llv = 0; } nx.frame.vset("LogLevel", llv); nx.logger.setLevel(llv); this.vset("gname", info.gameName || CFG.GName); this.vset("channel", info.channelId || nx.dt.queryURLArg("ch") || CFG.Channel); this.vset("channelName", info.channelName || CFG.Platform); this.vset("gm", info.openGM == "1"); this.vset("ssl", parseInt(info.ssl) == 1); this.vset("hideSwitch", parseInt(info.hideSwitch || "0") != 0); this.vset("enableGuest", parseInt(info.enableGuest || "0") != 0); this.vset("gmUrl", info.gmUrl || ""); this.vset("socialUrl", info.socialUrl || ""); this.vset("phpUrls", info.php || CFG.PHPs); // 汇率 this.vset("excRates", { name: info.currency_name || "¥", mult: parseInt(info.currency_multiple || "1"), divi: parseInt(info.currency_division || "1"), round: 0 != parseInt(info.currency_round || "1") }); // GM开关 if (CC_DEBUG && cc.sys.isBrowser) { this.vset("gm", true); } // MAC调试 // if( cc.sys.os == cc.sys.OS_OSX ) { // this.vset( "gm", true ); // nx.frame.vset( "hMode", true ); // nx.warn( "$Bridge:MAC调试开启" ); // } }, // 桥接服务初始化 initMods: function initMods() { // 桥接服务 nx.factory.createService("bridge.remote"); nx.factory.createService("bridge.mods"); // 工具服务 this.partner = require("bridge.partner"); this.jumper = require("bridge.jumper"); this.condition = require("bridge.conditions"); this.attrs = require("bridge.attributes"); this.time = require("bridge.time"); this.cmd = require("bridge.cmd"); }, // 桥接服务销毁 uninitMods: function uninitMods() { nx.factory.remove(nx.bridge.remote); // 工具服务 this.partner = null; this.jumper = null; this.condition = null; this.attrs = null; this.time = null; this.cmd = null; }, // 语种设置 setLang: function setLang(_key) { var key = _key || CFG.DesignLanguage; nx.setLocLanguage(key); }, // 设置游戏阶段 setGS: function setGS(_stage, _args) { var _this = this; var old = this.vget("GS"); if (old == _stage) { nx.warn("$Bridge:GS重复 ", _stage); return; } // 切换中 if (this.gsDoing) { nx.error("$Bridge:GS更改失败,尚在进行 %s -> %s", old, _stage); return; } nx.debug("$Bridge:GS更改 %s -> %s", old, _stage); this.vset("GSArgs", _args || {}); this.vset("GS", _stage); // 统计新阶段展示UI var wid1 = BDef.StageScene[_stage]; if (nx.dt.strEmpty(wid1)) { nx.warn("$Bridge:GS对应界面缺失: %s", _stage); return; } // 新界面展示 this.createPanel(wid1, _args); // 延迟关闭老阶段UI var wid2 = BDef.StageScene[old]; if (nx.dt.strNEmpty(wid2)) { setTimeout(function () { _this.closePanel(wid2); }, 1); } }, // ================================================================ // // 注册一些快捷方法 // // ================================================================ //子节点全部销毁 NodeChidrenDestroy: function NodeChidrenDestroy(parNode) { if (parNode instanceof cc.Node) { if (parNode.children) { for (var i in parNode.children) { if (parNode.children[i].destroy) { parNode.children[i].destroy(); } } } } }, // 条件检查 checkConditions: function checkConditions(_conds) { // 参数无效 if (nx.dt.arrEmpty(_conds)) { return {}; } // 条件参数规范 // 如果参数是一维数组[key,val],则转为二维数组[[key,val],[key,val]] var conds = _conds; if (!nx.dt.arrGood(conds[0])) { conds = [_conds]; } var ret = {}; for (var i in conds) { var item = conds[i]; var func = CFMap[item[0]]; if (!nx.dt.fnGood(func)) { nx.error("解锁条件未识别:", item[0]); continue; } var desc = func(item[1]); if (nx.dt.strNEmpty(desc)) { ret = { key: item[0], val: item[1], desc: desc }; break; } } return ret; }, // 快速图标设置 setIcon: function setIcon(_refnode, _names, _icon, _badPath) { var path = PathTool.queryIconPath(_icon); nx.gui.setSpriteFrame(_refnode, _names, path, function (_ret) { if (!_ret) { nx.gui.setSpriteFrame(_refnode, _names, _badPath || PathTool.BadIcon); } }); }, // 快速小图标设置 setIconS: function setIconS(_refnode, _names, _icon, _badPath) { var path = PathTool.querySmallIconPath(_icon); nx.gui.setSpriteFrame(_refnode, _names, path, function (_ret) { if (!_ret) { nx.gui.setSpriteFrame(_refnode, _names, _badPath || PathTool.BadIconS); } }); }, // 快速设置头像(face_id) setAvatarByFaceId: function setAvatarByFaceId(_refnode, _names, _faceId) { this.setIcon(_refnode, _names, _faceId, PathTool.BadAvatar); }, // 快速设置头像框(avatar_base_id) setAvatarFrame: function setAvatarFrame(_refnode, _names, _fid) { var path = cc.path.join("resDB/aframes", _fid); nx.gui.setSpriteFrame(_refnode, _names, path, function (_ret) { if (!_ret) { nx.gui.setSpriteFrame(_refnode, _names, PathTool.BadAvatarFrame); } }); }, // 快速设置聊天泡泡(bubble_bid) setChatBubble: function setChatBubble(_refnode, _names, _bid) { var path = cc.path.join("resDB/chatskin", _bid); nx.gui.setSpriteFrame(_refnode, _names, path, function (_ret) { if (!_ret) { nx.gui.setSpriteFrame(_refnode, _names, PathTool.BadChatBubble); } }); }, // 获取子节点上的BridgeWindow组件 getBridgeWindow: function getBridgeWindow(_refnode, _names) { var node = nx.gui.find(_refnode, _names); if (!node) { return null; } var components = node._components; if (nx.dt.arrEmpty(components)) { return null; } for (var i in components) { var cmp = components[i]; if (cmp && nx.dt.strGood(cmp.BKEY)) { return cmp; } } return null; }, // ================================================================ // 界面相关快捷方法 // ================================================================ // 创建界面 createPanel: function createPanel(_wname, _params) { this.ui.openWindow(_wname, _params); // //設置回溯界面 // this.setTag2PanelInfos(_wname, _params); }, // 关闭界面 closePanel: function closePanel(_wname) { this.ui.closeWindow(_wname); this.Tag2PanelClose(_wname); }, // 清理所有非场景层节点 cleanPanels: function cleanPanels() { this.ui.cleanWindows(); this.resetTag2Panels(); }, // 清理所有非场景层节点 cleanWindowsByTag: function cleanWindowsByTag(_tag) { this.ui.cleanWindowsByTag(_tag); }, // 設置回溯界面 setTag2PanelInfos: function setTag2PanelInfos(_wname, _args, _tag) { // if(!window.game.isMainScene)return; if (_wname == "MainScene" || _wname == "WndBattleScene" || _wname == "WndFormView" || _wname == "WndSummonAnimation" || _wname == "WndFromView" || _wname == "WndPersonalPush" || _wname == "WndCampfightFinal") return; //去重 for (var i in this.setTag2Infos) { var info = this.setTag2Infos[i]; if (info && info.panel) { if (_wname == info.panel) { return; } } } //最大回溯 size 3 if (this.setTag2Infos.length == 3) { //去除最早的 this.setTag2Infos.shift(); } this.setTag2Infos.push({ panel: _wname, args: _args, tag: _tag }); }, // 回溯界面已關閉 Tag2PanelClose: function Tag2PanelClose(_wname) { // if(!window.game.isMainScene)return; for (var i in this.setTag2Infos) { var info = this.setTag2Infos[i]; if (info && info.panel) { if (info.panel == _wname) { this.setTag2Infos.splice(i, 1); } } } }, // 界面回溯 resetTag2PanelfromBat: function resetTag2PanelfromBat() { for (var i in this.setTag2Infos) { var info = this.setTag2Infos[i]; if (info && info.panel && info.args) { var par = this.ui.getSceneNode(info.tag); var view = this.getBridgeWindow(par, info.panel); if (!view) { this.createPanel(info.panel, info.args); } } } //清空緩存 // this.setTag2Infos = []; }, // 界面回溯 resetTag2Panels: function resetTag2Panels() { //清空緩存 this.setTag2Infos = []; }, // ================================================================ // 全屏等待 // ================================================================ // 添加单等待 addWaiting: function addWaiting(_key, _desc, _tout) { if (_desc === void 0) { _desc = ""; } if (_tout === void 0) { _tout = 5; } if (nx.dt.strEmpty(_key)) { nx.error("无效空等待添加"); return; } nx.debug("全局等待(ADD):", _key, _desc); var keys = this.vget("GWaitings"); if (nx.dt.arrMember(keys, null, function (_m) { return _m && _m.key == _key; })) { nx.error("全屏等待:重复." + _key); return; } keys.push({ key: _key, desc: _desc, tout: _tout }); this.vset("GWaitings", keys); }, // 删除单等待 delWaiting: function delWaiting(_key) { if (nx.dt.strEmpty(_key)) { nx.error("无效空等待删除"); return; } nx.debug("全局等待(DEL):", _key); var keys = this.vget("GWaitings"); keys = nx.dt.arrDelete(keys, function (_m) { return _m && _m.key == _key; }); this.vset("GWaitings", keys); }, // 清空等待 cleanWaitings: function cleanWaitings() { nx.debug("全局等待(CLEAN):"); this.vset("GWaitings", []); }, // ================================================================ // 原方法参数保全兼容过渡 // ================================================================ // 获取服务器本地名字 localServerName: function localServerName(_srvid) { if (nx.dt.strEmpty(_srvid)) { return ""; } var RC = require("role_controller").getInstance(); var role = RC.getRoleVo(); if (!role) { return ""; } var name = ""; var listOr = _srvid.split("_"); var listMe = role.srv_id.split("_"); if (listOr[1] && listMe[0] && listOr[0] != listMe[0]) { name = nx.text.getKey("msg_functiontool_tip1"); } else if (listOr.length > 1) { name = cc.js.formatStr("S%s", listOr[listOr.length - 1]); } // 代表机器人 if (_srvid == "robot_1") { name = name; } return name; } }); module.exports = NxBridge; cc._RF.pop();