UIMain.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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("播放小秘书每天语音");
  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");
  204. //
  205. Laya.timer.clearAll(this);
  206. this.playSecretaryRandomSound();
  207. if (showFailWords) {
  208. //延迟播放进入主页面的失败音效
  209. setTimeout(() => {
  210. let str = Math.random() <= 0.5 ? "s_main02" : "s_main03";
  211. let words = -1;
  212. if (str == "s_main02") {
  213. words = 2;
  214. }
  215. else {
  216. words = 3;
  217. }
  218. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  219. xGame.soundMgr.playSound(str);
  220. }, 300);
  221. }
  222. //
  223. this.showGuide();
  224. this.ui.guideBtn.x = this.ui.liucheng2.myMask.x;
  225. this.ui.guideBtn.y = this.ui.liucheng2.myMask.y;
  226. //
  227. let guide = DataMgr.getSkillGuide();
  228. if (guide == 1) {
  229. let randTime = xGame.common.randomNum(300, 800);
  230. if (this.firstEnter) {
  231. this.firstEnter = false;
  232. randTime += 900;
  233. }
  234. Laya.timer.once(randTime, this, () => {
  235. xGame.common.autoPopUIView();
  236. })
  237. }
  238. }
  239. checkActive(show) {
  240. //console.log("是否处于最外层",show);
  241. //wx banner太大
  242. // if (!Moyu.isWx)
  243. // PlatMgr.showBanner(show);
  244. }
  245. showGuide() {
  246. let guide = DataMgr.getSkillGuide();
  247. this.ui.guideBtn.visible = guide == 0;
  248. this.ui.enterGuide.visible = false;
  249. this.ui.secretaryGuide.visible = guide == 0;
  250. if (guide == 0) {
  251. xGame.soundMgr.playSound("s_guide");
  252. xGame.common.showGirlTalkPop(16, this.ui.talkNode, this.ui.talkNode.womanTxt);
  253. }
  254. }
  255. ensureSecretary() {
  256. console.log('zh: ensureSecretary ensureSecretaryensureSecretaryensureSecretaryensureSecretaryensureSecretary')
  257. this.ui.secretaryGuide.visible = false;
  258. this.ui.enterGuide.visible = true;
  259. this.ui.wordsNode.t0.play();
  260. //todo
  261. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameReady");
  262. }
  263. playSecretaryIdle() {
  264. let parent = this.ui.secretary.displayObject;
  265. parent.destroyChildren();
  266. let xx = this.ui.secretary.width / 2;
  267. let yy = this.ui.secretary.height;
  268. // xx = Laya.stage.width / 2;
  269. // yy = Laya.stage.height;
  270. let scale = xGame.common.getSecretaryScale();
  271. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  272. console.log("zh:playSecretaryIdle", data);
  273. //xGame.common.secretary.play(data, 1, true, parent); 这是老的秘书
  274. xGame.common.secretary.play(data, 0, true, parent);
  275. }
  276. startGame(type: GameMode) {
  277. //进入游戏页面
  278. xGame.common.gameMode = type;
  279. //
  280. Moyu.sendDataEvent("PlayGame", { type: type });
  281. switch (xGame.common.gameMode) {
  282. case GameMode.classic:
  283. let challengeTimes = DataMgr.getChallengeTimes();
  284. if (challengeTimes == 0) {
  285. xGame.uiMgr.Show(UIInvitation);
  286. }
  287. else {
  288. this.beginGame();
  289. }
  290. break;
  291. case GameMode.bigMove:
  292. this.beginGame();
  293. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameStart0");
  294. break;
  295. default:
  296. break;
  297. }
  298. }
  299. beginGame(isNice = false) {
  300. //
  301. //let time = xGame.common.randomNum(1000, 2000);
  302. //Moyu.showInsertAd(time, 60000);
  303. //
  304. if (xGame.common.gameMode == GameMode.classic) {
  305. //
  306. if (isNice) {
  307. //巅峰赛直接进入
  308. this.enterClassic();
  309. }
  310. else {
  311. xGame.uiMgr.Show(UIModeSelection, () => {
  312. this.enterClassic();
  313. })
  314. }
  315. }
  316. else if (xGame.common.gameMode == GameMode.bigMove) {
  317. this.ui.enterGuide.visible = false;
  318. xGame.uiMgr.Show(UISkill);
  319. }
  320. }
  321. enterClassic() {
  322. xGame.uiMgr.Show(UIGame);
  323. xGame.uiMgr.Show(UIMatching, () => {
  324. if (!this.isHide) this.hide();
  325. xGame.common.gameUI.ui.alpha = 1;
  326. xGame.common.gameUI.startGame();
  327. xGame.uiMgr.Hide(UIGameEnd);
  328. });
  329. }
  330. startGlobal() {
  331. xGame.uiMgr.Show(UIMsg, "Coming Soon")
  332. //xGame.uiMgr.Show(UITry);
  333. // JSBridgeUtils.instance.showInternAd('');
  334. }
  335. startWeekly() {
  336. //xGame.uiMgr.Show(UIBox);
  337. xGame.uiMgr.Show(UIMsg, "Coming Soon")
  338. //测试AD
  339. // GlobalManager.instance.registerMethod('zhouSaiMonth', this.zhouSaiMonth);
  340. //JSBridgeUtils.instance.showRewardAd('zhouSaiMonth');
  341. }
  342. zhouSaiMonth() {
  343. console.log('zh: zhouSaiMonth 被调用')
  344. }
  345. startPlaceBall() {
  346. xGame.uiMgr.Show(UILevelDisplay);
  347. //xGame.uiMgr.Show(UIMsg, "敬请期待~")
  348. }
  349. public hide(): void {
  350. super.hide();
  351. xGame.common.stopGirlPop(this.ui.talkNode)
  352. }
  353. //点击头像
  354. onGetUserInfo(force = false) {
  355. if (Moyu.isWx) {
  356. let info = Moyu.getSystemInfo();
  357. if (info)
  358. Moyu.createWXUserBtn(0, 0, info.width, info.height, 'res/wxuser.png', this.freshUser);
  359. }
  360. else {
  361. Moyu.initUser(this, this.freshUser, force)
  362. }
  363. if (!Moyu.hasUserInfo) {
  364. let user = Moyu.getUserInfo();
  365. //user.nickName="我";
  366. user.headIcon = 'res/ty_touxiang.png';
  367. //console.log("未授权");
  368. }
  369. this.freshUser();
  370. }
  371. freshUser() {
  372. let user = Moyu.getUserInfo();
  373. if (!user.isAuth) {
  374. user.headIcon = 'res/ty_touxiang.png';
  375. }
  376. else
  377. DataMgr.upRankData();
  378. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(user.nickName, 16);
  379. xGame.common.createHead(this.ui.headNode.headRoot.headImg, user.headIcon);
  380. }
  381. interuptSecretary() {
  382. Laya.timer.clearAll(this);
  383. this.playSecretaryRandomSound();
  384. }
  385. //主界面和技能选择界面3-7秒未操作随机播放秘书音效
  386. playSecretaryRandomSound() {
  387. if (this.isHide) return;
  388. let time = xGame.common.randomNum(45000, 60000);
  389. Laya.timer.once(time, this, () => {
  390. if (this.isHide) return;
  391. let index = xGame.common.randomNum(4, 7);
  392. xGame.soundMgr.playSound("s_main0" + index);
  393. let words = 1;
  394. switch (index) {
  395. case 4:
  396. words = 5;
  397. break;
  398. case 5:
  399. words = 3;
  400. break;
  401. case 6:
  402. words = 6;
  403. break;
  404. case 7:
  405. words = 7;
  406. break;
  407. default:
  408. break;
  409. }
  410. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  411. //
  412. this.playSecretaryRandomSound();
  413. })
  414. }
  415. openSecretaryView() {
  416. xGame.uiMgr.Show(UISecretary);
  417. Moyu.sendDataEvent("secretary");
  418. }
  419. openShopView() {
  420. xGame.uiMgr.Show(UIShop);
  421. }
  422. openSignView() {
  423. xGame.uiMgr.Show(UISign);
  424. }
  425. openDrawView() {
  426. xGame.uiMgr.Show(UIDraw);
  427. }
  428. openRanking() {
  429. xGame.uiMgr.Show(UIRanking);
  430. Moyu.sendDataEvent("rankingList");
  431. }
  432. }
  433. UIMain.uiName = "UIMain";