BaseClass.js 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601
  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. console.log("房间信息--", pRoomInfo)
  481. this.m_dwRulesArr = pRoomInfo.dwRulesArr;
  482. this.m_dwServerRules = pRoomInfo.dwServerRules;
  483. this.m_dwClubID = pRoomInfo.dwClubID;
  484. this.m_dwRoomID = pRoomInfo.dwRoomID;
  485. this.m_dwRoomID2 = pRoomInfo.dwRoomID2;
  486. this.m_dwCreater = pRoomInfo.dwCreaterID;
  487. window.RoomID = this.m_dwRoomID
  488. ShowLobbyClub = pRoomInfo.dwClubID;
  489. window.RuleArr = this.m_dwRulesArr;
  490. window.ServerRules = this.m_dwServerRules;
  491. this.SetViewRoomInfo(this.m_dwServerRules, this.m_dwRulesArr);
  492. this.OnUserReSit();
  493. //房间记录
  494. var TempStr = cc.sys.localStorage.getItem(window.clientName + 'RoomHistory');
  495. var TempArr = new Array();
  496. if (TempStr) TempArr = JSON.parse(TempStr);
  497. if (this.m_dwRoomID > 0) {
  498. var bNotIn = true;
  499. for (var i in TempArr) {
  500. if (TempArr[i] == this.m_dwRoomID) bNotIn = false;
  501. }
  502. //if(bNotIn)TempArr.push(this.m_dwRoomID);
  503. }
  504. cc.sys.localStorage.setItem(window.clientName + 'RoomHistory', JSON.stringify(TempArr));
  505. //更新GPS
  506. if (GameDef.IsNoCheat(this.m_dwRulesArr)) this.GetSelfGPSInfo();
  507. //显示邀请按钮
  508. if (g_Table && g_Table.OnSetInviteBtShow) g_Table.OnSetInviteBtShow(this.GetMeUserItem());
  509. //微信H5分享链接
  510. cc.share.InitShareInfo_H5_WX(this.GetShareInfo.bind(this));
  511. return true;
  512. }
  513. case SUB_GF_ROOM_STATUS: {
  514. var pRoomStatus = new CMD_GF_RoomStatus();
  515. pRoomStatus.bLockArr = new Array(GameDef.GAME_PLAYER);
  516. if (datasize != gCByte.Bytes2Str(pRoomStatus, data)) return false;
  517. // this.m_wGameProgress = pRoomStatus.wProgress;
  518. this.m_LockArr = pRoomStatus.bLockArr;
  519. var kernel = gClientKernel.get();
  520. this.m_bLockInRoom = pRoomStatus.bLockArr[this.GetMeChairID()] && !kernel.IsLookonMode();
  521. //更新界面
  522. // this.m_GameClientView.UpdateRoomProgress();
  523. //更新GPS
  524. if (GameDef.IsNoCheat(this.m_dwRulesArr)) this.GetSelfGPSInfo();
  525. return true;
  526. }
  527. case SUB_GF_ROOM_GAME_FINISH: {
  528. this.OnEventRoomEnd(data, datasize);
  529. if (!this.m_ReplayMode) {
  530. this.m_TableViewFrame.mServerItem.IntermitConnect(false);
  531. }
  532. return true;
  533. }
  534. case SUB_GF_ROOM_DISSOLVE: {
  535. this.m_TableViewFrame.mServerItem.IntermitConnect(false);
  536. this.ShowAlert("房間已解散!", Alert_Yes, function (Res) {
  537. self.m_pTableScene.ExitGame();
  538. });
  539. return true;
  540. }
  541. case SUB_GF_ROOM_USER_DISSOLVE: {
  542. this.m_UserDiss = new CMD_GF_UserDissolve();
  543. if (datasize != gCByte.Bytes2Str(this.m_UserDiss, data)) return false;
  544. this.m_DissolveRes = null;
  545. this.m_UserDiss.byChoose = new Array();
  546. g_TimerEngine.PauseGameTimer();
  547. this.ShowPrefabDLG('DissolveRoom', this.node, function (Js) {
  548. this.m_DisCtrl = Js;
  549. this.m_DisCtrl.SetDissolveInfo(this.m_UserDiss.dwDisUserID, this.m_UserDiss.byChoose, this.m_UserDiss.dwAllCountDown, this.m_LockArr, this.m_UserDiss.dwAllCountDown);
  550. if (this.m_DissolveRes) this.m_DisCtrl.SetDisRes(this.m_DissolveRes.bDissolve);
  551. }.bind(this));
  552. return true;
  553. }
  554. case SUB_GF_ROOM_DISSOLVE_STATUS: {
  555. this.m_UserDiss = new CMD_GF_RoomDissolve();
  556. this.m_UserDiss.byChoose = new Array(GameDef.GAME_PLAYER);
  557. if (datasize != gCByte.Bytes2Str(this.m_UserDiss, data)) return false;
  558. this.m_DissolveRes = null;
  559. g_TimerEngine.PauseGameTimer();
  560. this.ShowPrefabDLG('DissolveRoom', this.node, function (Js) {
  561. this.m_DisCtrl = Js;
  562. this.m_DisCtrl.SetDissolveInfo(this.m_UserDiss.dwDisUserID, this.m_UserDiss.byChoose, this.m_UserDiss.dwCountDown, this.m_LockArr, this.m_UserDiss.dwAllCountDown);
  563. if (this.m_DissolveRes) this.m_DisCtrl.SetDisRes(this.m_DissolveRes.bDissolve);
  564. }.bind(this));
  565. return true;
  566. }
  567. case SUB_GF_ROOM_USERCHOOSE: {
  568. var pUserDiss = new CMD_GF_UserChooseRes();
  569. if (datasize != gCByte.Bytes2Str(pUserDiss, data)) return false;
  570. if (pUserDiss.byRes == 0) pUserDiss.byRes = 2;
  571. if (this.m_DisCtrl != null) {
  572. this.m_DisCtrl.SetUserChoose(pUserDiss.wChairID, pUserDiss.byRes);
  573. } else if (this.m_UserDiss != null) {
  574. this.m_UserDiss.byChoose[pUserDiss.wChairID] = pUserDiss.byRes;
  575. } else {
  576. this.ShowTips("DissolveRoom creat err??")
  577. }
  578. return true;
  579. }
  580. case SUB_GF_ROOM_DISSOLVE_RES: {
  581. this.m_DissolveRes = new CMD_GF_DissolveRes();
  582. if (datasize != gCByte.Bytes2Str(this.m_DissolveRes, data)) return false;
  583. g_TimerEngine.UnPauseGameTimer();
  584. if (this.m_DisCtrl) this.m_DisCtrl.SetDisRes(this.m_DissolveRes.bDissolve)
  585. return true;
  586. }
  587. }
  588. return false;
  589. },
  590. //发送数据
  591. SendGameData: function (wSubCmdID, Obj) {
  592. var kernel = gClientKernel.get();
  593. if (kernel != null) this.sendClass(MDM_GF_GAME, wSubCmdID, Obj);
  594. },
  595. //发送数据
  596. SendFrameData: function (wSubCmdID, Obj) {
  597. this.sendClass(MDM_GF_FRAME, wSubCmdID, Obj);
  598. return true;
  599. },
  600. sendClass: function (wMainCmdID, wSubCmdID, Obj) {
  601. var kernel = gClientKernel.get();
  602. if (kernel != null) kernel.SendSocketClass(wMainCmdID, wSubCmdID, Obj);
  603. },
  604. OnClick_CheckOut: function () {
  605. cc.gSoundRes.PlaySound('Button');
  606. window.isJoinGame =false;
  607. if (this.m_dwCreater != 0) {
  608. var kernel = gClientKernel.get();
  609. if (this.m_wGameProgress == 0 && this.m_dwCreater == kernel.mMeUserItem.GetUserID()) {
  610. this.ShowAlert("確認解散該房間?", Alert_All, function (Res) {
  611. if (Res) this.sendClass(MDM_GF_CARDROOM, SUB_GF_CREATER_DISSOLVE);
  612. }.bind(this));
  613. }
  614. if (this.m_wGameProgress > 0) {
  615. this.ShowAlert("確認申請解散?", Alert_All, function (Res) {
  616. if (Res) this.sendClass(MDM_GF_CARDROOM, SUB_GF_USER_DISSOLVE);
  617. }.bind(this));
  618. }
  619. }
  620. // else if(GameDef.m_dwGameRuleArr[3] > 0){
  621. // if (this.m_wGameProgress > 0) {
  622. // this.ShowAlert("確認申請解散?", Alert_All, function (Res) {
  623. // if (Res) this.sendClass(MDM_GF_CARDROOM, SUB_GF_USER_DISSOLVE);
  624. // }.bind(this));
  625. // }
  626. // }
  627. },
  628. OnBtReturn: function () {
  629. cc.gSoundRes.PlaySound('Button');
  630. window.isJoinGame =false;
  631. if (this.m_RoomEnd != null) return this.m_pTableScene.ExitGame();
  632. this.ShowAlert("確定要退出遊戲嗎?", Alert_YesNo, function (Res) {
  633. if (Res) this.m_pTableScene.ExitGame();
  634. }.bind(this));
  635. },
  636. OnBtChangeTable: function () {
  637. cc.gSoundRes.PlaySound('Button');
  638. if (this.m_pTableScene && this.m_pTableScene.m_ServerItem)
  639. this.m_pTableScene.m_ServerItem.ChangeTable();
  640. },
  641. //////////////////////////////////////////////////////////////////////////
  642. //获取用户
  643. GetClientUserItem: function (wChairID) {
  644. var kernel = gClientKernel.get();
  645. if (kernel == null) return null;
  646. return kernel.GetTableUserItem(wChairID);
  647. },
  648. IsValidChairID: function (wChairID) {
  649. if (wChairID >= 0 && wChairID < GameDef.GAME_PLAYER) return true;
  650. return false;
  651. },
  652. // 获取座位
  653. GetUserChairID: function (dwUserID) {
  654. for (var i = 0; i < GameDef.GAME_PLAYER; ++i) {
  655. var pIClientUserItem = this.GetClientUserItem(i);
  656. if (!pIClientUserItem) continue;
  657. if (pIClientUserItem.GetUserID() == dwUserID) return i;
  658. }
  659. return INVALID_CHAIR;
  660. },
  661. // 快捷短语
  662. OnSendPhrase: function (wItemID, TagUser) {
  663. var pExpression = new CMD_GF_C_UserExpression();
  664. pExpression.wItemIndex = wItemID;
  665. pExpression.dwTargetUserID = TagUser;
  666. this.SendFrameData(SUB_GF_USER_EXPRESSION, pExpression);
  667. },
  668. // 发送聊天
  669. OnSendChat: function (szText) {
  670. var pChithat = new CMD_GF_C_UserChat();
  671. pChithat.szChatString = szText + '\0';
  672. pChithat.wChatLength = pChithat.szChatString.length;
  673. pChithat.len_szChatString = pChithat.wChatLength * cc.TCHAR_SIZE;
  674. this.SendFrameData(SUB_GF_USER_CHAT, pChithat);
  675. },
  676. // 快捷短语
  677. OnSubUserPhrase: function (pData, wDataSize) {
  678. //效验
  679. var pShortcutPhrase = new CMD_GR_S_UserExpression();
  680. if (wDataSize != gCByte.Bytes2Str(pShortcutPhrase, pData)) return false;
  681. this.m_GameClientView.UserExpression(pShortcutPhrase.dwSendUserID, pShortcutPhrase.dwTargetUserID, pShortcutPhrase.wItemIndex)
  682. return true;
  683. },
  684. // 用户聊天
  685. OnSubUserChat: function (pData, wDataSize) {
  686. //效验
  687. var pChithat = new CMD_GF_S_UserChat();
  688. gCByte.Bytes2Str(pChithat, pData);
  689. this.m_GameClientView.UserChat(pChithat.dwSendUserID, pChithat.dwTargetUserID, pChithat.szChatString);
  690. return true;
  691. },
  692. ShowEndView: function () {
  693. console.log("ShowEndView--结束")
  694. if (this.m_ReplayMode) {
  695. this.RealShowEndView();
  696. } else {
  697. this.schedule(this.RealShowEndView, 3)
  698. }
  699. },
  700. RealShowEndView: function () {
  701. console.log("RealShowEndView--结束")
  702. this.unschedule(this.RealShowEndView)
  703. this.ShowPrefabDLG("GameEndInfo", null, function (Js) {
  704. this.m_REndCtrl = Js;
  705. }.bind(this));
  706. },
  707. //分享信息
  708. GetShareInfo: function () {
  709. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  710. var ShareInfo = new Object();
  711. ShareInfo.title = '房号【' + this.m_dwRoomID + '】 ' + g_GlobalUserInfo.m_UserInfoMap[pGlobalUserData.dwUserID].NickName + "邀请您来玩" + window.GameList[GameDef.KIND_ID];
  712. ShareInfo.desc = this.m_GameClientView.m_LbGameRules.string;
  713. ShareInfo.imgUrl = window.PHP_HOME + '/app01/App.jpg'
  714. ShareInfo.link = cc.share.MakeLink_InviteRoom(this.m_dwRoomID, this.m_dwClubID);
  715. return ShareInfo;
  716. },
  717. //点击设置
  718. OnBtClickedSet: function () {
  719. cc.gSoundRes.PlaySound('Button');
  720. this.ShowPrefabDLG('Setting');
  721. },
  722. OnClicked_GameSetting: function () {
  723. cc.gSoundRes.PlaySound('Button');
  724. this.ShowPrefabDLG('GameSetting', this.node, function (Js) {
  725. this.m_GameSetting = Js;
  726. this.m_GameSetting.SetGame(GameDef);
  727. }.bind(this));
  728. },
  729. //点击设置
  730. OnBtClick_BtMenu: function (Tag) {
  731. cc.gSoundRes.PlaySound('Button');
  732. this.ShowPrefabDLG('GameSetMenu', Tag.currentTarget.parent);
  733. },
  734. OnClick_BtLookOnList: function () {
  735. this.ShowPrefabDLG('GameLookOnList')
  736. },
  737. //+++++++录音和播放需要添加的内容 start++++++
  738. //发消息给其它玩家
  739. OnSendUserVoice: function (Platform, VoiceID) {
  740. var pVoice = new CMD_GF_C_UserVoice();
  741. pVoice.szVID = VoiceID;
  742. pVoice.byPlatform = Platform;
  743. this.SendFrameData(SUB_GF_USER_VOICE, pVoice);
  744. },
  745. OnSendUserVoice_A: function (Platform, VoiceID) {
  746. var pVoice = new CMD_GF_C_UserVoice_A();
  747. pVoice.szVID = VoiceID;
  748. pVoice.byPlatform = Platform;
  749. this.SendFrameData(SUB_GF_USER_VOICE_A, pVoice);
  750. },
  751. OnSubUserVoice: function (pData, wDataSize) {
  752. if (window.LOG_NET_DATA) console.log('OnSubUserVoice返回-1');
  753. //效验
  754. var pVoice = new CMD_GF_S_UserVoice();
  755. if (gCByte.Bytes2Str(pVoice, pData) != wDataSize) {
  756. if (window.LOG_NET_DATA) console.log('语音包大小错误!', wDataSize);
  757. // return false; todo
  758. return true;
  759. }
  760. //显示播放
  761. var VoiceCtrl = this.GetVoiceCtrl();
  762. if (VoiceCtrl) VoiceCtrl.PlayVoice(pVoice);
  763. return true;
  764. },
  765. OnSubUserVoice_A: function (pData, wDataSize) {
  766. if (window.LOG_NET_DATA) console.log('OnSubUserVoice返回A-1');
  767. //效验
  768. var pVoice = new CMD_GF_S_UserVoice_A();
  769. if (gCByte.Bytes2Str(pVoice, pData) != wDataSize) {
  770. if (window.LOG_NET_DATA) console.log('语音包大小错误A!', wDataSize);
  771. // return false; todo
  772. return true;
  773. }
  774. //显示播放
  775. var VoiceCtrl = this.GetVoiceCtrl();
  776. if (VoiceCtrl) VoiceCtrl.PlayVoice(pVoice);
  777. return true;
  778. },
  779. GetVoiceCtrl: function () {
  780. return this.m_GameClientView.m_VoiceCtrl;
  781. },
  782. //+++++++录音和播放需要添加的内容 end++++++
  783. GetSelfGPSInfo: function () {
  784. if (this.m_ReplayMode) return;
  785. if (this.IsLookonMode()) return;
  786. if (window.g_CntGameGPS >= 3) return;
  787. if (window.g_CntGameGPS > 0) g_CurScene.m_bTipGPS = false;
  788. window.g_CntGameGPS++;
  789. if (cc.sys.isNative) {
  790. ThirdPartyGetAddress();
  791. } else {
  792. var GPSInfo = new tagUserGps();
  793. var bShow = cc.sys.localStorage.getItem(window.Key_ShowGPS);
  794. if (bShow == null) bShow = 0;
  795. GPSInfo.byHide = parseInt(bShow);
  796. GPSInfo.dlatitude = 0;
  797. GPSInfo.dlongitude = 0;
  798. GPSInfo.szAddress = 'H5登入暫時無法獲取資訊!';
  799. this.SendFrameData(SUB_GF_GPS_INFO_SAVE, GPSInfo);
  800. }
  801. },
  802. UpdateGPS: function (Info) {
  803. if (Info == "") return
  804. var Obj = JSON.parse(Info);
  805. if (Obj.berror == true || Obj.code != 0) {
  806. this.unschedule(this.GetSelfGPSInfo);
  807. this.scheduleOnce(this.GetSelfGPSInfo, 3);
  808. return;
  809. }
  810. var pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  811. var GPSInfo = new tagUserGps();
  812. var bShow = cc.sys.localStorage.getItem(window.Key_ShowGPS);
  813. if (bShow == null) bShow = 0;
  814. GPSInfo.byHide = parseInt(bShow);
  815. GPSInfo.dlatitude = (Obj.latitude) * 1;
  816. GPSInfo.dlongitude = (Obj.longitude) * 1;
  817. GPSInfo.szAddress = Obj.address;
  818. if (GPSInfo.szAddress == '') GPSInfo.szAddress = '用戶運行環境無法準確獲取地理位置!';
  819. this.SendFrameData(SUB_GF_GPS_INFO_SAVE, GPSInfo);
  820. },
  821. IsLookonMode: function () {
  822. var kernel = gClientKernel.get();
  823. if (kernel && kernel.IsLookonMode()) return true;
  824. return false;
  825. },
  826. //设置状态
  827. SetGameStatus: function (cbGameStatus) {
  828. this.m_cbGameStatus = cbGameStatus;
  829. },
  830. GetGameStatus: function () {
  831. return this.m_cbGameStatus;
  832. },
  833. GetTableUserGPS: function () {
  834. this.SendFrameData(SUB_GF_GPS_INFO_GET);
  835. },
  836. OnGetTableGPSRes: function (GPSInfo) {
  837. if (this.m_GameClientView.OnGPSAddress) this.m_GameClientView.OnGPSAddress(GPSInfo);
  838. },
  839. ////////////////////////////////////////////////////////////////////////////////
  840. ShowLookOnView: function (bShow) {
  841. if (bShow) {
  842. this.OnBtLookOnSit();
  843. // this.ShowPrefabDLG('LookOn', this.m_GameClientView.node, function (Js) {
  844. // this.m_LookCtrl = Js;
  845. // }.bind(this));
  846. } else {
  847. if (this.m_LookCtrl) this.m_LookCtrl.node.active = false;
  848. }
  849. // this.UpdateLookSitView();
  850. },
  851. UpdateLookSitView: function () {
  852. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  853. var ViewID = this.SwitchViewChairID(i);
  854. var UserItem = this.GetClientUserItem(i);
  855. var NdSit = this.$('LookOnNode/SitNode/BtSit' + i);
  856. if (NdSit) {
  857. NdSit.active = (UserItem == null || UserItem == 0);
  858. NdSit.setPosition(this.m_GameClientView.m_UserPosArr[ViewID]);
  859. }
  860. }
  861. },
  862. OnBtLookOnSit: function (Tag, Data) {
  863. //this.SendFrameData(SUB_GF_LOOKON_SIT);
  864. var LookOn = new CMD_GR_S_LookOnUser();
  865. LookOn.dwUserChairID = parseInt(Data);
  866. this.SendFrameData(SUB_GF_LOOKON_SIT, LookOn);
  867. },
  868. AniFinish: function () {
  869. },
  870. // cpq消息
  871. OnEventCardTestMessage: function (wSubCmdID, pData, wDataSize) {
  872. if (!GameDef.CARD_TEST) return false;
  873. if (!this.m_ReplayMode
  874. && this.m_GameClientView.m_TestCtrl
  875. && this.m_GameClientView.m_TestCtrl.OnEventTestMessage(wSubCmdID, pData, wDataSize)) {
  876. return true;
  877. }
  878. return false;
  879. }
  880. });
  881. cc.GameView = cc.Class({
  882. extends: cc.BaseClass,
  883. properties: {
  884. m_UserPrefab: cc.Prefab, //用户信息预制体
  885. },
  886. InitView: function () {
  887. this.m_GameClientEngine = this.node.parent.getComponent('GameClientEngine_' + GameDef.KIND_ID);
  888. this.TraverseNode(this.node.parent);
  889. if (this.m_BtStart) this.m_BtStart.active = false;
  890. if (this.m_BtFriend) this.m_BtFriend.active = false;
  891. if (this.m_BtChat) this.m_BtChat.active = false;
  892. if (this.m_BtGPS) this.m_BtGPS.active = false;
  893. if (this.m_BtMenu) this.m_BtMenu.active = false;
  894. if (this.m_LbGameRules) this.m_LbGameRules.string = '';
  895. if (this.m_LbGameProgress) this.m_LbGameProgress.string = '';
  896. if (this.m_LbTableID) {
  897. this.m_LbTableID.string = '';
  898. if (window.g_dwRoomID) this.m_LbTableID.string = window.g_dwRoomID;
  899. }
  900. },
  901. //添加相应节点变量
  902. CheckNode: function (TagNode) {
  903. //UI节点
  904. if (TagNode.name == 'JetNode') this.m_JetNode = TagNode;
  905. if (TagNode.name == 'CardNode') this.m_CardNode = TagNode; //左上节点
  906. if (TagNode.name == 'UserNode') this.m_UserNode = TagNode; //左上节点
  907. if (TagNode.name == 'AniNode') this.m_AniNode = TagNode; //左上节点
  908. //
  909. if (TagNode.name == 'PhoneInfo') this.m_NdPhoneNode = TagNode; //左上节点
  910. if (TagNode.name == 'BtStart') this.m_BtStart = TagNode; //开始按钮
  911. if (TagNode.name == 'BtFriend') this.m_BtFriend = TagNode; //分享按钮 m_BtFriend
  912. if (TagNode.name == 'BtChat') this.m_BtChat = TagNode; //聊天按钮
  913. if (TagNode.name == 'BtGPS') this.m_BtGPS = TagNode; //GPS按钮
  914. if (TagNode.name == 'BtMenu') this.m_BtMenu = TagNode; //菜单按钮
  915. if (TagNode.name == 'TableNumber') this.m_LbTableID = TagNode.getComponent(cc.Label); //房间ID
  916. if (TagNode.name == 'ClubNumber') this.m_LbClubID = TagNode.getComponent(cc.Label); //俱乐部ID
  917. if (TagNode.name == 'LabRules') this.m_LbGameRules = TagNode.getComponent(cc.Label); //游戏规则
  918. if (TagNode.name == 'LabProgress') this.m_LbGameProgress = TagNode.getComponent(cc.Label); //游戏进度
  919. if (this.CheckNode2) this.CheckNode2(TagNode);
  920. },
  921. UpdateClubID: function () {
  922. if (this.m_LbClubID) {
  923. if (this.m_GameClientEngine.m_dwClubID > 0)
  924. this.m_LbClubID.string = ''; //'联盟ID:'+this.m_GameClientEngine.m_dwClubID;
  925. else
  926. this.m_LbClubID.string = '';
  927. }
  928. },
  929. //递归遍历子节点
  930. TraverseNode: function (TagNode) {
  931. this.CheckNode(TagNode);
  932. for (var i = 0; i < TagNode.childrenCount; i++) {
  933. this.TraverseNode(TagNode.children[i]);
  934. }
  935. return false;
  936. },
  937. OnBnClickedStart: function () {
  938. cc.gSoundRes.PlaySound('Button');
  939. this.m_GameClientEngine.OnMessageStart();
  940. },
  941. OnBnClickedFriend: function () {
  942. cc.gSoundRes.PlaySound('Button');
  943. this.m_GameClientEngine.OnFriend();
  944. },
  945. UserExpression: function (SendUserID, TagUserID, wIndex) {
  946. var SendChair = INVALID_CHAIR,
  947. RecvChair = INVALID_CHAIR;
  948. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  949. if (this.m_pIClientUserItem[i] == null) continue
  950. if (this.m_pIClientUserItem[i].GetUserID() == SendUserID) SendChair = i;
  951. if (this.m_pIClientUserItem[i].GetUserID() == TagUserID) RecvChair = i;
  952. }
  953. if (wIndex < 2000 && this.m_ChatControl) {
  954. this.m_ChatControl.ShowBubblePhrase(SendChair, wIndex, this.m_pIClientUserItem[SendChair].GetGender(), this.m_pIClientUserItem[SendChair].m_UserInfo.wChairID);
  955. // console.log("======================",this.m_pIClientUserItem[SendChair])
  956. }
  957. else if (wIndex < 3000 && this.m_FaceExCtrl) this.m_FaceExCtrl.OnSendFaceEx(SendChair, RecvChair, wIndex);
  958. },
  959. UserChat: function (SendUserID, TagUserID, str) {
  960. if (this.m_ChatControl == null) return
  961. for (var i = 0; i < GameDef.GAME_PLAYER; i++) {
  962. if (this.m_pIClientUserItem[i] == null) continue
  963. if (this.m_pIClientUserItem[i].GetUserID() == SendUserID) {
  964. this.m_ChatControl.ShowBubbleChat(i, str);
  965. break;
  966. }
  967. }
  968. },
  969. //聊天按钮回调
  970. OnBnClickedChat: function () {
  971. cc.gSoundRes.PlaySound('Button');
  972. if (this.m_ChatControl == null) return;
  973. this.m_ChatControl.node.active = true;
  974. this.m_ChatControl.ShowSendChat(true);
  975. },
  976. //聊天按钮回调
  977. OnClick_ShowLookOn: function () {
  978. cc.gSoundRes.PlaySound('Button');
  979. this.ShowPrefabDLG('GameLookOnList')
  980. },
  981. OnBtShowGPS: function () {
  982. console.log('OnBtShowGPS')
  983. if (!this.m_TableGPSCtrl) {
  984. this.ShowPrefabDLG('TableUserGPS', this.node, function (Js) {
  985. this.m_TableGPSCtrl = Js;
  986. this.m_TableGPSCtrl.SetGPSUserPos(this.m_UserInfo);
  987. this.m_TableGPSCtrl.InitUser();
  988. this.m_GameClientEngine.GetTableUserGPS();
  989. this.m_TableGPSCtrl.SetUserInfo(this.m_pIClientUserItem);
  990. this.m_TableGPSCtrl.node.zIndex = 1000;
  991. }.bind(this));
  992. return;
  993. } else {
  994. this.m_TableGPSCtrl.OnShowView();
  995. this.m_GameClientEngine.GetTableUserGPS();
  996. this.m_TableGPSCtrl.SetUserInfo(this.m_pIClientUserItem);
  997. }
  998. },
  999. OnGPSAddress: function (GPSInfo) {
  1000. if (!this.m_TableGPSCtrl || !this.m_GameClientEngine) return;
  1001. this.m_TableGPSCtrl.node.setPosition(0, 0);
  1002. this.m_TableGPSCtrl.UpdateAddress(this, GPSInfo);
  1003. },
  1004. AniFinish: function () {
  1005. },
  1006. LoadCardTestNode: function () { // 'TestMJ'
  1007. if (!USER_CARD_TEST || !GameDef.CARD_TEST) return;
  1008. if (this.m_TestCtrl) {
  1009. if (this.m_TestCtrl.HideView) this.m_TestCtrl.HideView();
  1010. return;
  1011. }
  1012. if (!this.m_CardTestName) return;
  1013. let self = this;
  1014. let pGlobalUserData = g_GlobalUserInfo.GetGlobalUserData();
  1015. let webUrl = PHP_HOME + '/UserFunc.php?GetMark=99&dwUserID=' + pGlobalUserData.dwUserID;
  1016. WebCenter.GetData(webUrl, 0, function (data) {
  1017. if (!data) return;
  1018. let UserInfo = JSON.parse(data);
  1019. if (null == UserInfo.UR) return;
  1020. if (0 == (UserInfo.UR & UR_GAME_TEST_USER)) return;
  1021. self.ShowPrefabDLG(self.m_CardTestName, self.node, function (Js) {
  1022. self.m_TestCtrl = Js;
  1023. self.m_TestCtrl.SetGameEngine(this.m_GameClientEngine);
  1024. self.m_TestCtrl.node.active = false;
  1025. }.bind(self));
  1026. }.bind(this));
  1027. },
  1028. OnGetCardTestInfo: function (tag) {
  1029. if (!GameDef.CARD_TEST) return;
  1030. if (!this.m_TestCtrl) return;
  1031. if (this.m_TestCtrl.node.active) {
  1032. this.m_TestCtrl.node.active = false;
  1033. return;
  1034. }
  1035. //this.m_TestCtrl.node.active = true;
  1036. if (1 == tag) this.m_TestCtrl.ShowUserCheatCtrl();
  1037. else if (2 == tag) this.m_TestCtrl.ShowCardCheatCtrl();
  1038. },
  1039. OnGetCardTestInfo2: function () {
  1040. if (!this.m_TestCtrl) return;
  1041. this.m_TestCtrl.node.active = true;
  1042. }
  1043. });
  1044. cc.BaseControl = cc.Class({
  1045. extends: cc.BaseClass,
  1046. properties: {},
  1047. ctor: function () {
  1048. this.m_fScaleValue = 1;
  1049. this.m_BenchmarkPos = cc.v2(0, 0);
  1050. this.m_AnchorPoint = cc.v2(0.5, 0.5);
  1051. this.m_CollocateMode = cc.v2(0, 0);
  1052. },
  1053. onLoad: function () {
  1054. },
  1055. start: function () {
  1056. },
  1057. SetAttribute: function (Attribute) {
  1058. this.m_Attribute = Attribute;
  1059. if (this.SetAttribute2) {
  1060. this.SetAttribute2();
  1061. }
  1062. },
  1063. //基准位置
  1064. SetBenchmarkPos: function (nXPos, nYPos, ModeX, ModeY) {
  1065. this.m_BenchmarkPos.x = nXPos;
  1066. this.m_BenchmarkPos.y = nYPos;
  1067. this.m_AnchorPoint.x = 0.5 * (ModeX - 1);
  1068. this.m_AnchorPoint.y = 0.5 * (ModeY - 1);
  1069. this.m_CollocateMode.x = ModeX;
  1070. this.m_CollocateMode.y = ModeY;
  1071. if (this.SetBenchmarkPos2) {
  1072. this.SetBenchmarkPos2()
  1073. }
  1074. },
  1075. //缩放
  1076. SetScale: function (fScaleValue) {
  1077. this.m_fScaleValue = fScaleValue;
  1078. if (this.SetScale2) {
  1079. this.SetScale2();
  1080. }
  1081. },
  1082. SetTouchOn: function () {
  1083. try {
  1084. if (this.onTouchBegan) this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchBegan, this);
  1085. if (this.onTouchMove) this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
  1086. if (this.onTouchEnded) this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnded, this);
  1087. if (this.onTouchCancel) this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
  1088. } catch (error) {
  1089. ASSERT(false, ' In BaseControl-SetTouchOn catch error is ' + error);
  1090. }
  1091. },
  1092. NewNode: function (Parent, Component) {
  1093. try {
  1094. var TempNode = new cc.Node();
  1095. if (!TempNode) return null;
  1096. if (Parent instanceof cc.Node) {
  1097. Parent.addChild(TempNode);
  1098. } else if (Parent.node instanceof cc.Node) {
  1099. Parent.node.addChild(TempNode);
  1100. }
  1101. if (Component) {
  1102. if (Component instanceof cc.Node) return TempNode;
  1103. TempNode.addComponent(Component);
  1104. return TempNode;
  1105. } else {
  1106. ASSERT(false, ' In BaseControl-NewNode wrong Component is ' + Component);
  1107. return TempNode;
  1108. }
  1109. } catch (error) {
  1110. ASSERT(false, ' In BaseControl-NewNode catch error is ' + error);
  1111. }
  1112. },
  1113. RemoveIntoPool: function (jsArr, Pool) {
  1114. try {
  1115. if (jsArr == null) jsArr = new Array();
  1116. for (var i in jsArr) {
  1117. if (jsArr[i] instanceof cc.Node) {
  1118. // jsArr[i].parent = null;
  1119. Pool.put(jsArr[i]);
  1120. } else if (jsArr[i].node instanceof cc.Node) {
  1121. // jsArr[i].node.parent = null;
  1122. Pool.put(jsArr[i].node);
  1123. }
  1124. }
  1125. jsArr.splice(0, jsArr.length);
  1126. } catch (error) {
  1127. ASSERT(false, ' In BaseControl-RemoveIntoPool catch error is ' + error);
  1128. }
  1129. },
  1130. RemoveIntoPoolByID: function (jsArr, Pool, cbID) {
  1131. try {
  1132. if (jsArr == null) jsArr = new Array();
  1133. if (!jsArr[cbID]) return;
  1134. if (jsArr[cbID] instanceof cc.Node) {
  1135. Pool.put(jsArr[cbID]);
  1136. } else if (jsArr[cbID].node instanceof cc.Node) {
  1137. Pool.put(jsArr[cbID].node);
  1138. }
  1139. jsArr.splice(cbID, 1);
  1140. } catch (error) {
  1141. ASSERT(false, ' In BaseControl-RemoveIntoPoolByID catch error is ' + error);
  1142. }
  1143. },
  1144. GetPreFormPool: function (Pool, SouceNode, Parent, Com1, Com2) {
  1145. try {
  1146. var TempNode;
  1147. if (Pool.size()) {
  1148. TempNode = Pool.get();
  1149. if (Parent instanceof cc.Node) Parent.addChild(TempNode);
  1150. else if (Parent.node instanceof cc.Node) Parent.node.addChild(TempNode);
  1151. } else {
  1152. if (SouceNode) {
  1153. if (SouceNode instanceof cc.Node) {
  1154. TempNode = cc.instantiate(SouceNode);
  1155. } else if (SouceNode.node instanceof cc.Node) {
  1156. TempNode = SouceNode.node;
  1157. }
  1158. if (Parent instanceof cc.Node) Parent.addChild(TempNode);
  1159. else if (Parent.node instanceof cc.Node) Parent.node.addChild(TempNode);
  1160. }
  1161. else {
  1162. TempNode = this.NewNode(Parent, Com1);
  1163. }
  1164. }
  1165. var js1 = TempNode;
  1166. if (Com1 != cc.Node) js1 = TempNode.getComponent(Com1);
  1167. if (js1) js1.m_Hook = this;
  1168. var js2 = null;
  1169. if (Com2) js2 = TempNode;
  1170. if (Com2 && Com2 != cc.Node) js2 = TempNode.getComponent(Com2);
  1171. if (js2) js2.m_Hook = this;
  1172. ASSERT(js1, ' In BaseControl-GetPreFormPool js1 is ' + js1 + '; Com1=' + Com1 + '; Com2=' + Com2);
  1173. return [js1, js2];
  1174. } catch (error) {
  1175. ASSERT(false, ' In BaseControl-GetPreFormPool catch error is ' + error);
  1176. }
  1177. },
  1178. //递归遍历子节点查找目标节点
  1179. // SearchInfo: ContentArray, SouceNode, SearchCom, HandlerComponet, HandlerFunc, CustomData
  1180. TraverseNode: function (SearchInfo) {
  1181. try {
  1182. if (!SearchInfo.SouceNode) return false;
  1183. var pCom = null;
  1184. if (SearchInfo.SouceNode instanceof cc.Node) pCom = SearchInfo.SouceNode.getComponent(SearchInfo.SearchCom);
  1185. else if (SearchInfo.SouceNode.node instanceof cc.Node) pCom = SearchInfo.SouceNode.node.getComponent(SearchInfo.SearchCom);
  1186. if (pCom) {
  1187. if (SearchInfo.HandlerComponet && SearchInfo.HandlerFunc) {
  1188. var pHandler = new cc.Component.EventHandler();
  1189. pHandler.target = this.node;
  1190. pHandler.component = SearchInfo.HandlerComponet;
  1191. pHandler.handler = SearchInfo.HandlerFunc;
  1192. if (SearchInfo.CustomData != null) pHandler.customEventData = SearchInfo.CustomData;
  1193. pCom.clickEvents.push(pHandler);
  1194. }
  1195. if (window.LOG_NET_DATA) console.log(" In BaseControl TraverseNode --------------- ");
  1196. if (window.LOG_NET_DATA) console.log("TraverseNode index: " + SearchInfo.ContentArray.length + " => " + pCom.node.name + " -- ");
  1197. if (window.LOG_NET_DATA) console.log(SearchInfo);
  1198. if (window.LOG_NET_DATA) console.log(" --------------- ");
  1199. if (SearchInfo.ContentArray) SearchInfo.ContentArray.push(pCom);
  1200. return true;
  1201. }
  1202. for (var i = 0; i < SearchInfo.SouceNode.childrenCount; i++) {
  1203. this.TraverseNode({
  1204. ContentArray: SearchInfo.ContentArray,
  1205. SouceNode: SearchInfo.SouceNode.children[i],
  1206. SearchCom: SearchInfo.SearchCom,
  1207. HandlerComponet: SearchInfo.HandlerComponet,
  1208. HandlerFunc: SearchInfo.HandlerFunc,
  1209. CustomData: i,
  1210. });
  1211. }
  1212. return false;
  1213. } catch (error) {
  1214. ASSERT(false, ' In BaseControl-TraverseNode catch error is ' + error);
  1215. }
  1216. },
  1217. AddClickHandler: function (souce, target, component, handler, CustomData) {
  1218. try {
  1219. for (var i in souce.clickEvents) {
  1220. if (souce.clickEvents[i].target == target && souce.clickEvents[i].component == component && souce.clickEvents[i].handler) {
  1221. if (CustomData != null) souce.clickEvents[i].customEventData = CustomData;
  1222. return;
  1223. }
  1224. }
  1225. var pHandler = new cc.Component.EventHandler();
  1226. pHandler.target = target;
  1227. pHandler.component = component;
  1228. pHandler.handler = handler;
  1229. if (CustomData != null) pHandler.customEventData = CustomData;
  1230. souce.clickEvents.push(pHandler);
  1231. } catch (error) {
  1232. ASSERT(false, ' In BaseControl-AddClickHandler catch error is ' + error);
  1233. }
  1234. },
  1235. //递归遍历子节点查找复选框
  1236. TraverseToggle: function (TagNode, pArray) {
  1237. if (!TagNode) return false;
  1238. if (!pArray) return false;
  1239. if (TagNode.name[0] != '$') {
  1240. var js = TagNode.getComponent(cc.Toggle);
  1241. if (js) {
  1242. pArray.push(js);
  1243. return true;
  1244. }
  1245. }
  1246. for (var i = 0; i < TagNode.childrenCount; i++) {
  1247. if (TagNode.children[i].name[0] == '$') continue;
  1248. this.TraverseToggle(TagNode.children[i], pArray);
  1249. }
  1250. return false;
  1251. },
  1252. GetPair: function (pToggle) {
  1253. if (!pToggle) return null;
  1254. var cbIndex = pToggle.node.name.indexOf('_');
  1255. if (cbIndex != -1) {
  1256. return {
  1257. key: pToggle.node.name.slice(0, cbIndex),
  1258. value: pToggle.node.name.slice(cbIndex + 1)
  1259. };
  1260. }
  1261. return null;
  1262. },
  1263. });
  1264. // 分享
  1265. cc.share = {
  1266. Type: cc.Enum({
  1267. NULL: 0,
  1268. Login: 1,
  1269. Download: 2,
  1270. InviteRoom: 3,
  1271. InviteClub: 4,
  1272. GameEnd: 5,
  1273. }),
  1274. Mode: cc.Enum({
  1275. NULL: 0,
  1276. Auto: 1,
  1277. ToH5: 2,
  1278. ToApp: 3,
  1279. }),
  1280. LoadConfig: function (callback) {
  1281. window.GetConfig('ShareLinkH5', {
  1282. error: function (e) {
  1283. if (LOG_WEB_DATA) console.log('请配置分享链接!');
  1284. if (callback) callback(null);
  1285. },
  1286. success: function (res) {
  1287. if (!res) {
  1288. if (LOG_WEB_DATA) console.log('分享链接-配置数据异常!');
  1289. if (callback) callback(null);
  1290. return;
  1291. }
  1292. if (res.String && res.String.length > 1) {
  1293. // 回调数据处理
  1294. window.SHARE_URL_H5 = res.String;
  1295. if (LOG_WEB_DATA && res.State == 1) console.log(res.Tip + ' 获取成功!');
  1296. if (callback) callback(res.String);
  1297. } else {
  1298. if (LOG_WEB_DATA && res.State == 1) console.log('请配置 ' + res.Tip);
  1299. if (callback) callback(res.String);
  1300. }
  1301. },
  1302. });
  1303. window.GetConfig('ShareLinkApp', {
  1304. error: function (e) {
  1305. if (LOG_WEB_DATA) console.log('请配置分享链接!');
  1306. if (callback) callback(null);
  1307. },
  1308. success: function (res) {
  1309. if (!res) {
  1310. if (LOG_WEB_DATA) console.log('分享链接-配置数据异常!');
  1311. if (callback) callback(null);
  1312. return;
  1313. }
  1314. if (res.String && res.String.length > 1) {
  1315. // 回调数据处理
  1316. window.SHARE_URL = res.String;
  1317. if (LOG_WEB_DATA && res.State == 1) console.log(res.Tip + ' 获取成功!');
  1318. if (callback) callback(res.String);
  1319. } else {
  1320. if (LOG_WEB_DATA && res.State == 1) console.log('请配置 ' + res.Tip);
  1321. if (callback) callback(res.String);
  1322. }
  1323. },
  1324. });
  1325. },
  1326. InitShareInfo_H5_WX: function (ShareFunc) {
  1327. if (this.IsH5_WX() && ShareFunc) {
  1328. var ShareInfo = ShareFunc();
  1329. if (ShareInfo) {
  1330. ThirdPartyShareMessage(ShareInfo, 0);
  1331. ThirdPartyShareMessage(ShareInfo, 1);
  1332. return true;
  1333. }
  1334. }
  1335. return false;
  1336. },
  1337. // 串接参数
  1338. Stringify: function (param) {
  1339. try {
  1340. var str = '';
  1341. if (typeof param == 'string') {
  1342. str = param;
  1343. } else if (typeof param == 'object') {
  1344. str = JSON.stringify(param);
  1345. } else {
  1346. return '';
  1347. }
  1348. var res = encodeURIComponent(unescape(str));
  1349. return res;
  1350. } catch (e) {
  1351. if (window.LOG_DEBUG) console.log(e);
  1352. return '';
  1353. }
  1354. },
  1355. // 解析参数
  1356. Parse: function (param) {
  1357. try {
  1358. var str = decodeURIComponent(param);
  1359. var obj = JSON.parse(str);
  1360. return obj;
  1361. } catch (e) {
  1362. if (window.LOG_DEBUG) console.log(e);
  1363. return null;
  1364. }
  1365. },
  1366. IsH5_WX: function (mode) {
  1367. if (mode == this.Mode.Auto || !!!mode) {
  1368. 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));
  1369. } else if (mode == this.Mode.ToH5) {
  1370. return true;
  1371. } else {
  1372. return false;
  1373. }
  1374. },
  1375. MakeLink_InviteRoom: function (roomID, clubID, mode) {
  1376. if (this.IsH5_WX(mode)) {
  1377. var obj = {};
  1378. obj.type = this.Type.InviteRoom;
  1379. obj.value = [roomID, clubID];
  1380. var link = `${window.SHARE_URL_H5}${this.Stringify(obj)}`;
  1381. return link;
  1382. } else {
  1383. return window.SHARE_URL;
  1384. }
  1385. },
  1386. MakeLink_InviteClub: function (kind, allianceID, mode) {
  1387. if (this.IsH5_WX(mode)) {
  1388. var obj = {};
  1389. obj.type = this.Type.InviteClub;
  1390. obj.value = [kind, allianceID];
  1391. var link = `${window.SHARE_URL_H5}${this.Stringify(obj)}`;
  1392. return link;
  1393. } else {
  1394. return window.SHARE_URL;
  1395. }
  1396. },
  1397. MakeLink_GameEnd: function (mode) {
  1398. if (this.IsH5_WX(mode)) {
  1399. return `${window.SHARE_URL_H5}0`;
  1400. } else {
  1401. return window.SHARE_URL;
  1402. }
  1403. },
  1404. MakeLink_Lobby: function (mode) {
  1405. if (this.IsH5_WX(mode)) {
  1406. return `${window.SHARE_URL_H5}0`;
  1407. } else {
  1408. return window.SHARE_URL;
  1409. }
  1410. },
  1411. MakeLink_Download: function (mode) {
  1412. if (this.IsH5_WX(mode)) {
  1413. return `${window.SHARE_URL_H5}0`;
  1414. } else {
  1415. return window.SHARE_URL;
  1416. }
  1417. },
  1418. GetShareParam: function (type) {
  1419. if (cc.sys.isNative) return null;
  1420. var state = getQueryString("state");
  1421. var param = null;
  1422. if (state && state != '') {
  1423. param = this.Parse(state);
  1424. }
  1425. var obj = {};
  1426. switch (type) {
  1427. case this.Type.InviteRoom: {
  1428. if (param && param.type == type) {
  1429. obj.roomNum = param.value[0];
  1430. obj.clubID = param.value[1];
  1431. } else {
  1432. obj.roomNum = 0;
  1433. obj.clubID = 0;
  1434. }
  1435. break;
  1436. }
  1437. case this.Type.InviteClub: {
  1438. if (param && param.type == type) {
  1439. obj.kind = param.value[0];
  1440. obj.allianceID = param.value[1];
  1441. } else {
  1442. obj.kind = 0;
  1443. obj.allianceID = 0;
  1444. }
  1445. break;
  1446. }
  1447. }
  1448. return obj;
  1449. },
  1450. }