1
0

UIMain.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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, LOGIN_OUT, LOGIN_IN } 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. xGame.eventMgr.on(LOGIN_OUT, this, this.setUserDefaultNickname);
  143. xGame.eventMgr.on(LOGIN_IN, this, this.event_login_in);
  144. ////// xGame.eventMgr.event(GET_USER_INFO);
  145. let curUse = DataMgr.getCurSecretary();
  146. this.changeSecretary(curUse);
  147. //
  148. //this.ui.rankBtn.visible = false;
  149. this.ui.talkNode.visible = false;
  150. let guide = DataMgr.getSkillGuide();
  151. if (xGame.common.isNewDay && guide == 1) {
  152. xGame.common.isNewDay = false;
  153. xGame.soundMgr.playSound("s_main01");
  154. xGame.common.showGirlTalkPop(1, this.ui.talkNode, this.ui.talkNode.womanTxt);
  155. console.log("zh:播放小秘书每天语音");
  156. }
  157. this.onGetUserInfo();
  158. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  159. DataMgr.getUserZiChanInfo();
  160. }
  161. this.ui.n83.visible = false;
  162. //万宁台球
  163. //Moyu.setShareInfo("8Ball Fury", ["台球", "台球", "桌球"], '2300002254');
  164. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  165. const d = LocalStorageManager.getItem<{ username: string, token: string }>(keyForLoginInfo);
  166. let ua = d.username;
  167. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(ua, 16);
  168. }
  169. this.c_btn_for_user();
  170. window['nativeCallJs'] = this.nativeCallJs.bind(this);
  171. // console.log('zh: 显示福利')
  172. // Laya.timer.once(100, this, () => {
  173. // console.log('zh: 1秒后 showFuLiSp1')
  174. // this.showFuLiSp1();
  175. // })
  176. this.loadUserSpOrderForAd();
  177. this.ui.n_fuli.visible = false;
  178. }
  179. Logout() {
  180. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  181. //const d = LocalStorageManager.getItem<{ username: string, token: string }>(keyForLoginInfo);
  182. LocalStorageManager.removeItem(keyForLoginInfo);
  183. this.freshUser();
  184. }
  185. //必须要调用APP退出登录
  186. JSBridgeUtils.instance.loginOutForApp();
  187. this.setUserDefaultNickname();
  188. DataMgr.setCoin2(4000);
  189. DataMgr.setDiamond2(0);
  190. this.setDefaultQiuGanInfo();
  191. DataMgr.setPlaceBallLevelList("");
  192. }
  193. /**
  194. * 球杆信息恢复原样
  195. */
  196. setDefaultQiuGanInfo() {
  197. DataMgr.setBallRod(0, 1);
  198. DataMgr.setBallRod(1, 0);
  199. DataMgr.setBallRod(2, 0);
  200. DataMgr.setBallRod(3, 0);
  201. DataMgr.setBallRod(4, 0);
  202. DataMgr.setBallRod(5, 1);
  203. }
  204. /**
  205. * 设置用户默认昵称
  206. */
  207. setUserDefaultNickname() {
  208. let defUsername = "player";
  209. this.ui.headNode.nameTxt.text = defUsername;
  210. DataMgr.updateUserNickName(defUsername);
  211. Moyu.updateUserInfo(defUsername);
  212. }
  213. gotoLogin() {
  214. xGame.uiMgr.Show(UILogin);
  215. }
  216. gotoRegUser() {
  217. xGame.uiMgr.Show(UIReg);
  218. }
  219. showFuLiSp1() {
  220. console.log('zh:福利1');
  221. this.checkForShowFuLi17(1);
  222. }
  223. showFuLiSp7() {
  224. console.log('zh:福利7');
  225. this.checkForShowFuLi17(7);
  226. }
  227. /**
  228. * 加载用户广告权利
  229. */
  230. loadUserSpOrderForAd() {
  231. let userInfo = LocalStorageManager.getItem(keyForLoginInfo);
  232. if (userInfo == null) {
  233. return;
  234. }
  235. let reqData = xGame.httpMgr.getReqData();
  236. xGame.httpMgr.sendPost2025('order/getOrderListForNoChongFuBuy', reqData, (res) => {
  237. try {
  238. console.log('zh:loadUserSpOrderForAd res = ' + JSON.stringify(res))
  239. let code = res.code;
  240. let msg = res.msg;
  241. if (code == 401) {
  242. Laya.LocalStorage.setItem(keyForLoginInfo, null);
  243. xGame.uiMgr.Show(UIMsg, TIP_MSG_key.pleaseLoginIn)
  244. return;
  245. }
  246. if (code == 200) {
  247. let data = res.data;
  248. let buy_spid1: boolean = false;
  249. let buy_spid7: boolean = false;
  250. for (let index = 0; index < data.length; index++) {
  251. let element = data[index];
  252. console.log('zh:list element.spid = ' + element.spid);
  253. if (element.spid == 1) {
  254. buy_spid1 = true;
  255. }
  256. if (element.spid == 7) {
  257. buy_spid7 = true;
  258. }
  259. }
  260. DataMgr.updateLocalUserDataForSpid17(1, buy_spid1);
  261. DataMgr.updateLocalUserDataForSpid17(7, buy_spid7);
  262. } else {
  263. xGame.uiMgr.Show(UIMsg, msg);
  264. }
  265. } catch (error) {
  266. console.log('error=' + error);
  267. alert(error);
  268. } finally {
  269. }
  270. });
  271. }
  272. /**
  273. *
  274. * @param spid 商品ID ,于数据库里的一致
  275. * @returns
  276. */
  277. checkForShowFuLi17(spid: number) {
  278. // let userInfo = LocalStorageManager.getItem(keyForLoginInfo);
  279. // if (userInfo == null) {
  280. // console.log('zh:没有登录就不显示福利弹框了');
  281. // return;
  282. // }
  283. let userInfo = LocalStorageManager.getItem(keyForLoginInfo);
  284. if (userInfo == null) {
  285. if (spid === 1) {
  286. xGame.uiMgr.Show(UIFuli1);
  287. } if (spid === 7) {
  288. xGame.uiMgr.Show(UIFuli2);
  289. }
  290. return;
  291. }
  292. console.log('zh:是否需要展示福利 ' + spid + ' 的弹窗');
  293. let reqData = xGame.httpMgr.getReqData();
  294. let pd: any = JSON.parse(reqData);
  295. pd.productId = spid;
  296. reqData = JSON.stringify(pd);
  297. xGame.httpMgr.sendPost2025('order/checkBuyFuLi', reqData, (res) => {
  298. try {
  299. console.log('zh:checkForShowFuLi17 res = ' + JSON.stringify(res))
  300. let code = res.code;
  301. let msg = res.msg;
  302. if (code == 401) {
  303. Laya.LocalStorage.setItem(keyForLoginInfo, null);
  304. xGame.uiMgr.Show(UIMsg, TIP_MSG_key.pleaseLoginIn)
  305. return;
  306. }
  307. if (code == 200) {//{"msg":"Please do not repeat the purchase.","code":200,"data":0}
  308. let isBuyOk = res.data;//true 表示已经购买
  309. DataMgr.updateLocalUserDataForSpid17(spid, isBuyOk);
  310. if (isBuyOk === false) {
  311. if (spid === 1) {
  312. xGame.uiMgr.Show(UIFuli1);
  313. } if (spid === 7) {
  314. xGame.uiMgr.Show(UIFuli2);
  315. }
  316. } else {
  317. console.log('zh:已经购买了SPID=' + spid + ',不需要再提示用户了')
  318. }
  319. } else {
  320. xGame.uiMgr.Show(UIMsg, msg);
  321. }
  322. } catch (error) {
  323. console.log('error=' + error);
  324. alert(error);
  325. } finally {
  326. }
  327. });
  328. }
  329. /**
  330. * 登录注册退出
  331. */
  332. c_btn_for_user() {
  333. this.ui.n_Logout.visible = false;
  334. this.ui.n_dengLu.visible = false;
  335. this.ui.n_zhuCe.visible = false;
  336. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  337. this.ui.n_Logout.visible = true;
  338. } else {
  339. this.ui.n_dengLu.visible = true;
  340. }
  341. }
  342. changeSecretary(curUse) {
  343. let name = cfgTable.secretaryshopData[curUse + 1].spine;
  344. xGame.common.secretary && xGame.common.secretary.dispose();
  345. this.addSecretarySpine(name);
  346. }
  347. addSecretarySpine(name) {
  348. let spine = new SpineMgr(name, () => {
  349. this.playSecretaryIdle();
  350. });
  351. xGame.common.secretary = spine;
  352. }
  353. addClickSpine() {
  354. let clickSpine = new SpineMgr("dianji", () => {
  355. Laya.stage.on(Laya.Event.CLICK, this, (e: Laya.Event) => {
  356. //
  357. let parent = Laya.stage;
  358. let data = { x: e.stageX, y: e.stageY, scaleX: 0.8, scaleY: 0.8 };
  359. clickSpine.play(data, 0, false, parent, (spine) => {
  360. spine.destroy(true);
  361. });
  362. })
  363. //
  364. });
  365. }
  366. private addEvent(): void {
  367. this.addUIClick(this.ui.classicBtn, this.startGame, [GameMode.classic]);
  368. this.addUIClick(this.ui.bigMoveBtn, this.startGame, [GameMode.bigMove])
  369. this.addUIClick(this.ui.ganFaMoShiBtn, this.startGame, [GameMode.bigMove])
  370. //
  371. this.addUIClick(this.ui.globalBtn, this.startGlobal);
  372. // this.addUIClick(this.ui.weeklyBtn, this.startWeekly);
  373. this.addUIClick(this.ui.placeBallBtn, this.startPlaceBall);
  374. //
  375. this.addUIClick(this.ui.headNode, this.onGetUserInfo, [true]);
  376. this.addUIClick(this.ui, this.interuptSecretary);
  377. this.addUIClick(this.ui.rightBtn, this.ensureSecretary);
  378. this.addUIClick(this.ui.guideBtn, this.startGame, [GameMode.bigMove]);
  379. this.addUIClick(this.ui.secretaryBtn, this.openSecretaryView);
  380. this.addUIClick(this.ui.shopBtn, this.openShopView);
  381. //
  382. this.addUIClick(this.ui.signBtn, this.openSignView);
  383. this.addUIClick(this.ui.drawBtn, this.openDrawView);
  384. this.addUIClick(this.ui.rankBtn, this.openRanking);
  385. //退出登录
  386. this.addUIClick(this.ui.n_Logout, this.Logout);
  387. this.addUIClick(this.ui.n_dengLu, this.gotoLogin);
  388. this.addUIClick(this.ui.n_zhuCe, this.gotoRegUser);
  389. this.addUIClick(this.ui.n_fuli, this.showFuLiSp7);
  390. //调试专用
  391. this.addUIClick(this.ui.n_moni_pay_ok, this.start_debug_for_moni_payOk);
  392. }
  393. public show(showFailWords): void {
  394. super.show();
  395. this.loadUserSpOrderForAd();
  396. //
  397. this.moneyNode.ui.c1.selectedIndex = 1;
  398. this.playSecretaryIdle();
  399. xGame.soundMgr.playMusic("caromhall01", 0);
  400. Laya.timer.clearAll(this);
  401. this.playSecretaryRandomSound();
  402. console.log('zh:uimain.ts show show FailWords=', showFailWords);
  403. if (showFailWords) {
  404. console.log('zh:uimain.ts ')
  405. //延迟播放进入主页面的失败音效
  406. setTimeout(() => {
  407. let str = Math.random() <= 0.5 ? "s_main02" : "s_main03";
  408. let words = -1;
  409. if (str == "s_main02") {
  410. words = 2;
  411. }
  412. else {
  413. words = 3;
  414. }
  415. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  416. xGame.soundMgr.playSound(str);
  417. }, 300);
  418. }
  419. // setTimeout(() => {
  420. // console.log('zh:播放7背景音乐 m ')
  421. // xGame.soundMgr.playSound('bjyy_m', 0);
  422. // }, 2000);
  423. //
  424. this.showGuide();
  425. this.ui.guideBtn.x = this.ui.liucheng2.myMask.x;
  426. this.ui.guideBtn.y = this.ui.liucheng2.myMask.y;
  427. //
  428. let guide = DataMgr.getSkillGuide();
  429. if (guide == 1) {
  430. let randTime = xGame.common.randomNum(300, 800);
  431. if (this.firstEnter) {
  432. console.log("zh: firstEnter");
  433. this.firstEnter = false;
  434. randTime += 900;
  435. } else {
  436. console.log("zh: no firstEnter");
  437. }
  438. Laya.timer.once(randTime, this, () => {
  439. // xGame.common.autoPopUIView();
  440. })
  441. Laya.timer.once(1000, this, () => {
  442. console.log('zh: 1秒后 showFuLiSp1')
  443. this.showFuLiSp1();
  444. })
  445. Laya.timer.once(10000, this, () => {
  446. console.log('zh: 10秒后 showFuLiSp1')
  447. this.showFuLiSp7();
  448. })
  449. }
  450. }
  451. checkActive(show) {
  452. //console.log("是否处于最外层",show);
  453. //wx banner太大
  454. // if (!Moyu.isWx)
  455. // PlatMgr.showBanner(show);
  456. }
  457. showGuide() {
  458. let guide = DataMgr.getSkillGuide();
  459. this.ui.guideBtn.visible = guide == 0;
  460. this.ui.enterGuide.visible = false;
  461. this.ui.secretaryGuide.visible = guide == 0;
  462. if (guide == 0) {
  463. console.log("zh:显示引导");
  464. xGame.soundMgr.playSound("s_guide");
  465. xGame.common.showGirlTalkPop(16, this.ui.talkNode, this.ui.talkNode.womanTxt);
  466. } else {
  467. console.log("zh:不需要显示引导");
  468. }
  469. }
  470. ensureSecretary() {
  471. console.log('zh: ensureSecretary ensureSecretaryensureSecretaryensureSecretaryensureSecretaryensureSecretary')
  472. this.ui.secretaryGuide.visible = false;
  473. this.ui.enterGuide.visible = true;
  474. this.ui.wordsNode.t0.play();
  475. //todo
  476. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameReady");
  477. }
  478. playSecretaryIdle() {
  479. let parent = this.ui.secretary.displayObject;
  480. parent.destroyChildren();
  481. let xx = this.ui.secretary.width / 2;
  482. let yy = this.ui.secretary.height;
  483. // xx = Laya.stage.width / 2;
  484. // yy = Laya.stage.height;
  485. let scale = xGame.common.getSecretaryScale();
  486. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  487. //console.log("zh:playSecretaryIdle", data);
  488. //xGame.common.secretary.play(data, 1, true, parent); 这是老的秘书
  489. xGame.common.secretary.play(data, 0, true, parent);
  490. }
  491. startGame(type: GameMode) {
  492. if (!this.isReadyForLoadNetSource()) {
  493. return;
  494. }
  495. // console.log('zh: 停止播放主頁面背景音乐');
  496. // xGame.soundMgr.stopMusic();
  497. //进入游戏页面
  498. xGame.common.gameMode = type;
  499. //
  500. Moyu.sendDataEvent("PlayGame", { type: type });
  501. console.log('zh:进入游戏gameMode =' + xGame.common.gameMode);
  502. switch (xGame.common.gameMode) {
  503. case GameMode.classic:
  504. console.log('zh:进入经典模式111111111');
  505. //zhdiy - challenge mode作为教学练习关,完成2关解锁classic,
  506. if (DataMgr.DIY_challengeMode_overLev_jieSuo_mark) {
  507. let db_over_lev = DataMgr.getChallengeMode_overLev();
  508. console.log('zh:classic db_over_lev=', db_over_lev);
  509. if (db_over_lev < DataMgr.DIY_challengeMode_overLev_jieSuo_Classic) {
  510. console.log('zh:判断是否可以玩该模式classic =NO');
  511. let tipStr = 'You must complete ' + DataMgr.DIY_challengeMode_overLev_jieSuo_Classic + ' levels in Challenge Mode to unlock Classic Mode.';
  512. xGame.uiMgr.Show(UIMsg, tipStr);
  513. return;
  514. } else {
  515. console.log('zh:可以玩该模式classic 66666666666666');
  516. this.beginGame();
  517. }
  518. } else {
  519. console.log('zh:不需要判断是否可以玩该classic');
  520. let challengeTimes = DataMgr.getChallengeTimes();
  521. if (challengeTimes == 0) {
  522. xGame.uiMgr.Show(UIInvitation);
  523. }
  524. else {
  525. this.beginGame();
  526. }
  527. break;
  528. }
  529. case GameMode.bigMove:
  530. console.error('zh:bigMove check');
  531. let guide = DataMgr.getSkillGuide();
  532. //zhdiy - challenge mode作为教学练习关,完成2关解锁classic,
  533. if (DataMgr.DIY_challengeMode_overLev_jieSuo_mark && guide == 1) {
  534. let db_over_lev = DataMgr.getChallengeMode_overLev();
  535. console.log('zh:bigMove db_over_lev=', db_over_lev);
  536. if (db_over_lev < DataMgr.DIY_challengeMode_overLev_jieSuo_rodMethod) {
  537. let tipStr = 'Complete ' + DataMgr.DIY_challengeMode_overLev_jieSuo_rodMethod + ' levels in Challenge Mode to unlock the Rod Method Mode';
  538. xGame.uiMgr.Show(UIMsg, tipStr);
  539. return;
  540. } else {
  541. console.log('zh:可以玩该模式 bigMove');
  542. this.beginGame();
  543. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameStart0");
  544. }
  545. } else {
  546. this.beginGame();
  547. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameStart0");
  548. }
  549. break;
  550. default:
  551. console.error('zh:未知错误!!!!');
  552. break;
  553. }
  554. }
  555. beginGame(isNice = false) {
  556. console.log('zh:beginGame ');
  557. //TODO:ZH 插屏AD
  558. //let time = xGame.common.randomNum(1000, 2000);
  559. //Moyu.showInsertAd(time, 60000);
  560. let guide = DataMgr.getSkillGuide();
  561. if (guide == 1) {//非新手引导,就显示,否则不显示
  562. console.log('zh:非新手引导,showInternAd ');
  563. JSBridgeUtils.instance.showInternAd('beginGame');
  564. } else {
  565. console.log('zh:新手引导,不显示AD ');
  566. }
  567. console.log('zh:beginGame 2 go');
  568. if (xGame.common.gameMode == GameMode.classic) {
  569. // xGame.uiMgr.Show(UIMsg, "Coming Soon")
  570. if (isNice) {
  571. //巅峰赛直接进入
  572. this.enterClassic();
  573. }
  574. else {
  575. xGame.uiMgr.Show(UIModeSelection, () => {
  576. console.log('zh:BBBBBBBBBBBBBBB');
  577. this.enterClassic();
  578. })
  579. }
  580. }
  581. else if (xGame.common.gameMode == GameMode.bigMove) {
  582. this.ui.enterGuide.visible = false;
  583. xGame.uiMgr.Show(UISkill);
  584. }
  585. }
  586. enterClassic() {
  587. xGame.uiMgr.Show(UIGame);
  588. xGame.uiMgr.Show(UIMatching, () => {
  589. if (!this.isHide) this.hide();
  590. xGame.common.gameUI.ui.alpha = 1;
  591. xGame.common.gameUI.startGame();
  592. xGame.uiMgr.Hide(UIGameEnd);
  593. });
  594. }
  595. /**
  596. * 模拟支付OK
  597. * @returns
  598. */
  599. start_debug_for_moni_payOk() {
  600. console.log('zh:start_debug_for_moni_payOk')
  601. let userInfo = LocalStorageManager.getItem(keyForLoginInfo);
  602. if (userInfo != null) {
  603. let token = userInfo.token;
  604. let ggSpid = 'com.vadltq.strike.ball.cue.gem50';
  605. JSBridgeUtils.instance.testPay1ForMoNiPayOver(token, ggSpid, 1);
  606. alert('模拟支付OK')
  607. return;
  608. } else {
  609. xGame.uiMgr.Show(UIMsg, TIP_MSG_key.pleaseLoginIn);
  610. }
  611. }
  612. startGlobal() {
  613. xGame.uiMgr.Show(UIMsg, "Coming Soon.")
  614. //xGame.uiMgr.Show(UITry);
  615. // JSBridgeUtils.instance.showInternAd('');
  616. }
  617. startWeekly() {
  618. //xGame.uiMgr.Show(UIBox);
  619. xGame.uiMgr.Show(UIMsg, "Coming Soon")
  620. //测试AD
  621. // GlobalManager.instance.registerMethod('zhouSaiMonth', this.zhouSaiMonth);
  622. //JSBridgeUtils.instance.showRewardAd('zhouSaiMonth');
  623. }
  624. zhouSaiMonth() {
  625. console.log('zh: zhouSaiMonth 被调用')
  626. }
  627. //网络资源是否准备好了
  628. public isReadyForLoadNetSource(): boolean {
  629. let reqCount = xGame.cfgMgr.httpReqCount;
  630. let ok = xGame.cfgMgr.httpReqOkCount;
  631. if (reqCount > ok) {
  632. //console.log('zh:网络资源没有准备完成,请稍后再试');
  633. xGame.uiMgr.Show(UIMsg, "Network not ready. Try again later.")
  634. console.log('zh:✅❌ 5秒后重新尝试加载网络资源');
  635. Laya.timer.once(5000, this, () => {
  636. let retryCount = 0;
  637. const maxRetries = 3;
  638. const tryFetchConfig = () => {
  639. try {
  640. xGame.cfgMgr.getConfigFromServer();
  641. } catch (error) {
  642. if (retryCount < maxRetries) {
  643. retryCount++;
  644. console.log(`🔄 第${retryCount}次重试获取配置...`);
  645. Laya.timer.once(5000, this, tryFetchConfig);
  646. } else {
  647. console.error("❌ 达到最大重试次数,配置获取失败");
  648. }
  649. }
  650. };
  651. tryFetchConfig();
  652. });
  653. return false;
  654. }
  655. return true;
  656. }
  657. startPlaceBall() {
  658. if (!this.isReadyForLoadNetSource()) {
  659. return;
  660. }
  661. xGame.uiMgr.Show(UILevelDisplay);
  662. }
  663. public hide(): void {
  664. console.log('zh:uimain hide ...');
  665. // console.log('zh:停止播放bjyy_m');
  666. //xGame.soundMgr.stopSound("bjyy_m");
  667. // console.log('zh: hide 停止播放主頁面背景音乐');
  668. // xGame.soundMgr.stopMusic();
  669. super.hide();
  670. xGame.common.stopGirlPop(this.ui.talkNode)
  671. }
  672. //点击头像
  673. onGetUserInfo(force = false) {
  674. if (Moyu.isWx) {
  675. let info = Moyu.getSystemInfo();
  676. if (info)
  677. Moyu.createWXUserBtn(0, 0, info.width, info.height, 'res/wxuser.png', this.freshUser);
  678. }
  679. else {
  680. Moyu.initUser(this, this.freshUser, force)
  681. }
  682. // if (!Moyu.hasUserInfo) {
  683. // let user = Moyu.getUserInfo();
  684. // //user.nickName="我";
  685. // user.headIcon = 'res/ty_touxiang.png';
  686. // //console.log("未授权");
  687. // }
  688. this.freshUser();
  689. console.log('zh:5秒后更新用戶資產信息')
  690. // Laya.timer.once(5000, this, () => {
  691. // console.log('zh:5秒over 更新用戶資產信息')
  692. // DataMgr.getUserZiChanInfo();
  693. // });
  694. setTimeout(() => {
  695. console.log('setTimeout 5秒over 執行');
  696. DataMgr.getUserZiChanInfo();
  697. }, 5000);
  698. }
  699. event_login_in() {
  700. console.log("zh:event_login_in被触发");
  701. this.freshUser();
  702. }
  703. freshUser() {
  704. let user = Moyu.getUserInfo();
  705. if (!user.isAuth) {
  706. user.headIcon = 'res/ty_touxiang.png';
  707. }
  708. else {
  709. DataMgr.upRankData();
  710. }
  711. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(user.nickName, 16);
  712. xGame.common.createHead(this.ui.headNode.headRoot.headImg, user.headIcon);
  713. let keyStr = keyForLoginInfo;
  714. if (LocalStorageManager.hasJosnKey(keyStr)) {
  715. const d = LocalStorageManager.getItem<{ username: string, token: string }>(keyStr);
  716. let ua = d.username;
  717. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(ua, 16);
  718. } else {
  719. }
  720. this.c_btn_for_user();
  721. }
  722. interuptSecretary() {
  723. Laya.timer.clearAll(this);
  724. this.playSecretaryRandomSound();
  725. }
  726. //主界面和技能选择界面3-7秒未操作随机播放秘书音效
  727. playSecretaryRandomSound() {
  728. if (this.isHide) return;
  729. let time = xGame.common.randomNum(45000, 60000);
  730. Laya.timer.once(time, this, () => {
  731. if (this.isHide) return;
  732. let index = xGame.common.randomNum(4, 7);
  733. xGame.soundMgr.playSound("s_main0" + index);
  734. let words = 1;
  735. switch (index) {
  736. case 4:
  737. words = 5;
  738. break;
  739. case 5:
  740. words = 3;
  741. break;
  742. case 6:
  743. words = 6;
  744. break;
  745. case 7:
  746. words = 7;
  747. break;
  748. default:
  749. break;
  750. }
  751. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  752. //
  753. this.playSecretaryRandomSound();
  754. })
  755. }
  756. openSecretaryView() {
  757. xGame.uiMgr.Show(UISecretary);
  758. Moyu.sendDataEvent("secretary");
  759. }
  760. openShopView() {
  761. xGame.uiMgr.Show(UIShop, 0);
  762. }
  763. openSignView() {
  764. xGame.uiMgr.Show(UISign);
  765. }
  766. openDrawView() {
  767. xGame.uiMgr.Show(UIDraw);
  768. }
  769. openRanking() {
  770. console.log('zh:phb openRanking')
  771. xGame.uiMgr.Show(UIRanking);
  772. Moyu.sendDataEvent("rankingList");
  773. }
  774. }
  775. UIMain.uiName = "UIMain";