BaseClass.js 58 KB

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