import ScenceManager from 'HNScenceManager' import GameManagerBase from 'GameManagerBase' var Global = require("Global"); var GameProtocol = require("CachetaGameProtocol"); var UIHelper = require("UIHelper"); var topTipMsg = require("topTipMsg"); var HomeSoundFun = require("homeSoundFunc"); var popScence = require("popScence"); var LanguageKey = require("LanguageKey"); import { CServerItem } from 'CServerItem' var SoundFun = require("CachetaSoundFun"); var BaseDefine = require("BaseDefine"); cc.Class({ extends: cc.Component, editor: { menu: 'Game/Cacheta/FuncBtnMgr' }, properties: { memeSpr: cc.SpriteFrame, _nodeChat:null, //聊天 }, // LIFE-CYCLE CALLBACKS: onLoad: function() { //功能按钮 var funcBtnNode = this.node.getChildByName("FuncBtnNode"); // this.initButtonHandler(funcBtnNode.getChildByName("btn_ChangeTable")); // this.initButtonHandler(funcBtnNode.getChildByName("btn_Ready")); this.initButtonHandler(funcBtnNode.getChildByName("btn_Listener").getChildByName("btn_Listener")); this.initButtonHandler(funcBtnNode.getChildByName("btn_Finish").getChildByName("btn_Finish")); this.initButtonHandler(funcBtnNode.getChildByName("btn_Menu")); this.initButtonHandler(funcBtnNode.getChildByName("btn_Tip")); this.initButtonHandler(funcBtnNode.getChildByName("btn_Monte")); this.initButtonHandler(funcBtnNode.getChildByName("btn_Lixo")); this.initButtonHandler(funcBtnNode.getChildByName("btn_Descartar")); let menuNode = funcBtnNode.getChildByName("MenuNode"); this.initButtonHandler(menuNode.getChildByName("btn_Setting")); this.initButtonHandler(menuNode.getChildByName("btn_Rule")); this.initButtonHandler(menuNode.getChildByName("btn_Exit")); var EventNode = this.node.getChildByName("Cards").getChildByName("EventNode"); this.initButtonHandler(EventNode.getChildByName("LeftNode")); this.initButtonHandler(EventNode.getChildByName("RightNode")); this.initButtonHandler(EventNode.getChildByName("RightNode").getChildByName("RightArrow")); // var GameEndNode = this.node.getChildByName("GameEnd").getChildByName("RootNode"); // this.initButtonHandler(GameEndNode.getChildByName("btn_EndClose")); // this.initButtonHandler(GameEndNode.getChildByName("btn_EndExit")); // this.initButtonHandler(GameEndNode.getChildByName("btn_EndNext")); this.initButtonHandler(funcBtnNode.getChildByName("btn_Sort")); funcBtnNode.getChildByName("btn_Debug").active = false//BaseDefine.LOCALTEST; this.initButtonHandler(funcBtnNode.getChildByName("btn_Debug")); this._refreshing = false; }, start () { this.serverItem = GameManagerBase.Instance().getGameServerItem(); }, //抓牌 sendGetCard:function(isDarkCard){ var jsGameSence = ScenceManager.Instance().getGameComponent(); if(jsGameSence._isPlayingAni){ return; } // if(!isDarkCard && jsGameSence.isRightCardMagic()) { // return; // } jsGameSence._isPlayingAni = true; var data = {}; data.bGetTableCard = isDarkCard;//(true=暗牌堆,false=明牌堆) jsGameSence.SendGameSocketData(GameProtocol.SUB_C_GET_CARD,data); }, //出牌 sendOutCard:function(cardData,groupData,bFinish){ var jsGameSence = ScenceManager.Instance().getGameComponent(); if(jsGameSence._isPlayingAni){ return; } jsGameSence._isPlayingAni = true; var data = {}; data.cbOutCardData = cardData; data.tagCardTeam = {}; data.tagCardTeam.cbTeamCount = groupData.length; data.tagCardTeam.tagTeamDataArr = []; for(let i = 0;i{ this._refreshing = false; }) .start() }, refreshSortState(bValue) { let node = this.node.getChildByName("FuncBtnNode").getChildByName("btn_Sort"); node.getChildByName("value").active = bValue; node.getChildByName("color").active = !bValue; }, onBtnCancelTrustee() { SoundFun.playEffectEX("open"); var jsGameSence = ScenceManager.Instance().getGameComponent(); jsGameSence.SendGameSocketData(GameProtocol.SUB_C_CANCEL_TRUSTEE, {}); }, onBtnChangeTable() { SoundFun.playEffectEX("open"); if(cc.__cachetaChangeTableTime) { let nowTime = new Date().getTime(); if(nowTime - cc.__cachetaChangeTableTime < 5000) { topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.change_table_frequently")); return; } } if(CServerItem.get()) { CServerItem.get().SendChangeChair(-1, -1); cc.__cachetaChangeTableTime = new Date().getTime(); } }, onBtnReady:function() { this.node.getChildByName("TimeNode").active = false; this.node.getChildByName("FuncBtnNode").getChildByName("btn_Ready").active = false; this.node.getChildByName("FuncBtnNode").getChildByName("btn_ChangeTable").x=(0); var jsGameSence = ScenceManager.Instance().getGameComponent(); jsGameSence.sendReady(); jsGameSence.stopCountdown(); }, onBtnCloseEnd:function() { this.node.getChildByName("GameEnd").active = false; var jsGameSence = ScenceManager.Instance().getGameComponent(); var selfPlayer = jsGameSence.getSelfLocalPlayer(); if (!selfPlayer) { if (this.serverItem){ GameManagerBase.Instance().connectGameServer(this.serverItem); }else{ jsGameSence.backHome(); jsGameSence.exitGame(); } }else{ //jsGameSence.autoReady(); } }, onClickToggle:function(toggle){ }, onButtonPlayerHeadClick: function(node) { UIHelper.playButtonEffect("open"); var player = ScenceManager.Instance().getGameComponent().getPlayerByUserID(node.target.userID); ScenceManager.Instance().getGameComponent().showHeadInfo(player); }, //聊天 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); }); */ }, onBtnGameMeme:function(){ var self = this; cc.resources.load("GamePrefabs/Public/GameMeme", cc.Prefab, function (err, prefab) { if (!self._GameMeme) { self._GameMeme = cc.instantiate(prefab); self._GameMeme.parent = self.node; } self._GameMeme.getComponent("GameMeme").show(self.memeSpr); }); }, 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; }, hideMenu() { let menuNode = this.node.getChildByName("FuncBtnNode").getChildByName("MenuNode"); this.menuOpenState = false; let menuBtn = this.node.getChildByName("FuncBtnNode").getChildByName("btn_Menu"); menuBtn.stopAllActions(); cc.tween(menuBtn) .to(0.1, {angle: 0}) .start() menuNode.stopAllActions(); cc.tween(menuNode) .to(0.1, {scaleY: 0}) .start() }, //menuNode onBtnMenu: function(){ SoundFun.playEffectEX("open"); // let menuNode = this.node.getChildByName("FuncBtnNode").getChildByName("MenuNode"); // this.menuOpenState = !this.menuOpenState; // let menuBtn = this.node.getChildByName("FuncBtnNode").getChildByName("btn_Menu"); // menuBtn.stopAllActions(); // cc.tween(menuBtn) // .to(0.1, {angle: this.menuOpenState?90:0}) // .start() // menuNode.stopAllActions(); // cc.tween(menuNode) // .to(0.1, {scaleY: this.menuOpenState?1:0}) // .start() UIHelper.loadRes('GamePrefabs/Public/GameMenu', cc.Prefab, (prefab)=>{ if (!this._ruleNode) { this._ruleNode = cc.instantiate(prefab); this._ruleNode.parent = this.node.getChildByName("MenuNode"); } this._ruleNode.getComponent("GameMenu").show(); this._ruleNode.getComponent("GameMenu").onBtnBangZhu = ()=>{ this.onBtnHowToPlay(); } }) }, onBtnExitToLobby:function(){ SoundFun.playEffectEX("open"); var jsGameSence = ScenceManager.Instance().getGameComponent(); jsGameSence.exitGameWhenPlaying(); }, onBtnRoomRules:function(){ SoundFun.playEffectEX("open"); this.node.getChildByName("RuleNode").active = true; }, onBtnGameSettings: function(){ SoundFun.playEffectEX("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(); }); }, onBtnHowToPlay: function(){ if(this._ruleNode) { this._ruleNode.active = false; } this.node.getChildByName("RuleNode").active = true; }, onBtnDebug:function(event){ SoundFun.playEffectEX("open"); var jsGameSence = ScenceManager.Instance().getGameComponent(); if(!jsGameSence.getSceneState()){ topTipMsg.showTopTipMsg("玩家不在游戏中"); return; } var data = {}; jsGameSence.SendGameSocketData(GameProtocol.SUB_C_TEST_GETCARD,data); }, showDebugUi:function(data){ var jsGameSence = ScenceManager.Instance().getGameComponent(); let self = this; UIHelper.showWaitNode("loadResSingle", ""); UIHelper.loadRes("resourcesPrefab/ControlNode", cc.Prefab, (prefab) => { UIHelper.hideWaitNode(); if (!self._DebugUI) { self._DebugUI = cc.instantiate(prefab); self._DebugUI.parent = self.node; self._DebugUI.zIndex=(100); } self._DebugUI.getComponent("CachetaControl").show(); }); }, onChangeCard:function(data) { var jsGameSence = ScenceManager.Instance().getGameComponent(); jsGameSence.SendGameSocketData(GameProtocol.SUB_C_TEST_SETCARD,data); setTimeout(() => { var _data = {}; jsGameSence.SendGameSocketData(GameProtocol.SUB_C_GET_GROUP,_data); }, 500); }, onBtnCloseRule: function() { SoundFun.playEffectEX("open"); this.node.getChildByName("RuleNode").active = false; }, onBtnClickGoRealRoom:function(){ HomeSoundFun.playEffectEX("close"); this.node.getChildByName("GoRealRoom").active = false; }, OnBtnNoThanks:function(){ HomeSoundFun.playEffectEX("close"); this.node.getChildByName("GoRealRoom").active = false; } });