CRASHButtonManager.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. let Global = require("Global");
  2. let topTipMsg = require("topTipMsg");
  3. let CServerItem = require("CServerItem");
  4. let ProtocolGameServer = require("ProtocolGameServer");
  5. const LanguageKey = require("LanguageKey");
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. },
  10. onLoad() {
  11. this.initData();
  12. this.initButton();
  13. },
  14. initData() {
  15. this.CServerItem = CServerItem.CServerItem.get();
  16. this.baseScript = this.node.getComponent("CRASHBase");
  17. this.CRASHMap = cc.find("layer_map/map", this.node).getComponent("CRASHMap");
  18. this.CRASHAudioManager = this.node.getComponent("CRASHAudioManager");
  19. this.scriptName = "CRASHButtonManager";
  20. this.scrollView_chip = cc.find("layer_scroll/scrollView_chip", this.node);
  21. this.scrollView_chat = cc.find("layer_scroll/scrollView_chat", this.node);
  22. this.label_chipScore = cc.find("layer_input/label_chipScore", this.node);
  23. this.button_num1 = cc.find("layer_button/button_num1", this.node);
  24. this.button_num2 = cc.find("layer_button/button_num2", this.node);
  25. this.button_num3 = cc.find("layer_button/button_num3", this.node);
  26. this.button_num4 = cc.find("layer_button/button_num4", this.node);
  27. this.button_num5 = cc.find("layer_button/button_num5", this.node);
  28. this.button_num6 = cc.find("layer_button/button_num6", this.node);
  29. this.button_menu = cc.find("layer_button/button_menu", this.node);
  30. this.button_chipState = cc.find("layer_button/button_chipState", this.node);
  31. this.button_cashOut = cc.find("layer_button/button_cashOut", this.node);
  32. this.layer_menu = cc.find("layer_menu", this.node);
  33. this.button_back = cc.find("layer_menu/button_back", this.node);
  34. this.button_exit = cc.find("layer_menu/button_exit", this.node);
  35. this.button_exit.addComponent(cc.Button);
  36. this.button_sendChat = cc.find("layer_scroll/scrollView_chat/button_sendChat", this.node);
  37. this.layer_menu.originalX = this.layer_menu.x = cc.winSize.width / -2;
  38. },
  39. initButton() {
  40. let clickAudioCallBack = () => {
  41. if (cc.isValid(this)) {
  42. this.CRASHAudioManager.playButton();
  43. }
  44. }
  45. UIHelper.addButtonListener(this.button_num1, this.node, this.scriptName, "chipScoreChange", -100, clickAudioCallBack);
  46. UIHelper.addButtonListener(this.button_num2, this.node, this.scriptName, "chipScoreChange", -10, clickAudioCallBack);
  47. UIHelper.addButtonListener(this.button_num3, this.node, this.scriptName, "chipScoreChange", "/", clickAudioCallBack);
  48. UIHelper.addButtonListener(this.button_num4, this.node, this.scriptName, "chipScoreChange", 100, clickAudioCallBack);
  49. UIHelper.addButtonListener(this.button_num5, this.node, this.scriptName, "chipScoreChange", 10, clickAudioCallBack);
  50. UIHelper.addButtonListener(this.button_num6, this.node, this.scriptName, "chipScoreChange", "*", clickAudioCallBack);
  51. UIHelper.addButtonListener(this.button_chipState, this.node, this.scriptName, "sendChipToServer", "*", clickAudioCallBack);
  52. UIHelper.addButtonListener(this.button_cashOut, this.node, this.scriptName, "sendJumpToServer", "*");
  53. UIHelper.addButtonListener(this.button_menu, this.node, this.scriptName, "openMenu", null, clickAudioCallBack);
  54. UIHelper.addButtonListener(this.button_back, this.node, this.scriptName, "closeMenu", null, clickAudioCallBack);
  55. UIHelper.addButtonListener(this.button_exit, this.node, "CRASHBase", "backHome", null, clickAudioCallBack);
  56. UIHelper.addButtonListener(this.button_sendChat, this.node, this.scriptName, "sendChatNotice", null, clickAudioCallBack);
  57. },
  58. changeScroll(event, data) {
  59. this.CRASHAudioManager.playButton();
  60. this.scrollView_chip.opacity = data == 1 ? 255 : 0;
  61. this.scrollView_chat.active = data == 2;
  62. },
  63. reSetChipScore() {
  64. let label_chipScore = this.label_chipScore.getComponent(cc.Label);
  65. let score = this.baseScript.label_score.getComponent(cc.Label).string;
  66. score = score.split("$: ")[1];
  67. if (this.baseScript.needRecharge && !this.baseScript.isVip) {
  68. this.label_chipScore.lockState2 = true;
  69. label_chipScore.string = LanguageKey.t("pubWords.xxx_can_bet");
  70. } else if (score < this.baseScript.miniBet && this.baseScript.serverCanBet == false) {
  71. this.label_chipScore.lockState = true;
  72. label_chipScore.string = LanguageKey.t("pubWords.min_bet_num") + this.baseScript.miniBet;
  73. } else if (parseInt(score) >= parseInt(label_chipScore.string)) {
  74. //donoting
  75. } else if (score >= this.baseScript.chipLowLimit) {
  76. this.label_chipScore.lockState = false;
  77. label_chipScore.string = this.baseScript.chipLowLimit;
  78. } else {
  79. this.label_chipScore.lockState = true;
  80. label_chipScore.string = LanguageKey.t("pubWords.min_bet_num") + this.baseScript.chipLowLimit;
  81. }
  82. },
  83. chipScoreChange(event, data) {
  84. let num = this.label_chipScore.getComponent(cc.Label).string;
  85. let score = this.baseScript.label_score.getComponent(cc.Label).string;
  86. score = score.split("$: ")[1];
  87. if (this.baseScript.isBet) {
  88. return;
  89. } else if (this.label_chipScore.lockState2) {
  90. topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.charge_before_bet"));
  91. return;
  92. } else if (this.label_chipScore.lockState) {
  93. topTipMsg.showTopTipMsg(num);
  94. return;
  95. } else if (this.baseScript.serverCanBet == false) {
  96. topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.min_bet_num") + this.baseScript.miniBet);
  97. }
  98. let chip = 0;
  99. if (data == "/") {
  100. chip = Math.floor(num / 2);
  101. } else if (data == "*") {
  102. chip = num * 2;
  103. } else {
  104. chip = parseInt(num) + parseInt(data);
  105. }
  106. let maxScore = this.baseScript.label_score.getComponent(cc.Label).string;
  107. maxScore = maxScore.split("$: ")[1];
  108. if (chip < this.baseScript.chipLowLimit) {
  109. chip = this.baseScript.chipLowLimit;
  110. topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.min_bet_num_2") + this.baseScript.chipLowLimit + LanguageKey.t("pubWords.bet_coin"));
  111. } if (chip > maxScore) {
  112. chip = maxScore;
  113. } if (chip > this.baseScript.chipHighLimit) {
  114. chip = this.baseScript.chipHighLimit;
  115. topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.max_bet_num") + this.baseScript.chipHighLimit);
  116. }
  117. this.label_chipScore.getComponent(cc.Label).string = Math.floor(chip);
  118. },
  119. sendChipToServer() {
  120. let score = this.baseScript.label_score.getComponent(cc.Label).string;
  121. score = parseFloat(score.split("$: ")[1]);
  122. if (this.label_chipScore.lockState2) {
  123. topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.charge_before_bet"));
  124. } else if (this.label_chipScore.lockState) {
  125. topTipMsg.showTopTipMsg(this.label_chipScore.getComponent(cc.Label).string);
  126. return;
  127. } else if (this.baseScript.serverCanBet == false) {
  128. topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.min_bet_num") + this.baseScript.miniBet);
  129. }
  130. let chip = this.label_chipScore.getComponent(cc.Label).string;
  131. let arrayBuffer = new ArrayBuffer(8 + 8);
  132. let dv = new DataView(arrayBuffer);
  133. dv.pos = 8;
  134. Global.WriteLL(dv, chip * 100);
  135. this.CServerItem.SendSocketData(ProtocolGameServer.MDM_GF_GAME, CRASHProto.typeCode.SUB_C_PLACE_JETTON, dv);
  136. },
  137. sendJumpToServer() {
  138. this.CRASHAudioManager.playJump();
  139. let arrayBuffer = new ArrayBuffer(8 + 2);
  140. let dv = new DataView(arrayBuffer);
  141. dv.pos = 8;
  142. Global.SetInt16(dv, this.CRASHMap.jumpID - 1);
  143. this.CServerItem.SendSocketData(ProtocolGameServer.MDM_GF_GAME, CRASHProto.typeCode.SUB_C_ROCK_DOWN, dv);
  144. },
  145. openMenu() {
  146. this.layer_menu.active = true;
  147. this.layer_menu.stopAllActions();
  148. this.layer_menu.runAction(cc.moveTo(0.3, cc.v2(this.layer_menu.originalX + this.layer_menu.width, 0)).easing(cc.easeSineOut()));
  149. },
  150. closeMenu() {
  151. if (this.lockMenu) { return; }
  152. this.lockMenu = true;
  153. this.layer_menu.stopAllActions();
  154. this.layer_menu.runAction(cc.sequence(
  155. cc.moveTo(0.3, cc.v2(this.layer_menu.originalX, 0)).easing(cc.easeSineIn()),
  156. cc.callFunc(() => {
  157. this.lockMenu = false;
  158. this.layer_menu.active = false;
  159. })
  160. ));
  161. },
  162. sendChatNotice() {
  163. let txt = cc.find("layer_scroll/scrollView_chat/EditBox", this.node).getComponent(cc.EditBox).string;
  164. let data = ProtocolGameServer.CMD_GR_C_TableTalk.data();
  165. let reg = /[\u4e00-\u9fa5]/g;
  166. txt = txt.replace(reg, "");
  167. let regex = /[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/g;
  168. if (txt.indexOf("www") >= 0 || txt.indexOf("http") >= 0 || txt.indexOf("https") >= 0 || txt.indexOf("com") >= 0) {
  169. topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.cant_send_sites"));
  170. return;
  171. } else if (regex.test(txt)) {
  172. topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.cant_insert_phonenum"));
  173. return;
  174. } else if (txt.trim() == "") {
  175. topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.cant_insert_null_value"));
  176. return;
  177. }
  178. data.ChairID = this.baseScript.myselfPlayer.getChairID();
  179. data.Type = ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_WORD;
  180. data.String = txt;
  181. let arrayBuffer = new ArrayBuffer(138 + data.TalkSize + 8);
  182. let dv = new DataView(arrayBuffer);
  183. dv.pos = 8;
  184. Global.SetUint8(dv, data.Type);
  185. Global.SetUint8(dv, data.ChairID);
  186. Global.WriteChar(dv, data.String, 128);
  187. Global.SetUint32(dv, data.TalkSize);
  188. for (let index = 0; index < data.TalkSize; index++) {
  189. Global.SetUint8(dv, data.TalkData[index]);
  190. }
  191. this.CServerItem.SendSocketData(ProtocolGameServer.MDM_GF_FRAME, ProtocolGameServer.SUB_GR_TABLE_TALK, dv);
  192. },
  193. });