MissionPanel.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { BaseView } from "../../../lightMVC/core/base/BaseView";
  2. import { App } from "../../Manager/App";
  3. import { Sex } from "../../Framework/Const/EnumDefine";
  4. import SuperScrollView from "../SuperScrollview/SuperScrollView";
  5. import MissionItem from "./MissionItem";
  6. import AESUtil from "../../AESUtil"
  7. import ATSDK from "../../AnyThinkAds/ATJSSDK";
  8. import ATRewardedVideoSDK from "../../AnyThinkAds/ATRewardedVideoJSSDK";
  9. import AAJS2 from "../../ATAndroidJS2";
  10. import GlobalManager from '../../GlobalManager';
  11. import ATInterstitialSDK from "../../AnyThinkAds/ATInterstitialJSSDK";
  12. import ATBannerSDK from "../../AnyThinkAds/ATBannerJSSDK";
  13. import { AdType } from '../../ATAndroidJS2';
  14. const { ccclass, property } = cc._decorator;
  15. @ccclass
  16. export default class MissionPanel extends BaseView {
  17. private skinNum: number = 6;
  18. private currentNum: number = 1;
  19. private list: any[] = [];
  20. protected onLoad(): void {
  21. console.log('zh:MissionPanel.ts onload ');
  22. //这个地方加了会有问题,导致列表无法加载
  23. // this.initAdForPageInter();
  24. // setTimeout(() => {
  25. // this.showInterAd("callBackFor_ClickBackMain",false, null);
  26. // }, 100);
  27. }
  28. //add判断插屏 开屏等,需要多次准备
  29. //add判断插屏 开屏等,需要多次准备
  30. initAdForPageInter() {
  31. if (cc.sys.os === cc.sys.OS_ANDROID) {
  32. console.log('zh:skillBox.ts 开始准备AD .....');
  33. let deviceId = AAJS2.getDeviceUserId();
  34. var setting = {};
  35. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  36. //add判断插屏 开屏等
  37. let pid_inter = AAJS2.getPlacementId2(AdType.Inter);
  38. console.log("zh: pid_inter checkstatus:", ATInterstitialSDK.checkAdStatus(pid_inter));
  39. ATInterstitialSDK.loadInterstitial(pid_inter, setting);
  40. }
  41. }
  42. public drawView(): void {
  43. console.log('zh:drawView');
  44. for (let i = 0; i < App.DataManager.MissionDataList.length; i++) {
  45. this.list[i] = i;
  46. }
  47. // 返回
  48. let closeBtn = this.ui.getNode("close");
  49. closeBtn.on(cc.Node.EventType.TOUCH_END, () => {
  50. this.closeView();
  51. }, this);
  52. this.CreateLevel();
  53. this.ui.getNode("item").active = false;
  54. }
  55. /**
  56. * 生成皮肤列表
  57. */
  58. private CreateLevel(): void {
  59. console.log('zh:CreateLevel');
  60. let skinList = this.ui.getNode("List");
  61. skinList.getComponent(SuperScrollView).setData(this.list, false, null);
  62. }
  63. public static path(): string {
  64. return "hallScene/prefabs/MissionPanel";
  65. }
  66. /**
  67. * 显示插屏广告
  68. *
  69. * @param adMarkForClose 插屏广告关闭后调用那个方法的具体指示标识
  70. * @param checkClose 是否需要判断关闭事件,有的不需要,如果AD占用游戏时间则为true
  71. * @param callback 插屏广告关闭(加载失败\非ANDROID平台)的回调
  72. */
  73. private showInterAd(adMarkForClose: string, checkClose: boolean, callback: () => void) {
  74. if (cc.sys.os === cc.sys.OS_ANDROID) {
  75. if (checkClose) {
  76. cc.sys.localStorage.setItem("adMarkForClose", adMarkForClose);//关闭后,调用哪个方法的标识
  77. }
  78. //add判断插屏 开屏等
  79. let pid_inter = AAJS2.getPlacementId2(AdType.Inter);
  80. let boo = ATInterstitialSDK.hasAdReady(pid_inter);
  81. if (boo) {
  82. // 暂停游戏
  83. cc.director.pause();
  84. console.log('zh:showInterAd AD OK');
  85. ATInterstitialSDK.showAd(pid_inter);
  86. //因为跨脚本,所以使用全局注册函数调用,后来发现切换APP,导致ad close事件失效
  87. if (!checkClose) {//如果不占用游戏时间
  88. this.safeCallback(callback);
  89. }
  90. } else {
  91. console.log('zh:showInterAd AD 没有准备好');
  92. //GlobalManager.getInstance().callMethod('initAdForPageInter');
  93. //this.initAdForPageInter();
  94. this.safeCallback(callback);
  95. }
  96. } else {
  97. this.safeCallback(callback);
  98. }
  99. }
  100. // 辅助方法:安全调用回调函数
  101. private safeCallback(callback?: () => void) {
  102. if (callback) {
  103. callback();
  104. }
  105. }
  106. }