ClubRoomPre.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. cc.Class({
  2. extends: cc.BaseClass,
  3. properties: {
  4. m_LabGame: cc.Label,
  5. m_LabRules: cc.Label,
  6. m_LabRoom: cc.Label,
  7. m_LabProgress: cc.Label,
  8. m_LabTime: cc.Label,
  9. m_ChairNode: cc.Node,
  10. m_BtInfoNode: cc.Node,
  11. },
  12. ctor: function () {
  13. this.m_ChairCtrl = new Array();
  14. this.m_CurCount = 0;
  15. this.m_TotalCount = 0;
  16. this.m_RoomLabInfor = {};
  17. },
  18. Init: function () {
  19. this.InitPre();
  20. },
  21. SetData: function (data) {
  22. this.SetPreInfo(data);
  23. },
  24. SetIndex: function (index) {
  25. this.$('InfoNode/LbIndex@Label').string = pad(index, 2);
  26. },
  27. InitPre: function () {
  28. this.m_BtInfoNode.active = false;
  29. for (var i = 0; i < this.m_ChairNode.childrenCount; i++) {
  30. if (this.m_ChairCtrl[i] == null) this.m_ChairCtrl[i] = this.$(i + '@UserCtrl', this.m_ChairNode);
  31. this.m_ChairCtrl[i].SetUserByID(0);
  32. this.m_ChairCtrl[i].node.active = false;
  33. }
  34. },
  35. SetPreInfo: function (ParaArr) {
  36. this.SetRoomInfo(ParaArr[0], ParaArr[1]);
  37. },
  38. SetRoomInfo: function (RoomInfo, RoomIndex) {
  39. // ServerRoomInfo
  40. //console.log(RoomInfo)
  41. this.m_GameDef = new window['CMD_GAME_' + RoomInfo.wKindID]();
  42. this.m_RoomLabInfor = {};
  43. this.m_RoomInfo = RoomInfo;
  44. this.m_LabGame.string = window.GameList[RoomInfo.wKindID];
  45. this.m_CurCount = RoomInfo.byPlayerCnt;
  46. this.m_PlayerCnt = this.m_GameDef.GetPlayerCount(RoomInfo.dwServerRules, RoomInfo.dwRules);
  47. this.m_LabRules.string = this.m_GameDef.GetRulesStr(RoomInfo.dwServerRules, RoomInfo.dwRules);
  48. this.m_LabProgress.string = this.m_GameDef.GetProgress(RoomInfo.wProgress, RoomInfo.dwServerRules, RoomInfo.dwRules);
  49. this.m_LabRoom.string = RoomInfo.dwRoomID;
  50. this.m_LabTime.string = Time2Str(RoomInfo.dwCreateTime);
  51. this.m_RoomLabInfor.GameName = this.m_LabGame.string;
  52. if (RoomInfo.wKindID == 21062) this.m_RoomLabInfor.GameName = this.m_GameDef.GetGameMode(RoomInfo.dwServerRules, RoomInfo.dwRules);
  53. this.m_RoomLabInfor.RoomNum = this.m_LabRoom.string;
  54. this.m_RoomLabInfor.GameRule = this.m_LabRules.string;
  55. this.m_RoomLabInfor.RoomRule = this.GetRoomRuleStr(RoomInfo);
  56. //GameDef.GetBaseScoreStr(ServerRules, GameRules);
  57. var cellScore = 3;
  58. if (this.m_GameDef.GetBaseScoreStr) {
  59. cellScore = this.m_GameDef.GetBaseScoreStr(RoomInfo.dwServerRules, RoomInfo.dwRules);
  60. }
  61. this.$('InfoNode/LbScore@Label').string = "底分 " + cellScore;
  62. this.$('InfoNode/LbPlayer@Label').string = "" + RoomInfo.byPlayerCnt + '/' + this.m_PlayerCnt;
  63. if (RoomInfo.byPlayerCnt == this.m_PlayerCnt) this.$('InfoNode/LbPlayer@Label').string = '客滿';
  64. //this.$('InfoNode/LbGame@Label').string = this.m_GameDef.GetGameCount(RoomInfo.dwServerRules,RoomInfo.dwRules);
  65. this.$('InfoNode/LbIndex@Label').string = pad(RoomIndex, 2);
  66. //this.$('InfoNode/LbState@Label').string = (RoomInfo.wProgress > 0?"游戏中":"等待中");
  67. //this.$('InfoNode/spWaiting').active = (RoomInfo.wProgress == 0);
  68. //this.$('InfoNode/spGameing').active = (RoomInfo.wProgress > 0);
  69. var strMode = '';
  70. if (this.m_GameDef.GetGameMode) {
  71. strMode = `${window.GameList[RoomInfo.wKindID]}(${this.m_GameDef.GetGameMode(RoomInfo.dwServerRules, RoomInfo.dwRules)})`;
  72. } else {
  73. strMode = window.GameList[RoomInfo.wKindID];
  74. }
  75. if (RoomInfo.wKindID == 21201 && (RoomInfo.dwRules[0] & this.m_GameDef.GAME_RULE_SP_15)) {
  76. strMode = "台灣北部麻將"
  77. }
  78. if (RoomInfo.wKindID == 21201 && (RoomInfo.dwRules[0] & this.m_GameDef.GAME_RULE_SP_16)) {
  79. strMode = "台灣南部麻將"
  80. }
  81. this.$('InfoNode/LbModel@Label').string = strMode;
  82. this.$('InfoNode/LbTag@Label').string = RoomInfo.szTag;
  83. //this.$('InfoNode/LbRoomID@Label').string = RoomInfo.dwRoomID;
  84. // for (var i in this.m_ChairCtrl) {
  85. // this.m_ChairCtrl[i].SetUserByID(0);
  86. // this.$('Layout/' + i + '/Nick@Label').string = '';
  87. // this.m_ChairCtrl[i].node.active = i < this.m_PlayerCnt;//this.m_GameDef.GetPlayerCount(RoomInfo.dwServerRules,RoomInfo.dwRules);
  88. // }
  89. this.UpdateRoomUser();
  90. this.OnSetRoomView();
  91. },
  92. OnSetRoomView: function () {
  93. var playCnt = this.m_PlayerCnt > 4 ? 4 : this.m_PlayerCnt;
  94. cc.gPreLoader.LoadRes(`Image_ClubDLG_Table${window.g_Setting[window.SetKey_CLUB_TABLE_COLOR]}${playCnt}`, 'Club', function (res) {
  95. this.$('BGTable@Sprite').spriteFrame = res;
  96. }.bind(this));
  97. if (this.m_PlayerCnt == 2) { //2人
  98. this.$('Layout/0').setPosition(-162, 2);
  99. this.$('Layout/1').setPosition(162, 2);
  100. } else if (this.m_PlayerCnt == 3) {
  101. this.$('Layout/0').setPosition(-162, 2);
  102. this.$('Layout/1').setPosition(0, -90);
  103. this.$('Layout/2').setPosition(162, 2);
  104. }
  105. else if (this.m_PlayerCnt == 4) {
  106. this.$('Layout/0').setPosition(-162, 2);
  107. this.$('Layout/1').setPosition(-70, -90);
  108. this.$('Layout/2').setPosition(70, -90);
  109. this.$('Layout/3').setPosition(162, 2);
  110. }
  111. else if (this.m_PlayerCnt == 5) {
  112. this.$('Layout/0').setPosition(-165, 40);
  113. this.$('Layout/1').setPosition(-127, -75);
  114. this.$('Layout/2').setPosition(0, -90);
  115. this.$('Layout/3').setPosition(127, -75);
  116. this.$('Layout/4').setPosition(165, 40);
  117. }
  118. else if (this.m_PlayerCnt == 6) { //6人
  119. this.$('Layout/0').setPosition(-165, 40);
  120. this.$('Layout/1').setPosition(-146, -61);
  121. this.$('Layout/2').setPosition(-45, -90);
  122. this.$('Layout/3').setPosition(45, -90);
  123. this.$('Layout/4').setPosition(146, -61);
  124. this.$('Layout/5').setPosition(165, 40);
  125. } else if (this.m_PlayerCnt == 7) { //7人
  126. this.$('Layout/0').setPosition(-143, 70);
  127. this.$('Layout/1').setPosition(-164, -15);
  128. this.$('Layout/2').setPosition(-112, -80);
  129. this.$('Layout/3').setPosition(0, -90);
  130. this.$('Layout/4').setPosition(112, -80);
  131. this.$('Layout/5').setPosition(164, -15);
  132. this.$('Layout/6').setPosition(143, 70);
  133. } else if (this.m_PlayerCnt <= 8) {//8人桌子样式
  134. this.$('Layout/0').setPosition(-138, 74);
  135. this.$('Layout/1').setPosition(-165, 2);
  136. this.$('Layout/2').setPosition(-130, -68);
  137. this.$('Layout/3').setPosition(-41, -90);
  138. this.$('Layout/4').setPosition(41, -90);
  139. this.$('Layout/5').setPosition(130, -68);
  140. this.$('Layout/6').setPosition(165, 2);
  141. this.$('Layout/7').setPosition(138, 74);
  142. } else if (this.m_PlayerCnt <= 10) {//10人桌子样式
  143. this.$('Layout/0').setPosition(-95, 91);
  144. this.$('Layout/1').setPosition(-155, 52);
  145. this.$('Layout/2').setPosition(-163, -20);
  146. this.$('Layout/3').setPosition(-120, -85);
  147. this.$('Layout/4').setPosition(-40, -91);
  148. this.$('Layout/5').setPosition(40, -91);
  149. this.$('Layout/6').setPosition(120, -85);
  150. this.$('Layout/7').setPosition(163, -20);
  151. this.$('Layout/8').setPosition(155, 52);
  152. this.$('Layout/9').setPosition(95, 91);
  153. }
  154. else if (this.m_PlayerCnt <= 12) {//10人桌子样式
  155. this.$('Layout/0').setPosition(-74, 90);
  156. this.$('Layout/1').setPosition(-137, 77);
  157. this.$('Layout/2').setPosition(-167, 14);
  158. this.$('Layout/3').setPosition(-155, -50);
  159. this.$('Layout/4').setPosition(-97, -88);
  160. this.$('Layout/5').setPosition(-31, -94);
  161. this.$('Layout/6').setPosition(31, -94);
  162. this.$('Layout/7').setPosition(97, -88);
  163. this.$('Layout/8').setPosition(155, -50);
  164. this.$('Layout/9').setPosition(167, 14);
  165. this.$('Layout/10').setPosition(137, 77);
  166. this.$('Layout/11').setPosition(74, 90);
  167. }
  168. },
  169. UpdateRoomUser: function () {
  170. var userList = this.m_Hook.m_RoomInfoMap.UserList;
  171. if (userList == null) return;
  172. for (var i in userList.UserInfo) {
  173. if (userList.UserInfo[i] == null) continue;
  174. var userInfo = userList.UserInfo[i];
  175. if (this.m_RoomInfo.dwRoomID != userInfo.dwRoomID) continue;
  176. var chairID = userInfo.wChairID;
  177. if (this.m_PlayerCnt == 2) {
  178. if (chairID > 1) chairID = 1;
  179. }
  180. this.m_ChairCtrl[chairID].SetUserByID(userInfo.dwUserID);
  181. this.m_ChairCtrl[chairID].SetShowFullName(false, 3);
  182. this.m_ChairCtrl[chairID].node.active = true;
  183. }
  184. },
  185. UpdateUserState: function (userInfo) {
  186. if (userInfo.dwRoomID != this.m_RoomInfo.dwRoomID) return;
  187. if (!this.m_Hook.m_RoomInfoMap.UserList) return;
  188. this.m_UserList = this.m_Hook.m_RoomInfoMap.UserList;
  189. if (this.m_UserList.UserInfo[`${userInfo.dwUserID}`]) {
  190. if (userInfo.cbUserStatus <= US_FREE) {//起立
  191. var chairID = this.m_UserList.UserInfo[`${userInfo.dwUserID}`].wChairID;
  192. if (this.m_PlayerCnt == 2) {
  193. if (chairID > 1) chairID = 1;
  194. }
  195. this.m_ChairCtrl[chairID].SetUserByID(0);
  196. this.m_CurCount--;
  197. this.m_ChairCtrl[chairID].node.active = false;
  198. }
  199. } else {
  200. if (userInfo.cbUserStatus != US_LOOKON && userInfo.cbUserStatus > US_FREE) {//区分旁观
  201. var chairID = userInfo.wChairID;
  202. if (this.m_PlayerCnt == 2) {
  203. if (chairID > 1) chairID = 1;
  204. }
  205. this.m_ChairCtrl[chairID].SetUserByID(userInfo.dwUserID);
  206. this.m_ChairCtrl[chairID].SetShowFullName(false, 3);
  207. this.m_CurCount++;
  208. this.m_ChairCtrl[chairID].node.active = true;
  209. }
  210. }
  211. this.$('InfoNode/LbPlayer@Label').string = " " + this.m_CurCount + '/' + this.m_PlayerCnt;
  212. if (this.m_CurCount == this.m_PlayerCnt) this.$('InfoNode/LbPlayer@Label').string = '客满';
  213. },
  214. UpdateUser: function (userInfo) {
  215. if (userInfo.dwRoomID != this.m_RoomInfo.dwRoomID) return;
  216. this['m_JsClubGameRuleSet'] && this['m_JsClubGameRuleSet'].ResetUserItem();
  217. },
  218. OnBtShowInfo: function () {
  219. //this.m_BtInfoNode.active = !this.m_BtInfoNode.active;
  220. this.ShowPrefabDLG('ClubGameRuleSet', this.m_Hook.m_Hook.node, function (Js) {
  221. Js.OnSetInof(this.m_RoomLabInfor);
  222. }.bind(this));
  223. },
  224. OnBtClickEnter: function () {
  225. this.m_Hook.OnEnterRoom(this.m_RoomInfo.dwRoomID);
  226. },
  227. OnBtClickShare: function () {
  228. this.ShowPrefabDLG("SharePre", this.m_Hook.node)
  229. },
  230. //分享信息
  231. GetShareInfo: function () {
  232. var ShareInfo = new Object();
  233. ShareInfo.title = '【' + this.m_LabGame.string + '】 房間號:' + this.m_LabRoom.string;
  234. ShareInfo.desc = this.m_LabRules.string + '【同盟會ID:' + this.m_RoomInfo.dwClubID + "】";
  235. ShareInfo.link = cc.share.MakeLink_InviteRoom(this.m_RoomInfo.dwRoomID, this.m_RoomInfo.dwClubID);
  236. return ShareInfo;
  237. },
  238. OnBtClickDiss: function (view) {
  239. if (this.m_RoomInfo.wProgress > 0 && g_ShowClubInfo.cbClubLevel < CLUB_LEVEL_MANAGER) {
  240. this.m_Hook.ShowTips("遊戲已經開始!");
  241. return
  242. }
  243. this.m_Hook.OnDissolveRoom(this.m_RoomInfo.dwRoomID, this.m_RoomInfo.dwCreaterID, g_ShowClubInfo.cbClubLevel == CLUB_LEVEL_OWNER ? 1 : 0, view);
  244. },
  245. GetRoomRuleStr: function (roomInfo) {
  246. var strRule = '';
  247. strRule += '參與分:' + Score2Str(roomInfo.llSitScore) + ' 淘汰分:' + Score2Str(roomInfo.llStandScore) + ' 大局贈送:';
  248. if (roomInfo.dwBigRevRules & CLUB_GAME_RULE_1) {
  249. strRule += '大赢家';
  250. } else if (roomInfo.dwBigRevRules & CLUB_GAME_RULE_2) {
  251. strRule += '赢家';
  252. } else {
  253. strRule += '所有人';
  254. }
  255. strRule += ' ';
  256. if (roomInfo.dwBigRevRules & CLUB_GAME_RULE_4) {
  257. strRule += '固定贈送';
  258. strRule += ' 起贈分:' + Score2Str(roomInfo.dwBigMinScore) + ' 贈送分值:' + Score2Str(roomInfo.dwBigCnt) + ' 小局贈送:';
  259. } else {
  260. strRule += '比例贈送';
  261. strRule += ' 起贈分:' + Score2Str(roomInfo.dwBigMinScore) + ' 贈送分值:' + roomInfo.dwBigCnt + ' 小局贈送:';
  262. }
  263. //strRule+=' 起赠分:'+Score2Str(roomInfo.dwBigMinScore)+' 赠送分值:'+Score2Str(roomInfo.dwBigCnt)+' 小局赠送:';
  264. if (roomInfo.dwSmallRevRules & CLUB_GAME_RULE_1) {
  265. strRule += '大赢家';
  266. } else if (roomInfo.dwSmallRevRules & CLUB_GAME_RULE_2) {
  267. strRule += '赢家';
  268. } else {
  269. strRule += '所有人';
  270. }
  271. strRule += ' ';
  272. if (roomInfo.dwSmallRevRules & CLUB_GAME_RULE_4) {
  273. strRule += '固定贈送';
  274. strRule += ' 起贈分:' + Score2Str(roomInfo.dwSmallMinScore) + ' 贈送分值:' + Score2Str(roomInfo.dwSmallCnt) + ' 模式:';
  275. } else {
  276. strRule += '比例贈送';
  277. strRule += ' 起贈分:' + Score2Str(roomInfo.dwSmallMinScore) + ' 贈送分值:' + roomInfo.dwSmallCnt + ' 模式:';
  278. }
  279. //strRule+=' 起赠分:'+Score2Str(roomInfo.dwSmallMinScore)+' 赠送分值:'+Score2Str(roomInfo.dwSmallCnt)+' 模式:';
  280. if (roomInfo.cbReturnType == 1) {
  281. strRule += '平攤模式';
  282. } else if (roomInfo.cbReturnType == 2) {
  283. strRule += '赢家模式';
  284. } else {
  285. strRule += '輸贏平攤模式';
  286. }
  287. strRule += ' ';
  288. if (roomInfo.bNegativeScore) {
  289. strRule += '可負分';
  290. } else {
  291. strRule += '不可負分';
  292. }
  293. strRule += ' ';
  294. strRule += '倍率:' + roomInfo.dwMagnification;
  295. strRule += '標籤:' + roomInfo.szTag;
  296. return strRule;
  297. },
  298. UpdateRoomInfor: function (Res) {
  299. this.m_RoomLabInfor.RoomRule = this.GetRoomRuleStr(Res);
  300. this.$('InfoNode/LbTag@Label').string = Res.szTag;
  301. },
  302. OnSwitchTableBG: function (index) {
  303. var playCnt = this.m_PlayerCnt > 4 ? 4 : this.m_PlayerCnt;
  304. cc.gPreLoader.LoadRes(`Image_ClubDLG_Table${index}${playCnt}`, 'Club', function (res) {
  305. this.$('BGTable@Sprite').spriteFrame = res;
  306. }.bind(this));
  307. }
  308. // update (dt) {},
  309. });