1
0

UIMain.ts 29 KB

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