roomListItem.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. const GameRulesUtil = require("./utils/GameRulesUtil.js");
  2. const LobbyListInfoUtil = require("./utils/LobbyListInfoUtil.js");
  3. //UI展示逻辑
  4. cc.Class({
  5. extends: cc.BaseClass,
  6. properties: {
  7. // 这里定义roomListItem模版中的UI控件引用
  8. SpriteAvater: {
  9. default: null,
  10. type: cc.Sprite,
  11. displayName: "房主头像"
  12. },
  13. owenRoomLabel: {
  14. default: null,
  15. type: cc.Label,
  16. displayName: "房主昵称"
  17. },
  18. roomPayLabel: {
  19. default: null,
  20. type: cc.Label,
  21. displayName: "房间支付"
  22. },
  23. circleLabel: {
  24. default: null,
  25. type: cc.Label,
  26. displayName: "圈数"
  27. },
  28. scoreLabel: {
  29. default: null,
  30. type: cc.Label,
  31. displayName: "底分"
  32. },
  33. nemberLabel: {
  34. default: null,
  35. type: cc.Label,
  36. displayName: "台数"
  37. },
  38. //用户头像
  39. userAvater_1: {
  40. default: null,
  41. type: cc.Sprite,
  42. displayName: "用户头像"
  43. },
  44. userAvater_2: {
  45. default: null,
  46. type: cc.Sprite,
  47. displayName: "用户头像"
  48. },
  49. userAvater_3: {
  50. default: null,
  51. type: cc.Sprite,
  52. displayName: "用户头像"
  53. },
  54. padLabel: {
  55. default: null,
  56. type: cc.Label,
  57. displayName: "密码"
  58. },
  59. //锁
  60. lockSprite: {
  61. default: null,
  62. type: cc.Sprite,
  63. displayName: "锁"
  64. },
  65. //加入房间按钮
  66. joinBtn: {
  67. default: null,
  68. type: cc.Button,
  69. displayName: "加入房间按钮"
  70. },
  71. //快速加入房间按钮
  72. quickJoinBtn: {
  73. default: null,
  74. type: cc.Button,
  75. displayName: '快速加入按钮'
  76. },
  77. //游戏进行中
  78. gaming: {
  79. default: null,
  80. type: cc.Sprite,
  81. displayName: "游戏进行中"
  82. },
  83. //用户人数 用于接收房间人数空数组
  84. m_userList: []
  85. },
  86. ctor: function () {
  87. this.m_Data = null;
  88. this.m_Hook = null;
  89. this.m_userList = [];
  90. },
  91. onLoad: function () {
  92. },
  93. // 初始化预制体
  94. InitPre: function () {
  95. // 初始化逻辑
  96. },
  97. // 设置回调钩子
  98. SetHook: function (hook) {
  99. this.m_Hook = hook;
  100. },
  101. // 设置预制体信息
  102. SetPreInfo: function (info) {
  103. this.m_Data = info;
  104. //console.log("房间信息==>:", info);//[byPartID, byPlayerCnt,dwClubID,,dwCreateTime,dwCreaterID, dwRoomID,dwRules(), dwServerRules,dwUserID(), wKindID,wProgress]
  105. // 房间人数
  106. this.m_userList = info.dwUserID;
  107. // console.log("房间人数==>:", this.m_userList);
  108. if (!info || info.length < 2) return;
  109. //获取房主信息
  110. this.getcreaterInfo(info.dwCreaterID);
  111. // 设置房间信息
  112. var rulesData = GameRulesUtil.GetRulesStr(info.dwServerRules, info.dwRules);
  113. // console.log("房间信息rulesData==>:", rulesData);
  114. // 设置房间支付
  115. this.roomPayLabel.string = rulesData[0].value;
  116. // 设置圈数
  117. this.circleLabel.string = rulesData[2].value;
  118. // 设置底分
  119. this.scoreLabel.string = rulesData[4].value;
  120. // 设置台数
  121. this.nemberLabel.string = "台数" + rulesData[5].value;
  122. // 设置密码
  123. if (rulesData[6] !== '其他场次') {
  124. this.lockSprite.node.active = false;
  125. }
  126. //设置密码文字
  127. this.padLabel.string = info.wProgress+"/"+rulesData[5].value;
  128. //用户头像
  129. if (rulesData[3].value == "2人") {
  130. //如果是2人房间,只显示房主头像和用户头像
  131. this.userAvater_1.node.active = true;
  132. this.userAvater_2.node.active = false;
  133. this.userAvater_3.node.active = false;
  134. //如果用户满了2人,则隐藏加入按钮,显示游戏进行中
  135. //遍历用户列表,判断是否有用户满了2人
  136. let userCount = 0;
  137. for (let i = 0; i < this.m_userList.length; i++) {
  138. if (this.m_userList[i] !== 0) {
  139. userCount++;
  140. }
  141. }
  142. if (userCount == 2) {
  143. this.joinBtn.node.active = false;
  144. this.gaming.node.active = true;
  145. }
  146. } else if (rulesData[3].value == "4人") {
  147. this.userAvater_1.node.active = true;
  148. this.userAvater_2.node.active = true;
  149. this.userAvater_3.node.active = true;
  150. let userCount = 0;
  151. for (let i = 0; i < this.m_userList.length; i++) {
  152. if (this.m_userList[i] !== 0) {
  153. userCount++;
  154. }
  155. }
  156. if (userCount == 4) {
  157. this.joinBtn.node.active = false;
  158. this.gaming.node.active = true;
  159. }
  160. }
  161. // 设置加入按钮点击事件
  162. if (this.joinBtn) {
  163. this.joinBtn.node.on('click', this.onJoinRoom, this);
  164. }
  165. // 设置快速加入房间按钮点击事件
  166. if (this.quickJoinBtn) {
  167. this.quickJoinBtn.node.on('click', this.onQuickJoinRoom, this);
  168. }
  169. },
  170. // 加入按钮点击事件
  171. onJoinRoom: function () {
  172. console.log("加入房间按钮点击事件==>:");
  173. cc.gSoundRes.PlaySound('Button');
  174. var roomID = this.m_Data.dwRoomID;
  175. var clubID = this.m_Data.dwClubID;
  176. // this.m_Hook.OnJoinRoom(roomID, clubID);
  177. g_Lobby.OnQueryRoom(roomID, clubID);
  178. },
  179. //快速加入房间按钮点击事件
  180. onQuickJoinRoom: function () {
  181. console.log("快速加入房间按钮点击事件==>:");
  182. cc.gSoundRes.PlaySound('Button');
  183. //当this.m_Data为空,说明当前没有房间信息,不能快速加入房间,给用户提示
  184. if (this.m_Data == null) {
  185. //弹出提示信息
  186. g_CurScene.ShowAlert("当前没有房间,快去创建一个房间吧");
  187. // g_CurScene.ShowAlert('网络连接异常,请检查网络后重试');
  188. return;
  189. }
  190. //加入该游戏房间
  191. var roomID = this.m_Data.dwRoomID;
  192. var clubID = this.m_Data.dwClubID;
  193. // this.m_Hook.OnJoinRoom(roomID, clubID);
  194. g_Lobby.OnQueryRoom(roomID, clubID);
  195. },
  196. //获取房主信息
  197. getcreaterInfo: function (creatorID) {
  198. var userIDArr = LobbyListInfoUtil.getPlayerId(this.m_Data.dwUserID);
  199. if (userIDArr == []) {
  200. return;
  201. } else if (userIDArr.length !== 0) {
  202. var userID = userIDArr[0].value;
  203. }
  204. //当前房主的ID
  205. var curCreatorID = creatorID == 0 ? userID : creatorID;
  206. let webUrl = window.PHP_HOME + '/UserFunc.php?GetMark=12&dwUserID=' + curCreatorID;
  207. WebCenter.GetData(webUrl, null, function (data) {
  208. var createInfo = JSON.parse(data);
  209. // console.log("senderInfo==>:", createInfo);
  210. // 获取发送者昵称
  211. var senderName = createInfo.NickName;
  212. //获取发送者头像URL
  213. var createHeadUrl = createInfo.HeadUrl
  214. //设置房主昵称
  215. // if(senderName = ''){
  216. // this.owenRoomLabel.string = " ";
  217. // }
  218. this.owenRoomLabel.string = "房主:" + senderName;
  219. //设置房主头像
  220. }.bind(this));
  221. },
  222. // 清理方法
  223. onDestroy: function () {
  224. if (this.m_BtnJoin) {
  225. this.m_BtnJoin.node.off('click', this.onJoinRoom, this);
  226. }
  227. },
  228. });