UIMain.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. import SpineMgr from "../core/mgrs/SpineMgr";
  2. import DataMgr from "../data/DataMgr";
  3. import { CHANGE_SECRETARY, GameMode, GET_USER_INFO, RESTART_GAME, keyForLoginInfo, TIP_MSG_key } from "../data/Define";
  4. import UIBase from "../fgui/core/UIBase";
  5. import ui_UIMain from "../fgui/res/game/ui_UIMain";
  6. import PlatMgr from "../game/PlatMgr";
  7. import { xGame } from "../xGame";
  8. import MoneyNode from "./item/MoneyNode";
  9. import SettingNode from "./item/SettingNode";
  10. import UIAddProp from "./UIAddProp";
  11. import UIDraw from "./UIDraw";
  12. import { UIGame } from "./UIGame";
  13. import UIGameEnd from "./UIGameEnd";
  14. import UIInvitation from "./UIInvitation";
  15. import UILevelDisplay from "./UILevelDisplay";
  16. import UIMatching from "./UIMatching";
  17. import UIRanking from "./UIRanking";
  18. import UISecretary from "./UISecretary";
  19. import UIShop from "./UIShop";
  20. import UISign from "./UISign";
  21. import UISkill from "./UISkill";
  22. import UIMsg from "./UIMsg";
  23. import UIModeSelection from "./UIModeSelection";
  24. import GlobalManager from "../utils/GlobalManager";
  25. import JSBridgeUtils from "../utils/JSBridgeUtils";
  26. import SkillDisplay from "./item/SkillDisplay";
  27. import UIReg from "./UIReg";
  28. import UILogin from "./UILogin";
  29. import UIFuli1 from "./UIFuli1";
  30. import UIFuli2 from "./UIFuli2";
  31. import UITry from "./UITry";
  32. import UIPower from "./UIPower";
  33. import UIGetAward from "./UIGetAward";
  34. import UIRepentProp from "./UIRepentProp";
  35. import UIBox from "./UIBox";
  36. import UIAddCoin from "./UIAddCoin";
  37. import { NoInternetDialog } from "./NoInternetDialog";
  38. //import NetCheckTool from "../utils/NetCheckTool";
  39. import { LocalStorageManager } from "../utils/LocalStorageManager";
  40. export default class UIMain extends UIBase {
  41. public ui: ui_UIMain;
  42. public settingNode: SettingNode;
  43. public moneyNode: MoneyNode;
  44. public firstEnter = true;
  45. nativeCallJs(msg: string) {
  46. let t = msg;
  47. console.log("zh: nativeCallJs 奖励开始发放:", t);
  48. //GlobalManager.instance.callMethod(msg)
  49. switch (t) {
  50. case 'qjff_chouJiang':
  51. let dui = <UIDraw>xGame.uiMgr.getUI(UIDraw);
  52. dui.qjff_chouJiang();
  53. break;
  54. case 'qjff_AD_for_uisign':
  55. let dui2 = <UISign>xGame.uiMgr.getUI(UISign);
  56. dui2.qjff_AD_for_uisign();
  57. break;
  58. case 'qjff_AD_for_uitry':
  59. let dui3 = <UITry>xGame.uiMgr.getUI(UITry);
  60. dui3.qjff_AD_for_uitry();
  61. break;
  62. case 'qjff_AD_for_uipower':
  63. let dui4 = <UIPower>xGame.uiMgr.getUI(UIPower);
  64. dui4.qjff_AD_for_uipower();
  65. break;
  66. case 'qjff_AD_for_uigetAward':
  67. let dui5 = <UIGetAward>xGame.uiMgr.getUI(UIGetAward);
  68. dui5.qjff_AD_for_uigetAward();
  69. break;
  70. case 'qjff_AD_for_uiGameEnd':
  71. let temp_level = Laya.LocalStorage.getItem('temp_qjff_AD_for_uiGameEnd_level');
  72. let dui6 = <UIGameEnd>xGame.uiMgr.getUI(UIGameEnd);
  73. dui6.qjff_AD_for_uiGameEnd(parseInt(temp_level))
  74. break;
  75. case 'qjff_AD_for_uiAddProp_videoGetDiamond':
  76. let dui7 = <UIAddProp>xGame.uiMgr.getUI(UIAddProp);
  77. dui7.qjff_AD_for_uiAddProp_videoGetDiamond();
  78. break;
  79. case 'qjff_AD_for_uiAddProp_videoGetCoin':
  80. let dui8 = <UIAddProp>xGame.uiMgr.getUI(UIAddProp);
  81. dui8.qjff_AD_for_uiAddProp_videoGetCoin();
  82. break;
  83. case 'qjff_AD_for_UIrepentProp_videoRegret':
  84. let dui9 = <UIRepentProp>xGame.uiMgr.getUI(UIRepentProp);
  85. dui9.qjff_AD_for_UIrepentProp_videoRegret();
  86. break;
  87. case 'qjff_AD_for_UIrepentProp_videoAddHelpLine':
  88. let dui10 = <UIRepentProp>xGame.uiMgr.getUI(UIRepentProp);
  89. dui10.qjff_AD_for_UIrepentProp_videoAddHelpLine();
  90. break;
  91. case 'qjff_AD_for_UIBOX_onOpenBox':
  92. let dui11 = <UIBox>xGame.uiMgr.getUI(UIBox);
  93. dui11.qjff_AD_for_UIBOX_onOpenBox();
  94. break;
  95. case 'qjff_AD_for_UIAddCoin':
  96. let dui12 = <UIAddCoin>xGame.uiMgr.getUI(UIAddCoin);
  97. dui12.qjff_AD_for_UIAddCoin();
  98. break;
  99. // case 'qjff_AD_for_skilldisplay_clickAddLevel':
  100. // // SkillDisplay s=new SkillDisplay();//改为插屏了
  101. // // s.qjff_AD_for_skilldisplay_clickAddLevel();
  102. // break;
  103. case '111a':
  104. let dui14 = <UISign>xGame.uiMgr.getUI(UISign);
  105. dui14.qjff_AD_for_uisign();
  106. break;
  107. case '222a':
  108. let dui15 = <UISign>xGame.uiMgr.getUI(UISign);
  109. dui15.qjff_AD_for_uisign();
  110. break;
  111. case '333a':
  112. let dui16 = <UISign>xGame.uiMgr.getUI(UISign);
  113. dui16.qjff_AD_for_uisign();
  114. break;
  115. default:
  116. console.log('zh:未知的方法名字' + t)
  117. break;
  118. }
  119. // if(t === 'qjff_shengJi_for_SkillDisplay'){
  120. // const dui = new
  121. // dui.qjff_shengJi();
  122. // }
  123. }
  124. public constructor() {
  125. super();
  126. }
  127. protected onConstructor(): void {
  128. console.log('zh: UIMain onConstructor');
  129. this.ui = ui_UIMain.createInstance();
  130. this.contentPane = this.ui;
  131. this.isEject = false;
  132. // this.ui.weeklyBtn.visible = false;
  133. this.addEvent();
  134. this.addClickSpine();
  135. //设置界面
  136. this.settingNode = new SettingNode(this.ui.settingNode);
  137. this.moneyNode = new MoneyNode(this.ui.moneyNode);
  138. //
  139. xGame.eventMgr.on(RESTART_GAME, this, this.beginGame);
  140. xGame.eventMgr.on(GET_USER_INFO, this, this.onGetUserInfo);
  141. xGame.eventMgr.on(CHANGE_SECRETARY, this, this.changeSecretary);
  142. let curUse = DataMgr.getCurSecretary();
  143. this.changeSecretary(curUse);
  144. //
  145. //this.ui.rankBtn.visible = false;
  146. this.ui.talkNode.visible = false;
  147. let guide = DataMgr.getSkillGuide();
  148. if (xGame.common.isNewDay && guide == 1) {
  149. xGame.common.isNewDay = false;
  150. xGame.soundMgr.playSound("s_main01");
  151. xGame.common.showGirlTalkPop(1, this.ui.talkNode, this.ui.talkNode.womanTxt);
  152. console.log("zh:播放小秘书每天语音");
  153. }
  154. this.onGetUserInfo();
  155. DataMgr.getUserZiChanInfo();
  156. this.ui.n83.visible = false;
  157. //万宁台球
  158. //Moyu.setShareInfo("8Ball Fury", ["台球", "台球", "桌球"], '2300002254');
  159. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  160. const d = LocalStorageManager.getItem<{ username: string, token: string }>(keyForLoginInfo);
  161. let ua = d.username;
  162. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(ua, 16);
  163. }
  164. this.c_btn_for_user();
  165. window['nativeCallJs'] = this.nativeCallJs.bind(this);
  166. }
  167. Logout() {
  168. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  169. //const d = LocalStorageManager.getItem<{ username: string, token: string }>(keyForLoginInfo);
  170. LocalStorageManager.removeItem(keyForLoginInfo);
  171. this.freshUser();
  172. }
  173. //必须要调用APP退出登录
  174. JSBridgeUtils.instance.loginOutForApp();
  175. }
  176. gotoLogin() {
  177. xGame.uiMgr.Show(UILogin);
  178. }
  179. gotoRegUser() {
  180. xGame.uiMgr.Show(UIReg);
  181. }
  182. showFuLi1() {
  183. console.log('zh:福利1');
  184. xGame.uiMgr.Show(UIFuli1);
  185. }
  186. showFuLi2() {
  187. console.log('zh:福利2');
  188. xGame.uiMgr.Show(UIFuli2);
  189. }
  190. /**
  191. * 登录注册退出
  192. */
  193. c_btn_for_user() {
  194. this.ui.n_Logout.visible = false;
  195. this.ui.n_dengLu.visible = false;
  196. this.ui.n_zhuCe.visible = false;
  197. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  198. this.ui.n_Logout.visible = true;
  199. } else {
  200. this.ui.n_dengLu.visible = true;
  201. }
  202. }
  203. changeSecretary(curUse) {
  204. let name = cfgTable.secretaryshopData[curUse + 1].spine;
  205. xGame.common.secretary && xGame.common.secretary.dispose();
  206. this.addSecretarySpine(name);
  207. }
  208. addSecretarySpine(name) {
  209. let spine = new SpineMgr(name, () => {
  210. this.playSecretaryIdle();
  211. });
  212. xGame.common.secretary = spine;
  213. }
  214. addClickSpine() {
  215. let clickSpine = new SpineMgr("dianji", () => {
  216. Laya.stage.on(Laya.Event.CLICK, this, (e: Laya.Event) => {
  217. //
  218. let parent = Laya.stage;
  219. let data = { x: e.stageX, y: e.stageY, scaleX: 0.8, scaleY: 0.8 };
  220. clickSpine.play(data, 0, false, parent, (spine) => {
  221. spine.destroy(true);
  222. });
  223. })
  224. //
  225. });
  226. }
  227. private addEvent(): void {
  228. this.addUIClick(this.ui.classicBtn, this.startGame, [GameMode.classic]);
  229. this.addUIClick(this.ui.bigMoveBtn, this.startGame, [GameMode.bigMove])
  230. this.addUIClick(this.ui.ganFaMoShiBtn, this.startGame, [GameMode.bigMove])
  231. //
  232. this.addUIClick(this.ui.globalBtn, this.startGlobal);
  233. // this.addUIClick(this.ui.weeklyBtn, this.startWeekly);
  234. this.addUIClick(this.ui.placeBallBtn, this.startPlaceBall);
  235. //
  236. this.addUIClick(this.ui.headNode, this.onGetUserInfo, [true]);
  237. this.addUIClick(this.ui, this.interuptSecretary);
  238. this.addUIClick(this.ui.rightBtn, this.ensureSecretary);
  239. this.addUIClick(this.ui.guideBtn, this.startGame, [GameMode.bigMove]);
  240. this.addUIClick(this.ui.secretaryBtn, this.openSecretaryView);
  241. this.addUIClick(this.ui.shopBtn, this.openShopView);
  242. //
  243. this.addUIClick(this.ui.signBtn, this.openSignView);
  244. this.addUIClick(this.ui.drawBtn, this.openDrawView);
  245. this.addUIClick(this.ui.rankBtn, this.openRanking);
  246. //退出登录
  247. this.addUIClick(this.ui.n_Logout, this.Logout);
  248. this.addUIClick(this.ui.n_dengLu, this.gotoLogin);
  249. this.addUIClick(this.ui.n_zhuCe, this.gotoRegUser);
  250. this.addUIClick(this.ui.n_fuli, this.showFuLi2);
  251. //调试专用
  252. this.addUIClick(this.ui.n_moni_pay_ok, this.start_debug_for_moni_payOk);
  253. }
  254. public show(showFailWords): void {
  255. super.show();
  256. //
  257. this.moneyNode.ui.c1.selectedIndex = 1;
  258. this.playSecretaryIdle();
  259. xGame.soundMgr.playMusic("caromhall01", 0);
  260. Laya.timer.clearAll(this);
  261. this.playSecretaryRandomSound();
  262. console.log('zh:uimain.ts show show FailWords=', showFailWords);
  263. if (showFailWords) {
  264. console.log('zh:uimain.ts ')
  265. //延迟播放进入主页面的失败音效
  266. setTimeout(() => {
  267. let str = Math.random() <= 0.5 ? "s_main02" : "s_main03";
  268. let words = -1;
  269. if (str == "s_main02") {
  270. words = 2;
  271. }
  272. else {
  273. words = 3;
  274. }
  275. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  276. xGame.soundMgr.playSound(str);
  277. }, 300);
  278. }
  279. // setTimeout(() => {
  280. // console.log('zh:播放7背景音乐 m ')
  281. // xGame.soundMgr.playSound('bjyy_m', 0);
  282. // }, 2000);
  283. //
  284. this.showGuide();
  285. this.ui.guideBtn.x = this.ui.liucheng2.myMask.x;
  286. this.ui.guideBtn.y = this.ui.liucheng2.myMask.y;
  287. //
  288. let guide = DataMgr.getSkillGuide();
  289. if (guide == 1) {
  290. let randTime = xGame.common.randomNum(300, 800);
  291. if (this.firstEnter) {
  292. console.log("zh: firstEnter");
  293. this.firstEnter = false;
  294. randTime += 900;
  295. } else {
  296. console.log("zh: no firstEnter");
  297. }
  298. Laya.timer.once(randTime, this, () => {
  299. // xGame.common.autoPopUIView();
  300. })
  301. Laya.timer.once(1000, this, () => {
  302. console.log('zh: 1秒后 showFuLi1')
  303. this.showFuLi1();
  304. })
  305. }
  306. }
  307. checkActive(show) {
  308. //console.log("是否处于最外层",show);
  309. //wx banner太大
  310. // if (!Moyu.isWx)
  311. // PlatMgr.showBanner(show);
  312. }
  313. showGuide() {
  314. let guide = DataMgr.getSkillGuide();
  315. this.ui.guideBtn.visible = guide == 0;
  316. this.ui.enterGuide.visible = false;
  317. this.ui.secretaryGuide.visible = guide == 0;
  318. if (guide == 0) {
  319. console.log("zh:显示引导");
  320. xGame.soundMgr.playSound("s_guide");
  321. xGame.common.showGirlTalkPop(16, this.ui.talkNode, this.ui.talkNode.womanTxt);
  322. } else {
  323. console.log("zh:不需要显示引导");
  324. }
  325. }
  326. ensureSecretary() {
  327. console.log('zh: ensureSecretary ensureSecretaryensureSecretaryensureSecretaryensureSecretaryensureSecretary')
  328. this.ui.secretaryGuide.visible = false;
  329. this.ui.enterGuide.visible = true;
  330. this.ui.wordsNode.t0.play();
  331. //todo
  332. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameReady");
  333. }
  334. playSecretaryIdle() {
  335. let parent = this.ui.secretary.displayObject;
  336. parent.destroyChildren();
  337. let xx = this.ui.secretary.width / 2;
  338. let yy = this.ui.secretary.height;
  339. // xx = Laya.stage.width / 2;
  340. // yy = Laya.stage.height;
  341. let scale = xGame.common.getSecretaryScale();
  342. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  343. //console.log("zh:playSecretaryIdle", data);
  344. //xGame.common.secretary.play(data, 1, true, parent); 这是老的秘书
  345. xGame.common.secretary.play(data, 0, true, parent);
  346. }
  347. startGame(type: GameMode) {
  348. if (!this.isReadyForLoadNetSource()) {
  349. return;
  350. }
  351. // console.log('zh: 停止播放主頁面背景音乐');
  352. // xGame.soundMgr.stopMusic();
  353. //进入游戏页面
  354. xGame.common.gameMode = type;
  355. //
  356. Moyu.sendDataEvent("PlayGame", { type: type });
  357. console.log('zh:进入游戏gameMode =' + xGame.common.gameMode);
  358. switch (xGame.common.gameMode) {
  359. case GameMode.classic:
  360. console.log('zh:进入经典模式111111111');
  361. //zhdiy - challenge mode作为教学练习关,完成2关解锁classic,
  362. if (DataMgr.DIY_challengeMode_overLev_jieSuo_mark) {
  363. let db_over_lev = DataMgr.getChallengeMode_overLev();
  364. console.log('zh:classic db_over_lev=', db_over_lev);
  365. if (db_over_lev < DataMgr.DIY_challengeMode_overLev_jieSuo_Classic) {
  366. console.log('zh:判断是否可以玩该模式classic =NO');
  367. let tipStr = 'You must complete ' + DataMgr.DIY_challengeMode_overLev_jieSuo_Classic + ' levels in Challenge Mode to unlock Classic Mode.';
  368. xGame.uiMgr.Show(UIMsg, tipStr);
  369. return;
  370. } else {
  371. console.log('zh:可以玩该模式classic 66666666666666');
  372. this.beginGame();
  373. }
  374. } else {
  375. console.log('zh:不需要判断是否可以玩该classic');
  376. let challengeTimes = DataMgr.getChallengeTimes();
  377. if (challengeTimes == 0) {
  378. xGame.uiMgr.Show(UIInvitation);
  379. }
  380. else {
  381. this.beginGame();
  382. }
  383. break;
  384. }
  385. case GameMode.bigMove:
  386. console.error('zh:bigMove check');
  387. let guide = DataMgr.getSkillGuide();
  388. //zhdiy - challenge mode作为教学练习关,完成2关解锁classic,
  389. if (DataMgr.DIY_challengeMode_overLev_jieSuo_mark && guide == 1) {
  390. let db_over_lev = DataMgr.getChallengeMode_overLev();
  391. console.log('zh:bigMove db_over_lev=', db_over_lev);
  392. if (db_over_lev < DataMgr.DIY_challengeMode_overLev_jieSuo_rodMethod) {
  393. let tipStr = 'Complete ' + DataMgr.DIY_challengeMode_overLev_jieSuo_rodMethod + ' levels in Challenge Mode to unlock the Rod Method Mode';
  394. xGame.uiMgr.Show(UIMsg, tipStr);
  395. return;
  396. } else {
  397. console.log('zh:可以玩该模式 bigMove');
  398. this.beginGame();
  399. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameStart0");
  400. }
  401. } else {
  402. this.beginGame();
  403. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameStart0");
  404. }
  405. break;
  406. default:
  407. console.error('zh:未知错误!!!!');
  408. break;
  409. }
  410. }
  411. beginGame(isNice = false) {
  412. console.log('zh:beginGame ');
  413. //TODO:ZH 插屏AD
  414. //let time = xGame.common.randomNum(1000, 2000);
  415. //Moyu.showInsertAd(time, 60000);
  416. let guide = DataMgr.getSkillGuide();
  417. if (guide == 1) {//非新手引导,就显示,否则不显示
  418. console.log('zh:非新手引导,showInternAd ');
  419. JSBridgeUtils.instance.showInternAd('beginGame');
  420. } else {
  421. console.log('zh:新手引导,不显示AD ');
  422. }
  423. console.log('zh:beginGame 2 go');
  424. if (xGame.common.gameMode == GameMode.classic) {
  425. // xGame.uiMgr.Show(UIMsg, "Coming Soon")
  426. if (isNice) {
  427. //巅峰赛直接进入
  428. this.enterClassic();
  429. }
  430. else {
  431. xGame.uiMgr.Show(UIModeSelection, () => {
  432. console.log('zh:BBBBBBBBBBBBBBB');
  433. this.enterClassic();
  434. })
  435. }
  436. }
  437. else if (xGame.common.gameMode == GameMode.bigMove) {
  438. this.ui.enterGuide.visible = false;
  439. xGame.uiMgr.Show(UISkill);
  440. }
  441. }
  442. enterClassic() {
  443. xGame.uiMgr.Show(UIGame);
  444. xGame.uiMgr.Show(UIMatching, () => {
  445. if (!this.isHide) this.hide();
  446. xGame.common.gameUI.ui.alpha = 1;
  447. xGame.common.gameUI.startGame();
  448. xGame.uiMgr.Hide(UIGameEnd);
  449. });
  450. }
  451. /**
  452. * 模拟支付OK
  453. * @returns
  454. */
  455. start_debug_for_moni_payOk() {
  456. console.log('zh:start_debug_for_moni_payOk 111')
  457. let userInfo = LocalStorageManager.getItem('userInfo');
  458. if (userInfo != null) {
  459. let token = userInfo.token;
  460. let ggSpid = 'com.vadltq.strike.ball.cue.gem50';
  461. JSBridgeUtils.instance.testPay1ForMoNiPayOver(token, ggSpid);
  462. return;
  463. } else {
  464. alert(TIP_MSG_key.pleaseLoginIn)
  465. }
  466. }
  467. startGlobal() {
  468. xGame.uiMgr.Show(UIMsg, "Coming Soon.")
  469. //xGame.uiMgr.Show(UITry);
  470. // JSBridgeUtils.instance.showInternAd('');
  471. }
  472. startWeekly() {
  473. //xGame.uiMgr.Show(UIBox);
  474. xGame.uiMgr.Show(UIMsg, "Coming Soon")
  475. //测试AD
  476. // GlobalManager.instance.registerMethod('zhouSaiMonth', this.zhouSaiMonth);
  477. //JSBridgeUtils.instance.showRewardAd('zhouSaiMonth');
  478. }
  479. zhouSaiMonth() {
  480. console.log('zh: zhouSaiMonth 被调用')
  481. }
  482. //网络资源是否准备好了
  483. public isReadyForLoadNetSource(): boolean {
  484. let reqCount = xGame.cfgMgr.httpReqCount;
  485. let ok = xGame.cfgMgr.httpReqOkCount;
  486. if (reqCount > ok) {
  487. //console.log('zh:网络资源没有准备完成,请稍后再试');
  488. xGame.uiMgr.Show(UIMsg, "Network not ready. Try again later.")
  489. console.log('zh:✅❌ 5秒后重新尝试加载网络资源');
  490. Laya.timer.once(5000, this, () => {
  491. let retryCount = 0;
  492. const maxRetries = 3;
  493. const tryFetchConfig = () => {
  494. try {
  495. xGame.cfgMgr.getConfigFromServer();
  496. } catch (error) {
  497. if (retryCount < maxRetries) {
  498. retryCount++;
  499. console.log(`🔄 第${retryCount}次重试获取配置...`);
  500. Laya.timer.once(5000, this, tryFetchConfig);
  501. } else {
  502. console.error("❌ 达到最大重试次数,配置获取失败");
  503. }
  504. }
  505. };
  506. tryFetchConfig();
  507. });
  508. return false;
  509. }
  510. return true;
  511. }
  512. startPlaceBall() {
  513. if (!this.isReadyForLoadNetSource()) {
  514. return;
  515. }
  516. xGame.uiMgr.Show(UILevelDisplay);
  517. }
  518. public hide(): void {
  519. console.log('zh:uimain hide ...');
  520. // console.log('zh:停止播放bjyy_m');
  521. //xGame.soundMgr.stopSound("bjyy_m");
  522. // console.log('zh: hide 停止播放主頁面背景音乐');
  523. // xGame.soundMgr.stopMusic();
  524. super.hide();
  525. xGame.common.stopGirlPop(this.ui.talkNode)
  526. }
  527. //点击头像
  528. onGetUserInfo(force = false) {
  529. if (Moyu.isWx) {
  530. let info = Moyu.getSystemInfo();
  531. if (info)
  532. Moyu.createWXUserBtn(0, 0, info.width, info.height, 'res/wxuser.png', this.freshUser);
  533. }
  534. else {
  535. Moyu.initUser(this, this.freshUser, force)
  536. }
  537. // if (!Moyu.hasUserInfo) {
  538. // let user = Moyu.getUserInfo();
  539. // //user.nickName="我";
  540. // user.headIcon = 'res/ty_touxiang.png';
  541. // //console.log("未授权");
  542. // }
  543. this.freshUser();
  544. }
  545. freshUser() {
  546. let user = Moyu.getUserInfo();
  547. if (!user.isAuth) {
  548. user.headIcon = 'res/ty_touxiang.png';
  549. }
  550. else {
  551. DataMgr.upRankData();
  552. }
  553. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(user.nickName, 16);
  554. xGame.common.createHead(this.ui.headNode.headRoot.headImg, user.headIcon);
  555. let keyStr = keyForLoginInfo;
  556. if (LocalStorageManager.hasJosnKey(keyStr)) {
  557. const d = LocalStorageManager.getItem<{ username: string, token: string }>(keyStr);
  558. let ua = d.username;
  559. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(ua, 16);
  560. } else {
  561. }
  562. this.c_btn_for_user();
  563. }
  564. interuptSecretary() {
  565. Laya.timer.clearAll(this);
  566. this.playSecretaryRandomSound();
  567. }
  568. //主界面和技能选择界面3-7秒未操作随机播放秘书音效
  569. playSecretaryRandomSound() {
  570. if (this.isHide) return;
  571. let time = xGame.common.randomNum(45000, 60000);
  572. Laya.timer.once(time, this, () => {
  573. if (this.isHide) return;
  574. let index = xGame.common.randomNum(4, 7);
  575. xGame.soundMgr.playSound("s_main0" + index);
  576. let words = 1;
  577. switch (index) {
  578. case 4:
  579. words = 5;
  580. break;
  581. case 5:
  582. words = 3;
  583. break;
  584. case 6:
  585. words = 6;
  586. break;
  587. case 7:
  588. words = 7;
  589. break;
  590. default:
  591. break;
  592. }
  593. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  594. //
  595. this.playSecretaryRandomSound();
  596. })
  597. }
  598. openSecretaryView() {
  599. xGame.uiMgr.Show(UISecretary);
  600. Moyu.sendDataEvent("secretary");
  601. }
  602. openShopView() {
  603. xGame.uiMgr.Show(UIShop, 0);
  604. }
  605. openSignView() {
  606. xGame.uiMgr.Show(UISign);
  607. }
  608. openDrawView() {
  609. xGame.uiMgr.Show(UIDraw);
  610. }
  611. openRanking() {
  612. console.log('zh:phb openRanking')
  613. xGame.uiMgr.Show(UIRanking);
  614. Moyu.sendDataEvent("rankingList");
  615. }
  616. }
  617. UIMain.uiName = "UIMain";