UIMain.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. import SpineMgr from "../core/mgrs/SpineMgr";
  2. import DataMgr from "../data/DataMgr";
  3. import { CHANGE_SECRETARY, GameMode, GET_USER_INFO, RESTART_GAME } 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 UITry from "./UITry";
  28. import UIPower from "./UIPower";
  29. import UIGetAward from "./UIGetAward";
  30. import UIRepentProp from "./UIRepentProp";
  31. import UIBox from "./UIBox";
  32. import UIAddCoin from "./UIAddCoin";
  33. import { NoInternetDialog } from "./NoInternetDialog";
  34. //import NetCheckTool from "../utils/NetCheckTool";
  35. export default class UIMain extends UIBase {
  36. public ui: ui_UIMain;
  37. //
  38. public settingNode: SettingNode;
  39. public moneyNode: MoneyNode;
  40. public firstEnter = true;
  41. nativeCallJs(msg: string) {
  42. let t = msg;
  43. console.log("zh: nativeCallJs 奖励开始发放:", t);
  44. //GlobalManager.instance.callMethod(msg)
  45. switch (t) {
  46. case 'qjff_chouJiang':
  47. let dui = <UIDraw>xGame.uiMgr.getUI(UIDraw);
  48. dui.qjff_chouJiang();
  49. break;
  50. case 'qjff_AD_for_uisign':
  51. let dui2 = <UISign>xGame.uiMgr.getUI(UISign);
  52. dui2.qjff_AD_for_uisign();
  53. break;
  54. case 'qjff_AD_for_uitry':
  55. let dui3 = <UITry>xGame.uiMgr.getUI(UITry);
  56. dui3.qjff_AD_for_uitry();
  57. break;
  58. case 'qjff_AD_for_uipower':
  59. let dui4 = <UIPower>xGame.uiMgr.getUI(UIPower);
  60. dui4.qjff_AD_for_uipower();
  61. break;
  62. case 'qjff_AD_for_uigetAward':
  63. let dui5 = <UIGetAward>xGame.uiMgr.getUI(UIGetAward);
  64. dui5.qjff_AD_for_uigetAward();
  65. break;
  66. case 'qjff_AD_for_uiGameEnd':
  67. let temp_level = Laya.LocalStorage.getItem('temp_qjff_AD_for_uiGameEnd_level');
  68. let dui6 = <UIGameEnd>xGame.uiMgr.getUI(UIGameEnd);
  69. dui6.qjff_AD_for_uiGameEnd(parseInt(temp_level))
  70. break;
  71. case 'qjff_AD_for_uiAddProp_videoGetDiamond':
  72. let dui7 = <UIAddProp>xGame.uiMgr.getUI(UIAddProp);
  73. dui7.qjff_AD_for_uiAddProp_videoGetDiamond();
  74. break;
  75. case 'qjff_AD_for_uiAddProp_videoGetCoin':
  76. let dui8 = <UIAddProp>xGame.uiMgr.getUI(UIAddProp);
  77. dui8.qjff_AD_for_uiAddProp_videoGetCoin();
  78. break;
  79. case 'qjff_AD_for_UIrepentProp_videoRegret':
  80. let dui9 = <UIRepentProp>xGame.uiMgr.getUI(UIRepentProp);
  81. dui9.qjff_AD_for_UIrepentProp_videoRegret();
  82. break;
  83. case 'qjff_AD_for_UIrepentProp_videoAddHelpLine':
  84. let dui10 = <UIRepentProp>xGame.uiMgr.getUI(UIRepentProp);
  85. dui10.qjff_AD_for_UIrepentProp_videoAddHelpLine();
  86. break;
  87. case 'qjff_AD_for_UIBOX_onOpenBox':
  88. let dui11 = <UIBox>xGame.uiMgr.getUI(UIBox);
  89. dui11.qjff_AD_for_UIBOX_onOpenBox();
  90. break;
  91. case 'qjff_AD_for_UIAddCoin':
  92. let dui12 = <UIAddCoin>xGame.uiMgr.getUI(UIAddCoin);
  93. dui12.qjff_AD_for_UIAddCoin();
  94. break;
  95. // case 'qjff_AD_for_skilldisplay_clickAddLevel':
  96. // // SkillDisplay s=new SkillDisplay();//改为插屏了
  97. // // s.qjff_AD_for_skilldisplay_clickAddLevel();
  98. // break;
  99. case '111a':
  100. let dui14 = <UISign>xGame.uiMgr.getUI(UISign);
  101. dui14.qjff_AD_for_uisign();
  102. break;
  103. case '222a':
  104. let dui15 = <UISign>xGame.uiMgr.getUI(UISign);
  105. dui15.qjff_AD_for_uisign();
  106. break;
  107. case '333a':
  108. let dui16 = <UISign>xGame.uiMgr.getUI(UISign);
  109. dui16.qjff_AD_for_uisign();
  110. break;
  111. default:
  112. console.log('zh:未知的方法名字' + t)
  113. break;
  114. }
  115. // if(t === 'qjff_shengJi_for_SkillDisplay'){
  116. // const dui = new
  117. // dui.qjff_shengJi();
  118. // }
  119. }
  120. public constructor() {
  121. super();
  122. }
  123. protected onConstructor(): void {
  124. console.log('zh: UIMain onConstructor');
  125. this.ui = ui_UIMain.createInstance();
  126. this.contentPane = this.ui;
  127. this.isEject = false;
  128. // this.ui.weeklyBtn.visible = false;
  129. this.addEvent();
  130. this.addClickSpine();
  131. //设置界面
  132. this.settingNode = new SettingNode(this.ui.settingNode);
  133. this.moneyNode = new MoneyNode(this.ui.moneyNode);
  134. //
  135. xGame.eventMgr.on(RESTART_GAME, this, this.beginGame);
  136. xGame.eventMgr.on(GET_USER_INFO, this, this.onGetUserInfo);
  137. xGame.eventMgr.on(CHANGE_SECRETARY, this, this.changeSecretary);
  138. let curUse = DataMgr.getCurSecretary();
  139. this.changeSecretary(curUse);
  140. //
  141. //this.ui.rankBtn.visible = false;
  142. this.ui.talkNode.visible = false;
  143. let guide = DataMgr.getSkillGuide();
  144. if (xGame.common.isNewDay && guide == 1) {
  145. xGame.common.isNewDay = false;
  146. xGame.soundMgr.playSound("s_main01");
  147. xGame.common.showGirlTalkPop(1, this.ui.talkNode, this.ui.talkNode.womanTxt);
  148. console.log("zh:播放小秘书每天语音");
  149. }
  150. // this.onGetUserInfo();
  151. this.ui.n83.visible = false;
  152. //万宁台球
  153. //Moyu.setShareInfo("8Ball Fury", ["台球", "台球", "桌球"], '2300002254');
  154. window['nativeCallJs'] = this.nativeCallJs.bind(this);
  155. }
  156. changeSecretary(curUse) {
  157. let name = cfgTable.secretaryshopData[curUse + 1].spine;
  158. xGame.common.secretary && xGame.common.secretary.dispose();
  159. this.addSecretarySpine(name);
  160. }
  161. addSecretarySpine(name) {
  162. let spine = new SpineMgr(name, () => {
  163. this.playSecretaryIdle();
  164. });
  165. xGame.common.secretary = spine;
  166. }
  167. addClickSpine() {
  168. let clickSpine = new SpineMgr("dianji", () => {
  169. Laya.stage.on(Laya.Event.CLICK, this, (e: Laya.Event) => {
  170. //
  171. let parent = Laya.stage;
  172. let data = { x: e.stageX, y: e.stageY, scaleX: 0.8, scaleY: 0.8 };
  173. clickSpine.play(data, 0, false, parent, (spine) => {
  174. spine.destroy(true);
  175. });
  176. })
  177. //
  178. });
  179. }
  180. private addEvent(): void {
  181. this.addUIClick(this.ui.classicBtn, this.startGame, [GameMode.classic]);
  182. this.addUIClick(this.ui.bigMoveBtn, this.startGame, [GameMode.bigMove])
  183. this.addUIClick(this.ui.ganFaMoShiBtn, this.startGame, [GameMode.bigMove])
  184. //
  185. this.addUIClick(this.ui.globalBtn, this.startGlobal);
  186. // this.addUIClick(this.ui.weeklyBtn, this.startWeekly);
  187. this.addUIClick(this.ui.placeBallBtn, this.startPlaceBall);
  188. //
  189. this.addUIClick(this.ui.headNode, this.onGetUserInfo, [true]);
  190. this.addUIClick(this.ui, this.interuptSecretary);
  191. this.addUIClick(this.ui.rightBtn, this.ensureSecretary);
  192. this.addUIClick(this.ui.guideBtn, this.startGame, [GameMode.bigMove]);
  193. this.addUIClick(this.ui.secretaryBtn, this.openSecretaryView);
  194. this.addUIClick(this.ui.shopBtn, this.openShopView);
  195. //
  196. this.addUIClick(this.ui.signBtn, this.openSignView);
  197. this.addUIClick(this.ui.drawBtn, this.openDrawView);
  198. this.addUIClick(this.ui.rankBtn, this.openRanking);
  199. }
  200. public show(showFailWords): void {
  201. super.show();
  202. //
  203. this.moneyNode.ui.c1.selectedIndex = 1;
  204. this.playSecretaryIdle();
  205. xGame.soundMgr.playMusic("caromhall01", 0);
  206. Laya.timer.clearAll(this);
  207. this.playSecretaryRandomSound();
  208. console.log('zh:uimain.ts show show FailWords=', showFailWords);
  209. if (showFailWords) {
  210. console.log('zh:uimain.ts ')
  211. //延迟播放进入主页面的失败音效
  212. setTimeout(() => {
  213. let str = Math.random() <= 0.5 ? "s_main02" : "s_main03";
  214. let words = -1;
  215. if (str == "s_main02") {
  216. words = 2;
  217. }
  218. else {
  219. words = 3;
  220. }
  221. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  222. xGame.soundMgr.playSound(str);
  223. }, 300);
  224. }
  225. // setTimeout(() => {
  226. // console.log('zh:播放7背景音乐 m ')
  227. // xGame.soundMgr.playSound('bjyy_m', 0);
  228. // }, 2000);
  229. //
  230. this.showGuide();
  231. this.ui.guideBtn.x = this.ui.liucheng2.myMask.x;
  232. this.ui.guideBtn.y = this.ui.liucheng2.myMask.y;
  233. //
  234. let guide = DataMgr.getSkillGuide();
  235. if (guide == 1) {
  236. let randTime = xGame.common.randomNum(300, 800);
  237. if (this.firstEnter) {
  238. console.log("zh: firstEnter");
  239. this.firstEnter = false;
  240. randTime += 900;
  241. } else {
  242. console.log("zh: no firstEnter");
  243. }
  244. Laya.timer.once(randTime, this, () => {
  245. xGame.common.autoPopUIView();
  246. })
  247. }
  248. }
  249. checkActive(show) {
  250. //console.log("是否处于最外层",show);
  251. //wx banner太大
  252. // if (!Moyu.isWx)
  253. // PlatMgr.showBanner(show);
  254. }
  255. showGuide() {
  256. let guide = DataMgr.getSkillGuide();
  257. this.ui.guideBtn.visible = guide == 0;
  258. this.ui.enterGuide.visible = false;
  259. this.ui.secretaryGuide.visible = guide == 0;
  260. if (guide == 0) {
  261. console.log("zh:显示引导");
  262. xGame.soundMgr.playSound("s_guide");
  263. xGame.common.showGirlTalkPop(16, this.ui.talkNode, this.ui.talkNode.womanTxt);
  264. } else {
  265. console.log("zh:不需要显示引导");
  266. }
  267. }
  268. ensureSecretary() {
  269. console.log('zh: ensureSecretary ensureSecretaryensureSecretaryensureSecretaryensureSecretaryensureSecretary')
  270. this.ui.secretaryGuide.visible = false;
  271. this.ui.enterGuide.visible = true;
  272. this.ui.wordsNode.t0.play();
  273. //todo
  274. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameReady");
  275. }
  276. playSecretaryIdle() {
  277. let parent = this.ui.secretary.displayObject;
  278. parent.destroyChildren();
  279. let xx = this.ui.secretary.width / 2;
  280. let yy = this.ui.secretary.height;
  281. // xx = Laya.stage.width / 2;
  282. // yy = Laya.stage.height;
  283. let scale = xGame.common.getSecretaryScale();
  284. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  285. console.log("zh:playSecretaryIdle", data);
  286. //xGame.common.secretary.play(data, 1, true, parent); 这是老的秘书
  287. xGame.common.secretary.play(data, 0, true, parent);
  288. }
  289. startGame(type: GameMode) {
  290. // console.log('zh: 停止播放主頁面背景音乐');
  291. // xGame.soundMgr.stopMusic();
  292. //进入游戏页面
  293. xGame.common.gameMode = type;
  294. //
  295. Moyu.sendDataEvent("PlayGame", { type: type });
  296. console.log('zh:进入游戏gameMode =' + xGame.common.gameMode);
  297. switch (xGame.common.gameMode) {
  298. case GameMode.classic:
  299. console.log('zh:进入经典模式111111111');
  300. //zhdiy - challenge mode作为教学练习关,完成2关解锁classic,
  301. if (DataMgr.DIY_challengeMode_overLev_jieSuo_mark) {
  302. let db_over_lev = DataMgr.getChallengeMode_overLev();
  303. console.log('zh:classic db_over_lev=', db_over_lev);
  304. if (db_over_lev < DataMgr.DIY_challengeMode_overLev_jieSuo_Classic) {
  305. console.log('zh:判断是否可以玩该模式classic =NO');
  306. let tipStr = 'You must complete ' + DataMgr.DIY_challengeMode_overLev_jieSuo_Classic + ' levels in Challenge Mode to unlock Classic Mode.';
  307. xGame.uiMgr.Show(UIMsg, tipStr);
  308. console.log('zh:返回');
  309. return;
  310. } else {
  311. console.log('zh:可以玩该模式classic 66666666666666');
  312. this.beginGame();
  313. }
  314. } else {
  315. console.log('zh:不需要判断是否可以玩该classic');
  316. let challengeTimes = DataMgr.getChallengeTimes();
  317. if (challengeTimes == 0) {
  318. xGame.uiMgr.Show(UIInvitation);
  319. }
  320. else {
  321. this.beginGame();
  322. }
  323. break;
  324. }
  325. case GameMode.bigMove:
  326. console.error('zh:bigMove check');
  327. let guide = DataMgr.getSkillGuide();
  328. //zhdiy - challenge mode作为教学练习关,完成2关解锁classic,
  329. if (DataMgr.DIY_challengeMode_overLev_jieSuo_mark && guide == 1) {
  330. let db_over_lev = DataMgr.getChallengeMode_overLev();
  331. console.log('zh:bigMove db_over_lev=', db_over_lev);
  332. if (db_over_lev < DataMgr.DIY_challengeMode_overLev_jieSuo_rodMethod) {
  333. let tipStr = 'Complete ' + DataMgr.DIY_challengeMode_overLev_jieSuo_rodMethod + ' levels in Challenge Mode to unlock the Rod Method Mode';
  334. xGame.uiMgr.Show(UIMsg, tipStr);
  335. return;
  336. } else {
  337. console.log('zh:可以玩该模式 bigMove');
  338. this.beginGame();
  339. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameStart0");
  340. }
  341. } else {
  342. this.beginGame();
  343. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameStart0");
  344. }
  345. break;
  346. default:
  347. console.error('zh:未知错误!!!!');
  348. break;
  349. }
  350. }
  351. beginGame(isNice = false) {
  352. console.log('zh:beginGame ');
  353. //TODO:ZH 插屏AD
  354. //let time = xGame.common.randomNum(1000, 2000);
  355. //Moyu.showInsertAd(time, 60000);
  356. let guide = DataMgr.getSkillGuide();
  357. if (guide == 1) {//非新手引导,就显示,否则不显示
  358. console.log('zh:非新手引导,showInternAd ');
  359. JSBridgeUtils.instance.showInternAd('beginGame');
  360. } else {
  361. console.log('zh:新手引导,不显示AD ');
  362. }
  363. console.log('zh:beginGame 2 go');
  364. if (xGame.common.gameMode == GameMode.classic) {
  365. // xGame.uiMgr.Show(UIMsg, "Coming Soon")
  366. if (isNice) {
  367. //巅峰赛直接进入
  368. this.enterClassic();
  369. }
  370. else {
  371. xGame.uiMgr.Show(UIModeSelection, () => {
  372. console.log('zh:BBBBBBBBBBBBBBB');
  373. this.enterClassic();
  374. })
  375. }
  376. }
  377. else if (xGame.common.gameMode == GameMode.bigMove) {
  378. this.ui.enterGuide.visible = false;
  379. xGame.uiMgr.Show(UISkill);
  380. }
  381. }
  382. enterClassic() {
  383. xGame.uiMgr.Show(UIGame);
  384. xGame.uiMgr.Show(UIMatching, () => {
  385. if (!this.isHide) this.hide();
  386. xGame.common.gameUI.ui.alpha = 1;
  387. xGame.common.gameUI.startGame();
  388. xGame.uiMgr.Hide(UIGameEnd);
  389. });
  390. }
  391. startGlobal() {
  392. xGame.uiMgr.Show(UIMsg, "Coming Soon")
  393. //xGame.uiMgr.Show(UITry);
  394. // JSBridgeUtils.instance.showInternAd('');
  395. }
  396. startWeekly() {
  397. //xGame.uiMgr.Show(UIBox);
  398. xGame.uiMgr.Show(UIMsg, "Coming Soon")
  399. //测试AD
  400. // GlobalManager.instance.registerMethod('zhouSaiMonth', this.zhouSaiMonth);
  401. //JSBridgeUtils.instance.showRewardAd('zhouSaiMonth');
  402. }
  403. zhouSaiMonth() {
  404. console.log('zh: zhouSaiMonth 被调用')
  405. }
  406. startPlaceBall() {
  407. xGame.uiMgr.Show(UILevelDisplay);
  408. //xGame.uiMgr.Show(UIMsg, "敬请期待~")
  409. }
  410. public hide(): void {
  411. console.log('zh:uimain hide ...');
  412. // console.log('zh:停止播放bjyy_m');
  413. //xGame.soundMgr.stopSound("bjyy_m");
  414. // console.log('zh: hide 停止播放主頁面背景音乐');
  415. // xGame.soundMgr.stopMusic();
  416. super.hide();
  417. xGame.common.stopGirlPop(this.ui.talkNode)
  418. }
  419. //点击头像
  420. onGetUserInfo(force = false) {
  421. if (Moyu.isWx) {
  422. let info = Moyu.getSystemInfo();
  423. if (info)
  424. Moyu.createWXUserBtn(0, 0, info.width, info.height, 'res/wxuser.png', this.freshUser);
  425. }
  426. else {
  427. Moyu.initUser(this, this.freshUser, force)
  428. }
  429. if (!Moyu.hasUserInfo) {
  430. let user = Moyu.getUserInfo();
  431. //user.nickName="我";
  432. user.headIcon = 'res/ty_touxiang.png';
  433. //console.log("未授权");
  434. }
  435. this.freshUser();
  436. }
  437. freshUser() {
  438. let user = Moyu.getUserInfo();
  439. if (!user.isAuth) {
  440. user.headIcon = 'res/ty_touxiang.png';
  441. }
  442. else
  443. DataMgr.upRankData();
  444. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(user.nickName, 16);
  445. xGame.common.createHead(this.ui.headNode.headRoot.headImg, user.headIcon);
  446. }
  447. interuptSecretary() {
  448. Laya.timer.clearAll(this);
  449. this.playSecretaryRandomSound();
  450. }
  451. //主界面和技能选择界面3-7秒未操作随机播放秘书音效
  452. playSecretaryRandomSound() {
  453. if (this.isHide) return;
  454. let time = xGame.common.randomNum(45000, 60000);
  455. Laya.timer.once(time, this, () => {
  456. if (this.isHide) return;
  457. let index = xGame.common.randomNum(4, 7);
  458. xGame.soundMgr.playSound("s_main0" + index);
  459. let words = 1;
  460. switch (index) {
  461. case 4:
  462. words = 5;
  463. break;
  464. case 5:
  465. words = 3;
  466. break;
  467. case 6:
  468. words = 6;
  469. break;
  470. case 7:
  471. words = 7;
  472. break;
  473. default:
  474. break;
  475. }
  476. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  477. //
  478. this.playSecretaryRandomSound();
  479. })
  480. }
  481. openSecretaryView() {
  482. xGame.uiMgr.Show(UISecretary);
  483. Moyu.sendDataEvent("secretary");
  484. }
  485. openShopView() {
  486. xGame.uiMgr.Show(UIShop);
  487. }
  488. openSignView() {
  489. xGame.uiMgr.Show(UISign);
  490. }
  491. openDrawView() {
  492. xGame.uiMgr.Show(UIDraw);
  493. }
  494. openRanking() {
  495. console.log('zh:phb openRanking')
  496. xGame.uiMgr.Show(UIRanking);
  497. Moyu.sendDataEvent("rankingList");
  498. }
  499. }
  500. UIMain.uiName = "UIMain";