| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- 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);
- }
- },
- });
|