UIRevivePanel.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import UIPage from "../Framework/UIPage";
  2. import Msg from "../Framework/Msg";
  3. import { PanelName } from "../Framework/Constant";
  4. import { cocosz } from "../Framework/CocosZ";
  5. import { utils } from "../../common-plugin/Scripts/Utils";
  6. import { gameMgr } from "../Game/gameMgr";
  7. import PlatUtils from "../../common-plugin/Scripts/PlatUtils";
  8. // @ts-ignore
  9. const i18n = require('LanguageData');
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class UIRevivePanel extends UIPage {
  13. private _mask: cc.Node = null;
  14. private _panel: cc.Node = null;
  15. private _timeLabel: cc.Label = null;
  16. private _proIcon: cc.Sprite = null;
  17. private _btnVideo: cc.Node = null;
  18. private _btnPass: cc.Node = null;
  19. constructor() {
  20. super(PanelName.UIRevivePanel);
  21. this.isValid() && this.onLoad();
  22. }
  23. protected onLoad() {
  24. this._mask = this._page.getChildByName("Mask");
  25. this._panel = this._page.getChildByName("Panel");
  26. this._timeLabel = this._panel.getChildByName("time").getComponent(cc.Label);
  27. this._proIcon = this._panel.getChildByName("shangquan").getComponent(cc.Sprite);
  28. this._btnVideo = this._panel.getChildByName("BtnVideo");
  29. this._btnVideo.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  30. this._btnPass = this._panel.getChildByName("BtnPass");
  31. this._btnPass.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  32. }
  33. protected onOpen() {
  34. utils.SendEvent("页面-复活");
  35. this.showAd();
  36. this._initPanel();
  37. cocosz.pauseCount++;
  38. }
  39. protected onClose(): void {
  40. cocosz.pauseCount--;
  41. }
  42. showAd() { }
  43. _tw1: cc.Tween = null;
  44. _tw2: cc.Tween = null;
  45. private _initPanel() {
  46. let opacityBack = this._mask.opacity;
  47. this._mask.opacity = 0;
  48. cc.tween(this._mask).to(0.2, { opacity: opacityBack }).start();
  49. this._panel.scale = 0;
  50. cc.tween(this._panel)
  51. .to(0.3, { scale: 1 }, { easing: "backOut" })
  52. .start();
  53. let count = 9;
  54. this._tw1 = cc.tween(this._timeLabel)
  55. .delay(1)
  56. .call(() => {
  57. this._timeLabel.string = (--count).toString();
  58. })
  59. .union()
  60. .repeat(9)
  61. .call(() => {
  62. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  63. gameMgr.fail();
  64. })
  65. .start();
  66. this._tw2 = cc.tween(this._proIcon)
  67. .to(9, { fillRange: 0 })
  68. .start();
  69. }
  70. stopTween() {
  71. if (cocosz.gameMode == 6) {
  72. this._tw1 && this._tw1.stop();
  73. this._tw2 && this._tw2.stop();
  74. }
  75. }
  76. /**
  77. * 所有按钮点击事件
  78. * @param event
  79. * @param data
  80. */
  81. private async _onBtnClickedHandler(event: cc.Event, data: any) {
  82. cocosz.audioMgr.playBtnEffect();
  83. this.stopTween();
  84. switch (event.target.name) {
  85. case "BtnVideo": {
  86. utils.umaEvent("gamefuhuo");
  87. // 分享
  88. if (this._btnVideo.getChildByName("share") && this._btnVideo.getChildByName("share").active) {
  89. utils.SendEvent("分享-复活");
  90. cocosz.share(() => {
  91. utils.SendEvent("分享-复活-成功")
  92. this._reLive();
  93. }, () => {
  94. utils.SendEvent("分享-复活-失败")
  95. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  96. gameMgr.fail();
  97. })
  98. }
  99. // 视频
  100. else if (this._btnVideo.getChildByName("video") && this._btnVideo.getChildByName("video").active) {
  101. utils.SendEvent("视频-复活-播放1");
  102. cocosz.watchAD(() => {
  103. utils.SendEvent("视频-复活-成功1")
  104. this._reLive();
  105. }, () => {
  106. utils.SendEvent("视频-复活-失败1")
  107. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  108. gameMgr.fail();
  109. });
  110. }
  111. // 失败
  112. else {
  113. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  114. gameMgr.fail();
  115. }
  116. break;
  117. }
  118. case "BtnPass": {
  119. utils.umaEvent("gamesurr");
  120. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  121. gameMgr.fail();
  122. break;
  123. }
  124. }
  125. }
  126. /**
  127. * 复活事件
  128. */
  129. private _reLive() {
  130. Msg.Show(i18n.t("msg.fhcg"));//复活成功
  131. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  132. gameMgr.revive();
  133. }
  134. }