1
0

UIMain.ts 29 KB

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