SelectGameMatch.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. var SelGame = window.clientName + '_C_G'
  2. const LobbyListInfoUtil = require('./utils/LobbyListInfoUtil');
  3. cc.Class({
  4. extends: cc.BaseClass,
  5. properties: {
  6. m_ldiamond: cc.Label,
  7. m_personT: [cc.Toggle],
  8. //开房间按钮
  9. createRoomBtn: {
  10. default: null,
  11. type: cc.Button,
  12. displayName: '创建房间按钮'
  13. },
  14. //加入房间按钮
  15. inputRoomBtn: {
  16. default: null,
  17. type: cc.Button,
  18. displayName: '输入房间号按钮'
  19. },
  20. },
  21. ctor: function () {
  22. this.m_RoomType = 0;// 0普通 1俱乐部
  23. this.m_personIndex = 1;
  24. this.m_playMethod = 0;
  25. //房间列表
  26. this.m_AllRoomList = [];
  27. // 两人房且是北部玩法房间列表
  28. this.twoPlayerAndNorthPlayRoomList = [];
  29. // 两人房且是南部玩法房间列表
  30. this.twoPlayerAndSouthPlayRoomList = [];
  31. // 四人房且是北部玩法房间列表
  32. this.fourPlayerAndNorthPlayRoomList = [];
  33. // 四人房且是南部玩法房间列表
  34. this.fourPlayerAndSouthPlayRoomList = [];
  35. },
  36. onLoad: function () {
  37. this._Sub = [];
  38. this._Sub.push(this.$('NewNode/Sub1'));
  39. // this._Sub.push(this.$('NewNode/Sub2'));
  40. // this._Sub.push(this.$('NewNode/Sub3'));
  41. this.updateDiamond()
  42. this.m_personIndex = cc.sys.localStorage.getItem("personIndex", 1);
  43. if (this.m_personIndex == null || this.m_personIndex == undefined) {
  44. this.m_personIndex = 1;
  45. }
  46. if (this.m_personT && this.m_personT.length > this.m_personIndex && this.m_personT[this.m_personIndex]) {
  47. this.m_personT[this.m_personIndex].isChecked = true;
  48. } else {
  49. // 如果索引无效,使用默认索引 0
  50. if (this.m_personT && this.m_personT.length > 0 && this.m_personT[0]) {
  51. this.m_personT[0].isChecked = true;
  52. this.m_personIndex = 0;
  53. }
  54. }
  55. this.initListCtrl();
  56. setTimeout(() => {
  57. //默认展示四人且是北部玩法房间列表
  58. this.showFourPlayerAndNorthPlayRoomList()
  59. }, 4000);
  60. },
  61. // 初始化列表控制器
  62. initListCtrl: function () {
  63. if (!this.m_ListCtrl) {
  64. this.m_ListCtrl = this.$('@CustomListCtrl');
  65. if (this.m_ListCtrl) {
  66. this.m_ListCtrl.InitList(0, 'roomListItem', this);
  67. }
  68. }
  69. },
  70. // 显示界面
  71. OnShowView: function () {
  72. if (this.m_FirstCtrl == null) {
  73. this.m_FirstCtrl = this.$('LeftBG/Layout/T0@Toggle');
  74. this.m_FirstCtrl.isChecked = false;
  75. this.m_FirstCtrl.check();
  76. }
  77. return
  78. },
  79. // 设置房间类型
  80. OnSetRoomType: function (type) {
  81. this.m_RoomType = type;
  82. this.FilterGame(type);
  83. },
  84. FilterGame: function (type) {
  85. // this.$('NewNode/Sub2/view/content/63500').active = type>0;
  86. },
  87. OnTogClick: function (tag, data) {
  88. // console.log('data:'+data);
  89. // for(let i =0;i<3;i++){
  90. // this._Sub[i].active = false;
  91. // }
  92. // this._Sub[data].active = true;
  93. },
  94. // 点击玩法
  95. onClickPlayMethod: function (data, tag) {
  96. this.initListCtrl();
  97. this.m_AllRoomList = window.currentLobbyList
  98. if (this.m_AllRoomList && this.m_AllRoomList.ListInfo && this.m_AllRoomList.ListInfo.length > 0) {
  99. this.twoPlayerAndNorthPlayRoomList = LobbyListInfoUtil.getTwoPlayerAndNorthPlayRoomList(this.m_AllRoomList.ListInfo);//两人北部玩法房间列表
  100. this.twoPlayerAndSouthPlayRoomList = LobbyListInfoUtil.getTwoPlayerAndSouthPlayRoomList(this.m_AllRoomList.ListInfo);//两人南部玩法房间列表
  101. this.fourPlayerAndNorthPlayRoomList = LobbyListInfoUtil.getFourPlayerAndNorthPlayRoomList(this.m_AllRoomList.ListInfo);//四人北部玩法房间列表
  102. this.fourPlayerAndSouthPlayRoomList = LobbyListInfoUtil.getFourPlayerAndSouthPlayRoomList(this.m_AllRoomList.ListInfo);//四人南部玩法房间列表
  103. }
  104. if (tag == 0) {//北部玩法
  105. if (this.m_personIndex == 0) {//四人且是北部玩法
  106. this.m_ListCtrl.RemoveListPre(0)
  107. this.showFourPlayerAndNorthPlayRoomList()
  108. } else {//两人且是北部玩法
  109. this.m_ListCtrl.RemoveListPre(0)
  110. this.showTwoPlayerAndNorthPlayRoomList()
  111. }
  112. } else {//南部玩法
  113. // this.m_ListCtrl.RemoveListPre(0)
  114. if (this.m_personIndex == 0) {//四人且是南部玩法
  115. this.m_ListCtrl.RemoveListPre(0)
  116. this.showFourPlayerAndSouthPlayRoomList()
  117. } else {//两人且是南部玩法
  118. this.m_ListCtrl.RemoveListPre(0)
  119. this.showTwoPlayerAndSouthPlayRoomList()
  120. }
  121. }
  122. console.log(tag == 0 ? "点击北部玩法" : "点击南部玩法")
  123. this.m_playMethod = tag;
  124. cc.sys.localStorage.setItem("playMethodIndex", this.m_playMethod)
  125. },
  126. // 点击玩家人数
  127. OnClickButtonPerson: function (data, tag) {
  128. // 确保列表控件已初始化
  129. this.initListCtrl();
  130. this.m_AllRoomList = window.currentLobbyList
  131. if (this.m_AllRoomList && this.m_AllRoomList.ListInfo && this.m_AllRoomList.ListInfo.length > 0) {
  132. this.twoPlayerAndNorthPlayRoomList = LobbyListInfoUtil.getTwoPlayerAndNorthPlayRoomList(this.m_AllRoomList.ListInfo);//两人北部玩法房间列表
  133. this.twoPlayerAndSouthPlayRoomList = LobbyListInfoUtil.getTwoPlayerAndSouthPlayRoomList(this.m_AllRoomList.ListInfo);//两人南部玩法房间列表
  134. this.fourPlayerAndNorthPlayRoomList = LobbyListInfoUtil.getFourPlayerAndNorthPlayRoomList(this.m_AllRoomList.ListInfo);//四人北部玩法房间列表
  135. this.fourPlayerAndSouthPlayRoomList = LobbyListInfoUtil.getFourPlayerAndSouthPlayRoomList(this.m_AllRoomList.ListInfo);//四人南部玩法房间列表
  136. }
  137. //0 ===>四人 1 ===>两人
  138. console.log(tag == 0 ? "点击四人房间" : "点击两人房间")
  139. if (tag == 0) {//四人房间
  140. // this.m_ListCtrl.RemoveListPre(0)
  141. if (this.m_playMethod == 0) {//四人且是北部玩法
  142. this.m_ListCtrl.RemoveListPre(0)
  143. this.showFourPlayerAndNorthPlayRoomList()
  144. } else {//四人且是南部玩法
  145. this.m_ListCtrl.RemoveListPre(0)
  146. this.showFourPlayerAndSouthPlayRoomList()
  147. }
  148. } else {//两人
  149. //展示两人房间列表之前,要先清空现有的所有列表
  150. this.m_ListCtrl.RemoveListPre(0)
  151. if (this.m_playMethod == 0) {//两人且是北部玩法
  152. this.showTwoPlayerAndNorthPlayRoomList()
  153. } else {//两人且是南部玩法
  154. this.showTwoPlayerAndSouthPlayRoomList()
  155. }
  156. }
  157. console.log("点击Person", tag)
  158. this.m_personIndex = tag;
  159. cc.sys.localStorage.setItem("personIndex", this.m_personIndex)
  160. },
  161. //展示两人且是北部玩法列表
  162. showTwoPlayerAndNorthPlayRoomList: function () {
  163. //展示北部玩法列表
  164. // this.m_ListCtrl.InitList(0, 'roomListItem', this);
  165. console.log("两人且是北部玩法房间列表", this.twoPlayerAndNorthPlayRoomList)
  166. for (var i = 0; i < this.twoPlayerAndNorthPlayRoomList.length; i++) {
  167. this.m_ListCtrl.InsertListInfo(0, this.twoPlayerAndNorthPlayRoomList[i]);
  168. }
  169. },
  170. //展示两人且是南部玩法列表
  171. showTwoPlayerAndSouthPlayRoomList: function () {
  172. //展示南部玩法列表
  173. // this.m_ListCtrl.InitList(0, 'roomListItem', this);
  174. for (var i = 0; i < this.twoPlayerAndSouthPlayRoomList.length; i++) {
  175. this.m_ListCtrl.InsertListInfo(0, this.twoPlayerAndSouthPlayRoomList[i]);
  176. }
  177. },
  178. //展示四人且是北部玩法列表
  179. showFourPlayerAndNorthPlayRoomList: function () {
  180. //展示北部玩法列表
  181. // this.m_ListCtrl.InitList(0, 'roomListItem', this);
  182. console.log("四人且是北部玩法房间列表", this.fourPlayerAndNorthPlayRoomList)
  183. for (var i = 0; i < this.fourPlayerAndNorthPlayRoomList.length; i++) {
  184. this.m_ListCtrl.InsertListInfo(0, this.fourPlayerAndNorthPlayRoomList[i]);
  185. }
  186. },
  187. //展示四人且是南部玩法列表
  188. showFourPlayerAndSouthPlayRoomList: function () {
  189. //展示南部玩法列表
  190. // this.m_ListCtrl.InitList(0, 'roomListItem', this);
  191. console.log("四人且是南部玩法房间列表", this.fourPlayerAndSouthPlayRoomList)
  192. for (var i = 0; i < this.fourPlayerAndSouthPlayRoomList.length; i++) {
  193. this.m_ListCtrl.InsertListInfo(0, this.fourPlayerAndSouthPlayRoomList[i]);
  194. }
  195. },
  196. // 进入比赛房间
  197. OnClickButtonMatch: function (data, tag) {
  198. console.log("点击data", tag)
  199. this.m_Hook.matchRoom(this.m_personIndex, tag, this.m_playMethod)
  200. // this.ShowPrefabDLG('CreateRoom2',null,(Js)=>{
  201. // Js.OnSetGameID(tag.currentTarget.name);
  202. // Js.OnClubAutoView(this.m_RoomType);
  203. // });
  204. },
  205. //创建房间
  206. OnCreateRoom: function (KindID, dwRules, dwServerRules, Name) {
  207. this.m_Hook.OnCreateRoom(KindID, dwRules, dwServerRules, Name, 0, 0);
  208. this.HideView();
  209. },
  210. //更新钻石
  211. updateDiamond: function () {
  212. let diamond = g_GlobalUserInfo.GetGlobalUserData().llUserIngot;
  213. this.m_ldiamond.string = diamond;
  214. },
  215. // 创建房间按钮点击事件
  216. OnBtCreateRoom: function () {
  217. cc.gSoundRes.PlaySound('Button');
  218. this.ShowPrefabDLG('SelectGame', this.m_DlgNode, function (Js) {
  219. Js.OnSetRoomType(0);
  220. }.bind(this));
  221. },
  222. OnBtJoinRoom: function () {
  223. cc.gSoundRes.PlaySound('Button');
  224. this.ShowPrefabDLG('JoinRoom', this.m_DlgNode);
  225. },
  226. // 查询房间方法
  227. OnQueryRoom: function (roomID, clubID) {
  228. console.log("查询房间:", roomID, clubID);
  229. g_Lobby.OnQueryRoom(roomID, clubID)
  230. }
  231. });