FailPanel.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import { BaseView } from "../../../lightMVC/core/base/BaseView";
  2. import SDK from "../../sdk/SDK";
  3. import gameScene from "../../gameScene";
  4. import { App } from "../../Manager/App";
  5. import { SoundManager } from "../../Manager/SoundManager";
  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 FailPanel extends BaseView {
  17. passTime = 0;
  18. protected onLoad(): void {
  19. console.log('zh:fp.ts onload ');
  20. SDK.Instance.initAdForPage();
  21. }
  22. public drawView(): void {
  23. SDK.Instance.showInterstitial();
  24. this.onLoadAll();
  25. this.btnReplay()
  26. this.BackMain();
  27. this.btnVideo();
  28. }
  29. onLoadAll() {
  30. this.ui.getNode("labelCoin").getComponent(cc.Label).string = App.DataManager.UserCoin + "";
  31. this.ui.getNode("labelDiamond").getComponent(cc.Label).string = App.DataManager.UserDiamond + "";
  32. this.ui.getNode("labelAwardCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin + "";
  33. this.ui.getNode("labelVideoCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin * 3 + "";
  34. App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin;
  35. App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Coin, App.DataManager.UserCoin);
  36. }
  37. /**
  38. * 点击回到主页
  39. */
  40. public BackMain(): void {
  41. let backMainBtn = this.ui.getNode("main");
  42. backMainBtn.on(cc.Node.EventType.TOUCH_END, () => {
  43. gameScene.instance.ClickBackMain();
  44. }, this);
  45. }
  46. btnReplay() {
  47. console.log('zh:btnReplay')
  48. let backMainBtn = this.ui.getNode("restart");
  49. backMainBtn.on(cc.Node.EventType.TOUCH_END, () => {
  50. if (cc.sys.os == cc.sys.OS_ANDROID) {
  51. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  52. cc.sys.localStorage.setItem('yxAdMark', 'callBack_btnReplay');//看广告用于 xx 标记
  53. GlobalManager.instance.registerMethod('callBack_btnReplay', this.callBack_btnReplay.bind(this));
  54. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  55. } else {
  56. console.log('zh:AD 没有OK');
  57. this.callBack_btnReplay();
  58. SDK.Instance.initAdForPage();
  59. }
  60. } else {
  61. this.callBack_btnReplay();
  62. }
  63. // this.showInterAd("callBack_btnReplay", true, () => this.callBack_btnReplay());
  64. // gameScene.instance.LoadLevel();
  65. // this.closeView();
  66. }, this);
  67. }
  68. public callBack_btnReplay() {
  69. console.log('zh:callBack_btnReplay 被触发')
  70. gameScene.instance.LoadLevel();
  71. this.closeView();
  72. }
  73. /**
  74. * 点击游戏重新开始
  75. */
  76. public btnVideo(): void {
  77. console.log('zh:抽奖-观看视频~11');
  78. let btnVideo = this.ui.getNode("btnVideo");
  79. btnVideo.active = true;
  80. btnVideo.on(cc.Node.EventType.TOUCH_END, () => {
  81. console.log('zh:抽奖-观看视频~22');
  82. SoundManager.getInstance().VideoStartStop();
  83. if (cc.sys.os == cc.sys.OS_ANDROID) {
  84. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  85. cc.sys.localStorage.setItem('yxAdMark', 'callBack_for_chouJiang');//看广告用于 xx 标记
  86. GlobalManager.instance.registerMethod('callBack_for_chouJiang', this.callBack_for_chouJiang.bind(this));
  87. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  88. } else {
  89. console.log('zh:AD 没有OK');
  90. this.callBack_for_chouJiang();
  91. SDK.Instance.initAdForPage();
  92. }
  93. } else {
  94. this.callBack_for_chouJiang();
  95. }
  96. //zh:diy 下面是原始的代码
  97. // SDK.Instance.showRewardVideo(() => {
  98. // console.log('抽奖-观看视频~3');
  99. // this.callBack_for_chouJiang();
  100. // }, () => {
  101. // console.log('抽奖-观看视频~4');
  102. // SoundManager.getInstance().VideoEndOpen();
  103. // }, () => {
  104. // console.log('抽奖-观看视频~5');
  105. // SoundManager.getInstance().VideoEndOpen();
  106. // });
  107. }, this);
  108. }
  109. public callBack_for_chouJiang() {
  110. console.log('zh:抽奖被触发')
  111. if (this.ui.getNode("jiantou").angle >= 42) {
  112. App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 2;
  113. console.log('zh:userCoin1=' + App.DataManager.UserCoin);
  114. }
  115. else if (this.ui.getNode("jiantou").angle >= -34 && this.ui.getNode("jiantou").angle < 42) {
  116. App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 3;
  117. console.log('zh:userCoin2=' + App.DataManager.UserCoin);
  118. }
  119. else if (this.ui.getNode("jiantou").angle >= -69 && this.ui.getNode("jiantou").angle < -34) {
  120. App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 4;
  121. console.log('zh:userCoin3=' + App.DataManager.UserCoin);
  122. }
  123. else if (this.ui.getNode("jiantou").angle < -69) {
  124. App.DataManager.UserCoin += gameScene.instance.curLevelWinCoin * 5;
  125. console.log('zh:userCoin4=' + App.DataManager.UserCoin);
  126. }
  127. console.log('zh:userCoin5=' + App.DataManager.UserCoin);
  128. App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Coin, App.DataManager.UserCoin);
  129. let cout2 = App.DataManager.UserCoin;
  130. // App.Facade.popView(TipPanelMediator, TipPanel, "金币:"+cout2, false);
  131. SoundManager.getInstance().VideoEndOpen();
  132. gameScene.instance.replay();
  133. }
  134. public static path(): string {
  135. return "gameScene/prefabs/FailPanel";
  136. }
  137. update(dt) {
  138. this.passTime += dt;
  139. if (this.passTime > 0.1) {
  140. this.passTime -= 0.1;
  141. if (this.ui.getNode("jiantou").angle >= 42) {
  142. this.ui.getNode("labelVideoCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin * 2 + "";
  143. }
  144. else if (this.ui.getNode("jiantou").angle >= -34 && this.ui.getNode("jiantou").angle < 42) {
  145. this.ui.getNode("labelVideoCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin * 3 + "";
  146. }
  147. else if (this.ui.getNode("jiantou").angle >= -69 && this.ui.getNode("jiantou").angle < -34) {
  148. this.ui.getNode("labelVideoCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin * 4 + "";
  149. }
  150. else if (this.ui.getNode("jiantou").angle < -69) {
  151. this.ui.getNode("labelVideoCoin").getComponent(cc.Label).string = gameScene.instance.curLevelWinCoin * 5 + "";
  152. }
  153. }
  154. }
  155. /**
  156. * 显示插屏广告
  157. *
  158. * @param adMarkForClose 插屏广告关闭后调用那个方法的具体指示标识
  159. * @param checkClose 是否需要判断关闭事件,有的不需要,如果AD占用游戏时间则为true
  160. * @param callback 插屏广告关闭(加载失败\非ANDROID平台)的回调
  161. */
  162. private showInterAd(adMarkForClose: string, checkClose: boolean, callback: () => void) {
  163. if (cc.sys.os === cc.sys.OS_ANDROID) {
  164. if (checkClose) {
  165. cc.sys.localStorage.setItem("adMarkForClose", adMarkForClose);//关闭后,调用哪个方法的标识
  166. }
  167. //add判断插屏 开屏等
  168. let pid_inter = AAJS2.getPlacementId2(AdType.Inter);
  169. let boo = ATInterstitialSDK.hasAdReady(pid_inter);
  170. if (boo) {
  171. // 暂停游戏
  172. cc.director.pause();
  173. console.log('zh:showInterAd AD OK');
  174. ATInterstitialSDK.showAd(pid_inter);
  175. //因为跨脚本,所以使用全局注册函数调用,后来发现切换APP,导致ad close事件失效
  176. if (!checkClose) {//如果不占用游戏时间
  177. this.safeCallback(callback);
  178. }
  179. } else {
  180. console.log('zh:showInterAd AD 没有准备好');
  181. //GlobalManager.getInstance().callMethod('initAdForPageInter');
  182. //this.initAdForPageInter();
  183. this.safeCallback(callback);
  184. }
  185. } else {
  186. this.safeCallback(callback);
  187. }
  188. }
  189. // 辅助方法:安全调用回调函数
  190. private safeCallback(callback?: () => void) {
  191. if (callback) {
  192. callback();
  193. }
  194. }
  195. }