1
0

UIMain.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. export default class UIMain extends UIBase {
  25. public ui: ui_UIMain;
  26. //
  27. public settingNode: SettingNode;
  28. public moneyNode: MoneyNode;
  29. public firstEnter = true;
  30. public constructor() {
  31. super();
  32. }
  33. protected onConstructor(): void {
  34. this.ui = ui_UIMain.createInstance();
  35. this.contentPane = this.ui;
  36. this.isEject = false;
  37. this.addEvent();
  38. this.addClickSpine();
  39. //设置界面
  40. this.settingNode = new SettingNode(this.ui.settingNode);
  41. this.moneyNode = new MoneyNode(this.ui.moneyNode);
  42. //
  43. xGame.eventMgr.on(RESTART_GAME, this, this.beginGame);
  44. xGame.eventMgr.on(GET_USER_INFO, this, this.onGetUserInfo);
  45. xGame.eventMgr.on(CHANGE_SECRETARY, this, this.changeSecretary);
  46. let curUse = DataMgr.getCurSecretary();
  47. this.changeSecretary(curUse);
  48. //
  49. //this.ui.rankBtn.visible=false;
  50. this.ui.talkNode.visible = false;
  51. let guide = DataMgr.getSkillGuide();
  52. if (xGame.common.isNewDay && guide == 1) {
  53. xGame.common.isNewDay = false;
  54. xGame.soundMgr.playSound("s_main01");
  55. xGame.common.showGirlTalkPop(1, this.ui.talkNode, this.ui.talkNode.womanTxt);
  56. console.log("播放小秘书每天语音");
  57. }
  58. this.onGetUserInfo();
  59. this.ui.n83.visible = false;
  60. //万宁台球
  61. Moyu.setShareInfo("8Ball Fury", ["台球", "万宁", "桌球"], '2300002254');
  62. }
  63. changeSecretary(curUse) {
  64. let name = cfgTable.secretaryshopData[curUse + 1].spine;
  65. xGame.common.secretary && xGame.common.secretary.dispose();
  66. this.addSecretarySpine(name);
  67. }
  68. addSecretarySpine(name) {
  69. let spine = new SpineMgr(name, () => {
  70. this.playSecretaryIdle();
  71. });
  72. xGame.common.secretary = spine;
  73. }
  74. addClickSpine() {
  75. let clickSpine = new SpineMgr("dianji", () => {
  76. Laya.stage.on(Laya.Event.CLICK, this, (e: Laya.Event) => {
  77. //
  78. let parent = Laya.stage;
  79. let data = { x: e.stageX, y: e.stageY, scaleX: 0.8, scaleY: 0.8 };
  80. clickSpine.play(data, 0, false, parent, (spine) => {
  81. spine.destroy(true);
  82. });
  83. })
  84. //
  85. });
  86. }
  87. private addEvent(): void {
  88. this.addUIClick(this.ui.classicBtn, this.startGame, [GameMode.classic]);
  89. this.addUIClick(this.ui.bigMoveBtn, this.startGame, [GameMode.bigMove])
  90. //
  91. this.addUIClick(this.ui.globalBtn, this.startGlobal);
  92. this.addUIClick(this.ui.weeklyBtn, this.startWeekly);
  93. this.addUIClick(this.ui.placeBallBtn, this.startPlaceBall);
  94. //
  95. this.addUIClick(this.ui.headNode, this.onGetUserInfo, [true]);
  96. this.addUIClick(this.ui, this.interuptSecretary);
  97. this.addUIClick(this.ui.rightBtn, this.ensureSecretary);
  98. this.addUIClick(this.ui.guideBtn, this.startGame, [GameMode.bigMove]);
  99. this.addUIClick(this.ui.secretaryBtn, this.openSecretaryView);
  100. this.addUIClick(this.ui.shopBtn, this.openShopView);
  101. //
  102. this.addUIClick(this.ui.signBtn, this.openSignView);
  103. this.addUIClick(this.ui.drawBtn, this.openDrawView);
  104. this.addUIClick(this.ui.rankBtn, this.openRanking);
  105. }
  106. public show(showFailWords): void {
  107. super.show();
  108. //
  109. this.moneyNode.ui.c1.selectedIndex = 1;
  110. this.playSecretaryIdle();
  111. xGame.soundMgr.playMusic("caromhall01");
  112. //
  113. Laya.timer.clearAll(this);
  114. this.playSecretaryRandomSound();
  115. if (showFailWords) {
  116. //延迟播放进入主页面的失败音效
  117. setTimeout(() => {
  118. let str = Math.random() <= 0.5 ? "s_main02" : "s_main03";
  119. let words = -1;
  120. if (str == "s_main02") {
  121. words = 2;
  122. }
  123. else {
  124. words = 3;
  125. }
  126. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  127. xGame.soundMgr.playSound(str);
  128. }, 300);
  129. }
  130. //
  131. this.showGuide();
  132. this.ui.guideBtn.x = this.ui.liucheng2.myMask.x;
  133. this.ui.guideBtn.y = this.ui.liucheng2.myMask.y;
  134. //
  135. let guide = DataMgr.getSkillGuide();
  136. if (guide == 1) {
  137. let randTime = xGame.common.randomNum(300, 800);
  138. if (this.firstEnter) {
  139. this.firstEnter = false;
  140. randTime += 900;
  141. }
  142. Laya.timer.once(randTime, this, () => {
  143. xGame.common.autoPopUIView();
  144. })
  145. }
  146. }
  147. checkActive(show) {
  148. //console.log("是否处于最外层",show);
  149. //wx banner太大
  150. // if (!Moyu.isWx)
  151. // PlatMgr.showBanner(show);
  152. }
  153. showGuide() {
  154. let guide = DataMgr.getSkillGuide();
  155. this.ui.guideBtn.visible = guide == 0;
  156. this.ui.enterGuide.visible = false;
  157. this.ui.secretaryGuide.visible = guide == 0;
  158. if (guide == 0) {
  159. xGame.soundMgr.playSound("s_guide");
  160. xGame.common.showGirlTalkPop(16, this.ui.talkNode, this.ui.talkNode.womanTxt);
  161. }
  162. }
  163. ensureSecretary() {
  164. this.ui.secretaryGuide.visible = false;
  165. this.ui.enterGuide.visible = true;
  166. this.ui.wordsNode.t0.play();
  167. //todo
  168. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameReady");
  169. }
  170. playSecretaryIdle() {
  171. let parent = this.ui.secretary.displayObject;
  172. parent.destroyChildren();
  173. let xx = this.ui.secretary.width / 2;
  174. let yy = this.ui.secretary.height;
  175. let scale = xGame.common.getSecretaryScale();
  176. let data = { x: xx, y: yy, scaleX: scale, scaleY: scale };
  177. xGame.common.secretary.play(data, 1, true, parent);
  178. }
  179. startGame(type: GameMode) {
  180. //进入游戏页面
  181. xGame.common.gameMode = type;
  182. //
  183. Moyu.sendDataEvent("PlayGame", { type: type });
  184. switch (xGame.common.gameMode) {
  185. case GameMode.classic:
  186. let challengeTimes = DataMgr.getChallengeTimes();
  187. if (challengeTimes == 0) {
  188. xGame.uiMgr.Show(UIInvitation);
  189. }
  190. else {
  191. this.beginGame();
  192. }
  193. break;
  194. case GameMode.bigMove:
  195. this.beginGame();
  196. if (DataMgr.getNewUser()) Moyu.sendDataEvent("gameStart0");
  197. break;
  198. default:
  199. break;
  200. }
  201. }
  202. beginGame(isNice = false) {
  203. //
  204. //let time = xGame.common.randomNum(1000, 2000);
  205. //Moyu.showInsertAd(time, 60000);
  206. //
  207. if (xGame.common.gameMode == GameMode.classic) {
  208. //
  209. if (isNice) {
  210. //巅峰赛直接进入
  211. this.enterClassic();
  212. }
  213. else {
  214. xGame.uiMgr.Show(UIModeSelection, () => {
  215. this.enterClassic();
  216. })
  217. }
  218. }
  219. else if (xGame.common.gameMode == GameMode.bigMove) {
  220. this.ui.enterGuide.visible = false;
  221. xGame.uiMgr.Show(UISkill);
  222. }
  223. }
  224. enterClassic() {
  225. xGame.uiMgr.Show(UIGame);
  226. xGame.uiMgr.Show(UIMatching, () => {
  227. if (!this.isHide) this.hide();
  228. xGame.common.gameUI.ui.alpha = 1;
  229. xGame.common.gameUI.startGame();
  230. xGame.uiMgr.Hide(UIGameEnd);
  231. });
  232. }
  233. startGlobal() {
  234. xGame.uiMgr.Show(UIMsg, "敬请期待~")
  235. //xGame.uiMgr.Show(UITry);
  236. }
  237. startWeekly() {
  238. //xGame.uiMgr.Show(UIBox);
  239. xGame.uiMgr.Show(UIMsg, "敬请期待~")
  240. }
  241. startPlaceBall() {
  242. xGame.uiMgr.Show(UILevelDisplay);
  243. //xGame.uiMgr.Show(UIMsg, "敬请期待~")
  244. }
  245. public hide(): void {
  246. super.hide();
  247. xGame.common.stopGirlPop(this.ui.talkNode)
  248. }
  249. //点击头像
  250. onGetUserInfo(force = false) {
  251. if (Moyu.isWx) {
  252. let info = Moyu.getSystemInfo();
  253. if (info)
  254. Moyu.createWXUserBtn(0, 0, info.width, info.height, 'res/wxuser.png', this.freshUser);
  255. }
  256. else {
  257. Moyu.initUser(this, this.freshUser, force)
  258. }
  259. if (!Moyu.hasUserInfo) {
  260. let user = Moyu.getUserInfo();
  261. //user.nickName="我";
  262. user.headIcon = 'res/ty_touxiang.png';
  263. //console.log("未授权");
  264. }
  265. this.freshUser();
  266. }
  267. freshUser() {
  268. let user = Moyu.getUserInfo();
  269. if (!user.isAuth) {
  270. user.headIcon = 'res/ty_touxiang.png';
  271. }
  272. else
  273. DataMgr.upRankData();
  274. this.ui.headNode.nameTxt.text = xGame.tools.reviseString(user.nickName, 16);
  275. xGame.common.createHead(this.ui.headNode.headRoot.headImg, user.headIcon);
  276. }
  277. interuptSecretary() {
  278. Laya.timer.clearAll(this);
  279. this.playSecretaryRandomSound();
  280. }
  281. //主界面和技能选择界面3-7秒未操作随机播放秘书音效
  282. playSecretaryRandomSound() {
  283. if (this.isHide) return;
  284. let time = xGame.common.randomNum(45000, 60000);
  285. Laya.timer.once(time, this, () => {
  286. if (this.isHide) return;
  287. let index = xGame.common.randomNum(4, 7);
  288. xGame.soundMgr.playSound("s_main0" + index);
  289. let words = 1;
  290. switch (index) {
  291. case 4:
  292. words = 5;
  293. break;
  294. case 5:
  295. words = 3;
  296. break;
  297. case 6:
  298. words = 6;
  299. break;
  300. case 7:
  301. words = 7;
  302. break;
  303. default:
  304. break;
  305. }
  306. xGame.common.showGirlTalkPop(words, this.ui.talkNode, this.ui.talkNode.womanTxt);
  307. //
  308. this.playSecretaryRandomSound();
  309. })
  310. }
  311. openSecretaryView() {
  312. xGame.uiMgr.Show(UISecretary);
  313. Moyu.sendDataEvent("secretary");
  314. }
  315. openShopView() {
  316. xGame.uiMgr.Show(UIShop);
  317. }
  318. openSignView() {
  319. xGame.uiMgr.Show(UISign);
  320. }
  321. openDrawView() {
  322. xGame.uiMgr.Show(UIDraw);
  323. }
  324. openRanking() {
  325. xGame.uiMgr.Show(UIRanking);
  326. Moyu.sendDataEvent("rankingList");
  327. }
  328. }
  329. UIMain.uiName = "UIMain";