UIReliveView.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import AccountModel from "../../../data/Account/AccountModel";
  8. import UIBase from "../../../framework/ui/UIBase";
  9. import { EVENT_TYPE } from "../../../gameLogic/utrl/gameEnum";
  10. import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
  11. import AESUtil from "../../../AESUtil"
  12. import ATSDK from "../../../AnyThinkAds/ATJSSDK";
  13. import ATRewardedVideoSDK from "../../../AnyThinkAds/ATRewardedVideoJSSDK";
  14. import AAJS2 from "../../../ATAndroidJS2";
  15. import GlobalManager from '../../../GlobalManager';
  16. const { ccclass, property } = cc._decorator;
  17. @ccclass
  18. export default class UIReliveView extends UIBase {
  19. protected static prefabUrl = "Interface/reliveView";
  20. protected static className = "UIReliveView";
  21. @property(cc.Node)
  22. reliveNum = null
  23. start() {
  24. this.reliveNum.getComponent(cc.Label).string = AccountModel.getInstance().reliveNum.toString();
  25. this.initAdForPage();
  26. }
  27. initAdForPage() {
  28. if (cc.sys.os === cc.sys.OS_ANDROID) {
  29. let deviceId = AAJS2.getDeviceUserId();
  30. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  31. var setting = {};
  32. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  33. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  34. }
  35. }
  36. reLive_btn(event, isRestart) {
  37. let self = this
  38. if (!isRestart) {
  39. zjSdk?.sendEvent('点击复活按钮')
  40. const params = {
  41. payType: zjSdk?.TYPE.VIDEO,
  42. success() {
  43. self.sendBtnEvent(isRestart);
  44. },
  45. fail() {
  46. self.sendBtnEvent(isRestart);
  47. }
  48. };
  49. if(2>1){//zh:diy
  50. if (cc.sys.os === cc.sys.OS_ANDROID) {
  51. GlobalManager.getInstance().registerMethod('doubleRewardForAdEventQd', this.doubleRewardForAdEventQd.bind(this));
  52. let adKey = "zh_ad_type"
  53. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  54. cc.sys.localStorage.setItem(adKey, 'doubleRewardForAdEventQd');
  55. console.log('zh:AD ready for idx2')
  56. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  57. } else {
  58. console.log('zh:AD not ready for idx2')
  59. self.doubleRewardForAdEventQd();
  60. }
  61. }
  62. return;
  63. }
  64. zjSdk?.doPay(params);
  65. } else {
  66. self.sendBtnEvent(isRestart);
  67. }
  68. }
  69. sendBtnEvent(isRestart) {
  70. gameEventManager.emit(EVENT_TYPE.GAME_RELIVE, isRestart);
  71. this.node.destroy();
  72. }
  73. //ZH:TODO
  74. sendBtnEventForAdEvent(isRestart) {
  75. gameEventManager.emit(EVENT_TYPE.GAME_RELIVE, isRestart);
  76. this.node.destroy();
  77. }
  78. }