123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- 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<GameProtocol.HAND_CARD_COUNT+1;i++){
- data.tagCardTeam.tagTeamDataArr[i] = {};
- data.tagCardTeam.tagTeamDataArr[i].cbCardType = 0;
- data.tagCardTeam.tagTeamDataArr[i].lLostScore = 0;
- data.tagCardTeam.tagTeamDataArr[i].cbCardCount = 0;
- data.tagCardTeam.tagTeamDataArr[i].cbCardDataArr = [];
- if(i < groupData.length){
- data.tagCardTeam.tagTeamDataArr[i].cbCardCount = groupData[i].length;
- for(let j = 0;j<GameProtocol.HAND_CARD_COUNT+1;j++){
- if(j < groupData[i].length){
- data.tagCardTeam.tagTeamDataArr[i].cbCardDataArr.push(groupData[i][j]);
- }else{
- data.tagCardTeam.tagTeamDataArr[i].cbCardDataArr.push(0);
- }
- }
- }else{
- for(let j = 0;j<GameProtocol.HAND_CARD_COUNT+1;j++){
- data.tagCardTeam.tagTeamDataArr[i].cbCardDataArr.push(0);
- }
- }
- }
- data.bFinishSlotRequest = bFinish;
- jsGameSence.SendGameSocketData(GameProtocol.SUB_C_OUT_CARD,data);
- },
- //按钮事件
- initButtonHandler: function (btn,opt) {
- if(btn){
- UIHelper.addButtonListener(btn, this.node, "CachetaFuncBtnMgr", "onBtnClicked",opt);
- }
- },
- onBtnClicked: function (event,opt) {
- var jsGameSence = ScenceManager.Instance().getGameComponent();
- if(event.target.name == "LeftNode"){//暗牌堆
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- if(jsGameSence.isTurnSelf() && jsGameSence._canGetCard){
- this.sendGetCard(true);
- }
- }else if(event.target.name == "RightNode"){//明牌堆
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- if(jsGameSence.isTurnSelf() && jsGameSence._canGetCard && !jsGameSence.isRightCardMagic()){
- this.sendGetCard(false);
- }else if(jsGameSence.isRightCardMagic()){
- topTipMsg.showTopTipMsg("Cacheta.not_pick_card");
- }
- }else if(event.target.name == "RightArrow"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- jsGameSence.OnCardRecord();
- // var data = {};
- // jsGameSence.SendGameSocketData(GameProtocol.SUB_C_MING_CARD,data);
- }
- else if(event.target.name == "btn_Listener"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- jsGameSence.OnListener();
- }else if(event.target.name == "btn_Finish"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- jsGameSence.OnFinish();
- }
- else if(event.target.name == "btn_Monte"){//牌堆区
- SoundFun.playEffectEX("open");
- jsGameSence.SendGameSocketData(GameProtocol.SUB_C_GET_CARD,{bGetTableCard: 1})
- }else if(event.target.name == "btn_Lixo"){//垃圾区
- SoundFun.playEffectEX("open");
- jsGameSence.SendGameSocketData(GameProtocol.SUB_C_GET_CARD,{bGetTableCard: 0})
- }else if(event.target.name == "btn_Descartar"){//弃牌
- SoundFun.playEffectEX("open");
- // this.onBtnCloseEnd();
- jsGameSence.outCard();
- }
- else if(event.target.name == "btn_Menu"){
- SoundFun.playEffectEX("open");
- this.onBtnMenu();
- }
- else if(event.target.name == "btn_Sort"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.onClickRefresh();
- // jsGameSence.refreshHandCardsGroup();
- }else if(event.target.name == "btn_Setting"){
- SoundFun.playEffectEX("open");
- this.onBtnGameSettings();
- }else if(event.target.name == "btn_Rule"){
- SoundFun.playEffectEX("open");
- this.onBtnRoomRules();
- }else if(event.target.name == "btn_Exit"){
- this.onBtnExitToLobby();
- // HomeSoundFun.playEffectEX("open");
- // this.node.getChildByName("RuleNode").active = true;
- }else if(event.target.name == "btn_Debug"){
- SoundFun.playEffectEX("open");
- this.showDebugUi();
- }
-
- },
- onClickRefresh() {
- if(this._refreshing) {
- return;
- }
- SoundFun.playEffectEX("open");
- this._refreshing = true;
- ScenceManager.Instance().getGameComponent().refreshHandCardsGroup(true);
- let node = this.node.getChildByName("FuncBtnNode").getChildByName("btn_Sort");
- node.stopAllActions();
- cc.tween(node)
- // .by(0.5, {angle: 360})
- .delay(0.5)
- .call(()=>{
- 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;
- }
- });
|