UIPausePanel.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import PlatUtils from "../../common-plugin/Scripts/PlatUtils";
  2. import { utils } from "../../common-plugin/Scripts/Utils";
  3. import { BannerLocation } from "../../common-plugin/Scripts/YZ_Constant";
  4. import { cocosz } from "../Framework/CocosZ";
  5. import { PageName, PanelName } from "../Framework/Constant";
  6. import TweenEffect from "../Framework/TweenEffect";
  7. import UIPage from "../Framework/UIPage";
  8. import { gameMgr } from "../Game/gameMgr";
  9. import { upgradeMgr } from "../Game/UpgradeMgr";
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class UIPausePanel extends UIPage {
  13. constructor() {
  14. super(PanelName.UIPausePanel);
  15. this.isValid() && this.onLoad();
  16. }
  17. private _mask: cc.Node = null;
  18. private _panel: cc.Node = null;
  19. onLoad() {
  20. this._mask = this._page.getChildByName("mask");
  21. this._panel = this._page.getChildByName("Panel");
  22. let btnNames: string[] = ["BtnRestart", "BtnResume", "BtnHome"];
  23. for (let i = 0; i < btnNames.length; i++) {
  24. let btn: cc.Node = cc.find(btnNames[i], this._panel);
  25. btn.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  26. }
  27. }
  28. protected onOpen(): void {
  29. utils.SendEvent("页面-暂停");
  30. this.showAd();
  31. TweenEffect.panel_mask_opacity(this._mask);
  32. TweenEffect.panel_open_moveY(this._panel);
  33. cocosz.pauseCount++;
  34. }
  35. protected onClose(): void {
  36. if (PlatUtils.IsVIVO) {
  37. utils.adManager.hideCustomAd({ location: BannerLocation.Pause });
  38. }
  39. cocosz.pauseCount--;
  40. }
  41. showAd() {
  42. if (cocosz.isShowAd) {
  43. if (PlatUtils.IsVIVO) {
  44. utils.adManager.showCustomAd({ location: BannerLocation.Pause });
  45. }
  46. }
  47. }
  48. /**
  49. * 所有按钮点击事件
  50. * @param event
  51. * @param data
  52. */
  53. private async _onBtnClickedHandler(event: cc.Event, data: any) {
  54. //播放按钮点击音效
  55. await cocosz.audioMgr.playBtnEffect().catch();
  56. switch (event.target.name) {
  57. case "BtnRestart": {
  58. gameMgr.isFail = true;
  59. gameMgr.unscheduleAllCallbacks();
  60. upgradeMgr && upgradeMgr.unscheduleAllCallbacks();
  61. cocosz.uiMgr.closePanel(PanelName.UIPausePanel);
  62. if (cocosz.gameMode == 6) {
  63. cocosz.gameMgr.gameStart(cocosz.dataMgr.TotoalCount_6);
  64. }
  65. break;
  66. }
  67. case "BtnResume": {
  68. cc.tween(this._panel)
  69. .to(0.5, { y: this._panel.y + 1000 }, { easing: "sineOut" })
  70. .call(() => {
  71. cocosz.uiMgr.closePanel(PanelName.UIPausePanel);
  72. })
  73. .start();
  74. break;
  75. }
  76. case "BtnHome": {
  77. gameMgr.isFail = true;
  78. gameMgr.unscheduleAllCallbacks();
  79. upgradeMgr && upgradeMgr.unscheduleAllCallbacks();
  80. cocosz.uiMgr.closePanel(PanelName.UIPausePanel);
  81. cocosz.sceneMgr.loadScene("Home", (() => {
  82. cocosz.uiMgr.openPage(PageName.UIHomePage);
  83. }))
  84. break;
  85. }
  86. }
  87. }
  88. }