SubRoom_21201.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. var RulesKey = window.QPName + '_Rules_';
  2. var RulesKey2 = window.QPName + '_S_Rules_';
  3. cc.Class({
  4. //extends: cc.BaseClass,
  5. extends: cc.SubRoomRules,
  6. properties: {
  7. // m_LabBaseScore: cc.Label,
  8. // m_LabRevenue: cc.Label,
  9. // m_ClubNode: cc.Node,
  10. // m_EbBaseScore: cc.EditBox,
  11. // m_BtNNSet: cc.Button, //牛牛设置按钮
  12. // m_togSpecialType: [cc.Toggle], //牛牛特殊牌型
  13. },
  14. //1000-1031 服务器规则 1050-1099 对应规则
  15. //1000 =>AA付 1050 =>房主付
  16. //1001 =>代开 1051 =>房主进入
  17. //1002 =>积分房间 1003 =>金币房间 1052 =>练习房间
  18. ctor: function () {
  19. this.m_bNeedUpdate = false;
  20. this.m_bFirstShow = true;
  21. // //对立规则 非计算索引需 大于 32
  22. // this.m_CheckMap = new Object();
  23. // this.m_CheckMap[10011] = new Array(
  24. // // [12,33],
  25. // );
  26. // this.m_CheckMap[60013] = new Array(
  27. // [6, 33], // 3息1囤 3息1分 / 1息1分
  28. // [7, 34], // 底牌 留底19张 / 留底39张
  29. // );
  30. // this.m_CheckMap2 = new Array(
  31. // [1000, 1050],
  32. // [1001, 1051],
  33. // [1002, 1052],
  34. // [1003, 1052],
  35. // );
  36. // this.m_BaseScore = 1;
  37. // this.m_SitScore = 100;
  38. // this.m_Revenue = 0;
  39. },
  40. //添加对立规则数组索引
  41. CheckToggle(ArrIndex, JS) {
  42. // for (var i in this.m_CheckMap) {
  43. // for (var j in this.m_CheckMap[i]) {
  44. // if (JS.node.name == this.m_CheckMap[i][j][1]) this.m_CheckMap[i][j][2] = ArrIndex;
  45. // }
  46. // }
  47. // for (var i in this.m_CheckMap2) {
  48. // if (JS.node.name == this.m_CheckMap2[i][1]) this.m_CheckMap2[i][2] = ArrIndex;
  49. // }
  50. },
  51. OnShowView: function () {
  52. // //初始化数据
  53. // if (this.m_togArr == null) {
  54. // this.m_togArr = this.node.getComponentsInChildren(cc.Toggle);
  55. // for (var i in this.m_togArr) {
  56. // this.CheckToggle(i, this.m_togArr[i]);
  57. // }
  58. // }
  59. this.m_bNeedUpdate = true;
  60. // this.m_bFirstShow = false;
  61. // var rules = JSON.parse(cc.sys.localStorage.getItem(RulesKey + this.m_KindID));
  62. // var rules2 = cc.sys.localStorage.getItem(RulesKey2 + this.m_KindID);
  63. // if (rules != null) {
  64. // for (var i in this.m_togArr) {
  65. // var rulesIndex = parseInt(this.m_togArr[i].node.name);
  66. // var rIndex = parseInt(rulesIndex / 100);
  67. // var rValue = parseInt(rulesIndex % 100);
  68. // if (rIndex >= 3) continue; //3底分 4抽水
  69. // if (rValue < 32) {
  70. // //游戏规则
  71. // if (rules[rIndex] & (1 << rValue)) {
  72. // this.m_togArr[i].check();
  73. // } else {
  74. // if (this.m_togArr[i].toggleGroup == null || this.m_togArr[i].toggleGroup.allowSwitchOff) { //复选框
  75. // this.m_togArr[i].isChecked = false;
  76. // } else if (this.m_CheckMap[this.m_KindID] != null) { //对立规则勾选
  77. // for (var j in this.m_CheckMap[this.m_KindID]) {
  78. // if (this.m_CheckMap[this.m_KindID][j][0] == rValue) {
  79. // this.m_togArr[this.m_CheckMap[this.m_KindID][j][2]].check();
  80. // }
  81. // }
  82. // }
  83. // }
  84. // }
  85. // }
  86. // }
  87. // if (rules == null) rules = [0, 0, 0, 0, 0];
  88. // //2底分 3入场分 4抽水
  89. // this.m_BaseScore = rules[2];
  90. // if (this.m_BaseScore == null || this.m_BaseScore == 0) this.m_BaseScore = 1;
  91. // if (this.m_EbBaseScore != null) this.m_EbBaseScore.string = this.m_BaseScore;
  92. // this.m_SitScore = rules[3];
  93. // if (this.m_SitScore == null || this.m_SitScore == 0) this.m_SitScore = 100;
  94. // this.m_Revenue = rules[4];
  95. // if (this.m_Revenue == null) this.m_Revenue = 0;
  96. // this.UpdateBaseScore();
  97. // this.UpdateRevenue();
  98. return;
  99. var rules = cc.sys.localStorage.getItem(RulesKey + this.m_KindID);
  100. var rules2 = cc.sys.localStorage.getItem(RulesKey2 + this.m_KindID);
  101. //还原选项
  102. for (var i in this.m_togArr) {
  103. if (rules == null || !this.m_bFirstShow) break;
  104. var rulesIndex = parseInt(this.m_togArr[i].node.name);
  105. if (rulesIndex < 32) {
  106. //游戏规则
  107. if (rules & (1 << rulesIndex)) {
  108. this.m_togArr[i].check();
  109. } else {
  110. if (this.m_togArr[i].toggleGroup == null || this.m_togArr[i].toggleGroup.allowSwitchOff) { //复选框
  111. this.m_togArr[i].isChecked = false;
  112. } else if (this.m_CheckMap[this.m_KindID] != null) { //对立规则勾选
  113. for (var j in this.m_CheckMap[this.m_KindID]) {
  114. if (this.m_CheckMap[this.m_KindID][j][0] == rulesIndex) {
  115. this.m_togArr[this.m_CheckMap[this.m_KindID][j][2]].check();
  116. }
  117. }
  118. }
  119. }
  120. } else if (rulesIndex >= 100 && rulesIndex < 150) {
  121. //服务器规则
  122. if (rules2 & (1 << (rulesIndex - 100))) {
  123. this.m_togArr[i].check();
  124. } else {
  125. if (this.m_togArr[i].toggleGroup == null || this.m_togArr[i].toggleGroup.allowSwitchOff) { //复选框
  126. this.m_togArr[i].isChecked = false;
  127. } else { //对立规则勾选
  128. for (var j in this.m_CheckMap2) {
  129. if (this.m_CheckMap2[j][0] == rulesIndex) {
  130. this.m_togArr[this.m_CheckMap2[j][2]].check();
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }
  137. this.m_bNeedUpdate = true;
  138. this.m_bFirstShow = false;
  139. },
  140. OnHideView: function () {
  141. this.getRulesEx();
  142. this.getServerRules();
  143. this.node.active = false;
  144. },
  145. SetClubView: function (RoomType) {
  146. //this.$('ClubNode').active = RoomType == 1;
  147. if (this.m_ClubNode != null) this.m_ClubNode.active = (RoomType != 0);
  148. this.m_bNeedUpdate = true;
  149. },
  150. OnToggleClick: function (Tag, Data) {
  151. this.m_bNeedUpdate = true;
  152. },
  153. // getRulesEx: function (bLog) {
  154. // var rules = [0, 0, 0, 0, 0];
  155. // for (var i in this.m_togArr) {
  156. // if (this.m_togArr[i].node.active && this.m_togArr[i].isChecked) {
  157. // var rulesIndex = parseInt(this.m_togArr[i].node.name);
  158. // if (bLog && window.LOG_NET_DATA) console.log(rulesIndex + ' ==> ' + this.$('Label@Label', this.m_togArr[i].node).string);
  159. // // if (rulesIndex >= 1000) {
  160. // // if (rulesIndex <= 1031) rules[5] += 1 << (rulesIndex - 1000);
  161. // // } else
  162. // {
  163. // var rIndex = parseInt(rulesIndex / 100);
  164. // var rValue = parseInt(rulesIndex % 100);
  165. // if (rIndex >= 3) continue; //3底分 4抽水
  166. // if (rValue <= 31) rules[rIndex] += 1 << rValue;
  167. // }
  168. // }
  169. // }
  170. // if (this.m_EbBaseScore != null) {
  171. // rules[2] = parseInt(this.m_EbBaseScore.string);
  172. // } else {
  173. // rules[2] = 1;
  174. // }
  175. // rules[3] = this.m_SitScore;
  176. // rules[4] = this.m_Revenue;
  177. // // if(this.$('ClubNode').active){
  178. // // rules[2] = parseInt(this.$('ClubNode/EnterGame/116/Background/BG/EditBox@EditBox').string);
  179. // // rules[3] = parseInt(this.$('ClubNode/EnterGame/117/Background/BG/EditBox@EditBox').string);
  180. // // rules[4] = parseInt(this.$('ClubNode/EnterGame/118/Background/BG/EditBox@EditBox').string);
  181. // // if(rules[2] > 0) {} else {rules[2] = 0};
  182. // // if(rules[3] > 0) {} else {rules[3] = 0};
  183. // // if(rules[4] > 0) {} else {rules[4] = 0};
  184. // // }
  185. // cc.sys.localStorage.setItem(RulesKey + this.m_KindID, JSON.stringify(rules));
  186. // return rules;
  187. // },
  188. // getRules: function (bLog) {
  189. // var rules = 0;
  190. // for (var i in this.m_togArr) {
  191. // if (this.m_togArr[i].node.active && this.m_togArr[i].isChecked) {
  192. // var rulesIndex = parseInt(this.m_togArr[i].node.name);
  193. // if (bLog && window.LOG_NET_DATA) console.log(rulesIndex + ' ==> ' + this.$('Label@Label', this.m_togArr[i].node).string);
  194. // if (rulesIndex <= 32) rules += 1 << rulesIndex;
  195. // }
  196. // }
  197. // cc.sys.localStorage.setItem(RulesKey + this.m_KindID, rules);
  198. // return rules;
  199. // },
  200. // getServerRules: function () {
  201. // var rules = 0;
  202. // for (var i in this.m_togArr) {
  203. // if (this.m_togArr[i].node.active && this.m_togArr[i].isChecked) {
  204. // var rulesIndex = parseInt(this.m_togArr[i].node.name);
  205. // if (rulesIndex < 1000 || rulesIndex >= 1050) continue;
  206. // rulesIndex -= 1000;
  207. // rules += 1 << rulesIndex;
  208. // }
  209. // }
  210. // cc.sys.localStorage.setItem(RulesKey2 + this.m_KindID, rules);
  211. // return rules;
  212. // },
  213. // update: function () {
  214. // if (this.m_bNeedUpdate) {
  215. // this.m_bNeedUpdate = false;
  216. // } else {
  217. // return;
  218. // }
  219. // for (var i in this.m_togArr) {
  220. // if (!this.m_togArr[i].node.active) continue;
  221. // var color = this.m_togArr[i].isChecked ? cc.color(182, 153, 95) : cc.color(143, 195, 203);
  222. // this.m_togArr[i].node.getChildByName('Label').color = color;
  223. // }
  224. // this.OnCheckHZMJ();
  225. // },
  226. OnUpdateCustomView:function()
  227. {
  228. this.GetPayWay();
  229. this.OnChecTWMJ();
  230. for (var i in this.m_togArr) {
  231. if (!this.m_togArr[i].node.active) continue;
  232. var color = this.m_togArr[i].isChecked ? cc.color(208,185,239) : cc.color(129,95,57);
  233. this.m_togArr[i].node.getChildByName('Label').color = color;
  234. }
  235. },
  236. // //底分加
  237. // OnBtBaseScoreAdd: function () {
  238. // if (this.m_LabBaseScore != null) {
  239. // if (this.m_SitScore < 1000) {
  240. // cc.gSoundRes.PlaySound('Button');
  241. // this.m_SitScore = this.m_SitScore + 100;
  242. // this.UpdateBaseScore();
  243. // }
  244. // }
  245. // },
  246. // //底分减
  247. // OnBtBaseScoreReduce: function () {
  248. // if (this.m_LabBaseScore != null) {
  249. // if (this.m_SitScore > 100) {
  250. // cc.gSoundRes.PlaySound('Button');
  251. // this.m_SitScore = this.m_SitScore - 100;
  252. // this.UpdateBaseScore();
  253. // }
  254. // }
  255. // },
  256. UpdateBaseScore: function () {
  257. if (this.m_LabBaseScore != null) this.m_LabBaseScore.string = this.m_SitScore;
  258. },
  259. // //抽水加
  260. // OnBtRevenueAdd: function () {
  261. // if (this.m_LabRevenue != null) {
  262. // if (this.m_Revenue < 10) {
  263. // cc.gSoundRes.PlaySound('Button');
  264. // this.m_Revenue = this.m_Revenue + 1;
  265. // this.UpdateRevenue();
  266. // }
  267. // }
  268. // },
  269. // //抽水减
  270. // OnBtRevenueReduce: function () {
  271. // if (this.m_LabRevenue != null) {
  272. // if (this.m_Revenue > 0) {
  273. // cc.gSoundRes.PlaySound('Button');
  274. // this.m_Revenue = this.m_Revenue - 1;
  275. // this.UpdateRevenue();
  276. // }
  277. // }
  278. // },
  279. // UpdateRevenue: function () {
  280. // if (this.m_LabRevenue != null) this.m_LabRevenue.string = this.m_Revenue + '%';
  281. // },
  282. //台湾麻将
  283. OnChecTWMJ: function () {
  284. // var RuleHZ;
  285. // var RuleHZ1, RuleHZ2, RuleHZ3;
  286. // for (var i in this.m_togArr) {
  287. // if (this.m_togArr[i].node.name == 10) RuleHZ = i;
  288. // if (this.m_togArr[i].node.name == 23) RuleHZ1 = i;
  289. // if (this.m_togArr[i].node.name == 24) RuleHZ2 = i;
  290. // if (this.m_togArr[i].node.name == 25) RuleHZ3 = i;
  291. // }
  292. // if (this.m_togArr[RuleHZ].isChecked)//台湾北部麻将玩法
  293. // {
  294. // this.m_togArr[RuleHZ1].interactable = true;
  295. // this.m_togArr[RuleHZ2].interactable = true;
  296. // this.m_togArr[RuleHZ3].interactable = true;
  297. // } else {
  298. // this.m_togArr[RuleHZ1].isChecked = false;
  299. // this.m_togArr[RuleHZ2].isChecked = false;
  300. // this.m_togArr[RuleHZ3].isChecked = false;
  301. // this.m_togArr[RuleHZ1].interactable = false;
  302. // this.m_togArr[RuleHZ2].interactable = false;
  303. // this.m_togArr[RuleHZ3].interactable = false;
  304. // }
  305. var RuleBB,RuleNB;
  306. var RuleBB1,RuleNB1;
  307. for (var i in this.m_togArr) {
  308. if (this.m_togArr[i].node.name == 26) RuleBB = i; //台湾北部麻将玩法
  309. if (this.m_togArr[i].node.name == 27) RuleNB = i; //台湾南部麻将玩法
  310. if (this.m_togArr[i].node.name == 28) RuleBB1 = i; //台湾北部呖咕呖咕 玩法
  311. // if (this.m_togArr[i].node.name == 9) RuleNB1 = i; //台湾南部庄家无台 玩法
  312. }
  313. // if (this.m_togArr[RuleNB].isChecked)
  314. // {
  315. // this.m_togArr[RuleBB1].node.active = false;
  316. // this.m_togArr[RuleNB1].node.active = true;
  317. // this.m_togArr[RuleBB1].isChecked = false;
  318. // } else if(this.m_togArr[RuleBB].isChecked) {
  319. // this.m_togArr[RuleNB1].isChecked = false;
  320. // this.m_togArr[RuleBB1].node.active = true;
  321. // this.m_togArr[RuleNB1].node.active = false;
  322. // }
  323. let isShowNorth = this.m_togArr[RuleBB].isChecked;
  324. this.m_togArr[RuleBB1].node.parent.active = isShowNorth;
  325. },
  326. // GetPayWay:function(){
  327. // var renshu2,renshu3,renshu4;
  328. // var Path = "ScrollView/view/content/";
  329. // for (var i in this.m_togArr) {
  330. // if (this.m_togArr[i].node.name == 1018) renshu2 =i;
  331. // if (this.m_togArr[i].node.name == 1017) renshu3 =i;
  332. // if (this.m_togArr[i].node.name == 1016) renshu4 =i;
  333. // }
  334. // if(this.m_togArr[renshu2].isChecked&&this.$(Path + "PayWay/1050@Toggle").isChecked){
  335. // this.$(Path + "GameCount/1019/Label@Label").string = '8局X4';
  336. // this.$(Path + "GameCount/1020/Label@Label").string = '12局X6';
  337. // this.$(Path + "GameCount/1021/Label@Label").string = '16局X8';
  338. // }
  339. // if(this.m_togArr[renshu3].isChecked&&this.$(Path + "PayWay/1050@Toggle").isChecked){
  340. // this.$(Path + "GameCount/1019/Label@Label").string = '8局X6';
  341. // this.$(Path + "GameCount/1020/Label@Label").string = '12局X9';
  342. // this.$(Path + "GameCount/1021/Label@Label").string = '16局X12';
  343. // }
  344. // if(this.m_togArr[renshu4].isChecked&&this.$(Path + "PayWay/1050@Toggle").isChecked){
  345. // this.$(Path + "GameCount/1019/Label@Label").string = '8局X8';
  346. // this.$(Path + "GameCount/1020/Label@Label").string = '12局X12';
  347. // this.$(Path + "GameCount/1021/Label@Label").string = '16局X16';
  348. // }
  349. // if(this.$(Path + "PayWay/1000@Toggle").isChecked){
  350. // this.$(Path + "GameCount/1019/Label@Label").string = '8局x2';
  351. // this.$(Path + "GameCount/1020/Label@Label").string = '12局x3';
  352. // this.$(Path + "GameCount/1021/Label@Label").string = '16局x4';
  353. // }
  354. // },
  355. GetPayWay: function () {
  356. var payWayPath = "PayWay/1050@Toggle";
  357. var gameCountPath = "GameCount/";
  358. var labels = [
  359. { node: '1019/Label@Label', text: ['8局X4', '8局X6', '8局X8'] },
  360. { node: '1020/Label@Label', text: ['12局X6', '12局X9', '12局X12'] },
  361. { node: '1021/Label@Label', text: ['16局X8', '16局X12', '16局X16'] }
  362. ];
  363. var alternativeLabels = ['8局x2', '12局x3', '16局x4'];
  364. var renshuIndices = { 1018: null, 1017: null, 1016: null };
  365. var Path = "ScrollView/view/content/";
  366. for (var i in this.m_togArr) {
  367. var nodeName = this.m_togArr[i].node.name;
  368. if (renshuIndices.hasOwnProperty(nodeName)) {
  369. renshuIndices[nodeName] = i;
  370. }
  371. }
  372. var setLabels = function (labelArray, checkedIndex) {
  373. for (var j in labelArray) {
  374. this.$(Path + gameCountPath + labelArray[j].node).string = labelArray[j].text[checkedIndex];
  375. }
  376. }.bind(this);
  377. if (this.$(Path + payWayPath).isChecked) {
  378. if (renshuIndices[1018] !== null && this.m_togArr[renshuIndices[1018]].isChecked) {
  379. setLabels(labels, 0);
  380. } else if (renshuIndices[1017] !== null && this.m_togArr[renshuIndices[1017]].isChecked) {
  381. setLabels(labels, 1);
  382. } else if (renshuIndices[1016] !== null && this.m_togArr[renshuIndices[1016]].isChecked) {
  383. setLabels(labels, 2);
  384. }
  385. }
  386. var alternativePayWayPath = "PayWay/1000@Toggle";
  387. if (this.$(Path + alternativePayWayPath).isChecked) {
  388. for (var k in alternativeLabels) {
  389. this.$(Path + gameCountPath + labels[k].node).string = alternativeLabels[k];
  390. }
  391. }
  392. },
  393. });