ClubRoomView.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. properties: {
  4. },
  5. ctor: function () {
  6. this._showIndex = 0;
  7. this.m_RoomKind = 0; //游戏类型筛选
  8. this.m_SelClubInfo = null; //当前俱乐部信息
  9. this.m_RoomInfoMap = null; //俱乐部房间
  10. this.m_Tag = 0;
  11. this._autoClick = true;
  12. this._tableMap = {};
  13. this._markMap = {};
  14. this._markCntMap = {};
  15. this._GameTagCntMap = {};
  16. this.m_RoomKindMap = {
  17. '10012': 'K1', '60001': 'K2', '10013': 'K3', '10011': 'K4', '50000': 'K5', '40107': 'K6', '21060': 'K7',
  18. '21201': 'K8', '52081': 'K9', '60014': 'K10', '500': 'K11', '62016': 'K12', '62005': 'K13', '52160': 'K14',
  19. '33301': 'K15', '21050': 'K16', '22201': 'K17', '501': 'K18', '63000': 'K19', '64000': 'K20', '10015': 'K21',
  20. '21070': 'K22', '21061': 'K7', '21062': 'K7', '21063': 'K23', '62007': 'K24', '21202': 'K25', '50001': 'K26','63504': 'K27','63500': 'K28','10020': 'K29',
  21. };
  22. },
  23. onLoad() {
  24. //界面初始化
  25. this._vMarkList = this.$('MarkTagList@VirtualList');
  26. this._vTableList = this.$('@VirtualList');
  27. this.m_tagBtnNode = this.$('GameTagList/view/content');
  28. this.m_markBtnNode = this.$('MarkTagList/view/content');
  29. this._gameTagAll = this.$('GameTagList/view/content/K0@Toggle');
  30. this._markTagAll = this.m_markBtnNode._children[1].getComponent(cc.Toggle);
  31. },
  32. InitRoomView: function (ClubInfo) {
  33. if (ClubInfo == null) return;
  34. this.m_SelClubInfo = ClubInfo;
  35. this.onSwitchCreateRoomBG();
  36. },
  37. //俱乐部房间
  38. LoadRoomInfo: function (RoomList) {
  39. if (this.m_SelClubInfo == null) return
  40. this._showIndex = 0;
  41. this.m_RoomKind = 0;
  42. this._tableMap = {};
  43. this._markMap = {};
  44. this._markCntMap = {};
  45. this._GameTagCntMap = {};
  46. this._vTableList.Init(2, this.scrollTableListCallBack.bind(this), this);
  47. this._vMarkList.Init(2, this.scrollMarkListCallBack.bind(this), this);
  48. if (RoomList) {
  49. this.m_RoomInfoMap = RoomList;
  50. g_Lobby.m_ClubRoomCnt[RoomList.dwClubID] = RoomList.wRoomCnt;
  51. this._autoClick = true;
  52. }
  53. if (this.m_RoomInfoMap.RoomInfo == null) {
  54. this.m_RoomInfoMap.RoomInfo = new Array();
  55. }
  56. this._initTable();
  57. this._inittMark();
  58. this._initGameTag();
  59. },
  60. _initTable: function () {
  61. if (this.m_RoomInfoMap && this.m_RoomInfoMap.RoomInfo) {
  62. for (var i in this.m_RoomInfoMap.RoomInfo) {
  63. let roomInfo = this.m_RoomInfoMap.RoomInfo[i];
  64. this._insertTable(roomInfo);
  65. }
  66. }
  67. },
  68. _inittMark: function () {
  69. if (!this.m_RoomInfoMap) return;
  70. for (var i in this.m_RoomInfoMap.RoomInfo) {
  71. this._insertMark(this.m_RoomInfoMap.RoomInfo[i]);
  72. }
  73. },
  74. _initGameTag: function () {
  75. if (!this.m_RoomInfoMap) return;
  76. this._GameTagCntMap = {};
  77. for (var i in this.m_RoomInfoMap.RoomInfo) {
  78. let item = this.m_RoomInfoMap.RoomInfo[i];
  79. if (this._GameTagCntMap[item.wKindID]) {
  80. this._GameTagCntMap[item.wKindID]++;
  81. continue;
  82. }
  83. this._GameTagCntMap[item.wKindID] = 1;
  84. }
  85. this._updateGameTag();
  86. },
  87. _filter: function (roomInfo) {
  88. let bShow = true;
  89. if (this.m_RoomKind && this.m_RoomKind != 0) {
  90. if (this.m_RoomKind == 21060) {
  91. if (roomInfo.wKindID != 21060 && roomInfo.wKindID != 21061 && roomInfo.wKindID != 21062) bShow = false;
  92. }
  93. else {
  94. if (roomInfo.wKindID != this.m_RoomKind) bShow = false;
  95. }
  96. }
  97. if (this.m_Tag != 0 && roomInfo.szTag != this.m_Tag) bShow = false;
  98. return bShow;
  99. },
  100. _insertTable: function (roomInfo) {
  101. roomInfo.bShow = this._filter(roomInfo);
  102. if (roomInfo.bShow) this._showIndex++;
  103. this._vTableList.InsertListData([roomInfo, this._showIndex]);
  104. },
  105. _insertMark: function (roomInfo) {
  106. if (roomInfo.szTag == '') return;
  107. let bShow = true;
  108. if (this._markCntMap[roomInfo.szTag]) {
  109. this._markCntMap[roomInfo.szTag].Cnt++;
  110. this._markCntMap[roomInfo.szTag].kindID.push(roomInfo.wKindID);
  111. return;
  112. }
  113. this._markCntMap[roomInfo.szTag] = { Cnt: 1, kindID: [roomInfo.wKindID] };
  114. if (this.m_RoomKind != 0 && roomInfo.wKindID != this.m_RoomKind) bShow = false;
  115. this._vMarkList.InsertListData([roomInfo.szTag, roomInfo.wKindID, bShow]);
  116. },
  117. scrollTableListCallBack: function (o) {
  118. this._tableMap[o.data[0].dwRoomID] = o;
  119. o.item.active = o.data[0].bShow;
  120. },
  121. scrollMarkListCallBack: function (o) {
  122. this._markMap[o.data[0]] = o;
  123. o.item.active = o.data[2];
  124. },
  125. _updateTableIndex: function (index) {
  126. this._showIndex = 0;
  127. this._vTableList.ForEachCtrl((js) => {
  128. this._showIndex++;
  129. js.SetIndex(this._showIndex);
  130. });
  131. },
  132. _updateGameTag: function () {
  133. for (var i in this.m_tagBtnNode._children) {
  134. if (i == 0) continue;
  135. this.m_tagBtnNode._children[i].active = false;
  136. }
  137. for (let i in this._GameTagCntMap) {
  138. this.$(`${this.m_RoomKindMap[i]}`, this.m_tagBtnNode).active = true;
  139. }
  140. },
  141. _updateMark: function () {
  142. for (let i in this._markMap) {
  143. if (this.m_RoomKind != 0) {
  144. let bShow = false;
  145. for (let k = 0; k < this._markCntMap[i].Cnt; k++) {
  146. if (this._markCntMap[i].kindID[k] == this.m_RoomKind) {
  147. bShow = true;
  148. break;
  149. }
  150. }
  151. this._markMap[i].item.active = bShow;
  152. } else {
  153. this._markMap[i].item.active = true;
  154. }
  155. }
  156. },
  157. _deleteMark: function (mark,kindID) {
  158. if(mark=='') return;
  159. let bUpdateTable = false;
  160. this._markCntMap[mark].Cnt--;
  161. let index = -1;
  162. for (var i in this._markCntMap[mark].kindID) {
  163. if (this._markCntMap[mark].kindID[i] == kindID) {
  164. index = i;
  165. break;
  166. }
  167. }
  168. if (index != -1) {
  169. bUpdateTable = true;
  170. this._markCntMap[mark].kindID.splice(index, 1)
  171. }
  172. if (this._markCntMap[mark].Cnt == 0) {
  173. this.m_Tag = 0;
  174. this._markTagAll.isChecked = true;
  175. bUpdateTable = true;
  176. this._vMarkList.RecycleItem(this._markMap[mark].item);
  177. delete this._markCntMap[mark];
  178. delete this._markMap[mark];
  179. }
  180. return bUpdateTable;
  181. },
  182. //插入新房间
  183. InsertRoomInfo: function (RoomInfo) {
  184. if (this.m_RoomInfoMap && RoomInfo && this.m_SelClubInfo.dwClubID == RoomInfo.dwClubID) {
  185. this._insertTable(RoomInfo);
  186. this._insertMark(RoomInfo);
  187. let kindID = RoomInfo.wKindID;
  188. if (kindID == 21061 && kindID == 21062) kindID = 21060;
  189. if (this._GameTagCntMap[kindID]) {
  190. this._GameTagCntMap[kindID]++;
  191. } else {
  192. this._GameTagCntMap[kindID] = 1;
  193. }
  194. this._updateGameTag();
  195. this.m_RoomInfoMap.RoomInfo.push(RoomInfo);
  196. var cnt = ++this.m_RoomInfoMap.wRoomCnt;
  197. g_Lobby.m_ClubRoomCnt[RoomInfo.dwClubID] = this.m_RoomInfoMap.wRoomCnt;
  198. }
  199. },
  200. //更新桌子上玩家
  201. UpdateUserState: function (userInfo) {
  202. if (!this.m_RoomInfoMap) return;
  203. let table = this._tableMap[userInfo.dwRoomID];
  204. if (!table) return;
  205. table.js.UpdateUserState(userInfo);
  206. var userItem = this.m_RoomInfoMap.UserList.UserInfo[`${userInfo.dwUserID}`];
  207. if (userItem) {
  208. if (userInfo.cbUserStatus <= US_FREE) {
  209. delete this.m_RoomInfoMap.UserList.UserInfo[`${userInfo.dwUserID}`];
  210. table.js.UpdateUser(userInfo);
  211. } else {
  212. this.m_RoomInfoMap.UserList.UserInfo[`${userInfo.dwUserID}`] = userInfo;
  213. }
  214. } else {
  215. if (userInfo.cbUserStatus <= US_FREE) return;
  216. this.m_RoomInfoMap.UserList.UserInfo[`${userInfo.dwUserID}`] = userInfo;
  217. table.js.UpdateUser(userInfo);
  218. }
  219. },
  220. onUpdateRoomInfo: function (roomInfo) {
  221. },
  222. //解散房间
  223. DisRoom: function (disRoom) {
  224. if (this.m_SelClubInfo == null) return;
  225. if (this.m_RoomInfoMap == null) return;
  226. var roomInfo = this.m_RoomInfoMap.RoomInfo;
  227. var index = -1;
  228. let bUpdateTable = false;
  229. if (this._tableMap[disRoom.dwRoomID]) {
  230. this._vTableList.RecycleItem(this._tableMap[disRoom.dwRoomID].item);
  231. let wKindID = this._tableMap[disRoom.dwRoomID].data[0].wKindID;
  232. let mark = this._tableMap[disRoom.dwRoomID].data[0].szTag;
  233. this._GameTagCntMap[wKindID]--;
  234. if (this._GameTagCntMap[wKindID] == 0) {
  235. this.m_RoomKind = 0;
  236. this._gameTagAll.isChecked = true;
  237. bUpdateTable = true;
  238. delete this._GameTagCntMap[wKindID];
  239. }
  240. bUpdateTable = this._deleteMark(mark,wKindID);
  241. delete this._tableMap[disRoom.dwRoomID];
  242. }
  243. this._updateTableIndex();
  244. this._updateGameTag();
  245. if (bUpdateTable) this._filterTable();
  246. for (var i in roomInfo) {
  247. if (roomInfo[i].dwRoomID == disRoom.dwRoomID) {
  248. index = i;
  249. break;
  250. }
  251. }
  252. if (index != -1) {
  253. roomInfo.splice(index, 1)
  254. this.m_RoomInfoMap.wRoomCnt--;
  255. }
  256. },
  257. //俱乐部房间玩家信息
  258. SetRoomUserInfo: function (UserList) {
  259. this.m_RoomInfoMap.UserList = UserList;
  260. if (UserList.dwClubID == this.m_SelClubInfo.dwClubID) {
  261. for (var i in UserList.UserInfo) {
  262. if (UserList.UserInfo[i] == null) continue;
  263. let item = this._tableMap[UserList.UserInfo[i].dwRoomID];
  264. if (!item) continue;
  265. item.js.UpdateRoomUser();
  266. }
  267. }
  268. },
  269. //进入俱乐部房间
  270. OnEnterRoom: function (RoomID) {
  271. if (this.m_SelClubInfo.cbCloseStatus == 1) return g_Lobby.ShowTips('已經打烊,不能進入房間');
  272. g_Lobby.OnQueryRoom(RoomID, this.m_SelClubInfo.dwClubID);
  273. },
  274. //解散俱乐部房间
  275. OnDissolveRoom: function (RoomID, CreaterID, Force, view) {
  276. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  277. if (pGlobalUserData.dwUserID != CreaterID && this.m_SelClubInfo.cbClubLevel < 8) {
  278. g_Lobby.ShowTips("您不是房主,無法解散房間!");
  279. return;
  280. }
  281. g_Lobby.ShowAlert("確認解散房間?", Alert_YesNo, function (Res) {
  282. if (Res) {
  283. if (view) view.HideView();
  284. var QueryDCR = new CMD_GP_C_DissClubRoom();
  285. QueryDCR.dwRoomID = RoomID;
  286. QueryDCR.dwUserID = pGlobalUserData.dwUserID;
  287. QueryDCR.dwClubID = this.m_SelClubInfo.dwClubID;
  288. QueryDCR.dwLeagueID = this.m_SelClubInfo.dwLeagueID;
  289. QueryDCR.byForce = Force;
  290. //var LoginMission = new CGPLoginMission(this, MDM_GP_GET_SERVER, SUB_GP_DISS_CLUB_ROOM, QueryDCR);
  291. window.gClubClientKernel.OnSendDissClubRoom(this, QueryDCR);
  292. }
  293. }.bind(this));
  294. },
  295. //
  296. OnClubRoomDisolve: function (UserList) {
  297. g_Lobby.ShowAlert("解散成功!", Alert_Yes, function (Res) {
  298. //this.UpdateRoomList(null, this.m_SelClubInfo);
  299. }.bind(this));
  300. },
  301. //创建/加入/解散 失败信息
  302. OnQueryFailed: function (FailedRes) {
  303. g_Lobby.ShowTips(FailStr[FailedRes.byRes]);
  304. },
  305. _filterTable: function () {
  306. for (var i in this._tableMap) {
  307. let t = this._tableMap[i];
  308. t.item.active = this._filter(t.data[0]);
  309. }
  310. this._updateTableIndex();
  311. this._vTableList.RefushList();
  312. },
  313. //按游戏类型显示列表
  314. OnClick_ShowRoomKind: function (Tag, KindID) {
  315. if (!this._autoClick) cc.gSoundRes.PlaySound('Button');
  316. this._autoClick = false;
  317. this.m_RoomKind = KindID;
  318. this._markTagAll.isChecked = true;
  319. this.m_Tag = 0;
  320. this._filterTable();
  321. this._updateMark();
  322. },
  323. //根据标签显示房间
  324. OnTagClick: function (_, Tag) {
  325. if (!this._autoClick) cc.gSoundRes.PlaySound('Button');
  326. this.m_Tag = Tag;
  327. this._filterTable();
  328. },
  329. OnShowQuickJoin: function () {
  330. cc.gSoundRes.PlaySound('Button');
  331. this.ShowPrefabDLG('ClubQuickJoin', this.m_Hook.node, function (Js) {
  332. Js.onSetRoomInfo(this.m_RoomInfoMap);
  333. }.bind(this));
  334. },
  335. ModifyRoomInfor: function (Res) {
  336. if (this._tableMap[Res.dwRoomID]) {
  337. this._tableMap[Res.dwRoomID].js.UpdateRoomInfor(Res);
  338. let bUpdateTable = false;
  339. let roomInfo = this._tableMap[Res.dwRoomID].data[0];
  340. if (roomInfo.szTag != Res.szTag) {
  341. if (this._markMap[roomInfo.szTag]) {
  342. bUpdateTable = this._deleteMark(roomInfo.szTag,roomInfo.wKindID);
  343. }
  344. }
  345. if (bUpdateTable) this._filterTable();
  346. roomInfo.llSitScore = Res.llSitScore; //参与分
  347. roomInfo.llStandScore = Res.llStandScore; //淘汰分
  348. roomInfo.dwBigRevRules = Res.dwBigRevRules; //大局表情规则
  349. roomInfo.dwBigMinScore = Res.dwBigMinScore; //大局表情起曾分
  350. roomInfo.dwBigCnt = Res.dwBigCnt; //大局百分比或固定数量
  351. roomInfo.dwSmallRevRules = Res.dwSmallRevRules; //小局表情规则
  352. roomInfo.dwSmallMinScore = Res.dwSmallMinScore; //小局表情起曾分
  353. roomInfo.dwSmallCnt = Res.dwSmallCnt; //小局百分比或固定数量
  354. roomInfo.cbReturnType = Res.cbReturnType; //反水类型
  355. roomInfo.bNegativeScore = Res.bNegativeScore; //反水类型
  356. roomInfo.dwMagnification = Res.dwMagnification; //倍率
  357. roomInfo.szTag = Res.szTag; //标签
  358. if(Res.szTag!=''){
  359. this._insertMark(roomInfo);
  360. }
  361. }
  362. },
  363. OnSwitchTableBG: function (index) {
  364. this._vTableList.ForEachCtrl(function (Js) {
  365. Js.OnSwitchTableBG(index);
  366. })
  367. this.onSwitchCreateRoomBG(index);
  368. },
  369. onSwitchCreateRoomBG: function (index) {
  370. if (index == null) index = window.g_Setting[window.SetKey_CLUB_TABLE_COLOR];
  371. cc.gPreLoader.LoadRes(`Image_ClubDLG_Table${index}4`, 'Club', function (res) {
  372. this.$('view/content/BtCreateRoom/BGTable@Sprite').spriteFrame = res;
  373. }.bind(this));
  374. },
  375. });