BaseClass.js 59 KB

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