const GameRulesUtil = require("./utils/GameRulesUtil.js"); const LobbyListInfoUtil = require("./utils/LobbyListInfoUtil.js"); //UI展示逻辑 cc.Class({ extends: cc.BaseClass, properties: { // 这里定义roomListItem模版中的UI控件引用 SpriteAvater: { default: null, type: cc.Sprite, displayName: "房主头像" }, owenRoomLabel: { default: null, type: cc.Label, displayName: "房主昵称" }, roomPayLabel: { default: null, type: cc.Label, displayName: "房间支付" }, circleLabel: { default: null, type: cc.Label, displayName: "圈数" }, scoreLabel: { default: null, type: cc.Label, displayName: "底分" }, nemberLabel: { default: null, type: cc.Label, displayName: "台数" }, //用户头像 userAvater_1: { default: null, type: cc.Sprite, displayName: "用户头像" }, userAvater_2: { default: null, type: cc.Sprite, displayName: "用户头像" }, userAvater_3: { default: null, type: cc.Sprite, displayName: "用户头像" }, padLabel: { default: null, type: cc.Label, displayName: "密码" }, //锁 lockSprite: { default: null, type: cc.Sprite, displayName: "锁" }, //加入房间按钮 joinBtn: { default: null, type: cc.Button, displayName: "加入房间按钮" }, //快速加入房间按钮 quickJoinBtn: { default: null, type: cc.Button, displayName: '快速加入按钮' }, //游戏进行中 gaming: { default: null, type: cc.Sprite, displayName: "游戏进行中" }, //用户人数 用于接收房间人数空数组 m_userList: [] }, ctor: function () { this.m_Data = null; this.m_Hook = null; this.m_userList = []; }, onLoad: function () { }, // 初始化预制体 InitPre: function () { // 初始化逻辑 }, // 设置回调钩子 SetHook: function (hook) { this.m_Hook = hook; }, // 设置预制体信息 SetPreInfo: function (info) { this.m_Data = info; //console.log("房间信息==>:", info);//[byPartID, byPlayerCnt,dwClubID,,dwCreateTime,dwCreaterID, dwRoomID,dwRules(), dwServerRules,dwUserID(), wKindID,wProgress] // 房间人数 this.m_userList = info.dwUserID; // console.log("房间人数==>:", this.m_userList); if (!info || info.length < 2) return; //获取房主信息 this.getcreaterInfo(info.dwCreaterID); // 设置房间信息 var rulesData = GameRulesUtil.GetRulesStr(info.dwServerRules, info.dwRules); // console.log("房间信息rulesData==>:", rulesData); // 设置房间支付 this.roomPayLabel.string = rulesData[0].value; // 设置圈数 this.circleLabel.string = rulesData[2].value; // 设置底分 this.scoreLabel.string = rulesData[4].value; // 设置台数 this.nemberLabel.string = "台数" + rulesData[5].value; // 设置密码 if (rulesData[6] !== '其他场次') { this.lockSprite.node.active = false; } //设置密码文字 this.padLabel.string = info.wProgress+"/"+rulesData[5].value; //用户头像 if (rulesData[3].value == "2人") { //如果是2人房间,只显示房主头像和用户头像 this.userAvater_1.node.active = true; this.userAvater_2.node.active = false; this.userAvater_3.node.active = false; //如果用户满了2人,则隐藏加入按钮,显示游戏进行中 //遍历用户列表,判断是否有用户满了2人 let userCount = 0; for (let i = 0; i < this.m_userList.length; i++) { if (this.m_userList[i] !== 0) { userCount++; } } if (userCount == 2) { this.joinBtn.node.active = false; this.gaming.node.active = true; } } else if (rulesData[3].value == "4人") { this.userAvater_1.node.active = true; this.userAvater_2.node.active = true; this.userAvater_3.node.active = true; let userCount = 0; for (let i = 0; i < this.m_userList.length; i++) { if (this.m_userList[i] !== 0) { userCount++; } } if (userCount == 4) { this.joinBtn.node.active = false; this.gaming.node.active = true; } } // 设置加入按钮点击事件 if (this.joinBtn) { this.joinBtn.node.on('click', this.onJoinRoom, this); } // 设置快速加入房间按钮点击事件 if (this.quickJoinBtn) { this.quickJoinBtn.node.on('click', this.onQuickJoinRoom, this); } }, // 加入按钮点击事件 onJoinRoom: function () { console.log("加入房间按钮点击事件==>:"); cc.gSoundRes.PlaySound('Button'); var roomID = this.m_Data.dwRoomID; var clubID = this.m_Data.dwClubID; // this.m_Hook.OnJoinRoom(roomID, clubID); g_Lobby.OnQueryRoom(roomID, clubID); }, //快速加入房间按钮点击事件 onQuickJoinRoom: function () { console.log("快速加入房间按钮点击事件==>:"); cc.gSoundRes.PlaySound('Button'); //当this.m_Data为空,说明当前没有房间信息,不能快速加入房间,给用户提示 if (this.m_Data == null) { //弹出提示信息 g_CurScene.ShowAlert("当前没有房间,快去创建一个房间吧"); // g_CurScene.ShowAlert('网络连接异常,请检查网络后重试'); return; } //加入该游戏房间 var roomID = this.m_Data.dwRoomID; var clubID = this.m_Data.dwClubID; // this.m_Hook.OnJoinRoom(roomID, clubID); g_Lobby.OnQueryRoom(roomID, clubID); }, //获取房主信息 getcreaterInfo: function (creatorID) { var userIDArr = LobbyListInfoUtil.getPlayerId(this.m_Data.dwUserID); if (userIDArr == []) { return; } else if (userIDArr.length !== 0) { var userID = userIDArr[0].value; } //当前房主的ID var curCreatorID = creatorID == 0 ? userID : creatorID; let webUrl = window.PHP_HOME + '/UserFunc.php?GetMark=12&dwUserID=' + curCreatorID; WebCenter.GetData(webUrl, null, function (data) { var createInfo = JSON.parse(data); // console.log("senderInfo==>:", createInfo); // 获取发送者昵称 var senderName = createInfo.NickName; //获取发送者头像URL var createHeadUrl = createInfo.HeadUrl //设置房主昵称 // if(senderName = ''){ // this.owenRoomLabel.string = " "; // } this.owenRoomLabel.string = "房主:" + senderName; //设置房主头像 }.bind(this)); }, // 清理方法 onDestroy: function () { if (this.m_BtnJoin) { this.m_BtnJoin.node.off('click', this.onJoinRoom, this); } }, });