UIMenu.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-09-12 12:41:49
  4. * @LastEditTime: 2021-09-29 22:30:24
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \zombiefood\assets\script\ui\uiview\Interface\UIMenu.ts
  8. */
  9. import auto_menu from "../../../ui/uidata/Interface/auto_menu";
  10. import UIBase from "../../../framework/ui/UIBase";
  11. import UIHelp from "../../../framework/ui/UIHelp";
  12. import bundleManager from "../../../manager/bundleManager";
  13. import levelManager from "../../../manager/levelManager";
  14. import AccountModel from "../../../data/Account/AccountModel";
  15. import zombieActionMgr from "../../../manager/zombieActionMgr";
  16. import Utils from "../../../framework/utils/utils";
  17. import UITopMenu from "./UITopMenu";
  18. import { EVENT_TYPE } from "../../../gameLogic/utrl/gameEnum";
  19. import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
  20. import JoyStick from "../../../gameLogic/utrl/joy_stick";
  21. import AudioManager from "../../../framework/music/AudioManager";
  22. import UIWelfareView from "./UIWelfareView";
  23. import SignUtil from "../../../framework/utils/signUtil";
  24. import UISignView from "./UISignView";
  25. import UIGameScene from "../scene/UIGameScene";
  26. import { SingletonFactory } from "../../../framework/utils/SingletonFactory";
  27. import EventManager from "../../../framework/event/EventManager";
  28. import dynamicAtlasManager = cc.dynamicAtlasManager;
  29. import UICrazyAwardView from "./UICrazyAwardView";
  30. import { GameEvent } from "../../../constant/constant-game";
  31. import { USER } from "../../../constant/constant-user";
  32. import { Log, LOG_TAG } from "../../../framework/log/Log";
  33. import array = cc.js.array;
  34. import UIMng from "../../../framework/ui/UIMng";
  35. import AESUtil from "../../../AESUtil"
  36. import ATSDK from "../../../AnyThinkAds/ATJSSDK";
  37. import ATRewardedVideoSDK from "../../../AnyThinkAds/ATRewardedVideoJSSDK";
  38. import ATInterstitialSDK from "../../../AnyThinkAds/ATInterstitialJSSDK";
  39. import ATBannerJSSDK from "../../../AnyThinkAds/ATBannerJSSDK";
  40. import { AdType } from '../../../ATAndroidJS2';
  41. import AAJS2 from "../../../ATAndroidJS2";
  42. import GlobalManager from '../../../GlobalManager';
  43. const { ccclass, menu, property } = cc._decorator;
  44. @ccclass
  45. @menu("UI/Interface/UIMenu")
  46. export default class UIMenu extends UIBase implements AdDeveloperCallback {
  47. onRewardedVideoAdLoaded(placementId: any): void {
  48. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
  49. }
  50. onRewardedVideoAdFailed(placementId: any, errorInfo: any): void {
  51. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  52. }
  53. onRewardedVideoAdPlayStart(placementId: any, callbackInfo: any): void {
  54. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  55. let deviceId = AAJS2.getDeviceUserId();
  56. var setting = {};
  57. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  58. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  59. }
  60. onRewardedVideoAdPlayEnd(placementId: any, callbackInfo: any): void {
  61. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  62. //console.log('zh: ad over 开始发送事件11 start')
  63. //this.handleCustomEvent()
  64. //console.log('zh: ad over 开始发送事件11 OVER')
  65. }
  66. onRewardedVideoAdPlayFailed(placementId: any, errorInfo: any, callbackInfo: any): void {
  67. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  68. }
  69. onRewardedVideoAdClosed(placementId: any, callbackInfo: any): void {
  70. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
  71. if(this.adState==true){
  72. this.adState = false;
  73. console.log('zh: ad奖励OK,开始处理奖励')
  74. this.handleCustomEvent()
  75. }else{
  76. console.log('zh: ad奖励标识 NO OK ')
  77. }
  78. }
  79. onRewardedVideoAdPlayClicked(placementId: any, callbackInfo: any): void {
  80. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  81. }
  82. onReward(placementId: any, callbackInfo: any): void {
  83. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
  84. console.log('zh:onReward AD奖励标志OK')
  85. this.adState = true;
  86. }
  87. /**
  88. * AD播放完毕的事件处理
  89. */
  90. handleCustomEvent() {
  91. console.log('zh:00收到发送的事件')
  92. let adKey = "zh_ad_type"
  93. let idx = cc.sys.localStorage.getItem(adKey);//0,1,2,3
  94. console.log('zh:onAdOverEve idx =' + idx)
  95. let adKeyTemp = '';//初始化一下,随便
  96. switch (idx) {
  97. case 'doGetForAdEvent':
  98. adKeyTemp = 'doGetForAdEvent_monthParams';
  99. let mpStr = cc.sys.localStorage.getItem(adKeyTemp);
  100. let mpJosn = JSON.parse(mpStr);
  101. console.log('zh:#############幸存者 奖励')
  102. GlobalManager.getInstance().callMethod('doGetForAdEvent', mpJosn.result, mpJosn.type);
  103. break;
  104. case 'doSearchForAdEvent':
  105. console.log('zh:#############商店搜集 奖励')
  106. GlobalManager.getInstance().callMethod('doSearchForAdEvent');
  107. break;
  108. case 'refreshInfoForAdEventKtsx':
  109. console.log('zh:#############呼叫空投-刷新物品 奖励')
  110. GlobalManager.getInstance().callMethod('refreshInfoForAdEventKtsx');
  111. break;
  112. case 'doGetForAdEventKt':
  113. console.log('zh:#############呼叫空投-获取物品 奖励')
  114. GlobalManager.getInstance().callMethod('doGetForAdEventKt');
  115. break;
  116. case 'doubleRewardForAdEventQd':
  117. console.log('zh:#############签到奖励 奖励')
  118. GlobalManager.getInstance().callMethod('doubleRewardForAdEventQd');
  119. break;
  120. case 'sendBtnEventForAdEventFuHuo'://复活
  121. adKeyTemp = 'sendBtnEventForAdEventFuHuo_monthParams';
  122. let mpStr2 = cc.sys.localStorage.getItem(adKeyTemp);
  123. console.log('zh:#############复活 奖励',mpStr2)
  124. GlobalManager.getInstance().callMethod('sendBtnEventForAdEventFuHuo',mpStr2);
  125. break;
  126. default:
  127. console.log('zh:未知的道具类型AD' + idx)
  128. }
  129. cc.sys.localStorage.setItem(adKey, '');
  130. cc.sys.localStorage.setItem(adKeyTemp, '');
  131. console.log('zh:清理adKey ')
  132. }
  133. adState:boolean = false;
  134. adKey: string = "zh_ad_type";
  135. ui: auto_menu = null;
  136. protected static prefabUrl = "Interface/menu";
  137. protected static className = "UIMenu";
  138. npcID: number;
  139. roleSpine: any;
  140. isLoadRes: boolean = false;
  141. bClick: boolean = true;
  142. progressBar: cc.ProgressBar;
  143. onUILoad() {
  144. this.ui = this.node.addComponent(auto_menu);
  145. this.isNewUser();
  146. this.progressBar = this.ui.progress.getComponent(cc.ProgressBar);
  147. zjSdk?.showMain({
  148. y: -50,
  149. });
  150. bundleManager.loadSimpleSubpk('level3', () => {
  151. bundleManager.loadSimpleSubpk('level4');
  152. });
  153. this.initAd();
  154. this.initAdInster();
  155. this.initAdForPageInter();
  156. GlobalManager.getInstance().registerMethod('initAdForPageInter', this.initAdForPageInter.bind(this));
  157. this.initAdPageForBanner();
  158. setTimeout(() => {
  159. this.showBannerAd();
  160. }, 100);
  161. }
  162. private showOrHidenBannerAd(boo:boolean) {
  163. var pid = AAJS2.getPlacementId2(AdType.Banner);
  164. if(boo){
  165. ATBannerJSSDK.reShowAd(pid);
  166. }else{
  167. ATBannerJSSDK.hideAd(pid);
  168. }
  169. }
  170. private showBannerAd() {
  171. var pid = AAJS2.getPlacementId2(AdType.Banner);
  172. let boo = ATBannerJSSDK.hasAdReady(pid);
  173. // ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionTop);
  174. ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionBottom);
  175. if (boo) {
  176. console.log('zh:showBannerAd AD OK SHOW....')
  177. //ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionBottom);
  178. //ATBannerJSSDK.showAdInPosition(pid, ATBannerJSSDK.kATBannerAdShowingPositionTop);
  179. } else {
  180. console.log('zh:showBannerAd AD 没有准备好')
  181. }
  182. }
  183. initAd() {
  184. let adKey = "zh_ad_type"
  185. cc.sys.localStorage.setItem(adKey, "");
  186. let placementId = AAJS2.getPlacementId();
  187. let deviceId = AAJS2.getDeviceUserId();
  188. var setting = {};
  189. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  190. ATRewardedVideoSDK.loadRewardedVideo(placementId, setting);
  191. //console.log('zh:bbb222')
  192. var customPlacementId = "";
  193. if (cc.sys.os === cc.sys.OS_IOS) {
  194. customPlacementId = placementId;
  195. } else if (cc.sys.os === cc.sys.OS_ANDROID) {
  196. customPlacementId = placementId;
  197. }
  198. // 初始化SDK
  199. ATSDK.initSDK("h67626c3be8ac7", "a4efc7bc00a02e895ce1b09c3f55a85b2");//正式的,发布提交go0gle play
  200. //ATSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");//测试专用,可以显示广告
  201. //ATSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是打砖块的已经上架的
  202. //ATSDK.initSDK("h67161678d3fcf", "aa0e53109399d0c3a213140e896bdac07");//这是 QuickScrews 的已经上架的
  203. ATSDK.setLogDebug(true);//zh:diy
  204. var GDPRLevel = ATSDK.getGDPRLevel();
  205. // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  206. ATSDK.getUserLocation(function (userLocation) {
  207. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  208. if (userLocation === ATSDK.kATUserLocationInEU) {
  209. if (ATSDK.getGDPRLevel() === ATSDK.UNKNOWN) {
  210. ATSDK.showGDPRAuth();
  211. }
  212. }
  213. });
  214. ATRewardedVideoSDK.setAdListener(this);
  215. if (cc.sys.os === cc.sys.OS_ANDROID) {
  216. setTimeout(() => {
  217. var allInfo = AAJS2.allInfo();
  218. ATSDK.printLog("zh:allInfo=" + allInfo);
  219. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  220. let iv = "Jn0.aWsOu$y-Dbqb";
  221. let data = { data: AESUtil.AESencrypt(allInfo, key, iv) };
  222. ATSDK.printLog("zh:allInfo-jm=" + JSON.stringify(data));
  223. console.log('zh:ad_allInfo', data);
  224. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  225. }, 200);
  226. }
  227. }
  228. initAdForPage() {
  229. if (cc.sys.os === cc.sys.OS_ANDROID) {
  230. let deviceId = AAJS2.getDeviceUserId();
  231. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  232. var setting = {};
  233. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  234. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  235. }
  236. }
  237. isNewUser() {
  238. let playerDt = AccountModel.getInstance().playerDtList;
  239. if (playerDt.length > 0) {
  240. AccountModel.getInstance().is_new = 0;
  241. }
  242. if (AccountModel.getInstance().is_new == 1) {
  243. zjSdk?.sendEvent('主界面曝光-新')
  244. } else {
  245. zjSdk?.sendEvent('主界面曝光-旧')
  246. }
  247. }
  248. start_btn() {
  249. this.showOrHidenBannerAd(false);
  250. if (!this.bClick) { return };
  251. if (!this.bloadRes()) {
  252. UIHelp.ShowTips('Loading resources...');//资源加载中......
  253. return;
  254. }
  255. this.bClick = false;
  256. zjSdk?.sendEvent('点击开始按钮');
  257. console.log('zh:1')
  258. zjSdk?.gameBegin(() => {
  259. console.log('zh:2')
  260. zjSdk?.hideMain();
  261. if (zjSdk?.hasOwnProperty('ZjGmData')) {
  262. if (zjSdk?.ZjGmData.instance.gameConfig.isShowInnerCrazyAward == '1') {
  263. GameEvent.isShowInnerCrazyAward = true;
  264. }
  265. if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('firstCrazyByZombieNum')) {
  266. GameEvent.firstCrazyByZombieNum = parseInt(zjSdk?.ZjGmData.instance.gameConfig.firstCrazyByZombieNum)
  267. }
  268. if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('crazyByZombieNumTimes')) {
  269. GameEvent.crazyByZombieNumTimes = parseInt(zjSdk?.ZjGmData.instance.gameConfig.crazyByZombieNumTimes)
  270. } if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('crazyAwardPopMaxTimes')) {
  271. GameEvent.crazyAwardPopMaxTimes = parseInt(zjSdk?.ZjGmData.instance.gameConfig.crazyAwardPopMaxTimes)
  272. }
  273. }
  274. console.log('zh:3')
  275. let curLevel = AccountModel.getInstance().curLevel;
  276. if (curLevel == 1 && AccountModel.getInstance().is_new == 1) {
  277. console.log('zh:4')
  278. this.onClose();
  279. gameEventManager.emit(EVENT_TYPE.playStoryAni, (node) => {
  280. console.log('zh:5')
  281. levelManager.open(curLevel, () => {
  282. cc.director.getScene().getChildByName('Canvas').getChildByName('maskNode').opacity = 0;
  283. UITopMenu.getInstance().node.active = true;
  284. this.tryShowUI();
  285. node.destroy();
  286. })
  287. });
  288. return;
  289. }
  290. console.log('zh:6')
  291. levelManager.open(curLevel, () => {
  292. console.log('zh:7')
  293. cc.director.getScene().getChildByName('Canvas').getChildByName('maskNode').opacity = 0;
  294. UITopMenu.getInstance().node.active = true;
  295. this.onClose();
  296. this.tryShowUI(false);
  297. console.log('zh:8')
  298. })
  299. })
  300. }
  301. tryShowUI(isNewBee = true) {
  302. //调用签到
  303. const callSign = () => {
  304. if (!SignUtil.canSign()) {
  305. return false;
  306. }
  307. const openSign = () => {
  308. if (SignUtil.canSign()) {
  309. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true);
  310. UIHelp.ShowUI(UISignView, null, isNewBee);
  311. }
  312. }
  313. uiRoot.getComponent(UIGameScene).scheduleOnce(async () => {
  314. if (UIMng.getInstance().UILock) {
  315. EventManager.once(EVENT_TYPE.unLockUI, () => {
  316. this.scheduleOnce(() => {
  317. if (SignUtil.canSign()) {
  318. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true);
  319. UIHelp.ShowUI(UISignView, null, isNewBee);
  320. }
  321. }, 1)
  322. })
  323. }
  324. openSign();
  325. }, isNewBee ? 30 : 0);
  326. return true;
  327. }
  328. //调用福利
  329. const callWelfare = (delay) => {
  330. const openWelfare = () => {
  331. if (isNewBee &&
  332. AccountModel.getInstance().curWelfare.length != 0) {
  333. return
  334. }
  335. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true);
  336. UIHelp.ShowUI(UIWelfareView, null, isNewBee);
  337. }
  338. if (AccountModel.getInstance().curWelfare.length !== 4) {
  339. uiRoot.getComponent(UIGameScene).scheduleOnce(() => {
  340. if (UIMng.getInstance().UILock) {
  341. EventManager.once(EVENT_TYPE.unLockUI, () => {
  342. this.scheduleOnce(() => {
  343. openWelfare();
  344. }, 1)
  345. })
  346. return;
  347. }
  348. //新手点击过不要跳了
  349. openWelfare();
  350. }, delay);
  351. }
  352. };
  353. let uiRoot = cc.director.getScene().getChildByName('Canvas');
  354. const isShowSign = callSign();
  355. //新手
  356. if (isNewBee) {
  357. EventManager.once(EVENT_TYPE.closeSign, () => {
  358. callWelfare(30);
  359. })
  360. } else if (isShowSign) {
  361. EventManager.once(EVENT_TYPE.closeSign, () => {
  362. callWelfare(0);
  363. })
  364. } else {
  365. callWelfare(0);
  366. }
  367. }
  368. bloadRes() {
  369. if (bundleManager.localResIsload == true && bundleManager.getBunleTotal() == bundleManager.bundleTotal) {
  370. return true;
  371. }
  372. return false;
  373. }
  374. update(dt) {
  375. if (this.bloadRes() && !this.isLoadRes) {
  376. this.node.$loading_lb.getComponent(cc.Label).string = 'loading completed';
  377. this.progressBar.progress = 1;
  378. this.scheduleOnce(() => {
  379. this.ui.progress.active = false;
  380. this.node.$loading_lb.active = false;
  381. this.ui.start_btn.active = true;
  382. }, 0.2)
  383. this.isLoadRes = true;
  384. this.addSprite();
  385. setTimeout(() => {
  386. AudioManager.play('bg', 1, true, 'BGM');
  387. }, 50);
  388. levelManager.preLoadLevel(AccountModel.getInstance().curLevel);
  389. }
  390. if (!this.bloadRes()) {
  391. this.node.$loading_lb.getComponent(cc.Label).string = 'loading......';
  392. if (this.progressBar.progress < 1) {
  393. this.progressBar.progress += dt * 0.5;
  394. }
  395. }
  396. }
  397. addSprite() {
  398. this.initRedWarn();
  399. }
  400. initRedWarn() {
  401. let redWarn = new cc.Node;
  402. redWarn.name = "redWarn";
  403. redWarn.setContentSize(cc.size(1800, 2000));
  404. redWarn.addComponent(cc.Sprite);
  405. bundleManager.setBundleFrame('UI', 'main/hjianbianBG', redWarn);
  406. redWarn.active = false;
  407. redWarn.parent = cc.director.getScene().getChildByName('Canvas');
  408. cc.tween(redWarn)
  409. .repeatForever(cc.tween().to(0.5, { opacity: 0 }).to(0.5, { opacity: 255 }))
  410. .start();
  411. }
  412. onClose() {
  413. UIHelp.CloseUI(UIMenu);
  414. }
  415. initAdInster() {
  416. let adKey = "zh_ad_type"
  417. cc.sys.localStorage.setItem(adKey, "");
  418. let deviceId = AAJS2.getDeviceUserId();
  419. var setting = {};
  420. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  421. var pid = AAJS2.getPlacementId2(AdType.Inter);
  422. let placementId = pid;
  423. setting[ATInterstitialSDK.UseRewardedVideoAsInterstitial] = false;
  424. //setting[ATInterstitialJSSDK.UseRewardedVideoAsInterstitial] = true;
  425. ATInterstitialSDK.loadInterstitial(pid, setting);
  426. //v5.6.8以下
  427. //ATInterstitialSDK.loadInterstitial(pid);
  428. let that = this;
  429. var interstitialListener = {
  430. //广告加载成功
  431. onInterstitialAdLoaded: function (placementId) {
  432. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdLoaded(" + placementId + ")");
  433. setTimeout(() => {
  434. that.initAdForPageInter();
  435. }, 500);
  436. },
  437. //广告加载失败
  438. onInterstitialAdLoadFail: function (placementId, errorInfo) {
  439. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdLoadFail(" + placementId + ", " + errorInfo + ")");
  440. setTimeout(() => {
  441. that.initAdForPageInter();
  442. }, 500);
  443. },
  444. //广告展示成功
  445. onInterstitialAdShow: function (placementId, callbackInfo) {
  446. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdShow(" + placementId + ", " + callbackInfo + ")");
  447. },
  448. //广告视频开始播放,部分平台有此回调
  449. onInterstitialAdStartPlayingVideo: function (placementId, callbackInfo) {
  450. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdStartPlayingVideo(" + placementId + ", " + callbackInfo + ")");
  451. },
  452. //广告视频播放结束,部分广告平台有此回调
  453. onInterstitialAdEndPlayingVideo: function (placementId, callbackInfo) {
  454. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdEndPlayingVideo(" + placementId + ", " + callbackInfo + ")");
  455. },
  456. //广告视频播放失败,部分广告平台有此回调
  457. onInterstitialAdFailedToPlayVideo: function (placementId, errorInfo) {
  458. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdFailedToPlayVideo(" + placementId + ", " + errorInfo + ")");
  459. },
  460. //广告展示失败
  461. onInterstitialAdFailedToShow: function (placementId) {
  462. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdFailedToShow(" + placementId + ")");
  463. },
  464. //广告被关闭
  465. onInterstitialAdClose: function (placementId, callbackInfo) {
  466. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdClose(" + placementId + ", " + callbackInfo + ")");
  467. //因为跨脚本,所以使用全局注册函数调用,后来发现切换APP,导致ad close事件失效
  468. // that.handleCustomEventForInter();
  469. },
  470. //广告被点击
  471. onInterstitialAdClick: function (placementId, callbackInfo) {
  472. ATSDK.printLog("AnyThinkInterstitialDemo::onInterstitialAdClick(" + placementId + ", " + callbackInfo + ")");
  473. }
  474. };
  475. ATInterstitialSDK.setAdListener(interstitialListener);//插屏广告
  476. }
  477. //add判断插屏 开屏等,需要多次准备
  478. initAdForPageInter() {
  479. if (cc.sys.os === cc.sys.OS_ANDROID) {
  480. console.log('zh:initAdForPageInter 开始准备AD .....');
  481. let deviceId = AAJS2.getDeviceUserId();
  482. var setting = {};
  483. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  484. //add判断插屏 开屏等
  485. let pid_inter = AAJS2.getPlacementId2(AdType.Inter);
  486. console.log("zh: pid_inter checkstatus:", ATInterstitialSDK.checkAdStatus(pid_inter));
  487. ATInterstitialSDK.loadInterstitial(pid_inter, setting);
  488. }
  489. }
  490. initAdPageForBanner() {
  491. //v5.6.8新增
  492. var setting = {};
  493. let deviceId = AAJS2.getDeviceUserId();
  494. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  495. setting[ATBannerJSSDK.kATBannerAdLoadingExtraBannerAdSizeStruct] = ATBannerJSSDK.createLoadAdSize(cc.view.getFrameSize().width, 200);
  496. //只针对Admob的自适应banner
  497. setting[ATBannerJSSDK.kATBannerAdAdaptiveWidth] = cc.view.getFrameSize().width;
  498. setting[ATBannerJSSDK.kATBannerAdAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdAdaptiveOrientationCurrent;
  499. // setting[ATBannerJSSDK.kATBannerAdAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdAdaptiveOrientationPortrait;
  500. // setting[ATBannerJSSDK.kATBannerAdAdaptiveOrientation] = ATBannerJSSDK.kATBannerAdAdaptiveOrientationLandscape;
  501. var pid = AAJS2.getPlacementId2(AdType.Banner);
  502. ATBannerJSSDK.loadBanner(pid, setting);
  503. var bannerListener = {
  504. //广告加载成功
  505. onBannerAdLoaded: function (placementId) {
  506. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdLoaded(" + placementId + ")");
  507. },
  508. //广告加载失败
  509. onBannerAdLoadFail: function (placementId, errorInfo) {
  510. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdLoadFail(" + placementId + ", " + errorInfo + ")");
  511. this.initAdPageForBanner();
  512. },
  513. //广告展示成功
  514. onBannerAdShow: function (placementId, callbackInfo) {
  515. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdShow(" + placementId + ", " + callbackInfo + ")");
  516. },
  517. //广告被点击
  518. onBannerAdClick: function (placementId, callbackInfo) {
  519. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdClick(" + placementId + ", " + callbackInfo + ")");
  520. },
  521. //广告自动刷新成功
  522. onBannerAdAutoRefresh: function (placementId, callbackInfo) {
  523. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdAutoRefresh(" + placementId + ", " + callbackInfo + ")");
  524. },
  525. //广告自动刷新失败
  526. onBannerAdAutoRefreshFail: function (placementId, errorInfo) {
  527. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdAutoRefreshFail(" + placementId + ", " + errorInfo + ")");
  528. },
  529. //广告关闭按钮被点击
  530. onBannerAdCloseButtonTapped: function (placementId, callbackInfo) {
  531. ATSDK.printLog("AnyThinkBannerDemo::onBannerAdCloseButtonTapped(" + placementId + ", " + callbackInfo + ")");
  532. this.initAdPageForBanner();
  533. }
  534. };
  535. ATBannerJSSDK.setAdListener(bannerListener);
  536. console.log("zh:initAdPageForBanner listener over ..... ");
  537. }
  538. /**
  539. * AD播放完毕的事件处理,插屏处理
  540. */
  541. handleCustomEventForInter() {
  542. let that = this;
  543. console.log('zh:00收到发送的事件handleCustomEventForInter')
  544. let mark = cc.sys.localStorage.getItem("adMarkForClose");
  545. console.log('zh:handleCustomEventForInter mark =' + mark)
  546. switch (mark) {
  547. case 'callBackForClickShop'://点击了超市
  548. console.log('zh:点击了超市')
  549. // 调用A页面的方法
  550. // GlobalManager.instance.callMethod('startGameForFailAD', 'value1', 'value2');
  551. // GlobalManager.getInstance().callMethod('callBackForClickShop');
  552. break;
  553. case 'xxxxxx2222'://开始游戏
  554. //发送事件。。。。todo: 重新开始游戏
  555. //this.node.emit('env_playAdEnd', 'Hello,你好');
  556. // 调用A页面的方法
  557. // GlobalManager.instance.callMethod('startGameForFailAD', 'value1', 'value2');
  558. // GlobalManager.instance.callMethod('startGameForFailAD');
  559. break;
  560. default:
  561. console.log('zh:未知的inster类型AD' + mark)
  562. }
  563. }
  564. }