123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- import ScenceManager from 'HNScenceManager'
- import GameManagerBase from 'GameManagerBase'
- var Global = require("Global");
- var GameProtocol = require("TrucoGameProtocol");
- 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("TrucoSoundFun");
- var BaseDefine = require("BaseDefine");
- cc.Class({
- extends: cc.Component,
- editor: {
- menu: 'Game/Truco/FuncBtnMgr'
- },
- properties: {
- memeSpr: cc.SpriteFrame,
- _nodeChat:null, //聊天
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad: function() {
- //功能按钮
- var funcBtnNode = this.node.getChildByName("FuncBtnNode");
- this.initButtonHandler(funcBtnNode.getChildByName("btn_rule"));
- this.initButtonHandler(funcBtnNode.getChildByName("btn_Exit"));
- this.initButtonHandler(funcBtnNode.getChildByName("btn_Menu"));
- this.initButtonHandler(funcBtnNode.getChildByName("btn_Emo"));
- this.initButtonHandler(funcBtnNode.getChildByName("btn_Ace"));
- this.initButtonHandler(funcBtnNode.getChildByName("btn_Cor"));
- this.initButtonHandler(funcBtnNode.getChildByName("btn_Truco"));
- this.forceExitBtn = funcBtnNode.getChildByName("btn_Exit");
- this.forceExitBtn.active = false;
- let menuNode = this.node.getChildByName("MenuNode").getChildByName("RootNode");
- this.musicBtn = menuNode.getChildByName("img_sz_yy").getChildByName("btn");
- this.effectBtn = menuNode.getChildByName("img_sz_sy").getChildByName("btn");
- this.shakeBtn = menuNode.getChildByName("img_sz_zd").getChildByName("btn");
- funcBtnNode.getChildByName("btn_Debug").active = false//BaseDefine.LOCALTEST;
- this.initButtonHandler(funcBtnNode.getChildByName("btn_Debug"));
- },
- start () {
- this.serverItem = GameManagerBase.Instance().getGameServerItem();
- },
-
- //按钮事件
- initButtonHandler: function (btn,opt) {
- if(btn){
- UIHelper.addButtonListener(btn, this.node, "TrucoFuncBtnMgr", "onBtnClicked",opt);
- }
- },
- onBtnClicked: function (event,opt) {
- var jsGameSence = ScenceManager.Instance().getGameComponent();
- if(event.target.name == "btn_Exit"){//强行退出
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.onBtnForceExit();
- }else if(event.target.name == "btn_Truco"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- jsGameSence.onClickTruco();
- }
- else if(event.target.name == "btn_Ace"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- jsGameSence.onClickTrucoChoose(1)
- }else if(event.target.name == "btn_Cor"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- jsGameSence.onClickTrucoChoose(2)
- }else if(event.target.name == "btn_Menu"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.onBtnMenu();
- }else if(event.target.name == "btn_Emo"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.onShowSelfBQ();
- }else if(event.target.name == "btn_rule"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.onBtnRoomRules();
- }else if(event.target.name == "btn_Debug"){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.showDebugUi();
- }
-
- },
- onBtnCancelTrustee() {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- var jsGameSence = ScenceManager.Instance().getGameComponent();
- jsGameSence.SendGameSocketData(GameProtocol.SUB_C_CANCEL_TRUSTEE, {});
- },
- onBtnChangeTable() {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- if(cc.__TrucoChangeTableTime) {
- let nowTime = new Date().getTime();
- if(nowTime - cc.__TrucoChangeTableTime < 5000) {
- topTipMsg.showTopTipMsg(LanguageKey.t("pubWords.change_table_frequently"));
- return;
- }
- }
- if(CServerItem.get()) {
- CServerItem.get().SendChangeChair(-1, -1);
- cc.__TrucoChangeTableTime = 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) {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- 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;
- },
- onBtnExitToLobby:function(){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- var jsGameSence = ScenceManager.Instance().getGameComponent();
- jsGameSence.exitGameWhenPlaying();
- },
- onCloseTipNode() {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.node.getChildByName("tipNode").active = false;
- },
- onConformLeave() {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- var jsGameSence = ScenceManager.Instance().getGameComponent();
- jsGameSence.backHome();
- jsGameSence.exitGame();
- },
- onBtnDebug:function(event){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- 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("TrucoControl").show();
- });
- },
-
- onBtnMenu() {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.upSetting();
- let rootNode = this.node.getChildByName("MenuNode").getChildByName("RootNode");
- let desX = rootNode.width/2-cc.winSize.width/2;
- rootNode.x = desX-800;
- this.node.getChildByName("MenuNode").active = true;
- rootNode.stopAllActions();
- cc.tween(rootNode)
- .to(0.2, {x:desX+30})
- .to(0.05, {x:desX})
- .start()
- },
- onBtnCloseMenu: function() {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.node.getChildByName("MenuNode").active = false;
- },
- onBtnRoomRules:function(){
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- var jsGameSence = ScenceManager.Instance().getGameComponent();
- let rootNode = this.node.getChildByName("RuleNode").getChildByName("RootNode");
- let desX = cc.winSize.width/2-rootNode.width/2;
- rootNode.x = desX+800;
- this.node.getChildByName("RuleNode").active = true;
- let centerNode = rootNode.getChildByName("CenterNode");
- centerNode.getChildByName("r1").getComponent(cc.Label).string = Global.formatString2Score(jsGameSence._baseScore);
- centerNode.getChildByName("r3").getComponent(cc.Label).string = Global.formatString2Score(jsGameSence._baseScore*8);
- rootNode.stopAllActions();
- cc.tween(rootNode)
- .to(0.2, {x:desX-30})
- .to(0.05, {x:desX})
- .start()
- },
- onBtnCloseRule: function() {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.node.getChildByName("RuleNode").active = false;
- },
- onBtnBangZhu() {
- var self = this;
- cc.resources.load("GamePrefabs/homescence/rule", cc.Prefab, function (err, prefab) {
- if (!self._rule) {
- self._rule = cc.instantiate(prefab);
- self._rule.parent = self.node;
- }
- self._rule.getComponent("homeRule").showGameRule(5);
- });
- },
- upSetting() {
- let bMusic = cc.vv.audioMgr.bgmVolume > 0;
- let bEffect = cc.vv.audioMgr.sfxVolume > 0;
- let bShake = cc.vv.audioMgr.shakeOpen > 0;
- this.musicBtn.getChildByName("on").active = bMusic;
- this.musicBtn.getChildByName("off").active = !bMusic;
- this.effectBtn.getChildByName("on").active = bEffect;
- this.effectBtn.getChildByName("off").active = !bEffect;
- this.shakeBtn.getChildByName("on").active = bShake;
- this.shakeBtn.getChildByName("off").active = !bShake;
- },
- onClickMusic(){
- // cc.vv.audioMgr.bgmVolume = cc.vv.audioMgr.bgmVolume>0?0:1;
- if(cc.vv.audioMgr.bgmVolume > 0) {
- cc.vv.audioMgr.setBGMVolume(0, false, true);
- }else{
- cc.vv.audioMgr.setBGMVolume(1, false, true);
- }
- this.upSetting();
- },
- onClickEffect(){
- // cc.vv.audioMgr.sfxVolume = cc.vv.audioMgr.sfxVolume>0?0:1;
- if(cc.vv.audioMgr.sfxVolume > 0) {
- cc.vv.audioMgr.setSFXVolume(0, false, true);
- }else{
- cc.vv.audioMgr.setSFXVolume(1, false, true);
- }
- this.upSetting();
- },
- onClickShake(){
- // cc.vv.audioMgr.shakeOpen = cc.vv.audioMgr.shakeOpen>0?0:1;
- if(cc.vv.audioMgr.shakeOpen > 0) {
- cc.vv.audioMgr.setShakeOpen(0);
- }else{
- cc.vv.audioMgr.setShakeOpen(1);
- }
- this.upSetting();
- },
- onBtnForceExit() {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this._needSendCancel = false;
- this.node.getChildByName("exitNode").active = true;
- this.upForceExitLabel();
- },
- onCloseExitNode() {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.node.getChildByName("exitNode").active = false;
- },
- onShowSelfBQ() {
- SoundFun.playEffectEX(SoundFun.EX_BUTTON);
- this.node.getChildByName("selfNode").getComponent("TrucoEmoji").show();
- },
- showForceExit() {
- this._needSendCancel = true;
- this.node.getChildByName("exitNode").active = true;
- this.upForceExitLabel();
- },
- upForceExitLabel() {
- let s1 = "Você deseja ANULAR este jogo?";
- let s2 = "Caso seu colega de trabalho aceite,a partida ter-minará mais cedo. E sua equipe perderá fichas,prazer em confirmar";
- if(this._needSendCancel) {
- s1 = "Seu parceiro quer terminar o jogo,você concorda?";
- s2 = "Se acordado, o jogo terminará mais cedo e sua equipe perderá fichas.";
- }
- let root = this.node.getChildByName("exitNode").getChildByName("RootNode");
- root.getChildByName("title1").active = !this._needSendCancel;
- root.getChildByName("title2").active = this._needSendCancel;
- root.getChildByName("sure1").active = !this._needSendCancel;
- root.getChildByName("sure2").active = this._needSendCancel;
- root.getChildByName("tips1").getComponent(cc.Label).string = s1;
- root.getChildByName("tips2").getComponent(cc.Label).string = s2;
- },
- onClickForceSure() {
- ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_FORCE_LEAVE,{cbChoose:1})
- this.node.getChildByName("exitNode").active = false;
- this.forceExitBtn.active = false;
- },
- onClickForceCancel() {
- if(this._needSendCancel) {
- ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_FORCE_LEAVE,{cbChoose:2})
- this.forceExitBtn.active = false;
- }
- this.node.getChildByName("exitNode").active = false;
- },
- });
|