123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- import ScenceManager from 'HNScenceManager'
- import GameManagerBase from 'GameManagerBase'
- var Global = require("Global");
- var GameProtocol = require("BRTPGameProtocol");
- var UIHelper = require("UIHelper");
- var topTipMsg = require("topTipMsg");
- var HomeSoundFun = require("homeSoundFunc")
- cc.Class({
- extends: cc.Component,
- properties: {
- _nodeChat:null, //聊天
- _selectJetonTag:-1, //选中筹码
- _selectArea:-1,//选中区域
- _openBankerList:false,
- _chipCache: [], // 下注操作缓存,用于续投
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad: function() {
- //功能按钮
- var funcBtnNode = this.node.getChildByName("FuncBtnNode");
-
- //金豆下注按钮
- var GoldNode = funcBtnNode.getChildByName("GoldBtnNode");
- for(let i = 0;i< 7;i++){
- this.initButtonHandler(GoldNode.children[i]);
- }
-
- //天地玄黄 下注按钮
- var PourBtnList = this.node.getChildByName("PourBtnList");
- this.initButtonHandler(PourBtnList.getChildByName("Button_tian"));
- this.initButtonHandler(PourBtnList.getChildByName("Button_di"));
- this.initButtonHandler(PourBtnList.getChildByName("Button_xuan"));
- this.initButtonHandler(PourBtnList.getChildByName("Button_huang"));
- this.initButtonHandler(this.node.getChildByName("Button_Null"));
- //上下庄按钮
- var ApplyBankerNode = funcBtnNode.getChildByName("ApplyBankerNode");
- this.initButtonHandler(ApplyBankerNode.getChildByName("Button_callList"));
- this.initButtonHandler(ApplyBankerNode.getChildByName("Button_callUp"));
- this.initButtonHandler(ApplyBankerNode.getChildByName("Button_callDown"));
- for(let i = 0; i < GameProtocol.MAX_SEAT_COUNT+1; ++i){//6个座位玩家和自己头像
- var playerNode = this.node.getChildByName("Players").getChildByName("Player"+i);
- if(playerNode){
- this.initButtonHandler(playerNode.getChildByName("PlayerHead").getChildByName("ButtonPlayerHeadClick"));
- }
- break;//别人不能点击头像
- }
- this.initButtonHandler(funcBtnNode.getChildByName("OtherPlayer"));//玩家列表按钮
- this._selectJetonTag = 0;
- this._selectArea = -1;
- this._openBankerList = false;
- },
- onBtnClicked: function (event) {
- if(event.target.name == "Button_Null"){
- this.onClickCloseAll();
- }else if (event.target.name == "ButtonPlayerHeadClick") {
- UIHelper.playButtonEffect("open");
- this.onButtonPlayerHeadClick(event.target);
- }
- else if(event.target.name == "Button_tian" || event.target.name == "Button_di" || event.target.name == "Button_xuan" || event.target.name == "Button_huang"){
- this.onBtnPourChips(event.target.name)
- }else if(event.target.name == "Button_GoldAddAgain"){
- UIHelper.playButtonEffect("open");
- this.onBtnAddAgain();
- }else if(event.target.name == "Button_GoldAdd0"){
- this.OnSelectJeton(0);
- }else if(event.target.name == "Button_GoldAdd1"){
- this.OnSelectJeton(1);
- }else if(event.target.name == "Button_GoldAdd2"){
- this.OnSelectJeton(2);
- }else if(event.target.name == "Button_GoldAdd3"){
- this.OnSelectJeton(3);
- }else if(event.target.name == "Button_GoldAdd4"){
- this.OnSelectJeton(4);
- }else if(event.target.name == "Button_GoldAdd5"){
- this.OnSelectJeton(5);
- }else if(event.target.name == "OtherPlayer"){
- UIHelper.playButtonEffect("open");
- var jsGameSence = ScenceManager.Instance().getGameComponent();
- var playerListNode = this.node.getChildByName("PlayerList").getChildByName("AllPlayerList")
- jsGameSence.showAllPlayerList(!playerListNode.active);
- }else if(event.target.name == "Button_callList"){
- UIHelper.playButtonEffect("open");
- if(!this._openBankerList){
- var data = {};
- ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_BANK_LIST,data);
- }else{
- ScenceManager.Instance().getGameComponent().showBankerList(false);
- }
- }else if(event.target.name == "Button_callUp"){
- UIHelper.playButtonEffect("open");
- var data = {};
- var jsGameSence = ScenceManager.Instance().getGameComponent();
- data.wApplyUser = jsGameSence.getSelfLocalPlayer().getUserID();
- ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_APPLY_BANKER,data);
- }else if(event.target.name == "Button_callDown"){
- UIHelper.playButtonEffect("open");
- var data = {};
- var jsGameSence = ScenceManager.Instance().getGameComponent();
- data.wCancelUser = jsGameSence.getSelfLocalPlayer().getUserID();
- ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_CANCEL_BANKER,data);
- }
- },
- //按钮事件
- initButtonHandler: function (btn) {
- if(btn){
- UIHelper.addButtonListener(btn, this.node, "BRTPFuncBtnMgr", "onBtnClicked");
- }
- },
- unpdateJetonTag:function(){
- var GoldNode = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode");
- var tip_ring = GoldNode.getChildByName("tip_ring");
- for(var i = 5;i>=0;i--){
- var node = GoldNode.getChildByName("Button_GoldAdd" + i);
- if(node.getComponent(cc.Button).interactable && this._selectJetonTag >= i){
- this._selectJetonTag = i;
- var pos = node.getPosition();
- tip_ring.setPosition(pos);
- tip_ring.active = true;
- break;
- }
- }
- var node = GoldNode.getChildByName("Button_GoldAdd0");
- if(!node.getComponent(cc.Button).interactable){
- this._selectJetonTag = 0;
- var pos = node.getPosition();
- tip_ring.setPosition(pos);
- tip_ring.active = false;
- }
- },
- OnSelectJeton:function(tag){
- UIHelper.playButtonEffect("open");
- if(tag >= 0){
- var node = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode").getChildByName("Button_GoldAdd"+tag);
- var tip_ring = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode").getChildByName("tip_ring");
-
- this._selectJetonTag = tag;
- var pos = node.getPosition();
- tip_ring.setPosition(pos);
- tip_ring.active = true;
- }else{
- this._selectJetonTag = 0;
- tip_ring.active = true;
- }
- },
- // 下注
- onBtnPourChips: function(btnName) {
- if(this._selectJetonTag < 0){
- topTipMsg.showTopTipMsg("BRTP.chip_error_tip");
- return;
- }
- if(btnName == "Button_tian"){
- this._selectArea = 0;
- }else if(btnName == "Button_di"){
- this._selectArea = 1;
- }else if(btnName == "Button_xuan"){
- this._selectArea = 2;
- }else if(btnName == "Button_huang"){
- this._selectArea = 3;
- }
- var data = {};
- data.dwIndex = this._selectArea;
- data.lScore = parseInt(ScenceManager.Instance().getGameComponent()._chipConfig[this._selectJetonTag]*100);
- ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_PLACE_JETTON,data);
- cc.find("FuncBtnNode/GoldBtnNode/Button_GoldAddAgain", this.node).getComponent(cc.Button).interactable = false;
- },
- onBtnAddAgain: function(){//续压
- if(this._selectJetonTag < 0){
- topTipMsg.showTopTipMsg("BRTP.chip_error_tip");
- return;
- }
- if(this._selectArea < 0){
- topTipMsg.showTopTipMsg("BRTP.area_error_tip");
- return;
- }
- var data = {};
- ScenceManager.Instance().getGameComponent().pourChipsAgain();
- },
- onButtonPlayerHeadClick: function(node) {
- var player = ScenceManager.Instance().getGameComponent().getPlayerByUserID(node.userID);
- var btnList = [];
- if (GameManagerBase.Instance().IsGoldGame()) {
- btnList.push("BR");
- }
- ScenceManager.Instance().getGameComponent().showHeadInfo(player, btnList);
- },
- onClickHelp: function() {
- UIHelper.playButtonEffect("open");
- this.node.getChildByName("helpNode").active = true;
- },
- onClickTrend: function() {
- UIHelper.playButtonEffect("open");
- ScenceManager.Instance().getGameComponent().showTrendPanel();
- },
- onClickChipRecord: function() {
- UIHelper.playButtonEffect("open");
-
- ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_GAME_RECORD_INFO, 0);
- },
- //聊天
- onBtnChat: function() {
- var self = this;
- cc.resources.load("GamePrefabs/Public/Chat", cc.prefab, function (err, prefab) {
- if (!self._nodeChat) {
- self._nodeChat = cc.instantiate(prefab);
- self._nodeChat.parent = self.node;
- }
- var jsChat = self._nodeChat.getComponent("LYCChat");
- if (!jsChat) {
- self._nodeChat.addComponent("LYCChat");
- }
- self._nodeChat.getComponent("LYCChat").setChatNodeVisible(true);
- });
- },
- initAr: function() {
- this.audioRecord = new sdk.TMGInterface();
- //参数分别为:appid,authkey,userid
- //测试用appid=1400089356, authkey=1cfbfd2a1a03a53e
- //正式用appid=1400158484, authkey=UDZY34l7geTfY3nP
- this.audioRecord.init("1400158484", "UDZY34l7geTfY3nP", ""+cc.vv.globalUserInfo.getUserID());
- // setMaxMessageLength
- var ar = this.audioRecord;
- var self = this;
- this.audioRecord.setEventCallback(function(iCode, jsData){
- var data = JSON.parse(jsData);
- Global.print("录音::"+JSON.stringify(data));
- if (typeof data != "object") return;
- if (data.result == 0) {
- switch (iCode) {
- case 5001:
- self.audioRecord.uploadRecordedFile(data.file_path);
- break;
- case 5002:
- self.SendTableVoice(data.file_id);
- break;
- case 5003:
- self.audioRecord.playRecordedFile(data.file_path);
- cc.vv.audioMgr.setBGMVolume(0, false, false);
- break;
- case 5004:
- cc.vv.audioMgr.setBGMVolume(cc.vv.audioMgr.bgmVolume, true, true);
- ScenceManager.Instance().getGameComponent().hideVoice();
- break;
- }
- } else {
- if (data.result == 4103) {
- //提示录音时间太短
- // topTipMsg.showTopTipMsg("录音时间太短!");
- } else if (data.result == 4102) {
- //topTipMsg.showTopTipMsg("麦克风未授权!");
- //提示开启授权
- cc.vv.reflection.reqPermissionRecordAudio();
- } else {
- // topTipMsg.showTopTipMsg("刚才没听清,请再试一次(" + data.result + ")");
- }
- }
- });
- },
- getAr: function() {
- if (!this.audioRecord) {
- this.initAr();
- }
- return this.audioRecord;
- },
- //menuNode
- onBtnMenu: function()
- {
- UIHelper.playButtonEffect("open");
- var self = this
- cc.resources.load("GamePrefabs/Public/MenuNode", cc.Prefab, function (err, prefab) {
- if (!self._menuNode) {
- self._menuNode = cc.instantiate(prefab);
- self._menuNode.parent = self.node.getChildByName("MenuNode");
- self._menuNode.zIndex=(2);
- }
- self._menuNode.getComponent("menuNode").show();
- });
- },
- onBtnExitToLobby:function(){
- // let ScenceJs = ScenceManager.Instance().getGameComponent();
- // let score = ScenceJs.getSelfLocalPlayer().getNowScore()*100;
- // cc.vv.globalUserInfo.setUserScore(score);
-
- UIHelper.playButtonEffect("open");
- ScenceManager.Instance().getGameComponent().exitGameWhenPlaying();
- },
- // onBtnRoomRules:function(){
- // UIHelper.playButtonEffect("open");
- // this.node.getChildByName("RuleNode").active = true;
- // },
- onBtnGameSettings: function(){
- UIHelper.playButtonEffect("open");
- var self = this;
- UIHelper.showWaitNode("loadResSingle", "");
- cc.resources.load("GamePrefabs/homescence/set", cc.Prefab, function (err, prefab) {
- UIHelper.hideWaitNode();
- if (!self._set) {
- self._set = cc.instantiate(prefab);
- self._set.parent = self.node;
- self._set.zIndex=(100);
- }
- self._set.getComponent("homeSet").showSet();
- self._set.getComponent("homeSet").hideNode();
- });
- },
- onBtnControlInfo:function(event, opt){
- UIHelper.playButtonEffect("open");
- let infoNode = cc.find("ControlInfo/info", this.node);
- infoNode.active = !infoNode.active;
- ScenceManager.Instance().getGameComponent().showControlInfo();
- },
- onClickCloseAll: function() {
- UIHelper.playButtonEffect("close");
- var jsGameSence = ScenceManager.Instance().getGameComponent();
- jsGameSence.showAllPlayerList(false);//强制隐藏
- jsGameSence.showBankerList(false);//强制隐藏
- this.node.getChildByName("RecordPanel").active = false;
- this.node.getChildByName("TrendPanel").active = false;
- this.node.getChildByName("helpNode").active = false;
- }
- });
|