UIMenu.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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 AAJS2 from "../../../ATAndroidJS2";
  39. import GlobalManager from '../../../GlobalManager';
  40. const { ccclass, menu, property } = cc._decorator;
  41. @ccclass
  42. @menu("UI/Interface/UIMenu")
  43. export default class UIMenu extends UIBase implements AdDeveloperCallback {
  44. onRewardedVideoAdLoaded(placementId: any): void {
  45. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
  46. }
  47. onRewardedVideoAdFailed(placementId: any, errorInfo: any): void {
  48. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  49. }
  50. onRewardedVideoAdPlayStart(placementId: any, callbackInfo: any): void {
  51. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  52. let deviceId = AAJS2.getDeviceUserId();
  53. var setting = {};
  54. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  55. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  56. }
  57. onRewardedVideoAdPlayEnd(placementId: any, callbackInfo: any): void {
  58. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  59. console.log('zh: ad over 开始发送事件11')
  60. //this.node.emit("handleCustomEvent");
  61. this.handleCustomEvent()
  62. console.log('zh: ad over 开始发送事件OVER22')
  63. }
  64. onRewardedVideoAdPlayFailed(placementId: any, errorInfo: any, callbackInfo: any): void {
  65. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  66. }
  67. onRewardedVideoAdClosed(placementId: any, callbackInfo: any): void {
  68. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
  69. }
  70. onRewardedVideoAdPlayClicked(placementId: any, callbackInfo: any): void {
  71. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  72. }
  73. onReward(placementId: any, callbackInfo: any): void {
  74. ATSDK.printLog("zh:AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
  75. }
  76. /**
  77. * AD播放完毕的事件处理
  78. */
  79. handleCustomEvent() {
  80. console.log('zh:00收到发送的事件')
  81. let adKey = "zh_ad_type"
  82. let idx = cc.sys.localStorage.getItem(adKey);//0,1,2,3
  83. console.log('zh:onAdOverEve idx =' + idx)
  84. let adKeyTemp = '';//初始化一下,随便
  85. switch (idx) {
  86. case 'doGetForAdEvent':
  87. adKeyTemp = 'doGetForAdEvent_monthParams';
  88. let mpStr = cc.sys.localStorage.getItem(adKeyTemp);
  89. let mpJosn = JSON.parse(mpStr);
  90. console.log('zh:#############幸存者 奖励')
  91. GlobalManager.getInstance().callMethod('doGetForAdEvent', mpJosn.result, mpJosn.type);
  92. break;
  93. case 'doSearchForAdEvent':
  94. console.log('zh:#############商店搜集 奖励')
  95. GlobalManager.getInstance().callMethod('doSearchForAdEvent');
  96. break;
  97. case 'refreshInfoForAdEventKtsx':
  98. console.log('zh:#############呼叫空投-刷新物品 奖励')
  99. GlobalManager.getInstance().callMethod('refreshInfoForAdEventKtsx');
  100. break;
  101. case 'doGetForAdEventKt':
  102. console.log('zh:#############呼叫空投-获取物品 奖励')
  103. GlobalManager.getInstance().callMethod('doGetForAdEventKt');
  104. break;
  105. case 'doubleRewardForAdEventQd':
  106. console.log('zh:#############签到奖励 奖励')
  107. GlobalManager.getInstance().callMethod('doubleRewardForAdEventQd');
  108. break;
  109. default:
  110. console.log('zh:未知的道具类型AD' + idx)
  111. }
  112. cc.sys.localStorage.setItem(adKey, '');
  113. cc.sys.localStorage.setItem(adKeyTemp, '');
  114. console.log('zh:清理adKey ')
  115. }
  116. adKey: string = "zh_ad_type";
  117. ui: auto_menu = null;
  118. protected static prefabUrl = "Interface/menu";
  119. protected static className = "UIMenu";
  120. npcID: number;
  121. roleSpine: any;
  122. isLoadRes: boolean = false;
  123. bClick: boolean = true;
  124. progressBar: cc.ProgressBar;
  125. onUILoad() {
  126. this.ui = this.node.addComponent(auto_menu);
  127. this.isNewUser();
  128. this.progressBar = this.ui.progress.getComponent(cc.ProgressBar);
  129. zjSdk?.showMain({
  130. y: -50,
  131. });
  132. bundleManager.loadSimpleSubpk('level3', () => {
  133. bundleManager.loadSimpleSubpk('level4');
  134. });
  135. this.initAd();
  136. }
  137. initAd() {
  138. let adKey = "zh_ad_type"
  139. cc.sys.localStorage.setItem(adKey, "");
  140. let placementId = AAJS2.getPlacementId();
  141. let deviceId = AAJS2.getDeviceUserId();
  142. var setting = {};
  143. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  144. ATRewardedVideoSDK.loadRewardedVideo(placementId, setting);
  145. //console.log('zh:bbb222')
  146. var customPlacementId = "";
  147. if (cc.sys.os === cc.sys.OS_IOS) {
  148. customPlacementId = placementId;
  149. } else if (cc.sys.os === cc.sys.OS_ANDROID) {
  150. customPlacementId = placementId;
  151. }
  152. // 初始化SDK
  153. // ATSDK.initSDK("h6752c78a49dc1", "aad31bcaf7f7ff45ba21a8bc87bd9318a");//正式的,发布提交go0gle play
  154. ATSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");//测试专用,可以显示广告
  155. //ATSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是打砖块的已经上架的
  156. ATSDK.setLogDebug(true);//zh:diy
  157. var GDPRLevel = ATSDK.getGDPRLevel();
  158. // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  159. ATSDK.getUserLocation(function (userLocation) {
  160. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  161. if (userLocation === ATSDK.kATUserLocationInEU) {
  162. if (ATSDK.getGDPRLevel() === ATSDK.UNKNOWN) {
  163. ATSDK.showGDPRAuth();
  164. }
  165. }
  166. });
  167. ATRewardedVideoSDK.setAdListener(this);
  168. if (cc.sys.os === cc.sys.OS_ANDROID) {
  169. setTimeout(() => {
  170. var allInfo = AAJS2.allInfo();
  171. ATSDK.printLog("zh:allInfo=" + allInfo);
  172. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  173. let iv = "Jn0.aWsOu$y-Dbqb";
  174. let data = { data: AESUtil.AESencrypt(allInfo, key, iv) };
  175. ATSDK.printLog("zh:allInfo-jm=" + JSON.stringify(data));
  176. console.log('zh:ad_allInfo', data);
  177. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  178. }, 200);
  179. }
  180. }
  181. initAdForPage() {
  182. if (cc.sys.os === cc.sys.OS_ANDROID) {
  183. let deviceId = AAJS2.getDeviceUserId();
  184. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  185. var setting = {};
  186. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  187. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  188. }
  189. }
  190. isNewUser() {
  191. let playerDt = AccountModel.getInstance().playerDtList;
  192. if (playerDt.length > 0) {
  193. AccountModel.getInstance().is_new = 0;
  194. }
  195. if (AccountModel.getInstance().is_new == 1) {
  196. zjSdk?.sendEvent('主界面曝光-新')
  197. } else {
  198. zjSdk?.sendEvent('主界面曝光-旧')
  199. }
  200. }
  201. start_btn() {
  202. if (!this.bClick) { return };
  203. if (!this.bloadRes()) {
  204. UIHelp.ShowTips('资源加载中......')
  205. return;
  206. }
  207. this.bClick = false;
  208. zjSdk?.sendEvent('点击开始按钮');
  209. console.log('zh:1')
  210. zjSdk?.gameBegin(() => {
  211. console.log('zh:2')
  212. zjSdk?.hideMain();
  213. if (zjSdk?.hasOwnProperty('ZjGmData')) {
  214. if (zjSdk?.ZjGmData.instance.gameConfig.isShowInnerCrazyAward == '1') {
  215. GameEvent.isShowInnerCrazyAward = true;
  216. }
  217. if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('firstCrazyByZombieNum')) {
  218. GameEvent.firstCrazyByZombieNum = parseInt(zjSdk?.ZjGmData.instance.gameConfig.firstCrazyByZombieNum)
  219. }
  220. if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('crazyByZombieNumTimes')) {
  221. GameEvent.crazyByZombieNumTimes = parseInt(zjSdk?.ZjGmData.instance.gameConfig.crazyByZombieNumTimes)
  222. } if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('crazyAwardPopMaxTimes')) {
  223. GameEvent.crazyAwardPopMaxTimes = parseInt(zjSdk?.ZjGmData.instance.gameConfig.crazyAwardPopMaxTimes)
  224. }
  225. }
  226. console.log('zh:3')
  227. let curLevel = AccountModel.getInstance().curLevel;
  228. if (curLevel == 1 && AccountModel.getInstance().is_new == 1) {
  229. console.log('zh:4')
  230. this.onClose();
  231. gameEventManager.emit(EVENT_TYPE.playStoryAni, (node) => {
  232. console.log('zh:5')
  233. levelManager.open(curLevel, () => {
  234. cc.director.getScene().getChildByName('Canvas').getChildByName('maskNode').opacity = 0;
  235. UITopMenu.getInstance().node.active = true;
  236. this.tryShowUI();
  237. node.destroy();
  238. })
  239. });
  240. return;
  241. }
  242. console.log('zh:6')
  243. levelManager.open(curLevel, () => {
  244. console.log('zh:7')
  245. cc.director.getScene().getChildByName('Canvas').getChildByName('maskNode').opacity = 0;
  246. UITopMenu.getInstance().node.active = true;
  247. this.onClose();
  248. this.tryShowUI(false);
  249. console.log('zh:8')
  250. })
  251. })
  252. }
  253. tryShowUI(isNewBee = true) {
  254. //调用签到
  255. const callSign = () => {
  256. if (!SignUtil.canSign()) {
  257. return false;
  258. }
  259. const openSign = () => {
  260. if (SignUtil.canSign()) {
  261. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true);
  262. UIHelp.ShowUI(UISignView, null, isNewBee);
  263. }
  264. }
  265. uiRoot.getComponent(UIGameScene).scheduleOnce(async () => {
  266. if (UIMng.getInstance().UILock) {
  267. EventManager.once(EVENT_TYPE.unLockUI, () => {
  268. this.scheduleOnce(() => {
  269. if (SignUtil.canSign()) {
  270. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true);
  271. UIHelp.ShowUI(UISignView, null, isNewBee);
  272. }
  273. }, 1)
  274. })
  275. }
  276. openSign();
  277. }, isNewBee ? 30 : 0);
  278. return true;
  279. }
  280. //调用福利
  281. const callWelfare = (delay) => {
  282. const openWelfare = () => {
  283. if (isNewBee &&
  284. AccountModel.getInstance().curWelfare.length != 0) {
  285. return
  286. }
  287. gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true);
  288. UIHelp.ShowUI(UIWelfareView, null, isNewBee);
  289. }
  290. if (AccountModel.getInstance().curWelfare.length !== 4) {
  291. uiRoot.getComponent(UIGameScene).scheduleOnce(() => {
  292. if (UIMng.getInstance().UILock) {
  293. EventManager.once(EVENT_TYPE.unLockUI, () => {
  294. this.scheduleOnce(() => {
  295. openWelfare();
  296. }, 1)
  297. })
  298. return;
  299. }
  300. //新手点击过不要跳了
  301. openWelfare();
  302. }, delay);
  303. }
  304. };
  305. let uiRoot = cc.director.getScene().getChildByName('Canvas');
  306. const isShowSign = callSign();
  307. //新手
  308. if (isNewBee) {
  309. EventManager.once(EVENT_TYPE.closeSign, () => {
  310. callWelfare(30);
  311. })
  312. } else if (isShowSign) {
  313. EventManager.once(EVENT_TYPE.closeSign, () => {
  314. callWelfare(0);
  315. })
  316. } else {
  317. callWelfare(0);
  318. }
  319. }
  320. bloadRes() {
  321. if (bundleManager.localResIsload == true && bundleManager.getBunleTotal() == bundleManager.bundleTotal) {
  322. return true;
  323. }
  324. return false;
  325. }
  326. update(dt) {
  327. if (this.bloadRes() && !this.isLoadRes) {
  328. this.node.$loading_lb.getComponent(cc.Label).string = '加载完成';
  329. this.progressBar.progress = 1;
  330. this.scheduleOnce(() => {
  331. this.ui.progress.active = false;
  332. this.node.$loading_lb.active = false;
  333. this.ui.start_btn.active = true;
  334. }, 0.2)
  335. this.isLoadRes = true;
  336. this.addSprite();
  337. setTimeout(() => {
  338. AudioManager.play('bg', 1, true, 'BGM');
  339. }, 50);
  340. levelManager.preLoadLevel(AccountModel.getInstance().curLevel);
  341. }
  342. if (!this.bloadRes()) {
  343. this.node.$loading_lb.getComponent(cc.Label).string = '正在加载中......';
  344. if (this.progressBar.progress < 1) {
  345. this.progressBar.progress += dt * 0.5;
  346. }
  347. }
  348. }
  349. addSprite() {
  350. this.initRedWarn();
  351. }
  352. initRedWarn() {
  353. let redWarn = new cc.Node;
  354. redWarn.name = "redWarn";
  355. redWarn.setContentSize(cc.size(1800, 2000));
  356. redWarn.addComponent(cc.Sprite);
  357. bundleManager.setBundleFrame('UI', 'main/hjianbianBG', redWarn);
  358. redWarn.active = false;
  359. redWarn.parent = cc.director.getScene().getChildByName('Canvas');
  360. cc.tween(redWarn)
  361. .repeatForever(cc.tween().to(0.5, { opacity: 0 }).to(0.5, { opacity: 255 }))
  362. .start();
  363. }
  364. onClose() {
  365. UIHelp.CloseUI(UIMenu);
  366. }
  367. }