cc.Class({ extends: cc.BaseClass, properties: { m_updateTipNode: cc.Node, }, ctor: function () { this.m_nNeedUpdate = 0; this.m_updateURL = null; }, // onLoad: function () { // cc.debug.setDisplayStats(false); // FitSize(this.node); // ShowO2I(this.node, 0.5); // this.$('Version@Label').string = ``; // if(!this.m_Loading) this.m_Loading = this.$('loading'); // this.m_Loading.zIndex = 100; // this.m_Loading.active = false; // this.$('ani').active = false; // this.$('Logo').active = false; // window.LoadSetting(); // this.m_StartAni = this.$('StartAni').getComponent(dragonBones.ArmatureDisplay); // if(window.START_ANIMATION == 0){ // this.m_nNeedUpdate = 1; // this.$('ani').active = true; // this.scheduleOnce(this.OnTimer_DelayShowLogo, 0.4); // this.m_StartAni.node.active = false; // }else{ // this.m_StartAni.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this); // this.m_StartAni.node.active = true; // this.m_StartAni.playAnimation('newAnimation', 1); // } // }, onLoad: function () { if (window.WPMJ == 0) { this.$('Logowp').active = true; this.$('Logommh').active = false; } else { this.$('Logowp').active = false; this.$('Logommh').active = true; } // 关闭调试统计信息显示(如FPS、DrawCall等) cc.debug.setDisplayStats(false); // 调整当前节点尺寸以适应屏幕大小(假设为自定义函数,用于屏幕适配) FitSize(this.node); // 显示从Out到In的过渡效果,持续0.5秒(假设为自定义动画效果函数) ShowO2I(this.node, 0.5); // 初始化版本号标签并置空(通过自定义选择器获取Label组件) if (cc.sys.OS_ANDROID == cc.sys.os) { this.$('Version@Label').string = window.APP_BOTTOM_VER_ANDROID; } else { this.$('Version@Label').string = window.APP_BOTTOM_VER_IOS; } this.$('VersionUI@Label').string = ""//window.APP_VERSION_UI; // 初始化加载界面节点 if (!this.m_Loading) this.m_Loading = this.$('loading'); // 获取loading子节点 this.m_Loading.zIndex = 100; // 设置渲染层级 this.m_Loading.active = false; // 默认隐藏加载界面 // 禁用动画节点和Logo节点 this.$('ani').active = false; //this.$('Logo').active = false; // 加载游戏设置(假设为全局函数,读取本地存储配置等) window.LoadSetting(); // 获取龙骨动画组件(开场动画) // this.m_StartAni = this.$('StartAni').getComponent(dragonBones.ArmatureDisplay); // 根据启动动画设置执行不同逻辑 if (window.START_ANIMATION == 0) { // 跳过开场动画的情况 this.m_nNeedUpdate = 1; // 标记需要更新状态(具体用途需结合上下文) // this.$('ani').active = true; // 启用备用动画节点 // 延迟0.4秒执行Logo显示(等待备用动画播放) this.scheduleOnce(this.OnTimer_DelayShowLogo, 0.4); // this.m_StartAni.node.active = false; // 隐藏龙骨动画节点 } else { // // 需要播放开场动画的情况 // // 添加动画播放完成事件监听 // this.m_StartAni.addEventListener( // dragonBones.EventObject.COMPLETE, // this.animationEventHandler, // 动画结束回调 // this // 回调上下文 // ); // this.m_StartAni.node.active = true; // 启用龙骨动画节点 // this.m_StartAni.playAnimation('newAnimation', 1); // 播放指定动画(1次) } if (this.m_updateTipNode) { this.m_updateTipNode.active = false; } // 在初始化页面时显示加载提示 // this.scheduleOnce(this.ShowLoading(null, '加载中...'),3) this.ShowLoading(null, '加载中...') // this.setTimeout(() => { // this.getServerIP // }, 2000); this.timeoutID = setTimeout(this.getServerIP.bind(this), 3000); // this.scheduleOnce(this.getServerIP, 2); // this.scheduleOnce(this.getServerIP, 5); this.getServerIP(); }, // start: function () { // g_Launch = this; // g_Login = null; // g_Lobby = null; // g_Table = null; // g_CurScene = this; // }, // animationEventHandler: function (event) { // if (event.type === dragonBones.EventObject.COMPLETE) { // this.m_StartAni.node.active = false; // this.m_nNeedUpdate = 1; // this.OnTimer_DelayShowLogo(); // //this.scheduleOnce(this.OnTimer_DelayShowLogo, 0.4); // } // }, // OnTimer_DelayShowLogo: function() { // this.$('ani').active = true; // this.$('Logo').active = true; // }, // onEnable: function() { // cc.director.on('LocalVersion',this.OnLocalVersion, this); // }, // OnLocalVersion: function(ver) { // if(!ver) return; // window.APP_VERSION = ver; // this.$('Version@Label').string = `v${ver}`; // }, // onDisable: function() { // cc.director.off('LocalVersion',this.OnLocalVersion, this); // }, start: function () { // 初始化全局场景引用 g_Launch = this; // 记录启动场景实例 g_Login = null; // 清空登录场景引用 g_Lobby = null; // 清空大厅场景引用 g_Table = null; // 清空游戏桌引用 g_CurScene = this; // 设置当前活动场景为启动场景 }, /* 动画事件处理回调 */ // animationEventHandler: function (event) { // // 当龙骨动画播放完成时 // if (event.type === dragonBones.EventObject.COMPLETE) { // // this.m_StartAni.node.active = false; // 隐藏开场动画节点 // this.m_nNeedUpdate = 1; // 触发状态更新标志 // this.OnTimer_DelayShowLogo(); // 立即显示Logo // // 原始延迟调用方案(已注释): // // this.scheduleOnce(this.OnTimer_DelayShowLogo, 0.4); // } // }, /* 延迟显示Logo的定时回调 */ OnTimer_DelayShowLogo: function () { this.$('ani').active = true; // 启用过渡动画节点 // this.$('Logo').active = true; // 显示主Logo节点 }, /* 组件启用时的生命周期回调 */ onEnable: function () { // 注册本地版本号事件监听 cc.director.on('LocalVersion', this.OnLocalVersion, this); }, /* 处理本地版本号事件 */ OnLocalVersion: function (ver) { if (!ver) return; // 无效版本号直接返回 // 更新全局版本号并显示在UI window.APP_VERSION = ver; // 存储到全局变量 this.$('Version@Label').string = `v${ver}`; // 更新版本号标签 console.log("OnLocalVersion----1", ver) }, /* 组件禁用时的生命周期回调 */ onDisable: function () { // 移除事件监听防止内存泄漏 cc.director.off('LocalVersion', this.OnLocalVersion, this); }, //获取服务器最新IP getServerIP() { if (window.GET_IP == false) return; if ((window.OPEN_DOMAIN_NET == true && cc.sys.isNative != cc.sys.os)) return; //this.ShowLogin(null, '加载中'); console.log("获取IP--") this.updateIP = true; var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 400)) { //this.StopLogin(); console.log("获取到ip:"); //获取到ip了就关闭定时器,不再轮询 clearTimeout(this.timeoutID); console.log("a1.wangpaimj.com 返回", xhr.responseText); this.updateIP = false; window.UpdateIPRelatedAddresses(xhr.responseText); } }.bind(this); xhr.timeout = 5000; xhr.open("GET", encodeURI('http://a1.wangpaimj.com'), true); xhr.send(); }, // getServerIP() { // // console.log("window.GET_IP:", window.GET_IP, "window.GET_IP == false:", window.GET_IP == false); // if (window.GET_IP == false) { // return; // } // // console.log("window.OPEN_DOMAIN_NET:", window.OPEN_DOMAIN_NET, "window.OPEN_DOMAIN_NET == true && cc.sys.isNative != cc.sys.os:", window.OPEN_DOMAIN_NET == true && cc.sys.isNative != cc.sys.os); // if ((window.OPEN_DOMAIN_NET == true && cc.sys.isNative != cc.sys.os)) { // return; // } // // 初始化轮询参数 // this.m_ipRetryCount = 0; // this.m_ipMaxRetries = 5; // 最大重试次数 // this.m_ipBaseDelay = 2000; // 基础重试间隔(毫秒) // this.m_ipRetryTimer = null; // console.log("✅ 开始获取IP(轮询模式)--"); // this.updateIP = true; // this._makeIPRequest(); // }, // // 发起IP请求(轮询核心方法) // _makeIPRequest() { // if (this.m_ipRetryCount >= this.m_ipMaxRetries) { // console.log("❌ IP获取失败,已达到最大重试次数:" + this.m_ipMaxRetries); // this.updateIP = false; // // 可以在这里添加失败回调或默认IP处理 // return; // } // console.log("🔄 第 " + (this.m_ipRetryCount + 1) + " 次尝试获取IP..."); // var xhr = new XMLHttpRequest(); // xhr.onreadystatechange = function () { // if (xhr.readyState === 4) { // if (xhr.status >= 200 && xhr.status < 400) { // // 请求成功 // console.log("✅ IP获取成功"); // this.updateIP = false; // this._clearRetryTimer(); // window.UpdateIPRelatedAddresses(xhr.responseText); // } else { // // 请求失败,安排重试 // this._scheduleRetry("HTTP错误: " + xhr.status); // } // } // }.bind(this); // xhr.onerror = function () { // this._scheduleRetry("网络错误"); // }.bind(this); // xhr.ontimeout = function () { // this._scheduleRetry("请求超时"); // }.bind(this); // xhr.timeout = 5000; // xhr.open("GET", encodeURI('http://a1.wangpaimj.com'), true); // xhr.send(); // }, // // 安排重试 // _scheduleRetry(errorMsg) { // this.m_ipRetryCount++; // console.log("⚠️ IP获取失败:" + errorMsg + ",将在" + this._getRetryDelay() + "ms后重试(" + this.m_ipRetryCount + "/" + this.m_ipMaxRetries + ")"); // this._clearRetryTimer(); // // 使用递增延迟(避免雪崩效应) // this.m_ipRetryTimer = this.scheduleOnce(function () { // this._makeIPRequest(); // }.bind(this), this._getRetryDelay() / 1000); // scheduleOnce使用秒为单位 // }, // // 计算重试延迟(递增算法) // _getRetryDelay() { // // 使用指数退避策略:基础延迟 * 2^重试次数,最大不超过30秒 // return Math.min(this.m_ipBaseDelay * Math.pow(2, this.m_ipRetryCount), 30000); // }, // // 清除重试定时器 // _clearRetryTimer() { // if (this.m_ipRetryTimer) { // this.unschedule(this.m_ipRetryTimer); // this.m_ipRetryTimer = null; // } // }, // update: function () { // if (this.m_nNeedUpdate > 0) { // this.m_nNeedUpdate--; // } else { // return; // } // this.LoadConfig(); // cc.gPreLoader.Init(function () { // if (cc.sys.isNative) { // this.ShowPrefabDLG("UpdateManager", this.node, function (Js) { // Js.CheckUpdate(function() { this.ShowLogin(); }.bind(this)); // }.bind(this)); // } else { // if (cc.sys.browserType == cc.sys.BROWSER_TYPE_WECHAT || cc.sys.browserType == cc.sys.BROWSER_TYPE_MOBILE_QQ) { // ChangeScene('Lobby'); // } else { // this.ShowLogin(); // } // } // }.bind(this)); // }, update: function () { //获取最新IP if (this.updateIP) { return; } // 更新逻辑控制:仅在 m_nNeedUpdate 有效时执行 if (this.m_nNeedUpdate > 0) { this.m_nNeedUpdate--; // 递减更新计数器 } else { return; // 未达到更新条件时直接退出 } // 加载基础配置文件(假设为游戏核心配置) this.LoadConfig(); // cc.assetManager.loadBundle("21201", "", function (err, bundle) { // if (err) { // console.log('加载bundle错误---', "21201"); // let bundle21201 = cc.assetManager.getBundle('21201'); // console.log('加载bundle---21201', bundle21201); // return console.error(err); // } // console.log('加载bundle成功---21201'); // //console.log('1-----------------',JSON.stringify(bundle)); // console.log('2-----------------', JSON.stringify(bundle._config.paths._map)); // for (let i in bundle._config.paths._map) { // let asset = bundle._config.paths._map[i]; // console.log('3-----------------', asset); // for (let j = 0; j < asset.length; j++) { // console.log('4-----------------', JSON.stringify(asset[j])); // console.log('41-----------------', JSON.stringify(asset[j].ctor)); // console.log('5-----------------', (asset[j].ctor)); // console.log('6-----------------', (asset[j].ctor.toString())); // for (let key in asset[j]) { // if (typeof asset[j][key] === 'function') { // console.log(key + '()'); // } else { // console.log(key + ': ' + asset[j][key]); // } // } // return; // } // } // console.dir(bundle, { depth: null }); // }.bind(this)); // return; // 初始化预加载系统 cc.gPreLoader.Init(function (url) { if (url) { this.m_updateURL = url; if (this.m_updateTipNode) { this.m_updateTipNode.active = true; } console.log("加载完毕"); this.StopLoading(); } else { this.ShowLogin(); } return; // 平台判断分支 if (cc.sys.isNative) { // 原生平台(iOS/Android)&& window.IS_UPDATE // 显示更新管理弹窗 this.ShowPrefabDLG("UpdateManager", this.node, function (Js) { // 执行更新检查 Js.CheckUpdate(function () { this.ShowLogin(); // 更新完成后显示登录界面 }.bind(this)); }.bind(this)); } else { // Web 平台 // 判断是否在微信/QQ内置浏览器 // if (cc.sys.browserType == cc.sys.BROWSER_TYPE_WECHAT || // cc.sys.browserType == cc.sys.BROWSER_TYPE_MOBILE_QQ) { // ChangeScene('Lobby'); // 特殊浏览器直接进入大厅 // } else { // this.ShowLogin(); // 普通浏览器显示登录界面 // } this.ShowLogin(); } }.bind(this)); // 保持上下文绑定 }, // ShowLogin: function () { // this.ShowPrefabDLG("Login", this.node, function () {}.bind(this)); // }, // ShowUpdate: function () { // this.ShowPrefabDLG("UpdateManager", this.node, function (Js) { // Js.StartPreload(true, 0, function(){ // this.ShowLogin(); // }.bind(this)); // }.bind(this)); // }, ShowLogin: function () { // 显示登录界面弹窗 console.log("ShowLogin----") // cc.assetManager.loadBundle('Test', (err, bundle) => { // console.log("bundle",bundle) // bundle.load(`Nutton`, cc.Prefab, function (err, prefab) { // let newNode = cc.instantiate(prefab); // console.log("newNode",newNode,prefab) // this.node.addChild(newNode); // }.bind(this)); // }); // return; this.ShowPrefabDLG( "Login", // 预制体名称:登录界面 this.node, // 父节点:当前场景根节点 function () { // 加载完成回调(空操作) // 可在此处添加登录界面初始化后操作 console.log("加载完毕"); this.StopLoading(); }.bind(this) // 确保回调函数中的this指向当前组件 ); }, ShowUpdate: function () { // 显示更新管理器弹窗并启动预加载 this.ShowPrefabDLG( "UpdateManager", // 预制体名称:更新管理器 this.node, // 父节点:当前场景根节点 function (Js) { // 弹窗实例回调 // 启动预加载流程 Js.StartPreload( true, // 参数1:是否显示进度条(假设) 0, // 参数2:预加载阶段标识 function () { this.ShowLogin(); // 预加载完成后显示登录界面 }.bind(this) ); }.bind(this) ); }, // //游戏入口 // EnterGameScene:function(){ // // 加载游戏 // if(GameDef && g_ServerListDataLast){ // if(window.LOG_NET_DATA)console.log("地址:", g_ServerListDataLast.szServerAddr+":"+g_ServerListDataLast.wServerPort); // this.m_Loading.active = true; // this.ShowPrefabDLG("UpdateManager", this.m_Loading, function (Js) { // Js.StartPreload(0, g_ServerListDataLast.wKindID, function() { // cc.gPreLoader.LoadRes(`Image_BG_BG${GameDef.BGIndex}`, '' + GameDef.KIND_ID, function(res) { // window.gGameBG = 'loading'; // ChangeScene('Table'); // }.bind(this)); // }.bind(this)); // }.bind(this)); // } // }, // LoadConfig: function() { // cc.share.LoadConfig(); // } //游戏入口 EnterGameScene: function () { // 进入游戏场景主流程 if (GameDef && g_ServerListDataLast) { // 校验游戏配置和服务器数据已加载 // 调试模式下打印服务器连接信息 if (window.LOG_NET_DATA) console.log("地址launch:", g_ServerListDataLast.szServerAddr + ":" + g_ServerListDataLast.wServerPort); // 显示加载界面 this.m_Loading.active = true; // 加载更新管理器弹窗 this.ShowPrefabDLG("UpdateManager", this.m_Loading, function (Js) { // 启动资源预加载流程 Js.StartPreload( 0, // 参数1:预加载模式(0可能表示基础资源加载) g_ServerListDataLast.wKindID, // 参数2:游戏种类ID function () { // 预加载完成回调 // 加载特定游戏背景资源 cc.gPreLoader.LoadRes( `Image_BG_BG${GameDef.BGIndex}`, // 动态拼接背景图路径 '' + GameDef.KIND_ID, // 资源分类标识 function (res) { // 资源加载完成回调 window.gGameBG = 'loading'; // 设置全局背景状态 ChangeScene('Table'); // 切换到游戏桌场景 }.bind(this) ); }.bind(this) ); }.bind(this)); } }, LoadConfig: function () { cc.share.LoadConfig(); // 可能包含:音效开关、语言包、UI皮肤等全局配置 }, onclickUpdateJump() { if (this.m_updateURL) { ThirdPartyOpenUrl(this.m_updateURL); } }, });