UIOverPage.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import UIPage from "../Framework/UIPage";
  2. import { PageName } from "../Framework/Constant";
  3. import { cocosz } from "../Framework/CocosZ";
  4. import PlatUtils from "../../common-plugin/Scripts/PlatUtils";
  5. import { utils } from "../../common-plugin/Scripts/Utils";
  6. import { BannerLocation } from "../../common-plugin/Scripts/YZ_Constant";
  7. import { gameMgr } from "../Game/gameMgr";
  8. import { upgradeMgr } from "../Game/UpgradeMgr";
  9. // @ts-ignore
  10. const i18n = require('LanguageData');
  11. const { ccclass, property } = cc._decorator;
  12. @ccclass
  13. export default class UIOverPage extends UIPage {
  14. private _panel: cc.Node = null;
  15. private _mask: cc.Node = null;
  16. private _btnContinue: cc.Node = null;
  17. private _btnHome: cc.Node = null;
  18. constructor() {
  19. super(PageName.UIOverPage);
  20. this.isValid() && this.onLoad();
  21. }
  22. protected onLoad() {
  23. this._mask = cc.find("Mask", this._page);
  24. this._panel = cc.find("Panel", this._page)
  25. this._btnContinue = cc.find("BtnContinue", this._panel);
  26. this._btnContinue.on(cc.Node.EventType.TOUCH_END, this._onBtnClickHandler, this);
  27. this._btnHome = cc.find("BtnHome", this._panel);
  28. this._btnHome.on(cc.Node.EventType.TOUCH_END, this._onBtnClickHandler, this);
  29. }
  30. protected onOpen() {
  31. utils.SendEvent("页面-结算-" + (gameMgr.isWin ? "胜利" : "失败"));
  32. this.showAd();
  33. this._initPanel();
  34. cocosz.dataMgr.TotoalCount_6++;
  35. }
  36. protected onClose() {
  37. cc.game.targetOff(this);
  38. utils.hideVivoGamePortalWidget();
  39. utils.hideOppoGameDrawerAdWidget();
  40. utils.adManager.hideBlockAd();
  41. utils.adManager.hideNativeTryGameWidget();
  42. utils.adManager.HideSingleNativeAd();
  43. if (PlatUtils.IsWechat) {
  44. utils.adManager.HideBanner(BannerLocation.Over);
  45. utils.adManager.hideCustomAd({ location: 5 });
  46. utils.adManager.hideCustomAd({ location: 6 });
  47. utils.adManager.hideCustomAd({ location: 7 });
  48. } else if (PlatUtils.IsVIVO) {
  49. utils.adManager.hideCustomAd({ location: BannerLocation.Over });
  50. }
  51. }
  52. protected showAd() {
  53. utils.adManager.ShowBanner(BannerLocation.Over, { width: 0.1, bottom: 1 });
  54. // 显示积木广告
  55. utils.adManager.showBlockAd({ top: 500 });
  56. // 悬浮icon
  57. utils.adManager.showNativeTryGameWidget({ right: 95, top: 500, scale: 1, parent: this._page });
  58. // 原生广告
  59. if (PlatUtils.IsWechat) {
  60. utils.adManager.showCustomAd({ location: 5 });
  61. utils.adManager.showCustomAd({ location: 6 });
  62. utils.adManager.showCustomAd({ location: 7 });
  63. } else if (PlatUtils.IsVIVO) {
  64. utils.adManager.showCustomAd({ location: BannerLocation.Over });
  65. }
  66. // 互推
  67. utils.showTryGamesWidget({ group: 'default', scale: 1, top: 180, right: 25, parent: this._page, location: BannerLocation.Over });
  68. utils.showMoreGamesWidget({ group: 'default', scale: 1, top: 300, left: 25, parent: this._page, location: BannerLocation.Over });
  69. utils.showRecommendGamesList({ group: 'default', scale: 1, parent: this._page, bottom: 1000 });
  70. utils.showVivoGamePortalWidget({ top: 500, location: BannerLocation.Over });
  71. utils.showOppoGameDrawerAdWidget({ bottom: 500, location: BannerLocation.Over });
  72. utils.showOppoRecBanner({ bottom: 500, left: 0, location: BannerLocation.Over });
  73. let result = null;
  74. if (gameMgr && gameMgr.isWin) {
  75. utils.GameWin(cocosz.getLevelId().toString());
  76. } else if (gameMgr && gameMgr.isFail) {
  77. utils.GameFail(cocosz.getLevelId().toString());
  78. }
  79. // //当返回值不为空,并且返回值的node不为空,会返回6个互推节点
  80. if (result && result.node) {
  81. //获取到节点后,将返回值的node节点添加到指定节点上。
  82. result.node.position = cc.v2(0, 0)
  83. this._page.addChild(result.node, 0);
  84. }
  85. }
  86. getSkillIDName(id: number) {
  87. return id + (upgradeMgr.upgradeSkillMaxLevelArr[id] > 1 ? "_" + (upgradeMgr.upgradeSkillArr[id] + 1) : "")
  88. }
  89. _initPanel() {
  90. // 弹窗效果
  91. this._mask.opacity = 0;
  92. cc.tween(this._mask).to(0.2, { opacity: 120 }).start();
  93. this._panel.scale = 0;
  94. cc.tween(this._panel).to(0.3, { scale: 1 }, { easing: "backOut" }).start();
  95. if (upgradeMgr && upgradeMgr.isValid) {
  96. // boss
  97. let kuang_boss = this._panel.getChildByName("kuang_boss");
  98. if (upgradeMgr.bossKillId.length) {
  99. let kuang_boss_layout = kuang_boss.getChildByName("layout");
  100. if (kuang_boss_layout) {
  101. kuang_boss_layout.active = true;
  102. kuang_boss_layout.children.forEach((v, i) => {
  103. if (upgradeMgr.bossKillId.includes(parseInt(v.name))) {
  104. v.active = true;
  105. } else {
  106. v.active = false;
  107. }
  108. })
  109. }
  110. } else {
  111. let kuang_boss_no = kuang_boss.getChildByName("no");
  112. if (kuang_boss_no) {
  113. kuang_boss_no.active = true;
  114. }
  115. }
  116. // 技能
  117. let kuang_skill = this._panel.getChildByName("kuang_skill");
  118. if (upgradeMgr.upgradeSkillArr.includes(1) || upgradeMgr.upgradeSkillArr.includes(2) || upgradeMgr.upgradeSkillArr.includes(3)) {
  119. let skill_scrollView = kuang_skill.getChildByName("skillScrollView");
  120. if (skill_scrollView) {
  121. skill_scrollView.active = true;
  122. let skill_content = cc.find("view/content", skill_scrollView);
  123. if (skill_content) {
  124. upgradeMgr.upgradeSkillArr.forEach((level, id) => {
  125. if (upgradeMgr.upgradeSkillMaxLevelArr[id] == 3) {
  126. // for (let i = 1; i <= level; i++) {
  127. let icon = cocosz.resMgr.getRes("zombieSkill_icon_" + id + "_" + level, cc.SpriteFrame);
  128. if (icon) {
  129. let node = new cc.Node();
  130. let sprit = node.addComponent(cc.Sprite);
  131. sprit.spriteFrame = icon;
  132. sprit.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  133. node.setContentSize(70, 70);
  134. skill_content.addChild(node);
  135. }
  136. // }
  137. } else if (level > 0) {
  138. let icon = cocosz.resMgr.getRes("zombieSkill_icon_" + id, cc.SpriteFrame);
  139. if (icon) {
  140. let node = new cc.Node();
  141. let sprit = node.addComponent(cc.Sprite);
  142. sprit.spriteFrame = icon;
  143. sprit.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  144. node.setContentSize(70, 70);
  145. skill_content.addChild(node);
  146. }
  147. }
  148. })
  149. }
  150. }
  151. } else {
  152. let kuang_skill_no = kuang_skill.getChildByName("no");
  153. if (kuang_skill_no) {
  154. kuang_skill_no.active = true;
  155. }
  156. }
  157. // 结算信息
  158. let info = cc.find("info", this._panel);
  159. if (info) {
  160. // 标题
  161. cc.log("iswin:", gameMgr.isWin, " isFail:",gameMgr.isFail)
  162. info.getChildByName('tittle').children[0].active = gameMgr.isWin;
  163. info.getChildByName('tittle').children[1].active = gameMgr.isFail;
  164. // 历史最佳
  165. // 游戏时间
  166. info.getChildByName('time2').getComponent(cc.Label).string = cocosz.StoHMS(cocosz.dataMgr.best_time);
  167. // 击杀数
  168. info.getChildByName('kill2').getComponent(cc.Label).string = cocosz.dataMgr.best_kill.toString();
  169. // 等级
  170. info.getChildByName('level2').getComponent(cc.Label).string = cocosz.dataMgr.best_level.toString();
  171. // 金币
  172. info.getChildByName('coin2').getComponent(cc.Label).string = cocosz.dataMgr.best_coin.toString();
  173. // 本局详情
  174. let newRecard1 = info.getChildByName('newRecard1');
  175. let newRecard2 = info.getChildByName('newRecard2');
  176. let newRecard3 = info.getChildByName('newRecard3');
  177. let newRecard4 = info.getChildByName('newRecard4');
  178. // 游戏时间
  179. info.getChildByName('time1').getComponent(cc.Label).string = cocosz.StoHMS(gameMgr.GameTime);
  180. if (gameMgr.GameTime > cocosz.dataMgr.best_time) {
  181. info.getChildByName('time1').color = cc.Color.RED;
  182. cocosz.dataMgr.best_time = gameMgr.GameTime;
  183. newRecard1.active = true;
  184. }
  185. // 击杀数
  186. info.getChildByName('kill1').getComponent(cc.Label).string = upgradeMgr.zombieKillNum.toString();
  187. if (upgradeMgr.zombieKillNum > cocosz.dataMgr.best_kill) {
  188. info.getChildByName('kill1').color = cc.Color.RED;
  189. cocosz.dataMgr.best_kill = upgradeMgr.zombieKillNum;
  190. newRecard2.active = true;
  191. }
  192. // 等级
  193. info.getChildByName('level1').getComponent(cc.Label).string = upgradeMgr.curLevel.toString();
  194. if (upgradeMgr.curLevel > cocosz.dataMgr.best_level) {
  195. info.getChildByName('level1').color = cc.Color.RED;
  196. cocosz.dataMgr.best_level = upgradeMgr.curLevel;
  197. newRecard3.active = true;
  198. }
  199. // 金币
  200. let count = upgradeMgr.zombieKillNum + upgradeMgr.curLevel * 10 + Math.min(500, Math.ceil(gameMgr.GameTime / 10));
  201. cocosz.dataMgr.CoinCount += count;
  202. info.getChildByName('coin1').getComponent(cc.Label).string = count.toString();
  203. if (count > cocosz.dataMgr.best_coin) {
  204. info.getChildByName('coin1').color = cc.Color.RED;
  205. cocosz.dataMgr.best_coin = count;
  206. newRecard4.active = true;
  207. }
  208. }
  209. }
  210. }
  211. private _isToHome: boolean = false;
  212. private async _onBtnClickHandler(event: any) {
  213. await cocosz.audioMgr.playBtnEffect().catch();
  214. if (this._isToHome) return;
  215. switch (event.target.name) {
  216. case "BtnContinue": {
  217. // 上报 继续游戏
  218. utils.umaEvent("gamecontinue");
  219. if (cocosz.gameMode == 6) {
  220. cocosz.gameMgr.gameStart(cocosz.dataMgr.TotoalCount_6);
  221. }
  222. break;
  223. }
  224. case "BtnHome": {
  225. // 上报 返回首页
  226. utils.umaEvent("gamereturn");
  227. cocosz.sceneMgr.loadScene("Home", () => {
  228. cocosz.uiMgr.openPage(PageName.UIHomePage);
  229. })
  230. break;
  231. }
  232. }
  233. }
  234. }