UIRevivePanel.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. import AESUtil from "../AESUtil"
  9. import ATSDK from "../AnyThinkAds/ATJSSDK";
  10. import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoJSSDK";
  11. import AAJS2 from "../ATAndroidJS2";
  12. import GlobalManager from '../GlobalManager';
  13. // @ts-ignore
  14. const i18n = require('LanguageData');
  15. const { ccclass, property } = cc._decorator;
  16. @ccclass
  17. export default class UIRevivePanel extends UIPage {
  18. private _mask: cc.Node = null;
  19. private _panel: cc.Node = null;
  20. private _timeLabel: cc.Label = null;
  21. private _proIcon: cc.Sprite = null;
  22. private _btnVideo: cc.Node = null;
  23. private _btnPass: cc.Node = null;
  24. adKey: string = "zh_ad_type";
  25. constructor() {
  26. super(PanelName.UIRevivePanel);
  27. this.isValid() && this.onLoad();
  28. }
  29. protected onLoad() {
  30. this._mask = this._page.getChildByName("Mask");
  31. this._panel = this._page.getChildByName("Panel");
  32. this._timeLabel = this._panel.getChildByName("time").getComponent(cc.Label);
  33. this._proIcon = this._panel.getChildByName("shangquan").getComponent(cc.Sprite);
  34. this._btnVideo = this._panel.getChildByName("BtnVideo");
  35. this._btnVideo.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  36. this._btnPass = this._panel.getChildByName("BtnPass");
  37. this._btnPass.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  38. this.initAdForPage();
  39. }
  40. initAdForPage() {
  41. if (cc.sys.os === cc.sys.OS_ANDROID) {
  42. let deviceId = AAJS2.getDeviceUserId();
  43. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  44. var setting = {};
  45. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  46. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  47. }
  48. }
  49. protected onOpen() {
  50. utils.SendEvent("页面-复活");
  51. this.showAd();
  52. this._initPanel();
  53. cocosz.pauseCount++;
  54. }
  55. protected onClose(): void {
  56. cocosz.pauseCount--;
  57. }
  58. showAd() { }
  59. _tw1: cc.Tween = null;
  60. _tw2: cc.Tween = null;
  61. private _initPanel() {
  62. let opacityBack = this._mask.opacity;
  63. this._mask.opacity = 0;
  64. cc.tween(this._mask).to(0.2, { opacity: opacityBack }).start();
  65. this._panel.scale = 0;
  66. cc.tween(this._panel)
  67. .to(0.3, { scale: 1 }, { easing: "backOut" })
  68. .start();
  69. let count = 9;
  70. this._tw1 = cc.tween(this._timeLabel)
  71. .delay(1)
  72. .call(() => {
  73. this._timeLabel.string = (--count).toString();
  74. })
  75. .union()
  76. .repeat(9)
  77. .call(() => {
  78. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  79. gameMgr.fail();
  80. })
  81. .start();
  82. this._tw2 = cc.tween(this._proIcon)
  83. .to(9, { fillRange: 0 })
  84. .start();
  85. }
  86. stopTween() {
  87. if (cocosz.gameMode == 6) {
  88. this._tw1 && this._tw1.stop();
  89. this._tw2 && this._tw2.stop();
  90. }
  91. }
  92. /**
  93. * 所有按钮点击事件
  94. * @param event
  95. * @param data
  96. */
  97. private async _onBtnClickedHandler(event: cc.Event, data: any) {
  98. cocosz.audioMgr.playBtnEffect();
  99. this.stopTween();
  100. switch (event.target.name) {
  101. case "BtnVideo": {
  102. utils.umaEvent("gamefuhuo");
  103. // 分享
  104. if (this._btnVideo.getChildByName("share") && this._btnVideo.getChildByName("share").active) {
  105. utils.SendEvent("分享-复活");
  106. cocosz.share(() => {
  107. utils.SendEvent("分享-复活-成功")
  108. this._reLive();
  109. }, () => {
  110. utils.SendEvent("分享-复活-失败")
  111. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  112. gameMgr.fail();
  113. })
  114. }
  115. // 视频
  116. else if (this._btnVideo.getChildByName("video") && this._btnVideo.getChildByName("video").active) {
  117. utils.SendEvent("视频-复活-播放1");
  118. // 注册方法 , this.ClickClose.bind(this));
  119. GlobalManager.getInstance().registerMethod('event_fuHuo', this._reLive.bind(this));
  120. cc.sys.localStorage.setItem(this.adKey, 'event_fuHuo');
  121. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  122. console.log('zh:AD ready for idx2')
  123. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  124. } else {
  125. console.log('zh:AD not ready for idx2')
  126. this._reLive();
  127. }
  128. if (2 > 1) {
  129. return;
  130. }
  131. //下面是原先的
  132. cocosz.watchAD(() => {
  133. utils.SendEvent("视频-复活-成功1")
  134. this._reLive();
  135. }, () => {
  136. utils.SendEvent("视频-复活-失败1")
  137. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  138. gameMgr.fail();
  139. });
  140. }
  141. // 失败
  142. else {
  143. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  144. gameMgr.fail();
  145. }
  146. break;
  147. }
  148. case "BtnPass": {
  149. utils.umaEvent("gamesurr");
  150. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  151. gameMgr.fail();
  152. break;
  153. }
  154. }
  155. }
  156. /**
  157. * 复活事件
  158. */
  159. public _reLive() {
  160. console.log('zh:复活被触发')
  161. Msg.Show(i18n.t("msg.fhcg"));//复活成功
  162. cocosz.uiMgr.closePanel(PanelName.UIRevivePanel);
  163. gameMgr.revive();
  164. }
  165. }