123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- let Global = require("Global");
- let topTipMsg = require("topTipMsg");
- let CServerItem = require("CServerItem");
- let ProtocolGameServer = require("ProtocolGameServer");
- const LanguageKey = require("LanguageKey");
- cc.Class({
- extends: cc.Component,
- properties: {
- },
- onLoad() {
- this.initData();
- this.initButton();
- },
- initData() {
- this.CServerItem = CServerItem.CServerItem.get();
- this.baseScript = this.node.getComponent("CRASHBase");
- this.CRASHMap = cc.find("layer_map/map", this.node).getComponent("CRASHMap");
- this.CRASHAudioManager = this.node.getComponent("CRASHAudioManager");
- this.scriptName = "CRASHButtonManager";
- this.scrollView_chip = cc.find("layer_scroll/scrollView_chip", this.node);
- this.scrollView_chat = cc.find("layer_scroll/scrollView_chat", this.node);
- this.label_chipScore = cc.find("layer_input/label_chipScore", this.node);
- this.button_num1 = cc.find("layer_button/button_num1", this.node);
- this.button_num2 = cc.find("layer_button/button_num2", this.node);
- this.button_num3 = cc.find("layer_button/button_num3", this.node);
- this.button_num4 = cc.find("layer_button/button_num4", this.node);
- this.button_num5 = cc.find("layer_button/button_num5", this.node);
- this.button_num6 = cc.find("layer_button/button_num6", this.node);
- this.button_menu = cc.find("layer_button/button_menu", this.node);
- this.button_chipState = cc.find("layer_button/button_chipState", this.node);
- this.button_cashOut = cc.find("layer_button/button_cashOut", this.node);
- this.layer_menu = cc.find("layer_menu", this.node);
- this.button_back = cc.find("layer_menu/button_back", this.node);
- this.button_exit = cc.find("layer_menu/button_exit", this.node);
- this.button_exit.addComponent(cc.Button);
- this.button_sendChat = cc.find("layer_scroll/scrollView_chat/button_sendChat", this.node);
- this.layer_menu.originalX = this.layer_menu.x = cc.winSize.width / -2;
- },
- initButton() {
- let clickAudioCallBack = () => {
- if (cc.isValid(this)) {
- this.CRASHAudioManager.playButton();
- }
- }
- UIHelper.addButtonListener(this.button_num1, this.node, this.scriptName, "chipScoreChange", -100, clickAudioCallBack);
- UIHelper.addButtonListener(this.button_num2, this.node, this.scriptName, "chipScoreChange", -10, clickAudioCallBack);
- UIHelper.addButtonListener(this.button_num3, this.node, this.scriptName, "chipScoreChange", "/", clickAudioCallBack);
- UIHelper.addButtonListener(this.button_num4, this.node, this.scriptName, "chipScoreChange", 100, clickAudioCallBack);
- UIHelper.addButtonListener(this.button_num5, this.node, this.scriptName, "chipScoreChange", 10, clickAudioCallBack);
- UIHelper.addButtonListener(this.button_num6, this.node, this.scriptName, "chipScoreChange", "*", clickAudioCallBack);
- UIHelper.addButtonListener(this.button_chipState, this.node, this.scriptName, "sendChipToServer", "*", clickAudioCallBack);
- UIHelper.addButtonListener(this.button_cashOut, this.node, this.scriptName, "sendJumpToServer", "*");
- UIHelper.addButtonListener(this.button_menu, this.node, this.scriptName, "openMenu", null, clickAudioCallBack);
- UIHelper.addButtonListener(this.button_back, this.node, this.scriptName, "closeMenu", null, clickAudioCallBack);
- UIHelper.addButtonListener(this.button_exit, this.node, "CRASHBase", "backHome", null, clickAudioCallBack);
- UIHelper.addButtonListener(this.button_sendChat, this.node, this.scriptName, "sendChatNotice", null, clickAudioCallBack);
- },
- changeScroll(event, data) {
- this.CRASHAudioManager.playButton();
- this.scrollView_chip.opacity = data == 1 ? 255 : 0;
- this.scrollView_chat.active = data == 2;
- },
- reSetChipScore() {
- let label_chipScore = this.label_chipScore.getComponent(cc.Label);
- let score = this.baseScript.label_score.getComponent(cc.Label).string;
- score = score.split("$: ")[1];
- if (this.baseScript.needRecharge && !this.baseScript.isVip) {
- this.label_chipScore.lockState2 = true;
- label_chipScore.string = LanguageKey.t("pubWords.xxx_can_bet");
- } else if (score < this.baseScript.miniBet && this.baseScript.serverCanBet == false) {
- this.label_chipScore.lockState = true;
- label_chipScore.string = LanguageKey.t("pubWords.min_bet_num") + this.baseScript.miniBet;
- } else if (parseInt(score) >= parseInt(label_chipScore.string)) {
- //donoting
- } else if (score >= this.baseScript.chipLowLimit) {
- this.label_chipScore.lockState = false;
- label_chipScore.string = this.baseScript.chipLowLimit;
- } else {
- this.label_chipScore.lockState = true;
- label_chipScore.string = LanguageKey.t("pubWords.min_bet_num") + this.baseScript.chipLowLimit;
- }
- },
- chipScoreChange(event, data) {
- let num = this.label_chipScore.getComponent(cc.Label).string;
- let score = this.baseScript.label_score.getComponent(cc.Label).string;
- score = score.split("$: ")[1];
- if (this.baseScript.isBet) {
- return;
- } else if (this.label_chipScore.lockState2) {
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.charge_before_bet"));
- return;
- } else if (this.label_chipScore.lockState) {
- topTipMsg.showTopTipMsg(num);
- return;
- } else if (this.baseScript.serverCanBet == false) {
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.min_bet_num") + this.baseScript.miniBet);
- }
- let chip = 0;
- if (data == "/") {
- chip = Math.floor(num / 2);
- } else if (data == "*") {
- chip = num * 2;
- } else {
- chip = parseInt(num) + parseInt(data);
- }
- let maxScore = this.baseScript.label_score.getComponent(cc.Label).string;
- maxScore = maxScore.split("$: ")[1];
- if (chip < this.baseScript.chipLowLimit) {
- chip = this.baseScript.chipLowLimit;
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.min_bet_num_2") + this.baseScript.chipLowLimit + LanguageKey.t("pubWords.bet_coin"));
- } if (chip > maxScore) {
- chip = maxScore;
- } if (chip > this.baseScript.chipHighLimit) {
- chip = this.baseScript.chipHighLimit;
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.max_bet_num") + this.baseScript.chipHighLimit);
- }
- this.label_chipScore.getComponent(cc.Label).string = Math.floor(chip);
- },
- sendChipToServer() {
- let score = this.baseScript.label_score.getComponent(cc.Label).string;
- score = parseFloat(score.split("$: ")[1]);
- if (this.label_chipScore.lockState2) {
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.charge_before_bet"));
- } else if (this.label_chipScore.lockState) {
- topTipMsg.showTopTipMsg(this.label_chipScore.getComponent(cc.Label).string);
- return;
- } else if (this.baseScript.serverCanBet == false) {
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.min_bet_num") + this.baseScript.miniBet);
- }
- let chip = this.label_chipScore.getComponent(cc.Label).string;
- let arrayBuffer = new ArrayBuffer(8 + 8);
- let dv = new DataView(arrayBuffer);
- dv.pos = 8;
- Global.WriteLL(dv, chip * 100);
- this.CServerItem.SendSocketData(ProtocolGameServer.MDM_GF_GAME, CRASHProto.typeCode.SUB_C_PLACE_JETTON, dv);
- },
- sendJumpToServer() {
- this.CRASHAudioManager.playJump();
- let arrayBuffer = new ArrayBuffer(8 + 2);
- let dv = new DataView(arrayBuffer);
- dv.pos = 8;
- Global.SetInt16(dv, this.CRASHMap.jumpID - 1);
- this.CServerItem.SendSocketData(ProtocolGameServer.MDM_GF_GAME, CRASHProto.typeCode.SUB_C_ROCK_DOWN, dv);
- },
- openMenu() {
- this.layer_menu.active = true;
- this.layer_menu.stopAllActions();
- this.layer_menu.runAction(cc.moveTo(0.3, cc.v2(this.layer_menu.originalX + this.layer_menu.width, 0)).easing(cc.easeSineOut()));
- },
- closeMenu() {
- if (this.lockMenu) { return; }
- this.lockMenu = true;
- this.layer_menu.stopAllActions();
- this.layer_menu.runAction(cc.sequence(
- cc.moveTo(0.3, cc.v2(this.layer_menu.originalX, 0)).easing(cc.easeSineIn()),
- cc.callFunc(() => {
- this.lockMenu = false;
- this.layer_menu.active = false;
- })
- ));
- },
- sendChatNotice() {
- let txt = cc.find("layer_scroll/scrollView_chat/EditBox", this.node).getComponent(cc.EditBox).string;
- let data = ProtocolGameServer.CMD_GR_C_TableTalk.data();
- let reg = /[\u4e00-\u9fa5]/g;
- txt = txt.replace(reg, "");
- let regex = /[1-9]{2}\-?[2-9]{1}\d{3,4}\-?\d{4}$/g;
- if (txt.indexOf("www") >= 0 || txt.indexOf("http") >= 0 || txt.indexOf("https") >= 0 || txt.indexOf("com") >= 0) {
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.cant_send_sites"));
- return;
- } else if (regex.test(txt)) {
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.cant_insert_phonenum"));
- return;
- } else if (txt.trim() == "") {
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.cant_insert_null_value"));
- return;
- }
- data.ChairID = this.baseScript.myselfPlayer.getChairID();
- data.Type = ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_WORD;
- data.String = txt;
- let arrayBuffer = new ArrayBuffer(138 + data.TalkSize + 8);
- let dv = new DataView(arrayBuffer);
- dv.pos = 8;
- Global.SetUint8(dv, data.Type);
- Global.SetUint8(dv, data.ChairID);
- Global.WriteChar(dv, data.String, 128);
- Global.SetUint32(dv, data.TalkSize);
- for (let index = 0; index < data.TalkSize; index++) {
- Global.SetUint8(dv, data.TalkData[index]);
- }
- this.CServerItem.SendSocketData(ProtocolGameServer.MDM_GF_FRAME, ProtocolGameServer.SUB_GR_TABLE_TALK, dv);
- },
- });
|