BRTPFuncBtnMgr.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. import ScenceManager from 'HNScenceManager'
  2. import GameManagerBase from 'GameManagerBase'
  3. var Global = require("Global");
  4. var GameProtocol = require("BRTPGameProtocol");
  5. var UIHelper = require("UIHelper");
  6. var topTipMsg = require("topTipMsg");
  7. var HomeSoundFun = require("homeSoundFunc")
  8. cc.Class({
  9. extends: cc.Component,
  10. properties: {
  11. _nodeChat:null, //聊天
  12. _selectJetonTag:-1, //选中筹码
  13. _selectArea:-1,//选中区域
  14. _openBankerList:false,
  15. _chipCache: [], // 下注操作缓存,用于续投
  16. },
  17. // LIFE-CYCLE CALLBACKS:
  18. onLoad: function() {
  19. //功能按钮
  20. var funcBtnNode = this.node.getChildByName("FuncBtnNode");
  21. //金豆下注按钮
  22. var GoldNode = funcBtnNode.getChildByName("GoldBtnNode");
  23. for(let i = 0;i< 7;i++){
  24. this.initButtonHandler(GoldNode.children[i]);
  25. }
  26. //天地玄黄 下注按钮
  27. var PourBtnList = this.node.getChildByName("PourBtnList");
  28. this.initButtonHandler(PourBtnList.getChildByName("Button_tian"));
  29. this.initButtonHandler(PourBtnList.getChildByName("Button_di"));
  30. this.initButtonHandler(PourBtnList.getChildByName("Button_xuan"));
  31. this.initButtonHandler(PourBtnList.getChildByName("Button_huang"));
  32. this.initButtonHandler(this.node.getChildByName("Button_Null"));
  33. //上下庄按钮
  34. var ApplyBankerNode = funcBtnNode.getChildByName("ApplyBankerNode");
  35. this.initButtonHandler(ApplyBankerNode.getChildByName("Button_callList"));
  36. this.initButtonHandler(ApplyBankerNode.getChildByName("Button_callUp"));
  37. this.initButtonHandler(ApplyBankerNode.getChildByName("Button_callDown"));
  38. for(let i = 0; i < GameProtocol.MAX_SEAT_COUNT+1; ++i){//6个座位玩家和自己头像
  39. var playerNode = this.node.getChildByName("Players").getChildByName("Player"+i);
  40. if(playerNode){
  41. this.initButtonHandler(playerNode.getChildByName("PlayerHead").getChildByName("ButtonPlayerHeadClick"));
  42. }
  43. break;//别人不能点击头像
  44. }
  45. this.initButtonHandler(funcBtnNode.getChildByName("OtherPlayer"));//玩家列表按钮
  46. this._selectJetonTag = 0;
  47. this._selectArea = -1;
  48. this._openBankerList = false;
  49. },
  50. onBtnClicked: function (event) {
  51. if(event.target.name == "Button_Null"){
  52. this.onClickCloseAll();
  53. }else if (event.target.name == "ButtonPlayerHeadClick") {
  54. UIHelper.playButtonEffect("open");
  55. this.onButtonPlayerHeadClick(event.target);
  56. }
  57. else if(event.target.name == "Button_tian" || event.target.name == "Button_di" || event.target.name == "Button_xuan" || event.target.name == "Button_huang"){
  58. this.onBtnPourChips(event.target.name)
  59. }else if(event.target.name == "Button_GoldAddAgain"){
  60. UIHelper.playButtonEffect("open");
  61. this.onBtnAddAgain();
  62. }else if(event.target.name == "Button_GoldAdd0"){
  63. this.OnSelectJeton(0);
  64. }else if(event.target.name == "Button_GoldAdd1"){
  65. this.OnSelectJeton(1);
  66. }else if(event.target.name == "Button_GoldAdd2"){
  67. this.OnSelectJeton(2);
  68. }else if(event.target.name == "Button_GoldAdd3"){
  69. this.OnSelectJeton(3);
  70. }else if(event.target.name == "Button_GoldAdd4"){
  71. this.OnSelectJeton(4);
  72. }else if(event.target.name == "Button_GoldAdd5"){
  73. this.OnSelectJeton(5);
  74. }else if(event.target.name == "OtherPlayer"){
  75. UIHelper.playButtonEffect("open");
  76. var jsGameSence = ScenceManager.Instance().getGameComponent();
  77. var playerListNode = this.node.getChildByName("PlayerList").getChildByName("AllPlayerList")
  78. jsGameSence.showAllPlayerList(!playerListNode.active);
  79. }else if(event.target.name == "Button_callList"){
  80. UIHelper.playButtonEffect("open");
  81. if(!this._openBankerList){
  82. var data = {};
  83. ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_BANK_LIST,data);
  84. }else{
  85. ScenceManager.Instance().getGameComponent().showBankerList(false);
  86. }
  87. }else if(event.target.name == "Button_callUp"){
  88. UIHelper.playButtonEffect("open");
  89. var data = {};
  90. var jsGameSence = ScenceManager.Instance().getGameComponent();
  91. data.wApplyUser = jsGameSence.getSelfLocalPlayer().getUserID();
  92. ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_APPLY_BANKER,data);
  93. }else if(event.target.name == "Button_callDown"){
  94. UIHelper.playButtonEffect("open");
  95. var data = {};
  96. var jsGameSence = ScenceManager.Instance().getGameComponent();
  97. data.wCancelUser = jsGameSence.getSelfLocalPlayer().getUserID();
  98. ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_CANCEL_BANKER,data);
  99. }
  100. },
  101. //按钮事件
  102. initButtonHandler: function (btn) {
  103. if(btn){
  104. UIHelper.addButtonListener(btn, this.node, "BRTPFuncBtnMgr", "onBtnClicked");
  105. }
  106. },
  107. unpdateJetonTag:function(){
  108. var GoldNode = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode");
  109. var tip_ring = GoldNode.getChildByName("tip_ring");
  110. for(var i = 5;i>=0;i--){
  111. var node = GoldNode.getChildByName("Button_GoldAdd" + i);
  112. if(node.getComponent(cc.Button).interactable && this._selectJetonTag >= i){
  113. this._selectJetonTag = i;
  114. var pos = node.getPosition();
  115. tip_ring.setPosition(pos);
  116. tip_ring.active = true;
  117. break;
  118. }
  119. }
  120. var node = GoldNode.getChildByName("Button_GoldAdd0");
  121. if(!node.getComponent(cc.Button).interactable){
  122. this._selectJetonTag = 0;
  123. var pos = node.getPosition();
  124. tip_ring.setPosition(pos);
  125. tip_ring.active = false;
  126. }
  127. },
  128. OnSelectJeton:function(tag){
  129. UIHelper.playButtonEffect("open");
  130. if(tag >= 0){
  131. var node = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode").getChildByName("Button_GoldAdd"+tag);
  132. var tip_ring = this.node.getChildByName("FuncBtnNode").getChildByName("GoldBtnNode").getChildByName("tip_ring");
  133. this._selectJetonTag = tag;
  134. var pos = node.getPosition();
  135. tip_ring.setPosition(pos);
  136. tip_ring.active = true;
  137. }else{
  138. this._selectJetonTag = 0;
  139. tip_ring.active = true;
  140. }
  141. },
  142. // 下注
  143. onBtnPourChips: function(btnName) {
  144. if(this._selectJetonTag < 0){
  145. topTipMsg.showTopTipMsg("BRTP.chip_error_tip");
  146. return;
  147. }
  148. if(btnName == "Button_tian"){
  149. this._selectArea = 0;
  150. }else if(btnName == "Button_di"){
  151. this._selectArea = 1;
  152. }else if(btnName == "Button_xuan"){
  153. this._selectArea = 2;
  154. }else if(btnName == "Button_huang"){
  155. this._selectArea = 3;
  156. }
  157. var data = {};
  158. data.dwIndex = this._selectArea;
  159. data.lScore = parseInt(ScenceManager.Instance().getGameComponent()._chipConfig[this._selectJetonTag]*100);
  160. ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_PLACE_JETTON,data);
  161. cc.find("FuncBtnNode/GoldBtnNode/Button_GoldAddAgain", this.node).getComponent(cc.Button).interactable = false;
  162. },
  163. onBtnAddAgain: function(){//续压
  164. if(this._selectJetonTag < 0){
  165. topTipMsg.showTopTipMsg("BRTP.chip_error_tip");
  166. return;
  167. }
  168. if(this._selectArea < 0){
  169. topTipMsg.showTopTipMsg("BRTP.area_error_tip");
  170. return;
  171. }
  172. var data = {};
  173. ScenceManager.Instance().getGameComponent().pourChipsAgain();
  174. },
  175. onButtonPlayerHeadClick: function(node) {
  176. var player = ScenceManager.Instance().getGameComponent().getPlayerByUserID(node.userID);
  177. var btnList = [];
  178. if (GameManagerBase.Instance().IsGoldGame()) {
  179. btnList.push("BR");
  180. }
  181. ScenceManager.Instance().getGameComponent().showHeadInfo(player, btnList);
  182. },
  183. onClickHelp: function() {
  184. UIHelper.playButtonEffect("open");
  185. this.node.getChildByName("helpNode").active = true;
  186. },
  187. onClickTrend: function() {
  188. UIHelper.playButtonEffect("open");
  189. ScenceManager.Instance().getGameComponent().showTrendPanel();
  190. },
  191. onClickChipRecord: function() {
  192. UIHelper.playButtonEffect("open");
  193. ScenceManager.Instance().getGameComponent().SendGameSocketData(GameProtocol.SUB_C_GAME_RECORD_INFO, 0);
  194. },
  195. //聊天
  196. onBtnChat: function() {
  197. var self = this;
  198. cc.resources.load("GamePrefabs/Public/Chat", cc.prefab, function (err, prefab) {
  199. if (!self._nodeChat) {
  200. self._nodeChat = cc.instantiate(prefab);
  201. self._nodeChat.parent = self.node;
  202. }
  203. var jsChat = self._nodeChat.getComponent("LYCChat");
  204. if (!jsChat) {
  205. self._nodeChat.addComponent("LYCChat");
  206. }
  207. self._nodeChat.getComponent("LYCChat").setChatNodeVisible(true);
  208. });
  209. },
  210. initAr: function() {
  211. this.audioRecord = new sdk.TMGInterface();
  212. //参数分别为:appid,authkey,userid
  213. //测试用appid=1400089356, authkey=1cfbfd2a1a03a53e
  214. //正式用appid=1400158484, authkey=UDZY34l7geTfY3nP
  215. this.audioRecord.init("1400158484", "UDZY34l7geTfY3nP", ""+cc.vv.globalUserInfo.getUserID());
  216. // setMaxMessageLength
  217. var ar = this.audioRecord;
  218. var self = this;
  219. this.audioRecord.setEventCallback(function(iCode, jsData){
  220. var data = JSON.parse(jsData);
  221. Global.print("录音::"+JSON.stringify(data));
  222. if (typeof data != "object") return;
  223. if (data.result == 0) {
  224. switch (iCode) {
  225. case 5001:
  226. self.audioRecord.uploadRecordedFile(data.file_path);
  227. break;
  228. case 5002:
  229. self.SendTableVoice(data.file_id);
  230. break;
  231. case 5003:
  232. self.audioRecord.playRecordedFile(data.file_path);
  233. cc.vv.audioMgr.setBGMVolume(0, false, false);
  234. break;
  235. case 5004:
  236. cc.vv.audioMgr.setBGMVolume(cc.vv.audioMgr.bgmVolume, true, true);
  237. ScenceManager.Instance().getGameComponent().hideVoice();
  238. break;
  239. }
  240. } else {
  241. if (data.result == 4103) {
  242. //提示录音时间太短
  243. // topTipMsg.showTopTipMsg("录音时间太短!");
  244. } else if (data.result == 4102) {
  245. //topTipMsg.showTopTipMsg("麦克风未授权!");
  246. //提示开启授权
  247. cc.vv.reflection.reqPermissionRecordAudio();
  248. } else {
  249. // topTipMsg.showTopTipMsg("刚才没听清,请再试一次(" + data.result + ")");
  250. }
  251. }
  252. });
  253. },
  254. getAr: function() {
  255. if (!this.audioRecord) {
  256. this.initAr();
  257. }
  258. return this.audioRecord;
  259. },
  260. //menuNode
  261. onBtnMenu: function()
  262. {
  263. UIHelper.playButtonEffect("open");
  264. var self = this
  265. cc.resources.load("GamePrefabs/Public/MenuNode", cc.Prefab, function (err, prefab) {
  266. if (!self._menuNode) {
  267. self._menuNode = cc.instantiate(prefab);
  268. self._menuNode.parent = self.node.getChildByName("MenuNode");
  269. self._menuNode.zIndex=(2);
  270. }
  271. self._menuNode.getComponent("menuNode").show();
  272. });
  273. },
  274. onBtnExitToLobby:function(){
  275. // let ScenceJs = ScenceManager.Instance().getGameComponent();
  276. // let score = ScenceJs.getSelfLocalPlayer().getNowScore()*100;
  277. // cc.vv.globalUserInfo.setUserScore(score);
  278. UIHelper.playButtonEffect("open");
  279. ScenceManager.Instance().getGameComponent().exitGameWhenPlaying();
  280. },
  281. // onBtnRoomRules:function(){
  282. // UIHelper.playButtonEffect("open");
  283. // this.node.getChildByName("RuleNode").active = true;
  284. // },
  285. onBtnGameSettings: function(){
  286. UIHelper.playButtonEffect("open");
  287. var self = this;
  288. UIHelper.showWaitNode("loadResSingle", "");
  289. cc.resources.load("GamePrefabs/homescence/set", cc.Prefab, function (err, prefab) {
  290. UIHelper.hideWaitNode();
  291. if (!self._set) {
  292. self._set = cc.instantiate(prefab);
  293. self._set.parent = self.node;
  294. self._set.zIndex=(100);
  295. }
  296. self._set.getComponent("homeSet").showSet();
  297. self._set.getComponent("homeSet").hideNode();
  298. });
  299. },
  300. onBtnControlInfo:function(event, opt){
  301. UIHelper.playButtonEffect("open");
  302. let infoNode = cc.find("ControlInfo/info", this.node);
  303. infoNode.active = !infoNode.active;
  304. ScenceManager.Instance().getGameComponent().showControlInfo();
  305. },
  306. onClickCloseAll: function() {
  307. UIHelper.playButtonEffect("close");
  308. var jsGameSence = ScenceManager.Instance().getGameComponent();
  309. jsGameSence.showAllPlayerList(false);//强制隐藏
  310. jsGameSence.showBankerList(false);//强制隐藏
  311. this.node.getChildByName("RecordPanel").active = false;
  312. this.node.getChildByName("TrendPanel").active = false;
  313. this.node.getChildByName("helpNode").active = false;
  314. }
  315. });