BaseClass.js 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  1. //基本方法封裝
  2. cc.BaseClass = cc.Class({
  3. extends: cc.Component,
  4. ctor: function () { },
  5. SetHook: function (Hook) {
  6. this.m_Hook = Hook;
  7. },
  8. OnCheckLoadingPre: function () {
  9. //通用队列
  10. for (var i in this.m_WaitArr) {
  11. var bInGame = this.m_WaitArr[i][3];
  12. var PreName = this.m_WaitArr[i][0];
  13. var res;
  14. // console.log("-OnCheckLoadingPre-------3",PreName)
  15. if (bInGame) res = cc.gPreLoader.LoadGamePrefab(PreName);
  16. else res = cc.gPreLoader.LoadPrefab(PreName);
  17. if (res == null) continue;
  18. if (res != 'err') {
  19. var memVar = 'm_Js' + PreName;
  20. this[memVar] = res;
  21. this.m_WaitArr[i][1].addChild(this[memVar].node);
  22. this[memVar].SetHook(this);
  23. this[memVar].ShowView();
  24. if (this.m_WaitArr[i][2] != null) {
  25. if (typeof (this.m_WaitArr[i][2]) == "string") this[this.m_WaitArr[i][2]](res);
  26. else this.m_WaitArr[i][2](res);
  27. }
  28. }
  29. this.m_WaitArr.splice(i, 1);
  30. }
  31. if (this.m_WaitArr.length == 0) this.unschedule(this.OnCheckLoadingPre);
  32. },
  33. ShowPrefabDLG: function (PreName, Parent, Call, KindID) {
  34. //默认子节点
  35. if (Parent == null) Parent = this.node;
  36. if (this.m_WaitArr == null) this.m_WaitArr = new Array();
  37. var memVar = 'm_Js' + PreName;
  38. if (this[memVar] && this[memVar].node == null) this[memVar] = null;
  39. //已有直接显示
  40. if (this[memVar]) {
  41. if (this[memVar].node.parent != Parent) this[memVar].node.parent = Parent;
  42. this[memVar].ShowView();
  43. if (Call != null) {
  44. if (typeof (Call) == "string") this[Call](this[memVar]);
  45. else Call(this[memVar]);
  46. }
  47. return this[memVar];
  48. } else {
  49. //判断是否已在检查队列
  50. var bInArr = false;
  51. for (var i in this.m_WaitArr) {
  52. if (this.m_WaitArr[i][0] == PreName) {
  53. bInArr = true;
  54. break;
  55. }
  56. }
  57. if (!bInArr) {
  58. var res = cc.gPreLoader.LoadPrefab(PreName, null);
  59. if (res == null) { //未加载完成插入检查队列
  60. console.log("-ShowPrefabDLG-----------3")
  61. // Call(res)
  62. // return;
  63. if (this.m_WaitArr.length == 0) this.schedule(this.OnCheckLoadingPre, 0.02);
  64. this.m_WaitArr.push([PreName, Parent, Call, KindID]);
  65. } else { //已经预加载
  66. if (res != 'err') {
  67. this[memVar] = res;
  68. Parent.addChild(this[memVar].node);
  69. this[memVar].SetHook(this);
  70. this[memVar].ShowView();
  71. if (Call != null) {
  72. if (typeof (Call) == "string") this[Call](res);
  73. else Call(res);
  74. }
  75. return res;
  76. }
  77. }
  78. }
  79. }
  80. this.OnCheckLoadingPre();
  81. return null;
  82. },
  83. ShowGamePrefab: function (PreName, KindID, Parent, Call) {
  84. return this.ShowPrefabDLG(PreName + '_' + KindID, Parent, Call, KindID);
  85. },
  86. ShowTips: function (str) {
  87. cc.gPreLoader.LoadPrefab("CustomTips", function (Js) {
  88. Js.SetTips(str);
  89. this.node.addChild(Js.node);
  90. }.bind(this));
  91. },
  92. //Func 回调参数 确定1 取消0 关闭null
  93. ShowAlert: function (str, style, Func, Hook) {
  94. cc.gPreLoader.LoadPrefab("Alert", function (Js) {
  95. this.node.addChild(Js.node);
  96. Js.ShowView();
  97. if (style == null) style = Alert_Yes; //默认参数
  98. Js.ShowAlert(str, style, Func, Hook);
  99. this['m_JsAlert'] = Js;
  100. }.bind(this));
  101. },
  102. OnDestroy: function (Tag, self) {
  103. if (self == null) {
  104. if (this.node) this.node.destroy();
  105. }
  106. else {
  107. if (self.node) self.node.destroy();
  108. }
  109. },
  110. HideView: function () {
  111. if (this.OnHideView)
  112. this.OnHideView();
  113. else
  114. this.node.active = false;
  115. },
  116. ShowView: function () {
  117. this.node.active = true;
  118. // var curScale = this.node.getScale();
  119. // this.node.setScale(0.01);
  120. // this.node.runAction(cc.scaleTo(0.1, curScale))
  121. if (this.OnShowView) this.OnShowView();
  122. },
  123. OnBtClickSound: function () {
  124. cc.gSoundRes.PlaySound('Button');
  125. },
  126. ShowLoading: function (OverTime, StrWord) {
  127. if (this.m_LoadCnt == null) this.m_LoadCnt = 0;
  128. this.m_LoadCnt++;
  129. if (OverTime == null) OverTime = 8;
  130. this.ShowPrefabDLG('CustomLoading', this.node, function (Js) {
  131. this.m_DlgLoading = Js;
  132. if (OverTime) this.m_DlgLoading.SetOverTime(OverTime);
  133. if (StrWord) this.m_DlgLoading.SetWorkStr(StrWord);
  134. if (this.m_LoadCnt == 0) this.m_DlgLoading.HideView();
  135. }.bind(this));
  136. },
  137. LoadingOver: function () {
  138. this.ShowTips("請求超時,請檢查網絡!")
  139. this.StopLoading();
  140. },
  141. StopLoading: function () {
  142. if (this.m_LoadCnt) this.m_LoadCnt--;
  143. if (this.m_DlgLoading && this.m_LoadCnt == 0) {
  144. this.m_DlgLoading.HideView();
  145. }
  146. },
  147. ////////////////////////////////////////////////////////////////
  148. GetComponentName: function (component) {
  149. return component.name.match(/<.*>$/)[0].slice(1, -1);
  150. },
  151. $: function (Path, StartNode) {
  152. if (StartNode == null) StartNode = this.node;
  153. if (!StartNode) return null;
  154. var NdJs = Path.split('@');
  155. var NdArr = NdJs[0].split('/');
  156. for (var i in NdArr) {
  157. if (NdArr[i] != '') {
  158. if (NdArr[i] == '..') StartNode = StartNode.parent;
  159. else StartNode = StartNode.getChildByName(NdArr[i]);
  160. if (StartNode == null) {
  161. if (this.m_bShowLostPath) console.log('$ find err !!! path=', Path)
  162. return null;
  163. }
  164. }
  165. }
  166. if (NdJs[1] == null) {
  167. return StartNode;
  168. } else {
  169. var Coms = StartNode._components;
  170. for (var i in Coms) {
  171. if (this.GetComponentName(Coms[i]) == NdJs[1]) return Coms[i];
  172. }
  173. if (this.m_bShowLostPath) console.log('$ find Com err !!! path=', Path)
  174. return null;
  175. }
  176. },
  177. BindButtonInit: function () {
  178. var BtArr = this.node.getComponentsInChildren(cc.Button);
  179. for (var i in BtArr) {
  180. if (BtArr[i].clickEvents.length == 0) {
  181. if (BtArr[i].node.name[0] == '$') continue;
  182. var ParseArr = BtArr[i].node.name.split('#');
  183. var FuncName = 'OnClick_' + ParseArr[0];
  184. if (this[FuncName]) {
  185. var eventHandler = new cc.Component.EventHandler();
  186. eventHandler.target = this.node;
  187. eventHandler.component = this.GetComponentName(this);
  188. eventHandler.handler = FuncName;
  189. eventHandler.customEventData = ParseArr[1];
  190. //eventHandler.emit([BtArr[i].node]);
  191. BtArr[i].clickEvents.push(eventHandler)
  192. } else {
  193. console.log('bind err in FuncName=', FuncName, BtArr[i].node)
  194. }
  195. }
  196. }
  197. },
  198. /////////////////////////////////////////////////////////////////////////
  199. OnEventLinkErr: function () {
  200. this.ShowTips("網路連接失敗!!!");
  201. this.StopLoading();
  202. },
  203. ////////////////////////////////////////////////////////////////
  204. });
  205. window.RulesKey = window.clientName + '_Rules_';
  206. window.RulesKey2 = window.clientName + '_S_Rules_';
  207. window.RoomBaseInfo = {
  208. 1: [30, 100, 300, 600, 1000], //底分
  209. 2: [10, 20, 50, 100, 200], //台数
  210. }
  211. cc.SubRoomRules = cc.Class({
  212. extends: cc.BaseClass,
  213. properties: {
  214. m_Font: cc.Font, //用户信息预制体
  215. },
  216. //1000-1031 服务器规则 1050-1099 对应规则
  217. //1000 =>AA付 1050 =>房主付
  218. //1001 =>代开 1051 =>房主进入
  219. //1002 =>积分房间 1003 =>金币房间 1052 =>练习房间
  220. ctor: function () {
  221. this.m_bNeedUpdate = false;
  222. this.m_bFirstShow = true;
  223. this.m_Color = [
  224. cc.color(201, 73, 36), // 选中状态
  225. cc.color(135, 103, 65), // 未选中状态
  226. cc.color(135, 103, 65), // 分项文字颜色
  227. ];
  228. },
  229. InitView: function (Kind, Key, RoomType) {
  230. console.log('==========================InitView', Kind, Key, RoomType);
  231. if (this.m_togArr == null) this.m_togArr = this.node.getComponentsInChildren(cc.Toggle);
  232. this.m_KindID = Kind;
  233. this.m_KeyStr = window.RulesKey + this.m_KindID;
  234. var rules = cc.sys.localStorage.getItem(this.m_KeyStr);
  235. if (rules != null) rules = JSON.parse(rules);
  236. //初始化数据
  237. if (this.m_bFirstShow && rules) {
  238. for (var i in this.m_togArr) {
  239. var IsChecked = false;
  240. for (var j in rules) {
  241. if (this.m_togArr[i].node.name == rules[j]) {
  242. IsChecked = true;
  243. break;
  244. }
  245. }
  246. this.m_togArr[i].isChecked = IsChecked;
  247. }
  248. }
  249. this.UpdateSubitemTitleColor();
  250. this.SetLabelColor();
  251. this.SetClubView(RoomType);
  252. this.SetKeyView(Key);
  253. this.m_bNeedUpdate = true;
  254. this.m_bFirstShow = false;
  255. },
  256. SetLabelColor: function () {
  257. var LabelArr = this.node.getComponentsInChildren(cc.Label);
  258. for (const i in LabelArr) {
  259. LabelArr[i].node.color = this.m_Color[0];
  260. if (this.m_Font) LabelArr[i].font = this.m_Font;
  261. }
  262. },
  263. OnHideView: function () {
  264. this.getRules();
  265. this.getServerRules();
  266. this.node.active = false;
  267. },
  268. OnUpdateToggleColor: function () {
  269. for (var i in this.m_togArr) {
  270. if (!this.m_togArr[i].node.active) continue;
  271. var color = this.m_togArr[i].isChecked ? this.m_Color[0] : this.m_Color[1];
  272. this.m_togArr[i].node.getChildByName("Label").color = color
  273. }
  274. },
  275. OnToggleClick: function (Tag, Data) {
  276. this.m_bNeedUpdate = true;
  277. },
  278. getRulesEx: function (bLog) {
  279. var rules = [0, 0, 0, 0, 0];
  280. var ruleshistory = new Array();
  281. for (var i in this.m_togArr) {
  282. if (this.m_togArr[i].node.active && this.m_togArr[i].isChecked) {
  283. var rulesIndex = parseInt(this.m_togArr[i].node.name);
  284. ruleshistory.push(rulesIndex);
  285. if (bLog && window.LOG_NET_DATA) console.log(rulesIndex + " ==> " + this.$('Label@Label', this.m_togArr[i].node).string);
  286. if (rulesIndex < 1000) {
  287. var rIndex = parseInt(rulesIndex / 100);
  288. var rValue = parseInt(rulesIndex % 100);
  289. if (rValue <= 31 && rIndex < 5) rules[rIndex] += 1 << rValue;
  290. } else if (rulesIndex > 10000) {
  291. var rIndex = parseInt(rulesIndex / 1000) % 10;
  292. var rValueIndex = parseInt(rulesIndex % 10);
  293. if (RoomBaseInfo[rIndex]) {
  294. rules[rIndex] = RoomBaseInfo[rIndex][rValueIndex] || 0;
  295. }
  296. }
  297. }
  298. }
  299. this.GetCustomRules(rules);
  300. console.log('getRulesEx', rules, ruleshistory);
  301. cc.sys.localStorage.setItem(this.m_KeyStr, JSON.stringify(ruleshistory));
  302. return rules;
  303. },
  304. getServerRules: function () {
  305. var rules = 0;
  306. for (var i in this.m_togArr) {
  307. if (this.m_togArr[i].node.active && this.m_togArr[i].isChecked) {
  308. var rulesIndex = parseInt(this.m_togArr[i].node.name);
  309. if (rulesIndex < 1000 || rulesIndex >= 1050) continue;
  310. rulesIndex -= 1000;
  311. rules += 1 << rulesIndex;
  312. }
  313. }
  314. return rules;
  315. },
  316. update: function () {
  317. if (this.m_bNeedUpdate) {
  318. this.m_bNeedUpdate = false;
  319. } else {
  320. return;
  321. }
  322. //私有联动
  323. this.OnUpdateCustomView();
  324. //单选颜色
  325. this.OnUpdateToggleColor();
  326. },
  327. //游戏自定义借口
  328. SetKeyView: function () { },
  329. SetClubView: function () { },
  330. GetCustomRules: function () { },
  331. OnUpdateCustomView: function () { },
  332. UpdateSubitemTitleColor: function () { },
  333. resetCheck: function () { },
  334. });
  335. cc.GameEngine = cc.Class({
  336. extends: cc.BaseClass,
  337. properties: {},
  338. onLoad: function () {
  339. this.m_GameClientView = this.$('GameClientView@GameClientView_' + GameDef.KIND_ID);
  340. },
  341. ctor: function () {
  342. this.m_dwRoomID = 0;
  343. this.m_dwRoomID2 = 0;
  344. this.m_dwCreater = 0; //创建者ID
  345. this.m_dwClubID = 0;
  346. this.m_dwRulesArr = new Array(0, 0, 0, 0, 0);
  347. this.m_wGameProgress = 0;
  348. this.m_wGameCount = 0;
  349. this.m_ReplayMode = false;
  350. this.m_bLockInRoom = false;
  351. this.m_LockArr = new Array();
  352. this.m_LoadFinished = false;
  353. },
  354. SetTableScene: function (tableScene) {
  355. this.m_pTableScene = tableScene;
  356. this.m_TableViewFrame = tableScene.m_TableViewFrame;
  357. },
  358. LoadSound: function () {
  359. if (this.m_ReplayMode) return
  360. cc.gSoundRes.LoadGameSoundArr(GameDef.KIND_ID, this.m_SoundArr);
  361. cc.gSoundRes.PlayMusic('BGM', true);
  362. if (1 || this.m_szText == null) {
  363. for (var i = 1; i <= 12; i++) {
  364. cc.gSoundRes.LoadSound("Phrase_w_" + (i < 10 ? '0' + i : i));
  365. cc.gSoundRes.LoadSound("Phrase_m_" + (i < 10 ? '0' + i : i));
  366. }
  367. }
  368. },
  369. //播放操作声音
  370. PlayActionSound: function (wChairId, byAction) {
  371. if (this.m_ReplayMode) return
  372. //椅子效验
  373. var pIClientUserItem = this.GetClientUserItem(wChairId);
  374. if (pIClientUserItem == null) return;
  375. if (pIClientUserItem.GetGender() == 1) {
  376. cc.gSoundRes.PlayGameSound("M_" + byAction);
  377. } else {
  378. cc.gSoundRes.PlayGameSound("W_" + byAction);
  379. }
  380. },
  381. OnSwitchAcc: function () {
  382. this.m_pTableScene.m_ServerItem.CloseSocket();
  383. },
  384. //启动游戏
  385. SetupGameClient: function () {
  386. return true;
  387. },
  388. //旁观消息
  389. OnEventLookonMode: function (pData, wDataSize) {
  390. return true;
  391. },
  392. //用户进入
  393. OnEventUserEnter: function (pIClientUserItem, bLookonUser) {
  394. //视图用户
  395. if (bLookonUser == false) {
  396. //获取属性
  397. var wChairID = this.SwitchViewChairID(pIClientUserItem.GetChairID());
  398. this.m_GameClientView.OnUserEnter(pIClientUserItem, wChairID);
  399. if (wChairID == GameDef.MYSELF_VIEW_ID) {
  400. this.m_GameClientView.LoadCardTestNode();
  401. }
  402. }
  403. this.UpdateLookSitView();
  404. },
  405. //用户状态
  406. OnEventUserStatus: function (pIClientUserItem, bLookonUser) {
  407. //视图用户
  408. if (bLookonUser == false) {
  409. //获取属性
  410. var wChairID = this.SwitchViewChairID(pIClientUserItem.GetChairID());
  411. this.m_GameClientView.OnUserState(pIClientUserItem, wChairID);
  412. }
  413. this.UpdateLookSitView();
  414. },
  415. //用户离开
  416. OnEventUserLeave: function (pIClientUserItem, bLookonUser) {
  417. if (pIClientUserItem.GetUserID() == this.m_dwCreater && this.m_wGameProgress == 0) {
  418. //this.OnCreatorExit();
  419. }
  420. if (bLookonUser == false) {
  421. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  422. if (this.m_GameClientView.m_pIClientUserItem[i] == null) continue;
  423. if (pIClientUserItem.GetUserID() == this.m_GameClientView.m_pIClientUserItem[i].GetUserID()) {
  424. this.m_GameClientView.OnUserLeave(pIClientUserItem, i);
  425. }
  426. }
  427. }
  428. },
  429. // 当玩家分数更新时触发的事件处理函数
  430. OnEventScoreUpdare: function (pIClientUserItem, bLookonUser) {
  431. // 如果当前不是视图用户的情况
  432. if (bLookonUser == false) {
  433. // 将玩家的实际椅子ID转换为视图中的椅子ID
  434. var wChairID = this.SwitchViewChairID(pIClientUserItem.GetChairID());
  435. // 在游戏客户端视图中更新用户分数显示
  436. this.m_GameClientView.OnUserScore(pIClientUserItem, wChairID);
  437. }
  438. },
  439. GetMeChairID: function () {
  440. var kernel = gClientKernel.get();
  441. if (kernel == null) return INVALD_CHAIR;
  442. return kernel.GetMeChairID();
  443. },
  444. GetMeUserItem: function () {
  445. var kernel = gClientKernel.get();
  446. if (!kernel) return null;
  447. return kernel.GetMeUserItem();
  448. },
  449. //切换椅子
  450. SwitchViewChairID: function (wChairID) {
  451. var MeChairID = this.GetMeChairID();
  452. if (wChairID == INVALD_CHAIR || MeChairID == INVALD_CHAIR) return INVALD_CHAIR;
  453. if (this.SwitchViewChairID2) return this.SwitchViewChairID2(wChairID);
  454. //转换椅子
  455. var wViewChairID = (wChairID + GameDef.GAME_PLAYER - this.GetMeChairID());
  456. return (wViewChairID + GameDef.MYSELF_VIEW_ID) % GameDef.GAME_PLAYER;
  457. },
  458. IsValidChairID: function (wChairID) {
  459. if (wChairID >= 0 && wChairID < GameDef.GAME_PLAYER) return true;
  460. return false;
  461. },
  462. OnUserReSit: function () {
  463. for (var i in this.m_GameClientView.m_pIClientUserItem) {
  464. var UserItem = this.m_GameClientView.m_pIClientUserItem[i];
  465. if (UserItem) this.m_GameClientView.OnUserLeave(UserItem, i);
  466. }
  467. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  468. var UserItem = this.GetClientUserItem(i);
  469. var ViewID = this.SwitchViewChairID(i);
  470. if (UserItem) this.m_GameClientView.OnUserEnter(UserItem, ViewID);
  471. }
  472. },
  473. OnCardRoomMessage: function (sub, data, datasize) {
  474. var self = this;
  475. var kernel = gClientKernel.get();
  476. switch (sub) {
  477. case SUB_GF_ROOM_INFO: {
  478. var pRoomInfo = new CMD_GF_RoomInfo();
  479. if (datasize != gCByte.Bytes2Str(pRoomInfo, data)) return false;
  480. this.m_dwRulesArr = pRoomInfo.dwRulesArr;
  481. this.m_dwServerRules = pRoomInfo.dwServerRules;
  482. this.m_dwClubID = pRoomInfo.dwClubID;
  483. this.m_dwRoomID = pRoomInfo.dwRoomID;
  484. this.m_dwRoomID2 = pRoomInfo.dwRoomID2;
  485. this.m_dwCreater = pRoomInfo.dwCreaterID;
  486. ShowLobbyClub = pRoomInfo.dwClubID;
  487. this.SetViewRoomInfo(this.m_dwServerRules, this.m_dwRulesArr);
  488. this.OnUserReSit();
  489. //房间记录
  490. var TempStr = cc.sys.localStorage.getItem(window.clientName + 'RoomHistory');
  491. var TempArr = new Array();
  492. if (TempStr) TempArr = JSON.parse(TempStr);
  493. if (this.m_dwRoomID > 0) {
  494. var bNotIn = true;
  495. for (var i in TempArr) {
  496. if (TempArr[i] == this.m_dwRoomID) bNotIn = false;
  497. }
  498. //if(bNotIn)TempArr.push(this.m_dwRoomID);
  499. }
  500. cc.sys.localStorage.setItem(window.clientName + 'RoomHistory', JSON.stringify(TempArr));
  501. //更新GPS
  502. if (GameDef.IsNoCheat(this.m_dwRulesArr)) this.GetSelfGPSInfo();
  503. //显示邀请按钮
  504. if (g_Table && g_Table.OnSetInviteBtShow) g_Table.OnSetInviteBtShow(this.GetMeUserItem());
  505. //微信H5分享链接
  506. cc.share.InitShareInfo_H5_WX(this.GetShareInfo.bind(this));
  507. return true;
  508. }
  509. case SUB_GF_ROOM_STATUS: {
  510. var pRoomStatus = new CMD_GF_RoomStatus();
  511. pRoomStatus.bLockArr = new Array(GameDef.GAME_PLAYER);
  512. if (datasize != gCByte.Bytes2Str(pRoomStatus, data)) return false;
  513. // this.m_wGameProgress = pRoomStatus.wProgress;
  514. this.m_LockArr = pRoomStatus.bLockArr;
  515. var kernel = gClientKernel.get();
  516. this.m_bLockInRoom = pRoomStatus.bLockArr[this.GetMeChairID()] && !kernel.IsLookonMode();
  517. //更新界面
  518. // this.m_GameClientView.UpdateRoomProgress();
  519. //更新GPS
  520. if (GameDef.IsNoCheat(this.m_dwRulesArr)) this.GetSelfGPSInfo();
  521. return true;
  522. }
  523. case SUB_GF_ROOM_GAME_FINISH: {
  524. this.OnEventRoomEnd(data, datasize);
  525. if (!this.m_ReplayMode) {
  526. this.m_TableViewFrame.mServerItem.IntermitConnect(false);
  527. }
  528. return true;
  529. }
  530. case SUB_GF_ROOM_DISSOLVE: {
  531. this.m_TableViewFrame.mServerItem.IntermitConnect(false);
  532. this.ShowAlert("房間已解散!", Alert_Yes, function (Res) {
  533. self.m_pTableScene.ExitGame();
  534. });
  535. return true;
  536. }
  537. case SUB_GF_ROOM_USER_DISSOLVE: {
  538. this.m_UserDiss = new CMD_GF_UserDissolve();
  539. if (datasize != gCByte.Bytes2Str(this.m_UserDiss, data)) return false;
  540. this.m_DissolveRes = null;
  541. this.m_UserDiss.byChoose = new Array();
  542. g_TimerEngine.PauseGameTimer();
  543. this.ShowPrefabDLG('DissolveRoom', this.node, function (Js) {
  544. this.m_DisCtrl = Js;
  545. this.m_DisCtrl.SetDissolveInfo(this.m_UserDiss.dwDisUserID, this.m_UserDiss.byChoose, this.m_UserDiss.dwAllCountDown, this.m_LockArr, this.m_UserDiss.dwAllCountDown);
  546. if (this.m_DissolveRes) this.m_DisCtrl.SetDisRes(this.m_DissolveRes.bDissolve);
  547. }.bind(this));
  548. return true;
  549. }
  550. case SUB_GF_ROOM_DISSOLVE_STATUS: {
  551. this.m_UserDiss = new CMD_GF_RoomDissolve();
  552. this.m_UserDiss.byChoose = new Array(GameDef.GAME_PLAYER);
  553. if (datasize != gCByte.Bytes2Str(this.m_UserDiss, data)) return false;
  554. this.m_DissolveRes = null;
  555. g_TimerEngine.PauseGameTimer();
  556. this.ShowPrefabDLG('DissolveRoom', this.node, function (Js) {
  557. this.m_DisCtrl = Js;
  558. this.m_DisCtrl.SetDissolveInfo(this.m_UserDiss.dwDisUserID, this.m_UserDiss.byChoose, this.m_UserDiss.dwCountDown, this.m_LockArr, this.m_UserDiss.dwAllCountDown);
  559. if (this.m_DissolveRes) this.m_DisCtrl.SetDisRes(this.m_DissolveRes.bDissolve);
  560. }.bind(this));
  561. return true;
  562. }
  563. case SUB_GF_ROOM_USERCHOOSE: {
  564. var pUserDiss = new CMD_GF_UserChooseRes();
  565. if (datasize != gCByte.Bytes2Str(pUserDiss, data)) return false;
  566. if (pUserDiss.byRes == 0) pUserDiss.byRes = 2;
  567. if (this.m_DisCtrl != null) {
  568. this.m_DisCtrl.SetUserChoose(pUserDiss.wChairID, pUserDiss.byRes);
  569. } else if (this.m_UserDiss != null) {
  570. this.m_UserDiss.byChoose[pUserDiss.wChairID] = pUserDiss.byRes;
  571. } else {
  572. this.ShowTips("DissolveRoom creat err??")
  573. }
  574. return true;
  575. }
  576. case SUB_GF_ROOM_DISSOLVE_RES: {
  577. this.m_DissolveRes = new CMD_GF_DissolveRes();
  578. if (datasize != gCByte.Bytes2Str(this.m_DissolveRes, data)) return false;
  579. g_TimerEngine.UnPauseGameTimer();
  580. if (this.m_DisCtrl) this.m_DisCtrl.SetDisRes(this.m_DissolveRes.bDissolve)
  581. return true;
  582. }
  583. }
  584. return false;
  585. },
  586. //发送数据
  587. SendGameData: function (wSubCmdID, Obj) {
  588. var kernel = gClientKernel.get();
  589. if (kernel != null) this.sendClass(MDM_GF_GAME, wSubCmdID, Obj);
  590. },
  591. //发送数据
  592. SendFrameData: function (wSubCmdID, Obj) {
  593. this.sendClass(MDM_GF_FRAME, wSubCmdID, Obj);
  594. return true;
  595. },
  596. sendClass: function (wMainCmdID, wSubCmdID, Obj) {
  597. var kernel = gClientKernel.get();
  598. if (kernel != null) kernel.SendSocketClass(wMainCmdID, wSubCmdID, Obj);
  599. },
  600. OnClick_CheckOut: function () {
  601. cc.gSoundRes.PlaySound('Button');
  602. if (this.m_dwCreater != 0) {
  603. var kernel = gClientKernel.get();
  604. if (this.m_wGameProgress == 0 && this.m_dwCreater == kernel.mMeUserItem.GetUserID()) {
  605. this.ShowAlert("確認解散該房間?", Alert_All, function (Res) {
  606. if (Res) this.sendClass(MDM_GF_CARDROOM, SUB_GF_CREATER_DISSOLVE);
  607. }.bind(this));
  608. }
  609. if (this.m_wGameProgress > 0) {
  610. this.ShowAlert("確認申請解散?", Alert_All, function (Res) {
  611. if (Res) this.sendClass(MDM_GF_CARDROOM, SUB_GF_USER_DISSOLVE);
  612. }.bind(this));
  613. }
  614. }
  615. },
  616. OnBtReturn: function () {
  617. cc.gSoundRes.PlaySound('Button');
  618. if (this.m_RoomEnd != null) return this.m_pTableScene.ExitGame();
  619. this.ShowAlert("確定要退出遊戲嗎?", Alert_YesNo, function (Res) {
  620. if (Res) this.m_pTableScene.ExitGame();
  621. }.bind(this));
  622. },
  623. //////////////////////////////////////////////////////////////////////////
  624. //获取用户
  625. GetClientUserItem: function (wChairID) {
  626. var kernel = gClientKernel.get();
  627. if (kernel == null) return null;
  628. return kernel.GetTableUserItem(wChairID);
  629. },
  630. IsValidChairID: function (wChairID) {
  631. if (wChairID >= 0 && wChairID < GameDef.GAME_PLAYER) return true;
  632. return false;
  633. },
  634. // 获取座位
  635. GetUserChairID: function (dwUserID) {
  636. for (var i = 0; i < GameDef.GAME_PLAYER; ++i) {
  637. var pIClientUserItem = this.GetClientUserItem(i);
  638. if (!pIClientUserItem) continue;
  639. if (pIClientUserItem.GetUserID() == dwUserID) return i;
  640. }
  641. return INVALID_CHAIR;
  642. },
  643. // 快捷短语
  644. OnSendPhrase: function (wItemID, TagUser) {
  645. var pExpression = new CMD_GF_C_UserExpression();
  646. pExpression.wItemIndex = wItemID;
  647. pExpression.dwTargetUserID = TagUser;
  648. this.SendFrameData(SUB_GF_USER_EXPRESSION, pExpression);
  649. },
  650. // 发送聊天
  651. OnSendChat: function (szText) {
  652. var pChithat = new CMD_GF_C_UserChat();
  653. pChithat.szChatString = szText + '\0';
  654. pChithat.wChatLength = pChithat.szChatString.length;
  655. pChithat.len_szChatString = pChithat.wChatLength * cc.TCHAR_SIZE;
  656. this.SendFrameData(SUB_GF_USER_CHAT, pChithat);
  657. },
  658. // 快捷短语
  659. OnSubUserPhrase: function (pData, wDataSize) {
  660. //效验
  661. var pShortcutPhrase = new CMD_GR_S_UserExpression();
  662. if (wDataSize != gCByte.Bytes2Str(pShortcutPhrase, pData)) return false;
  663. this.m_GameClientView.UserExpression(pShortcutPhrase.dwSendUserID, pShortcutPhrase.dwTargetUserID, pShortcutPhrase.wItemIndex)
  664. return true;
  665. },
  666. // 用户聊天
  667. OnSubUserChat: function (pData, wDataSize) {
  668. //效验
  669. var pChithat = new CMD_GF_S_UserChat();
  670. gCByte.Bytes2Str(pChithat, pData);
  671. this.m_GameClientView.UserChat(pChithat.dwSendUserID, pChithat.dwTargetUserID, pChithat.szChatString);
  672. return true;
  673. },
  674. ShowEndView: function () {
  675. console.log("ShowEndView--结束")
  676. if (this.m_ReplayMode) {
  677. this.RealShowEndView();
  678. } else {
  679. this.schedule(this.RealShowEndView, 3)
  680. }
  681. },
  682. RealShowEndView: function () {
  683. console.log("RealShowEndView--结束")
  684. this.unschedule(this.RealShowEndView)
  685. this.ShowPrefabDLG("GameEndInfo", null, function (Js) {
  686. this.m_REndCtrl = Js;
  687. }.bind(this));
  688. },
  689. //分享信息
  690. GetShareInfo: function () {
  691. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  692. var ShareInfo = new Object();
  693. ShareInfo.title = '房号【' + this.m_dwRoomID + '】 ' + g_GlobalUserInfo.m_UserInfoMap[pGlobalUserData.dwUserID].NickName + "邀请您来玩" + window.GameList[GameDef.KIND_ID];
  694. ShareInfo.desc = this.m_GameClientView.m_LbGameRules.string;
  695. ShareInfo.imgUrl = window.PHP_HOME + '/app01/App.jpg'
  696. ShareInfo.link = cc.share.MakeLink_InviteRoom(this.m_dwRoomID, this.m_dwClubID);
  697. return ShareInfo;
  698. },
  699. //点击设置
  700. OnBtClickedSet: function () {
  701. cc.gSoundRes.PlaySound('Button');
  702. this.ShowPrefabDLG('Setting');
  703. },
  704. OnClicked_GameSetting: function () {
  705. cc.gSoundRes.PlaySound('Button');
  706. this.ShowPrefabDLG('GameSetting', this.node, function (Js) {
  707. this.m_GameSetting = Js;
  708. this.m_GameSetting.SetGame(GameDef);
  709. }.bind(this));
  710. },
  711. //点击设置
  712. OnBtClick_BtMenu: function (Tag) {
  713. cc.gSoundRes.PlaySound('Button');
  714. this.ShowPrefabDLG('GameSetMenu', Tag.currentTarget.parent);
  715. },
  716. OnClick_BtLookOnList: function () {
  717. this.ShowPrefabDLG('GameLookOnList')
  718. },
  719. //+++++++录音和播放需要添加的内容 start++++++
  720. //发消息给其它玩家
  721. OnSendUserVoice: function (Platform, VoiceID) {
  722. var pVoice = new CMD_GF_C_UserVoice();
  723. pVoice.szVID = VoiceID;
  724. pVoice.byPlatform = Platform;
  725. this.SendFrameData(SUB_GF_USER_VOICE, pVoice);
  726. },
  727. OnSendUserVoice_A: function (Platform, VoiceID) {
  728. var pVoice = new CMD_GF_C_UserVoice_A();
  729. pVoice.szVID = VoiceID;
  730. pVoice.byPlatform = Platform;
  731. this.SendFrameData(SUB_GF_USER_VOICE_A, pVoice);
  732. },
  733. OnSubUserVoice: function (pData, wDataSize) {
  734. if (window.LOG_NET_DATA) console.log('OnSubUserVoice返回-1');
  735. //效验
  736. var pVoice = new CMD_GF_S_UserVoice();
  737. if (gCByte.Bytes2Str(pVoice, pData) != wDataSize) {
  738. if (window.LOG_NET_DATA) console.log('语音包大小错误!', wDataSize);
  739. // return false; todo
  740. return true;
  741. }
  742. //显示播放
  743. var VoiceCtrl = this.GetVoiceCtrl();
  744. if (VoiceCtrl) VoiceCtrl.PlayVoice(pVoice);
  745. return true;
  746. },
  747. OnSubUserVoice_A: function (pData, wDataSize) {
  748. if (window.LOG_NET_DATA) console.log('OnSubUserVoice返回A-1');
  749. //效验
  750. var pVoice = new CMD_GF_S_UserVoice_A();
  751. if (gCByte.Bytes2Str(pVoice, pData) != wDataSize) {
  752. if (window.LOG_NET_DATA) console.log('语音包大小错误A!', wDataSize);
  753. // return false; todo
  754. return true;
  755. }
  756. //显示播放
  757. var VoiceCtrl = this.GetVoiceCtrl();
  758. if (VoiceCtrl) VoiceCtrl.PlayVoice(pVoice);
  759. return true;
  760. },
  761. GetVoiceCtrl: function () {
  762. return this.m_GameClientView.m_VoiceCtrl;
  763. },
  764. //+++++++录音和播放需要添加的内容 end++++++
  765. GetSelfGPSInfo: function () {
  766. if (this.m_ReplayMode) return;
  767. if (this.IsLookonMode()) return;
  768. if (window.g_CntGameGPS >= 3) return;
  769. if (window.g_CntGameGPS > 0) g_CurScene.m_bTipGPS = false;
  770. window.g_CntGameGPS++;
  771. if (cc.sys.isNative) {
  772. ThirdPartyGetAddress();
  773. } else {
  774. var GPSInfo = new tagUserGps();
  775. var bShow = cc.sys.localStorage.getItem(window.Key_ShowGPS);
  776. if (bShow == null) bShow = 0;
  777. GPSInfo.byHide = parseInt(bShow);
  778. GPSInfo.dlatitude = 0;
  779. GPSInfo.dlongitude = 0;
  780. GPSInfo.szAddress = 'H5登入暫時無法獲取資訊!';
  781. this.SendFrameData(SUB_GF_GPS_INFO_SAVE, GPSInfo);
  782. }
  783. },
  784. UpdateGPS: function (Info) {
  785. if (Info == "") return
  786. var Obj = JSON.parse(Info);
  787. if (Obj.berror == true || Obj.code != 0) {
  788. this.unschedule(this.GetSelfGPSInfo);
  789. this.scheduleOnce(this.GetSelfGPSInfo, 3);
  790. return;
  791. }
  792. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  793. var GPSInfo = new tagUserGps();
  794. var bShow = cc.sys.localStorage.getItem(window.Key_ShowGPS);
  795. if (bShow == null) bShow = 0;
  796. GPSInfo.byHide = parseInt(bShow);
  797. GPSInfo.dlatitude = (Obj.latitude) * 1;
  798. GPSInfo.dlongitude = (Obj.longitude) * 1;
  799. GPSInfo.szAddress = Obj.address;
  800. if (GPSInfo.szAddress == '') GPSInfo.szAddress = '用戶運行環境無法準確獲取地理位置!';
  801. this.SendFrameData(SUB_GF_GPS_INFO_SAVE, GPSInfo);
  802. },
  803. IsLookonMode: function () {
  804. var kernel = gClientKernel.get();
  805. if (kernel && kernel.IsLookonMode()) return true;
  806. return false;
  807. },
  808. //设置状态
  809. SetGameStatus: function (cbGameStatus) {
  810. this.m_cbGameStatus = cbGameStatus;
  811. },
  812. GetGameStatus: function () {
  813. return this.m_cbGameStatus;
  814. },
  815. GetTableUserGPS: function () {
  816. this.SendFrameData(SUB_GF_GPS_INFO_GET);
  817. },
  818. OnGetTableGPSRes: function (GPSInfo) {
  819. if (this.m_GameClientView.OnGPSAddress) this.m_GameClientView.OnGPSAddress(GPSInfo);
  820. },
  821. ////////////////////////////////////////////////////////////////////////////////
  822. ShowLookOnView: function (bShow) {
  823. if (bShow) {
  824. this.OnBtLookOnSit();
  825. // this.ShowPrefabDLG('LookOn', this.m_GameClientView.node, function (Js) {
  826. // this.m_LookCtrl = Js;
  827. // }.bind(this));
  828. } else {
  829. if (this.m_LookCtrl) this.m_LookCtrl.node.active = false;
  830. }
  831. // this.UpdateLookSitView();
  832. },
  833. UpdateLookSitView: function () {
  834. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  835. var ViewID = this.SwitchViewChairID(i);
  836. var UserItem = this.GetClientUserItem(i);
  837. var NdSit = this.$('LookOnNode/SitNode/BtSit' + i);
  838. if (NdSit) {
  839. NdSit.active = (UserItem == null || UserItem == 0);
  840. NdSit.setPosition(this.m_GameClientView.m_UserPosArr[ViewID]);
  841. }
  842. }
  843. },
  844. OnBtLookOnSit: function (Tag, Data) {
  845. //this.SendFrameData(SUB_GF_LOOKON_SIT);
  846. var LookOn = new CMD_GR_S_LookOnUser();
  847. LookOn.dwUserChairID = parseInt(Data);
  848. this.SendFrameData(SUB_GF_LOOKON_SIT, LookOn);
  849. },
  850. AniFinish: function () {
  851. },
  852. // cpq消息
  853. OnEventCardTestMessage: function (wSubCmdID, pData, wDataSize) {
  854. if (!GameDef.CARD_TEST) return false;
  855. if (!this.m_ReplayMode
  856. && this.m_GameClientView.m_TestCtrl
  857. && this.m_GameClientView.m_TestCtrl.OnEventTestMessage(wSubCmdID, pData, wDataSize)) {
  858. return true;
  859. }
  860. return false;
  861. }
  862. });
  863. cc.GameView = cc.Class({
  864. extends: cc.BaseClass,
  865. properties: {
  866. m_UserPrefab: cc.Prefab, //用户信息预制体
  867. },
  868. InitView: function () {
  869. this.m_GameClientEngine = this.node.parent.getComponent('GameClientEngine_' + GameDef.KIND_ID);
  870. this.TraverseNode(this.node.parent);
  871. if (this.m_BtStart) this.m_BtStart.active = false;
  872. if (this.m_BtFriend) this.m_BtFriend.active = false;
  873. if (this.m_BtChat) this.m_BtChat.active = false;
  874. if (this.m_BtGPS) this.m_BtGPS.active = false;
  875. if (this.m_BtMenu) this.m_BtMenu.active = false;
  876. if (this.m_LbGameRules) this.m_LbGameRules.string = '';
  877. if (this.m_LbGameProgress) this.m_LbGameProgress.string = '';
  878. if (this.m_LbTableID) {
  879. this.m_LbTableID.string = '';
  880. if (window.g_dwRoomID) this.m_LbTableID.string = window.g_dwRoomID;
  881. }
  882. },
  883. //添加相应节点变量
  884. CheckNode: function (TagNode) {
  885. //UI节点
  886. if (TagNode.name == 'JetNode') this.m_JetNode = TagNode;
  887. if (TagNode.name == 'CardNode') this.m_CardNode = TagNode; //左上节点
  888. if (TagNode.name == 'UserNode') this.m_UserNode = TagNode; //左上节点
  889. if (TagNode.name == 'AniNode') this.m_AniNode = TagNode; //左上节点
  890. //
  891. if (TagNode.name == 'PhoneInfo') this.m_NdPhoneNode = TagNode; //左上节点
  892. if (TagNode.name == 'BtStart') this.m_BtStart = TagNode; //开始按钮
  893. if (TagNode.name == 'BtFriend') this.m_BtFriend = TagNode; //分享按钮 m_BtFriend
  894. if (TagNode.name == 'BtChat') this.m_BtChat = TagNode; //聊天按钮
  895. if (TagNode.name == 'BtGPS') this.m_BtGPS = TagNode; //GPS按钮
  896. if (TagNode.name == 'BtMenu') this.m_BtMenu = TagNode; //菜单按钮
  897. if (TagNode.name == 'TableNumber') this.m_LbTableID = TagNode.getComponent(cc.Label); //房间ID
  898. if (TagNode.name == 'ClubNumber') this.m_LbClubID = TagNode.getComponent(cc.Label); //俱乐部ID
  899. if (TagNode.name == 'LabRules') this.m_LbGameRules = TagNode.getComponent(cc.Label); //游戏规则
  900. if (TagNode.name == 'LabProgress') this.m_LbGameProgress = TagNode.getComponent(cc.Label); //游戏进度
  901. if (this.CheckNode2) this.CheckNode2(TagNode);
  902. },
  903. UpdateClubID: function () {
  904. if (this.m_LbClubID) {
  905. if (this.m_GameClientEngine.m_dwClubID > 0)
  906. this.m_LbClubID.string = ''; //'联盟ID:'+this.m_GameClientEngine.m_dwClubID;
  907. else
  908. this.m_LbClubID.string = '';
  909. }
  910. },
  911. //递归遍历子节点
  912. TraverseNode: function (TagNode) {
  913. this.CheckNode(TagNode);
  914. for (var i = 0; i < TagNode.childrenCount; i++) {
  915. this.TraverseNode(TagNode.children[i]);
  916. }
  917. return false;
  918. },
  919. OnBnClickedStart: function () {
  920. cc.gSoundRes.PlaySound('Button');
  921. this.m_GameClientEngine.OnMessageStart();
  922. },
  923. OnBnClickedFriend: function () {
  924. cc.gSoundRes.PlaySound('Button');
  925. this.m_GameClientEngine.OnFriend();
  926. },
  927. UserExpression: function (SendUserID, TagUserID, wIndex) {
  928. var SendChair = INVALID_CHAIR,
  929. RecvChair = INVALID_CHAIR;
  930. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  931. if (this.m_pIClientUserItem[i] == null) continue
  932. if (this.m_pIClientUserItem[i].GetUserID() == SendUserID) SendChair = i;
  933. if (this.m_pIClientUserItem[i].GetUserID() == TagUserID) RecvChair = i;
  934. }
  935. if (wIndex < 2000 && this.m_ChatControl) {
  936. this.m_ChatControl.ShowBubblePhrase(SendChair, wIndex, this.m_pIClientUserItem[SendChair].GetGender(), this.m_pIClientUserItem[SendChair].m_UserInfo.wChairID);
  937. // console.log("======================",this.m_pIClientUserItem[SendChair])
  938. }
  939. else if (wIndex < 3000 && this.m_FaceExCtrl) this.m_FaceExCtrl.OnSendFaceEx(SendChair, RecvChair, wIndex);
  940. },
  941. UserChat: function (SendUserID, TagUserID, str) {
  942. if (this.m_ChatControl == null) return
  943. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  944. if (this.m_pIClientUserItem[i] == null) continue
  945. if (this.m_pIClientUserItem[i].GetUserID() == SendUserID) {
  946. this.m_ChatControl.ShowBubbleChat(i, str);
  947. break;
  948. }
  949. }
  950. },
  951. //聊天按钮回调
  952. OnBnClickedChat: function () {
  953. cc.gSoundRes.PlaySound('Button');
  954. if (this.m_ChatControl == null) return;
  955. this.m_ChatControl.node.active = true;
  956. this.m_ChatControl.ShowSendChat(true);
  957. },
  958. //聊天按钮回调
  959. OnClick_ShowLookOn: function () {
  960. cc.gSoundRes.PlaySound('Button');
  961. this.ShowPrefabDLG('GameLookOnList')
  962. },
  963. OnBtShowGPS: function () {
  964. console.log('OnBtShowGPS')
  965. if (!this.m_TableGPSCtrl) {
  966. this.ShowPrefabDLG('TableUserGPS', this.node, function (Js) {
  967. this.m_TableGPSCtrl = Js;
  968. this.m_TableGPSCtrl.SetGPSUserPos(this.m_UserInfo);
  969. this.m_TableGPSCtrl.InitUser();
  970. this.m_GameClientEngine.GetTableUserGPS();
  971. this.m_TableGPSCtrl.SetUserInfo(this.m_pIClientUserItem);
  972. this.m_TableGPSCtrl.node.zIndex = 1000;
  973. }.bind(this));
  974. return;
  975. } else {
  976. this.m_TableGPSCtrl.OnShowView();
  977. this.m_GameClientEngine.GetTableUserGPS();
  978. this.m_TableGPSCtrl.SetUserInfo(this.m_pIClientUserItem);
  979. }
  980. },
  981. OnGPSAddress: function (GPSInfo) {
  982. if (!this.m_TableGPSCtrl || !this.m_GameClientEngine) return;
  983. this.m_TableGPSCtrl.node.setPosition(0, 0);
  984. this.m_TableGPSCtrl.UpdateAddress(this, GPSInfo);
  985. },
  986. AniFinish: function () {
  987. },
  988. LoadCardTestNode: function () { // 'TestMJ'
  989. if (!USER_CARD_TEST || !GameDef.CARD_TEST) return;
  990. if (this.m_TestCtrl) {
  991. if (this.m_TestCtrl.HideView) this.m_TestCtrl.HideView();
  992. return;
  993. }
  994. if (!this.m_CardTestName) return;
  995. let self = this;
  996. let pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  997. let webUrl = PHP_HOME + '/UserFunc.php?GetMark=99&dwUserID=' + pGlobalUserData.dwUserID;
  998. WebCenter.GetData(webUrl, 0, function (data) {
  999. if (!data) return;
  1000. let UserInfo = JSON.parse(data);
  1001. if (null == UserInfo.UR) return;
  1002. if (0 == (UserInfo.UR & UR_GAME_TEST_USER)) return;
  1003. self.ShowPrefabDLG(self.m_CardTestName, self.node, function (Js) {
  1004. self.m_TestCtrl = Js;
  1005. self.m_TestCtrl.SetGameEngine(this.m_GameClientEngine);
  1006. self.m_TestCtrl.node.active = false;
  1007. }.bind(self));
  1008. }.bind(this));
  1009. },
  1010. OnGetCardTestInfo: function (tag) {
  1011. if (!GameDef.CARD_TEST) return;
  1012. if (!this.m_TestCtrl) return;
  1013. if (this.m_TestCtrl.node.active) {
  1014. this.m_TestCtrl.node.active = false;
  1015. return;
  1016. }
  1017. //this.m_TestCtrl.node.active = true;
  1018. if (1 == tag) this.m_TestCtrl.ShowUserCheatCtrl();
  1019. else if (2 == tag) this.m_TestCtrl.ShowCardCheatCtrl();
  1020. },
  1021. OnGetCardTestInfo2: function () {
  1022. if (!this.m_TestCtrl) return;
  1023. this.m_TestCtrl.node.active = true;
  1024. }
  1025. });
  1026. cc.BaseControl = cc.Class({
  1027. extends: cc.BaseClass,
  1028. properties: {},
  1029. ctor: function () {
  1030. this.m_fScaleValue = 1;
  1031. this.m_BenchmarkPos = cc.v2(0, 0);
  1032. this.m_AnchorPoint = cc.v2(0.5, 0.5);
  1033. this.m_CollocateMode = cc.v2(0, 0);
  1034. },
  1035. onLoad: function () {
  1036. },
  1037. start: function () {
  1038. },
  1039. SetAttribute: function (Attribute) {
  1040. this.m_Attribute = Attribute;
  1041. if (this.SetAttribute2) {
  1042. this.SetAttribute2();
  1043. }
  1044. },
  1045. //基准位置
  1046. SetBenchmarkPos: function (nXPos, nYPos, ModeX, ModeY) {
  1047. this.m_BenchmarkPos.x = nXPos;
  1048. this.m_BenchmarkPos.y = nYPos;
  1049. this.m_AnchorPoint.x = 0.5 * (ModeX - 1);
  1050. this.m_AnchorPoint.y = 0.5 * (ModeY - 1);
  1051. this.m_CollocateMode.x = ModeX;
  1052. this.m_CollocateMode.y = ModeY;
  1053. if (this.SetBenchmarkPos2) {
  1054. this.SetBenchmarkPos2()
  1055. }
  1056. },
  1057. //缩放
  1058. SetScale: function (fScaleValue) {
  1059. this.m_fScaleValue = fScaleValue;
  1060. if (this.SetScale2) {
  1061. this.SetScale2();
  1062. }
  1063. },
  1064. SetTouchOn: function () {
  1065. try {
  1066. if (this.onTouchBegan) this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchBegan, this);
  1067. if (this.onTouchMove) this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
  1068. if (this.onTouchEnded) this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnded, this);
  1069. if (this.onTouchCancel) this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
  1070. } catch (error) {
  1071. ASSERT(false, ' In BaseControl-SetTouchOn catch error is ' + error);
  1072. }
  1073. },
  1074. NewNode: function (Parent, Component) {
  1075. try {
  1076. var TempNode = new cc.Node();
  1077. if (!TempNode) return null;
  1078. if (Parent instanceof cc.Node) {
  1079. Parent.addChild(TempNode);
  1080. } else if (Parent.node instanceof cc.Node) {
  1081. Parent.node.addChild(TempNode);
  1082. }
  1083. if (Component) {
  1084. if (Component instanceof cc.Node) return TempNode;
  1085. TempNode.addComponent(Component);
  1086. return TempNode;
  1087. } else {
  1088. ASSERT(false, ' In BaseControl-NewNode wrong Component is ' + Component);
  1089. return TempNode;
  1090. }
  1091. } catch (error) {
  1092. ASSERT(false, ' In BaseControl-NewNode catch error is ' + error);
  1093. }
  1094. },
  1095. RemoveIntoPool: function (jsArr, Pool) {
  1096. try {
  1097. if (jsArr == null) jsArr = new Array();
  1098. for (var i in jsArr) {
  1099. if (jsArr[i] instanceof cc.Node) {
  1100. // jsArr[i].parent = null;
  1101. Pool.put(jsArr[i]);
  1102. } else if (jsArr[i].node instanceof cc.Node) {
  1103. // jsArr[i].node.parent = null;
  1104. Pool.put(jsArr[i].node);
  1105. }
  1106. }
  1107. jsArr.splice(0, jsArr.length);
  1108. } catch (error) {
  1109. ASSERT(false, ' In BaseControl-RemoveIntoPool catch error is ' + error);
  1110. }
  1111. },
  1112. RemoveIntoPoolByID: function (jsArr, Pool, cbID) {
  1113. try {
  1114. if (jsArr == null) jsArr = new Array();
  1115. if (!jsArr[cbID]) return;
  1116. if (jsArr[cbID] instanceof cc.Node) {
  1117. Pool.put(jsArr[cbID]);
  1118. } else if (jsArr[cbID].node instanceof cc.Node) {
  1119. Pool.put(jsArr[cbID].node);
  1120. }
  1121. jsArr.splice(cbID, 1);
  1122. } catch (error) {
  1123. ASSERT(false, ' In BaseControl-RemoveIntoPoolByID catch error is ' + error);
  1124. }
  1125. },
  1126. GetPreFormPool: function (Pool, SouceNode, Parent, Com1, Com2) {
  1127. try {
  1128. var TempNode;
  1129. if (Pool.size()) {
  1130. TempNode = Pool.get();
  1131. if (Parent instanceof cc.Node) Parent.addChild(TempNode);
  1132. else if (Parent.node instanceof cc.Node) Parent.node.addChild(TempNode);
  1133. } else {
  1134. if (SouceNode) {
  1135. if (SouceNode instanceof cc.Node) {
  1136. TempNode = cc.instantiate(SouceNode);
  1137. } else if (SouceNode.node instanceof cc.Node) {
  1138. TempNode = SouceNode.node;
  1139. }
  1140. if (Parent instanceof cc.Node) Parent.addChild(TempNode);
  1141. else if (Parent.node instanceof cc.Node) Parent.node.addChild(TempNode);
  1142. }
  1143. else {
  1144. TempNode = this.NewNode(Parent, Com1);
  1145. }
  1146. }
  1147. var js1 = TempNode;
  1148. if (Com1 != cc.Node) js1 = TempNode.getComponent(Com1);
  1149. if (js1) js1.m_Hook = this;
  1150. var js2 = null;
  1151. if (Com2) js2 = TempNode;
  1152. if (Com2 && Com2 != cc.Node) js2 = TempNode.getComponent(Com2);
  1153. if (js2) js2.m_Hook = this;
  1154. ASSERT(js1, ' In BaseControl-GetPreFormPool js1 is ' + js1 + '; Com1=' + Com1 + '; Com2=' + Com2);
  1155. return [js1, js2];
  1156. } catch (error) {
  1157. ASSERT(false, ' In BaseControl-GetPreFormPool catch error is ' + error);
  1158. }
  1159. },
  1160. //递归遍历子节点查找目标节点
  1161. // SearchInfo: ContentArray, SouceNode, SearchCom, HandlerComponet, HandlerFunc, CustomData
  1162. TraverseNode: function (SearchInfo) {
  1163. try {
  1164. if (!SearchInfo.SouceNode) return false;
  1165. var pCom = null;
  1166. if (SearchInfo.SouceNode instanceof cc.Node) pCom = SearchInfo.SouceNode.getComponent(SearchInfo.SearchCom);
  1167. else if (SearchInfo.SouceNode.node instanceof cc.Node) pCom = SearchInfo.SouceNode.node.getComponent(SearchInfo.SearchCom);
  1168. if (pCom) {
  1169. if (SearchInfo.HandlerComponet && SearchInfo.HandlerFunc) {
  1170. var pHandler = new cc.Component.EventHandler();
  1171. pHandler.target = this.node;
  1172. pHandler.component = SearchInfo.HandlerComponet;
  1173. pHandler.handler = SearchInfo.HandlerFunc;
  1174. if (SearchInfo.CustomData != null) pHandler.customEventData = SearchInfo.CustomData;
  1175. pCom.clickEvents.push(pHandler);
  1176. }
  1177. if (window.LOG_NET_DATA) console.log(" In BaseControl TraverseNode --------------- ");
  1178. if (window.LOG_NET_DATA) console.log("TraverseNode index: " + SearchInfo.ContentArray.length + " => " + pCom.node.name + " -- ");
  1179. if (window.LOG_NET_DATA) console.log(SearchInfo);
  1180. if (window.LOG_NET_DATA) console.log(" --------------- ");
  1181. if (SearchInfo.ContentArray) SearchInfo.ContentArray.push(pCom);
  1182. return true;
  1183. }
  1184. for (var i = 0; i < SearchInfo.SouceNode.childrenCount; i++) {
  1185. this.TraverseNode({
  1186. ContentArray: SearchInfo.ContentArray,
  1187. SouceNode: SearchInfo.SouceNode.children[i],
  1188. SearchCom: SearchInfo.SearchCom,
  1189. HandlerComponet: SearchInfo.HandlerComponet,
  1190. HandlerFunc: SearchInfo.HandlerFunc,
  1191. CustomData: i,
  1192. });
  1193. }
  1194. return false;
  1195. } catch (error) {
  1196. ASSERT(false, ' In BaseControl-TraverseNode catch error is ' + error);
  1197. }
  1198. },
  1199. AddClickHandler: function (souce, target, component, handler, CustomData) {
  1200. try {
  1201. for (var i in souce.clickEvents) {
  1202. if (souce.clickEvents[i].target == target && souce.clickEvents[i].component == component && souce.clickEvents[i].handler) {
  1203. if (CustomData != null) souce.clickEvents[i].customEventData = CustomData;
  1204. return;
  1205. }
  1206. }
  1207. var pHandler = new cc.Component.EventHandler();
  1208. pHandler.target = target;
  1209. pHandler.component = component;
  1210. pHandler.handler = handler;
  1211. if (CustomData != null) pHandler.customEventData = CustomData;
  1212. souce.clickEvents.push(pHandler);
  1213. } catch (error) {
  1214. ASSERT(false, ' In BaseControl-AddClickHandler catch error is ' + error);
  1215. }
  1216. },
  1217. //递归遍历子节点查找复选框
  1218. TraverseToggle: function (TagNode, pArray) {
  1219. if (!TagNode) return false;
  1220. if (!pArray) return false;
  1221. if (TagNode.name[0] != '$') {
  1222. var js = TagNode.getComponent(cc.Toggle);
  1223. if (js) {
  1224. pArray.push(js);
  1225. return true;
  1226. }
  1227. }
  1228. for (var i = 0; i < TagNode.childrenCount; i++) {
  1229. if (TagNode.children[i].name[0] == '$') continue;
  1230. this.TraverseToggle(TagNode.children[i], pArray);
  1231. }
  1232. return false;
  1233. },
  1234. GetPair: function (pToggle) {
  1235. if (!pToggle) return null;
  1236. var cbIndex = pToggle.node.name.indexOf('_');
  1237. if (cbIndex != -1) {
  1238. return {
  1239. key: pToggle.node.name.slice(0, cbIndex),
  1240. value: pToggle.node.name.slice(cbIndex + 1)
  1241. };
  1242. }
  1243. return null;
  1244. },
  1245. });
  1246. // 分享
  1247. cc.share = {
  1248. Type: cc.Enum({
  1249. NULL: 0,
  1250. Login: 1,
  1251. Download: 2,
  1252. InviteRoom: 3,
  1253. InviteClub: 4,
  1254. GameEnd: 5,
  1255. }),
  1256. Mode: cc.Enum({
  1257. NULL: 0,
  1258. Auto: 1,
  1259. ToH5: 2,
  1260. ToApp: 3,
  1261. }),
  1262. LoadConfig: function (callback) {
  1263. window.GetConfig('ShareLinkH5', {
  1264. error: function (e) {
  1265. if (LOG_WEB_DATA) console.log('请配置分享链接!');
  1266. if (callback) callback(null);
  1267. },
  1268. success: function (res) {
  1269. if (!res) {
  1270. if (LOG_WEB_DATA) console.log('分享链接-配置数据异常!');
  1271. if (callback) callback(null);
  1272. return;
  1273. }
  1274. if (res.String && res.String.length > 1) {
  1275. // 回调数据处理
  1276. window.SHARE_URL_H5 = res.String;
  1277. if (LOG_WEB_DATA && res.State == 1) console.log(res.Tip + ' 获取成功!');
  1278. if (callback) callback(res.String);
  1279. } else {
  1280. if (LOG_WEB_DATA && res.State == 1) console.log('请配置 ' + res.Tip);
  1281. if (callback) callback(res.String);
  1282. }
  1283. },
  1284. });
  1285. window.GetConfig('ShareLinkApp', {
  1286. error: function (e) {
  1287. if (LOG_WEB_DATA) console.log('请配置分享链接!');
  1288. if (callback) callback(null);
  1289. },
  1290. success: function (res) {
  1291. if (!res) {
  1292. if (LOG_WEB_DATA) console.log('分享链接-配置数据异常!');
  1293. if (callback) callback(null);
  1294. return;
  1295. }
  1296. if (res.String && res.String.length > 1) {
  1297. // 回调数据处理
  1298. window.SHARE_URL = res.String;
  1299. if (LOG_WEB_DATA && res.State == 1) console.log(res.Tip + ' 获取成功!');
  1300. if (callback) callback(res.String);
  1301. } else {
  1302. if (LOG_WEB_DATA && res.State == 1) console.log('请配置 ' + res.Tip);
  1303. if (callback) callback(res.String);
  1304. }
  1305. },
  1306. });
  1307. },
  1308. InitShareInfo_H5_WX: function (ShareFunc) {
  1309. if (this.IsH5_WX() && ShareFunc) {
  1310. var ShareInfo = ShareFunc();
  1311. if (ShareInfo) {
  1312. ThirdPartyShareMessage(ShareInfo, 0);
  1313. ThirdPartyShareMessage(ShareInfo, 1);
  1314. return true;
  1315. }
  1316. }
  1317. return false;
  1318. },
  1319. // 串接参数
  1320. Stringify: function (param) {
  1321. try {
  1322. var str = '';
  1323. if (typeof param == 'string') {
  1324. str = param;
  1325. } else if (typeof param == 'object') {
  1326. str = JSON.stringify(param);
  1327. } else {
  1328. return '';
  1329. }
  1330. var res = encodeURIComponent(unescape(str));
  1331. return res;
  1332. } catch (e) {
  1333. if (window.LOG_DEBUG) console.log(e);
  1334. return '';
  1335. }
  1336. },
  1337. // 解析参数
  1338. Parse: function (param) {
  1339. try {
  1340. var str = decodeURIComponent(param);
  1341. var obj = JSON.parse(str);
  1342. return obj;
  1343. } catch (e) {
  1344. if (window.LOG_DEBUG) console.log(e);
  1345. return null;
  1346. }
  1347. },
  1348. IsH5_WX: function (mode) {
  1349. if (mode == this.Mode.Auto || !!!mode) {
  1350. return (cc.sys.isBrowser && (cc.sys.browserType == cc.sys.BROWSER_TYPE_WECHAT || cc.sys.browserType == cc.sys.BROWSER_TYPE_MOBILE_QQ || cc.sys.browserType == cc.sys.BROWSER_TYPE_QQ));
  1351. } else if (mode == this.Mode.ToH5) {
  1352. return true;
  1353. } else {
  1354. return false;
  1355. }
  1356. },
  1357. MakeLink_InviteRoom: function (roomID, clubID, mode) {
  1358. if (this.IsH5_WX(mode)) {
  1359. var obj = {};
  1360. obj.type = this.Type.InviteRoom;
  1361. obj.value = [roomID, clubID];
  1362. var link = `${window.SHARE_URL_H5}${this.Stringify(obj)}`;
  1363. return link;
  1364. } else {
  1365. return window.SHARE_URL;
  1366. }
  1367. },
  1368. MakeLink_InviteClub: function (kind, allianceID, mode) {
  1369. if (this.IsH5_WX(mode)) {
  1370. var obj = {};
  1371. obj.type = this.Type.InviteClub;
  1372. obj.value = [kind, allianceID];
  1373. var link = `${window.SHARE_URL_H5}${this.Stringify(obj)}`;
  1374. return link;
  1375. } else {
  1376. return window.SHARE_URL;
  1377. }
  1378. },
  1379. MakeLink_GameEnd: function (mode) {
  1380. if (this.IsH5_WX(mode)) {
  1381. return `${window.SHARE_URL_H5}0`;
  1382. } else {
  1383. return window.SHARE_URL;
  1384. }
  1385. },
  1386. MakeLink_Lobby: function (mode) {
  1387. if (this.IsH5_WX(mode)) {
  1388. return `${window.SHARE_URL_H5}0`;
  1389. } else {
  1390. return window.SHARE_URL;
  1391. }
  1392. },
  1393. MakeLink_Download: function (mode) {
  1394. if (this.IsH5_WX(mode)) {
  1395. return `${window.SHARE_URL_H5}0`;
  1396. } else {
  1397. return window.SHARE_URL;
  1398. }
  1399. },
  1400. GetShareParam: function (type) {
  1401. if (cc.sys.isNative) return null;
  1402. var state = getQueryString("state");
  1403. var param = null;
  1404. if (state && state != '') {
  1405. param = this.Parse(state);
  1406. }
  1407. var obj = {};
  1408. switch (type) {
  1409. case this.Type.InviteRoom: {
  1410. if (param && param.type == type) {
  1411. obj.roomNum = param.value[0];
  1412. obj.clubID = param.value[1];
  1413. } else {
  1414. obj.roomNum = 0;
  1415. obj.clubID = 0;
  1416. }
  1417. break;
  1418. }
  1419. case this.Type.InviteClub: {
  1420. if (param && param.type == type) {
  1421. obj.kind = param.value[0];
  1422. obj.allianceID = param.value[1];
  1423. } else {
  1424. obj.kind = 0;
  1425. obj.allianceID = 0;
  1426. }
  1427. break;
  1428. }
  1429. }
  1430. return obj;
  1431. },
  1432. }