1
0

UIMain.ts 17 KB

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