UIMain.ts 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  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, TipsType } 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. import UITips from "../ui/UITips";
  41. export default class UIMain extends UIBase {
  42. public ui: ui_UIMain;
  43. public settingNode: SettingNode;
  44. public moneyNode: MoneyNode;
  45. public firstEnter = true;
  46. nativeCallJs(msg: string) {
  47. let t = msg;
  48. console.log("zh: nativeCallJs 奖励开始发放:", t);
  49. //GlobalManager.instance.callMethod(msg)
  50. switch (t) {
  51. case 'qjff_chouJiang':
  52. let dui = <UIDraw>xGame.uiMgr.getUI(UIDraw);
  53. dui.qjff_chouJiang();
  54. break;
  55. case 'qjff_AD_for_uisign':
  56. let dui2 = <UISign>xGame.uiMgr.getUI(UISign);
  57. dui2.qjff_AD_for_uisign();
  58. break;
  59. case 'qjff_AD_for_uitry':
  60. let dui3 = <UITry>xGame.uiMgr.getUI(UITry);
  61. dui3.qjff_AD_for_uitry();
  62. break;
  63. case 'qjff_AD_for_uipower':
  64. let dui4 = <UIPower>xGame.uiMgr.getUI(UIPower);
  65. dui4.qjff_AD_for_uipower();
  66. break;
  67. case 'qjff_AD_for_uigetAward':
  68. let dui5 = <UIGetAward>xGame.uiMgr.getUI(UIGetAward);
  69. dui5.qjff_AD_for_uigetAward();
  70. break;
  71. case 'qjff_AD_for_uiGameEnd':
  72. let temp_level = Laya.LocalStorage.getItem('temp_qjff_AD_for_uiGameEnd_level');
  73. let dui6 = <UIGameEnd>xGame.uiMgr.getUI(UIGameEnd);
  74. dui6.qjff_AD_for_uiGameEnd(parseInt(temp_level))
  75. break;
  76. case 'qjff_AD_for_uiAddProp_videoGetDiamond':
  77. let dui7 = <UIAddProp>xGame.uiMgr.getUI(UIAddProp);
  78. dui7.qjff_AD_for_uiAddProp_videoGetDiamond();
  79. break;
  80. case 'qjff_AD_for_uiAddProp_videoGetCoin':
  81. let dui8 = <UIAddProp>xGame.uiMgr.getUI(UIAddProp);
  82. dui8.qjff_AD_for_uiAddProp_videoGetCoin();
  83. break;
  84. case 'qjff_AD_for_UIrepentProp_videoRegret':
  85. let dui9 = <UIRepentProp>xGame.uiMgr.getUI(UIRepentProp);
  86. dui9.qjff_AD_for_UIrepentProp_videoRegret();
  87. break;
  88. case 'qjff_AD_for_UIrepentProp_videoAddHelpLine':
  89. let dui10 = <UIRepentProp>xGame.uiMgr.getUI(UIRepentProp);
  90. dui10.qjff_AD_for_UIrepentProp_videoAddHelpLine();
  91. break;
  92. case 'qjff_AD_for_UIBOX_onOpenBox':
  93. let dui11 = <UIBox>xGame.uiMgr.getUI(UIBox);
  94. dui11.qjff_AD_for_UIBOX_onOpenBox();
  95. break;
  96. case 'qjff_AD_for_UIAddCoin':
  97. let dui12 = <UIAddCoin>xGame.uiMgr.getUI(UIAddCoin);
  98. dui12.qjff_AD_for_UIAddCoin();
  99. break;
  100. // case 'qjff_AD_for_skilldisplay_clickAddLevel':
  101. // // SkillDisplay s=new SkillDisplay();//改为插屏了
  102. // // s.qjff_AD_for_skilldisplay_clickAddLevel();
  103. // break;
  104. //当APP中购买成功之后,需要回调这里,然后通知更新用户资产信息
  105. case 'app_sign_for_buyProduct_onSuccess':
  106. console.log('zh:收到APP通知,需要更新用户游戏资产信息app_sign_for_buyProduct_onSuccess ');
  107. DataMgr.getUserZiChanInfo(false);
  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. //xGame.eventMgr.on(COIN_CHANGE)
  148. let curUse = DataMgr.getCurSecretary();
  149. this.changeSecretary(curUse);
  150. //
  151. //this.ui.rankBtn.visible = false;
  152. this.ui.talkNode.visible = false;
  153. let guide = DataMgr.getSkillGuide();
  154. if (xGame.common.isNewDay && guide == 1) {
  155. xGame.common.isNewDay = false;
  156. xGame.soundMgr.playSound("s_main01");
  157. xGame.common.showGirlTalkPop(1, this.ui.talkNode, this.ui.talkNode.womanTxt);
  158. console.log("zh:播放小秘书每天语音");
  159. }
  160. this.onGetUserInfo();
  161. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  162. DataMgr.getUserZiChanInfo(false);
  163. }
  164. this.ui.n83.visible = false;
  165. //万宁台球
  166. //Moyu.setShareInfo("8Ball Fury", ["台球", "台球", "桌球"], '2300002254');
  167. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  168. const d = LocalStorageManager.getItem<{ username: string, token: string }>(keyForLoginInfo);
  169. let ua = d.username;
  170. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(ua, 16);
  171. }
  172. this.c_btn_for_user();
  173. window['nativeCallJs'] = this.nativeCallJs.bind(this);
  174. // console.log('zh: 显示福利')
  175. // Laya.timer.once(100, this, () => {
  176. // console.log('zh: 1秒后 showFuLiSp1')
  177. // this.showFuLiSp1();
  178. // })
  179. }
  180. Logout() {
  181. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  182. //const d = LocalStorageManager.getItem<{ username: string, token: string }>(keyForLoginInfo);
  183. LocalStorageManager.removeItem(keyForLoginInfo);
  184. this.freshUser();
  185. }
  186. //必须要调用APP退出登录
  187. JSBridgeUtils.instance.loginOutForApp();
  188. this.setUserDefaultNickname();
  189. DataMgr.setCoin2(4000);
  190. DataMgr.setDiamond2(0);
  191. this.setDefaultQiuGanInfo();
  192. DataMgr.setPlaceBallLevelList("");
  193. DataMgr.setChallengeMode_overLev(1);
  194. this.setDefaultSignData();
  195. DataMgr.setBigSkillFormServer('[1, 1, 1, 1, 1]');//初始值
  196. }
  197. /**
  198. * 默认签到数据
  199. * @param val
  200. */
  201. setDefaultSignData() {
  202. DataMgr.setSignData(1);
  203. DataMgr.setSignTime(new Date().getTime());
  204. }
  205. /**
  206. * 球杆信息恢复原样
  207. */
  208. setDefaultQiuGanInfo() {
  209. DataMgr.setBallRod(0, 1);
  210. DataMgr.setBallRod(1, 0);
  211. DataMgr.setBallRod(2, 0);
  212. DataMgr.setBallRod(3, 0);
  213. DataMgr.setBallRod(4, 0);
  214. DataMgr.setBallRod(5, 1);
  215. }
  216. /**
  217. * 设置用户默认昵称
  218. */
  219. setUserDefaultNickname() {
  220. let defUsername = "player";
  221. this.ui.headNode.nameTxt.text = defUsername;
  222. DataMgr.updateUserNickName(defUsername);
  223. Moyu.updateUserInfo(defUsername);
  224. }
  225. gotoLogin() {
  226. // if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  227. // this.ui.n_dengLu.c1.selectedIndex = 1;
  228. // } else {
  229. // this.ui.n_dengLu.c1.selectedIndex = 0
  230. // }
  231. if (this.ui.n_dengLu.c1.selectedIndex == 0) {
  232. xGame.uiMgr.Show(UILogin);
  233. }
  234. if (this.ui.n_dengLu.c1.selectedIndex == 1) {
  235. this.Logout();
  236. }
  237. }
  238. gotoRegUser() {
  239. xGame.uiMgr.Show(UIReg);
  240. }
  241. showFuLiSp1() {
  242. console.log('zh:福利1');
  243. DataMgr.checkForShowFuLi17AndAlert(1)
  244. }
  245. showFuLiSp7() {
  246. console.log('zh:福利7');
  247. DataMgr.checkForShowFuLi17AndAlert(7)
  248. }
  249. /**
  250. * 登录注册退出
  251. */
  252. c_btn_for_user() {
  253. this.ui.n_dengLu.c1.selectedIndex = 0
  254. if (LocalStorageManager.hasJosnKey(keyForLoginInfo)) {
  255. this.ui.n_dengLu.c1.selectedIndex = 1;
  256. } else {
  257. this.ui.n_dengLu.c1.selectedIndex = 0
  258. }
  259. }
  260. changeSecretary(curUse) {
  261. let name = cfgTable.secretaryshopData[curUse + 1].spine;
  262. xGame.common.secretary && xGame.common.secretary.dispose();
  263. this.addSecretarySpine(name);
  264. }
  265. addSecretarySpine(name) {
  266. let spine = new SpineMgr(name, () => {
  267. this.playSecretaryIdle();
  268. });
  269. xGame.common.secretary = spine;
  270. }
  271. addClickSpine() {
  272. let clickSpine = new SpineMgr("dianji", () => {
  273. Laya.stage.on(Laya.Event.CLICK, this, (e: Laya.Event) => {
  274. //
  275. let parent = Laya.stage;
  276. let data = { x: e.stageX, y: e.stageY, scaleX: 0.8, scaleY: 0.8 };
  277. clickSpine.play(data, 0, false, parent, (spine) => {
  278. spine.destroy(true);
  279. });
  280. })
  281. //
  282. });
  283. }
  284. private addEvent(): void {
  285. this.addUIClick(this.ui.classicBtn, this.startGame, [GameMode.classic]);
  286. this.addUIClick(this.ui.bigMoveBtn, this.startGame, [GameMode.bigMove])
  287. // this.addUIClick(this.ui.ganFaMoShiBtn, this.startGame, [GameMode.bigMove])
  288. this.addUIClick(this.ui.ganFaMoShiBtn, this.openShopView0)//原先右下角的干法模式改为链接到shop
  289. //
  290. this.addUIClick(this.ui.globalBtn, this.startGlobal);
  291. // this.addUIClick(this.ui.weeklyBtn, this.startWeekly);
  292. this.addUIClick(this.ui.placeBallBtn, this.startPlaceBall);
  293. //
  294. this.addUIClick(this.ui.headNode, this.onGetUserInfo, [true]);
  295. this.addUIClick(this.ui, this.interuptSecretary);
  296. this.addUIClick(this.ui.rightBtn, this.ensureSecretary);
  297. this.addUIClick(this.ui.guideBtn, this.startGame, [GameMode.bigMove]);
  298. this.addUIClick(this.ui.secretaryBtn, this.openSecretaryView);
  299. this.addUIClick(this.ui.shopBtn, this.openShopView);
  300. //
  301. this.addUIClick(this.ui.signBtn, this.openSignView);
  302. this.addUIClick(this.ui.drawBtn, this.openDrawView);
  303. this.addUIClick(this.ui.rankBtn, this.openRanking);
  304. //那個小手
  305. this.addUIClick(this.ui.n73, this.startGame, [GameMode.bigMove]);
  306. ///练习模式的引导start
  307. this.addUIClick(this.ui.n_yd_challenge_1_btn, this.startPlaceBall);
  308. //退出登录
  309. this.addUIClick(this.ui.n_dengLu, this.gotoLogin);
  310. // this.addUIClick(this.ui.n_fuli, this.showFuLiSp7);
  311. //调试专用
  312. this.addUIClick(this.ui.n_moni_pay_ok, this.start_debug_for_moni_payOk);
  313. }
  314. public show(showFailWords): void {
  315. super.show();
  316. DataMgr.loadUserSpOrderForAd();
  317. //
  318. this.moneyNode.ui.c1.selectedIndex = 1;
  319. this.playSecretaryIdle();
  320. xGame.soundMgr.playMusic("caromhall01", 0);
  321. Laya.timer.clearAll(this);
  322. this.playSecretaryRandomSound();
  323. console.log('zh:uimain.ts show show FailWords=', showFailWords);
  324. if (showFailWords) {
  325. console.log('zh:uimain.ts ')
  326. //延迟播放进入主页面的失败音效
  327. setTimeout(() => {
  328. let str = Math.random() <= 0.5 ? "s_main02" : "s_main03";
  329. let words = -1;
  330. if (str == "s_main02") {
  331. words = 2;
  332. }
  333. else {
  334. words = 3;
  335. }
  336. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  337. xGame.soundMgr.playSound(str);
  338. }, 300);
  339. }
  340. // setTimeout(() => {
  341. // console.log('zh:播放7背景音乐 m ')
  342. // xGame.soundMgr.playSound('bjyy_m', 0);
  343. // }, 2000);
  344. this.showGuide();
  345. this.ui.guideBtn.x = this.ui.liucheng2.myMask.x;
  346. this.ui.guideBtn.y = this.ui.liucheng2.myMask.y;
  347. //
  348. let guide = DataMgr.getSkillGuide();
  349. if (guide == 1) {
  350. let randTime = xGame.common.randomNum(300, 800);
  351. if (this.firstEnter) {
  352. console.log("zh: firstEnter");
  353. this.firstEnter = false;
  354. randTime += 900;
  355. } else {
  356. console.log("zh: no firstEnter");
  357. }
  358. Laya.timer.once(randTime, this, () => {
  359. // xGame.common.autoPopUIView();
  360. })
  361. // Laya.timer.once(1000, this, () => {
  362. // console.log('zh: 1秒后 showFuLiSp1')
  363. // this.showFuLiSp1();
  364. // })
  365. Laya.timer.once(1000, this, () => {
  366. console.log('zh: 1秒后 showFuLiSp7')
  367. this.showFuLiSp7();
  368. })
  369. //引导登录
  370. this.showTipForGuest();
  371. }
  372. this.setGlobalFont(this.ui)
  373. // this.yinDaoForLianxi();
  374. }
  375. /**
  376. * 练习模式 引导 ,他给人家起名字是什么挑战模式
  377. */
  378. yinDaoForLianxi() {
  379. let x = this.ui.placeBallBtn.x;
  380. let y = this.ui.placeBallBtn.y;
  381. this.ui.n_yd_challenge_1.visible = true;
  382. this.ui.n_yd_challenge_1_hand.x = x + 150;
  383. this.ui.n_yd_challenge_1_hand.y = y;
  384. this.ui.n_yd_challenge_1_btn.x = x;
  385. this.ui.n_yd_challenge_1_btn.y = y;
  386. console.log('zh:yinDaoForLianxi set ok')
  387. }
  388. showTipForGuest() {
  389. let userInfo = LocalStorageManager.getItem(keyForLoginInfo);
  390. if (userInfo == null) {
  391. console.log('zh: 游客模式下数据可能丢失,建议登录账号')
  392. //游客模式下数据可能丢失,建议登录账号
  393. //JSBridgeUtils.instance.showToast2('Data may be lost in guest mode. Logging in is recommended.');
  394. let tips = "Data may be lost in guest mode. Logging in is recommended."
  395. let woman = "this is an important notice."
  396. xGame.uiMgr.Show(UITips, tips, woman, TipsType.foul);
  397. return;
  398. }
  399. }
  400. checkActive(show) {
  401. //console.log("是否处于最外层",show);
  402. //wx banner太大
  403. // if (!Moyu.isWx)
  404. // PlatMgr.showBanner(show);
  405. }
  406. showGuide() {
  407. let guide = DataMgr.getSkillGuide();
  408. this.ui.guideBtn.visible = guide == 0;
  409. this.ui.enterGuide.visible = false;
  410. this.ui.secretaryGuide.visible = guide == 0;
  411. if (guide == 0) {
  412. console.log("zh:显示引导");
  413. xGame.soundMgr.playSound("s_guide");
  414. xGame.common.showGirlTalkPop(16, this.ui.talkNode, this.ui.talkNode.womanTxt);
  415. } else {
  416. console.log("zh:不需要显示引导");
  417. }
  418. }
  419. ensureSecretary() {
  420. console.log('zh: ensureSecretary ');
  421. this.ui.secretaryGuide.visible = false;
  422. this.ui.enterGuide.visible = true;
  423. this.ui.wordsNode.t0.play();
  424. //todo
  425. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameReady");
  426. }
  427. playSecretaryIdle() {
  428. let parent = this.ui.secretary.displayObject;
  429. parent.destroyChildren();
  430. let xx = this.ui.secretary.width / 2;
  431. let yy = this.ui.secretary.height;
  432. // xx = Laya.stage.width / 2;
  433. // yy = Laya.stage.height;
  434. let scale = xGame.common.getSecretaryScale();
  435. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  436. //console.log("zh:playSecretaryIdle", data);
  437. //xGame.common.secretary.play(data, 1, true, parent); 这是老的秘书
  438. xGame.common.secretary.play(data, 0, true, parent);
  439. }
  440. startGame(type: GameMode) {
  441. if (!this.isReadyForLoadNetSource()) {
  442. return;
  443. }
  444. // console.log('zh: 停止播放主頁面背景音乐');
  445. // xGame.soundMgr.stopMusic();
  446. //进入游戏页面
  447. xGame.common.gameMode = type;
  448. Moyu.sendDataEvent("PlayGame", { type: type });
  449. let gm = xGame.common.gameMode;
  450. console.log('zh:进入游戏gameMode =' + gm);
  451. switch (gm) {
  452. case GameMode.classic:
  453. console.log('zh:进入经典模式111111111');
  454. //zhdiy - challenge mode作为教学练习关,完成2关解锁classic,
  455. if (DataMgr.DIY_challengeMode_overLev_jieSuo_mark) {
  456. let db_over_lev = DataMgr.getChallengeMode_overLev();
  457. console.log('zh:classic 经典模式 db_over_lev=', db_over_lev);
  458. if (db_over_lev < DataMgr.DIY_challengeMode_overLev_jieSuo_Classic) {
  459. console.log('zh:判断是否可以玩该模式classic =NO');
  460. let tipStr = 'You must complete ' + DataMgr.DIY_challengeMode_overLev_jieSuo_Classic + ' levels in Challenge Mode to unlock Classic Mode.';
  461. xGame.uiMgr.Show(UIMsg, tipStr);
  462. return;
  463. } else {
  464. console.log('zh:可以玩该模式classic');
  465. this.beginGame();
  466. }
  467. } else {
  468. console.log('zh:不需要判断是否可以玩该classic');
  469. let challengeTimes = DataMgr.getChallengeTimes();
  470. if (challengeTimes == 0) {
  471. xGame.uiMgr.Show(UIInvitation);
  472. }
  473. else {
  474. this.beginGame();
  475. }
  476. }
  477. break;
  478. case GameMode.bigMove:
  479. console.info('zh:bigMove check 大招');
  480. let guide = DataMgr.getSkillGuide();
  481. //zhdiy - challenge mode作为教学练习关,完成2关解锁classic,
  482. if (DataMgr.DIY_challengeMode_overLev_jieSuo_mark && guide == 1) {
  483. let db_over_lev = DataMgr.getChallengeMode_overLev();
  484. console.log('zh:bigMove db_over_lev=', db_over_lev);
  485. if (db_over_lev < DataMgr.DIY_challengeMode_overLev_jieSuo_rodMethod) {
  486. console.log('zh:提示不可以玩')
  487. let tipStr = 'Complete ' + DataMgr.DIY_challengeMode_overLev_jieSuo_rodMethod + ' levels in Challenge Mode to unlock the Rod Method Mode';
  488. xGame.uiMgr.Show(UIMsg, tipStr);
  489. return;
  490. } else {
  491. console.log('zh:可以玩该模式 bigMove');
  492. this.beginGame();
  493. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameStart0");
  494. }
  495. } else {
  496. this.beginGame();
  497. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameStart0");
  498. }
  499. break;
  500. default:
  501. console.error('zh:未知错误!!!!');
  502. break;
  503. }
  504. }
  505. beginGame(isNice = false) {
  506. console.log('zh:beginGame ');
  507. //TODO:ZH 插屏AD
  508. //let time = xGame.common.randomNum(1000, 2000);
  509. //Moyu.showInsertAd(time, 60000);
  510. let guide = DataMgr.getSkillGuide();
  511. if (guide == 1) {//非新手引导,就显示,否则不显示
  512. console.log('zh:非新手引导,showInternAd ');
  513. JSBridgeUtils.instance.showInternAd('beginGame');
  514. } else {
  515. console.log('zh:新手引导,不显示AD ');
  516. }
  517. console.log('zh:beginGame gameMode=' + xGame.common.gameMode)
  518. console.log('zh:beginGame 1');
  519. if (xGame.common.gameMode == GameMode.classic) {
  520. console.log('zh:beginGame 2');
  521. // xGame.uiMgr.Show(UIMsg, "Coming Soon")
  522. if (isNice) {
  523. //巅峰赛直接进入
  524. console.log('zh:进入巅峰赛');
  525. this.enterClassic();
  526. }
  527. else {
  528. console.log('zh:beginGame 3-1');
  529. /////////下面的代码是原油的逻辑,但是我怀疑有问题
  530. xGame.uiMgr.Show(UIModeSelection, () => {
  531. console.log('zh:beginGame 3-2');
  532. this.enterClassic();
  533. })
  534. }
  535. }
  536. else if (xGame.common.gameMode == GameMode.bigMove) {
  537. console.log('zh:beginGame 5');
  538. this.ui.enterGuide.visible = false;
  539. xGame.uiMgr.Show(UISkill);
  540. }
  541. }
  542. enterClassic() {
  543. console.log('zh:beginGame 7');
  544. xGame.uiMgr.Show(UIGame);
  545. xGame.uiMgr.Show(UIMatching, () => {
  546. if (!this.isHide) this.hide();
  547. xGame.common.gameUI.ui.alpha = 1;
  548. console.log('zh:beginGame 8');
  549. xGame.common.gameUI.startGame();
  550. xGame.uiMgr.Hide(UIGameEnd);
  551. });
  552. }
  553. private moni_click_count: number = 0;
  554. /**
  555. * 模拟支付OK
  556. * @returns
  557. */
  558. start_debug_for_moni_payOk() {
  559. let ccc = this.moni_click_count + 1;
  560. this.moni_click_count = ccc;
  561. if (ccc % 5 == 0) {
  562. console.log('zh:start_debug_for_moni_payOk')
  563. let userInfo = LocalStorageManager.getItem(keyForLoginInfo);
  564. if (userInfo != null) {
  565. let token = userInfo.token;
  566. let ggSpid = 'com.vadltq.strike.ball.cue.gem50';
  567. JSBridgeUtils.instance.testPay1ForMoNiPayOver(token, ggSpid, 1);
  568. alert('模拟支付OK')
  569. return;
  570. } else {
  571. xGame.uiMgr.Show(UIMsg, TIP_MSG_key.pleaseLoginIn);
  572. }
  573. }
  574. }
  575. startGlobal() {
  576. xGame.uiMgr.Show(UIMsg, "Coming Soon.")
  577. //xGame.uiMgr.Show(UITry);
  578. // JSBridgeUtils.instance.showInternAd('');
  579. }
  580. startWeekly() {
  581. //xGame.uiMgr.Show(UIBox);
  582. xGame.uiMgr.Show(UIMsg, "Coming Soon")
  583. //测试AD
  584. // GlobalManager.instance.registerMethod('zhouSaiMonth', this.zhouSaiMonth);
  585. //JSBridgeUtils.instance.showRewardAd('zhouSaiMonth');
  586. }
  587. zhouSaiMonth() {
  588. console.log('zh: zhouSaiMonth 被调用')
  589. }
  590. //网络资源是否准备好了
  591. public isReadyForLoadNetSource(): boolean {
  592. let reqCount = xGame.cfgMgr.httpReqCount;
  593. let ok = xGame.cfgMgr.httpReqOkCount;
  594. if (reqCount > ok) {
  595. //console.log('zh:网络资源没有准备完成,请稍后再试');
  596. xGame.uiMgr.Show(UIMsg, "Network not ready. Try again later.")
  597. console.log('zh:✅❌ 5秒后重新尝试加载网络资源');
  598. Laya.timer.once(5000, this, () => {
  599. let retryCount = 0;
  600. const maxRetries = 3;
  601. const tryFetchConfig = () => {
  602. try {
  603. xGame.cfgMgr.getConfigFromServer();
  604. } catch (error) {
  605. if (retryCount < maxRetries) {
  606. retryCount++;
  607. console.log(`🔄 第${retryCount}次重试获取配置...`);
  608. Laya.timer.once(5000, this, tryFetchConfig);
  609. } else {
  610. console.error("❌ 达到最大重试次数,配置获取失败");
  611. }
  612. }
  613. };
  614. tryFetchConfig();
  615. });
  616. return false;
  617. }
  618. return true;
  619. }
  620. startPlaceBall() {
  621. if (!this.isReadyForLoadNetSource()) {
  622. return;
  623. }
  624. xGame.uiMgr.Show(UILevelDisplay);
  625. }
  626. public hide(): void {
  627. console.log('zh:uimain hide ...');
  628. // console.log('zh:停止播放bjyy_m');
  629. //xGame.soundMgr.stopSound("bjyy_m");
  630. // console.log('zh: hide 停止播放主頁面背景音乐');
  631. // xGame.soundMgr.stopMusic();
  632. super.hide();
  633. xGame.common.stopGirlPop(this.ui.talkNode)
  634. }
  635. //点击头像
  636. onGetUserInfo(force = false) {
  637. if (Moyu.isWx) {
  638. let info = Moyu.getSystemInfo();
  639. if (info)
  640. Moyu.createWXUserBtn(0, 0, info.width, info.height, 'res/wxuser.png', this.freshUser);
  641. }
  642. else {
  643. Moyu.initUser(this, this.freshUser, force)
  644. }
  645. // if (!Moyu.hasUserInfo) {
  646. // let user = Moyu.getUserInfo();
  647. // //user.nickName="我";
  648. // user.headIcon = 'res/ty_touxiang.png';
  649. // //console.log("未授权");
  650. // }
  651. this.freshUser();
  652. console.log('zh:5秒后更新用户信息');
  653. // Laya.timer.once(5000, this, () => {
  654. // console.log('zh:5秒over 更新用戶資產信息')
  655. // DataMgr.getUserZiChanInfo22();
  656. // });
  657. setTimeout(() => {
  658. // console.log('setTimeout 5秒over 執行');
  659. DataMgr.getUserZiChanInfo(true);
  660. }, 5000);
  661. }
  662. event_login_in() {
  663. console.log("zh:event_login_in被触发");
  664. this.freshUser();
  665. }
  666. freshUser() {
  667. let user = Moyu.getUserInfo();
  668. if (!user.isAuth) {
  669. user.headIcon = 'res/ty_touxiang.png';
  670. }
  671. else {
  672. DataMgr.upRankData();
  673. }
  674. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(user.nickName, 16);
  675. xGame.common.createHead(this.ui.headNode.headRoot.headImg, user.headIcon);
  676. let keyStr = keyForLoginInfo;
  677. if (LocalStorageManager.hasJosnKey(keyStr)) {
  678. const d = LocalStorageManager.getItem<{ username: string, token: string }>(keyStr);
  679. let ua = d.username;
  680. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(ua, 16);
  681. } else {
  682. }
  683. this.c_btn_for_user();
  684. }
  685. interuptSecretary() {
  686. Laya.timer.clearAll(this);
  687. this.playSecretaryRandomSound();
  688. }
  689. //主界面和技能选择界面3-7秒未操作随机播放秘书音效
  690. playSecretaryRandomSound() {
  691. if (this.isHide) return;
  692. let time = xGame.common.randomNum(45000, 60000);
  693. Laya.timer.once(time, this, () => {
  694. if (this.isHide) return;
  695. let index = xGame.common.randomNum(4, 7);
  696. xGame.soundMgr.playSound("s_main0" + index);
  697. let words = 1;
  698. switch (index) {
  699. case 4:
  700. words = 5;
  701. break;
  702. case 5:
  703. words = 3;
  704. break;
  705. case 6:
  706. words = 6;
  707. break;
  708. case 7:
  709. words = 7;
  710. break;
  711. default:
  712. break;
  713. }
  714. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  715. //
  716. this.playSecretaryRandomSound();
  717. })
  718. }
  719. openSecretaryView() {
  720. xGame.uiMgr.Show(UISecretary);
  721. Moyu.sendDataEvent("secretary");
  722. }
  723. /**
  724. * 默认展示钻石tab
  725. */
  726. openShopView() {
  727. xGame.uiMgr.Show(UIShop, 1);
  728. }
  729. /**
  730. * 默认展示球杆tab
  731. */
  732. openShopView0() {
  733. xGame.uiMgr.Show(UIShop, 0);
  734. }
  735. openSignView() {
  736. xGame.uiMgr.Show(UISign);
  737. }
  738. openDrawView() {
  739. xGame.uiMgr.Show(UIDraw);
  740. }
  741. openRanking() {
  742. console.log('zh:phb openRanking')
  743. xGame.uiMgr.Show(UIRanking);
  744. Moyu.sendDataEvent("rankingList");
  745. }
  746. }
  747. UIMain.uiName = "UIMain";