UIGamePage.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. import UIPage from "../Framework/UIPage";
  2. import Constant, { PageName, PanelName } from "../Framework/Constant";
  3. import { cocosz } from "../Framework/CocosZ";
  4. import PlatUtils from "../../common-plugin/Scripts/PlatUtils";
  5. import { utils } from "../../common-plugin/Scripts/Utils";
  6. import { BannerLocation } from "../../common-plugin/Scripts/YZ_Constant";
  7. import { gameMgr } from "../Game/gameMgr";
  8. import { guideLayer } from "./GuideLayer";
  9. import { start } from "repl";
  10. import AESUtil from "../AESUtil"
  11. import ATSDK from "../AnyThinkAds/ATJSSDK";
  12. import ATRewardedVideoSDK from "../AnyThinkAds/ATRewardedVideoJSSDK";
  13. import AAJS2 from "../ATAndroidJS2";
  14. import GlobalManager from '../GlobalManager';
  15. // @ts-ignore
  16. const i18n = require('LanguageData');
  17. const { ccclass, property } = cc._decorator;
  18. /**
  19. * 游戏页面
  20. */
  21. @ccclass
  22. export default class UIGamePage extends UIPage {
  23. private _handAni: cc.Node = null;
  24. private _btnCt: cc.Node = null;
  25. private _btnQpbz: cc.Node = null;
  26. constructor() {
  27. super(PageName.UIGamePage);
  28. this.isValid() && this.onLoad();
  29. }
  30. protected onLoad() {
  31. console.log('zh:UIGP.TS onLoad')
  32. this._handAni = cc.find("handAni", this._page);
  33. let btnList1 = ["rangedWeapon", "rangedWeaponAd", "BtnPause", "BtnBullet", "BtnShuxing", "BtnHideBanner", "BtnCt", "BtnQpbz"];
  34. btnList1.forEach(btnName => {
  35. let btn = this._page.getChildByName(btnName);
  36. if (btn) {
  37. btn.on(cc.Node.EventType.TOUCH_END, this._onBtnClickHandler, this);
  38. if (btn.name == "rangedWeaponAd") {
  39. if (cocosz.isADON && cocosz.getConfigByKey("isVideoAd_advanced_weapon") != "false") {
  40. btn.active = true;
  41. } else {
  42. btn.active = false;
  43. }
  44. } else if (btn.name == "BtnHideBanner") {
  45. if (cocosz.isShowAd && cocosz.isADON && cocosz.getConfigByKey("isVideoAd_hideBanner") == "true") {
  46. btn.active = true;
  47. } else {
  48. btn.active = false;
  49. }
  50. } else if (btn.name == "BtnCt") {
  51. this._btnCt = btn;
  52. if (cocosz.isShowAd && cocosz.isADON && !cocosz.dataMgr.guide_skill && cocosz.getConfigByKey("isVideoAd_Citie") != "false") {
  53. this._btnCt.active = true;
  54. // 隐藏图标
  55. if (this._btnCt.childrenCount) {
  56. this._btnCt.children.forEach((child) => { child.active = false });
  57. }
  58. } else {
  59. this._btnCt.active = false;
  60. let widget = this._btnCt.getComponent(cc.Widget);
  61. if (widget) { widget.enabled = false; }
  62. }
  63. } else if (btn.name == "BtnQpbz") {
  64. this._btnQpbz = btn;
  65. if (cocosz.isShowAd && cocosz.isADON && !cocosz.dataMgr.guide_skill && cocosz.getConfigByKey("isVideoAd_Qpbz") != "false") {
  66. this._btnQpbz.active = true;
  67. // 隐藏图标
  68. if (this._btnQpbz.childrenCount) {
  69. this._btnQpbz.children.forEach((child) => { child.active = false });
  70. }
  71. } else {
  72. this._btnQpbz.active = false;
  73. let widget = this._btnQpbz.getComponent(cc.Widget);
  74. if (widget) { widget.enabled = false; }
  75. }
  76. }
  77. }
  78. })
  79. }
  80. initAdForPage() {
  81. if (cc.sys.os === cc.sys.OS_ANDROID) {
  82. let deviceId = AAJS2.getDeviceUserId();
  83. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  84. var setting = {};
  85. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  86. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  87. }
  88. }
  89. protected onOpen() {
  90. utils.SendEvent("页面-游戏");
  91. //监听游戏事件
  92. // cc.game.on(Constant.E_GAME_LOGIC, this._onGameMessageHandler, this);
  93. gameMgr.uiGamePage = this._page;
  94. gameMgr.moveArea = cc.find("moveArea", this._page);
  95. gameMgr.yaogan = cc.find("move", this._page);
  96. let widge = gameMgr.yaogan.getComponent(cc.Widget);
  97. if (widge) {
  98. gameMgr.yaogan.getComponent(cc.Widget).updateAlignment();
  99. widge.enabled = false;
  100. }
  101. // gameMgr.btnSkill = cc.find("BtnSkill", this._page);
  102. // gameMgr.btnSkillAd = cc.find("BtnSkillAd", this._page);
  103. gameMgr.rangedWeaponMess = this._page.getChildByName("rangedWeapon");
  104. gameMgr.ammo = gameMgr.rangedWeaponMess.getChildByName("ammo").getComponent(cc.Label);
  105. gameMgr.rangedWeaponAdMess = this._page.getChildByName("rangedWeaponAd");
  106. gameMgr.ammoAd = gameMgr.rangedWeaponAdMess.getChildByName("ammo").getComponent(cc.Label);
  107. gameMgr.qlzc = this._page.getChildByName("qlzc");
  108. gameMgr.BtnBullet = this._page.getChildByName("BtnBullet");
  109. // 地下城
  110. if (cocosz.gameMode == 6) {
  111. // boss血条
  112. gameMgr.model6_bossBar = this._page.getChildByName("bossBar").getComponent(cc.ProgressBar);
  113. // 经验条
  114. gameMgr.model6_jingyanBar = this._page.getChildByName("jingyanBar").getComponent(cc.ProgressBar);
  115. // 技能条
  116. gameMgr.model6_skillScrollView = this._page.getChildByName("skillScrollView").getComponent(cc.ScrollView);
  117. gameMgr.model6_skillScrollView_content = cc.find("skillScrollView/view/content", this._page);
  118. gameMgr.model6_skillScrollView_item = this._page.getChildByName("item");
  119. // 头像
  120. let BtnShuxing = this._page.getChildByName("BtnShuxing");
  121. gameMgr.model6_touxiang = BtnShuxing.getChildByName("touxiang");
  122. let pre = cocosz.resMgr.getRes("head" + (cocosz.gameMgr.gameCtr.curUseSkinId + 1), cc.Prefab);
  123. if (pre) {
  124. let touxiang = cc.instantiate(pre);
  125. touxiang.setParent(gameMgr.model6_touxiang);
  126. touxiang.scale = 1;
  127. if (touxiang.children[0]) { touxiang.children[0].active = false; }
  128. }
  129. // 属性按钮
  130. gameMgr.model6_btnShuxing = this._page.getChildByName("BtnShuxing");
  131. if (gameMgr.model6_btnShuxing) gameMgr.model6_btnShuxing.active = true;
  132. gameMgr.model6_shuxing = BtnShuxing.getChildByName("shuxing");
  133. gameMgr.model6_shuxing.active = false;
  134. // 等级
  135. gameMgr.model6_levelLabel = this._page.getChildByName("levelLabel").getComponent(cc.Label);
  136. // 计时
  137. gameMgr.model6_timeLabel = this._page.getChildByName("timeLabel").getComponent(cc.Label);
  138. // boss提示
  139. gameMgr.model6_ts = this._page.getChildByName("ts");
  140. if (cocosz.dataMgr.guide_skill && (cocosz.getConfigByKey("isVideoAd_Qpbz") != "false" || cocosz.getConfigByKey("isVideoAd_Citie") != "false")) {
  141. let count: number = 0;
  142. let tw: cc.Tween = cc.tween(this._page)
  143. .delay(1)
  144. .call(() => {
  145. if (gameMgr.isGameStart && !cocosz.isPause) {
  146. count++;
  147. cc.log("count:", count)
  148. if (count == 5) {
  149. if (cocosz.getConfigByKey("isVideoAd_Qpbz") != "false") {
  150. this.showSkill(this._btnQpbz);
  151. }
  152. } else if (count == 8) {
  153. if (cocosz.getConfigByKey("isVideoAd_Citie") != "false") {
  154. this.showSkill(this._btnCt);
  155. }
  156. } else if (count > 8) {
  157. cocosz.dataMgr.guide_skill = false;
  158. tw && tw.stop();
  159. }
  160. }
  161. })
  162. .union()
  163. .repeatForever()
  164. .start();
  165. }
  166. }
  167. gameMgr.startGame();
  168. this.showAd();
  169. cc.game.on(Constant.E_GAME_LOGIC, this._onGameMessageHandler, this);
  170. }
  171. protected onClose() {
  172. cc.game.targetOff(this);
  173. utils.adManager.hideBlockAd();
  174. utils.adManager.hideNativeTryGameWidget();
  175. utils.hideVivoGamePortalWidget();
  176. utils.adManager.HideSingleNativeAd();
  177. if (PlatUtils.IsWechat) {
  178. utils.adManager.hideCustomAd({ location: 3 });
  179. utils.adManager.hideCustomAd({ location: 4 });
  180. utils.adManager.hideCustomAd({ location: 8 });
  181. } else if (PlatUtils.IsVIVO) {
  182. utils.adManager.hideCustomAd({ location: BannerLocation.Game });
  183. }
  184. }
  185. protected showAd() {
  186. // 录屏
  187. utils.showRecordWidget({ group: "default", scale: 1, top: 50, left: 100, parent: this._page });
  188. if (cocosz.isShowAd) {
  189. // banner
  190. if (!cocosz.isShowGameBanner || PlatUtils.IsWechat || PlatUtils.IsDouyin || PlatUtils.IsAndroidDouYin) {
  191. utils.adManager.HideBanner(BannerLocation.Game);
  192. } else {
  193. utils.adManager.ShowBanner(BannerLocation.Game, { width: 0.1, bottom: 0 });
  194. }
  195. utils.adManager.showNativeTryGameWidget({ left: 10, top: 500, scale: 1, parent: this._page });
  196. // 原生广告
  197. if (PlatUtils.IsWechat) {
  198. utils.adManager.showCustomAd({ location: 3 });
  199. utils.adManager.showCustomAd({ location: 4 });
  200. utils.adManager.showCustomAd({ location: 8 });
  201. } else if (PlatUtils.IsVIVO) {
  202. utils.adManager.showCustomAd({ location: BannerLocation.Game });
  203. }
  204. }
  205. }
  206. showSkill(n: cc.Node) {
  207. let widget = n.getComponent(cc.Widget);
  208. if (widget) widget.enabled = false;
  209. if (n && n.isValid) {
  210. cocosz.pauseCount++;
  211. n.setPosition(0, cc.winSize.height / 2);
  212. n.scale = 2;
  213. n.active = true;
  214. let call = () => {
  215. n.stopAllActions();
  216. cc.tween(n)
  217. .call(() => {
  218. if (this._handAni && this._handAni.isValid) {
  219. this._handAni.active = false;
  220. }
  221. })
  222. .to(0.5, { scale: 1, x: - cc.winSize.width / 2 + widget.left + n.width / 2, y: - cc.winSize.height / 2 + widget.bottom + n.height / 2 })
  223. .call(() => {
  224. if (widget) widget.enabled = true;
  225. cocosz.pauseCount--;
  226. })
  227. .start();
  228. }
  229. n.once(cc.Node.EventType.TOUCH_END, call, this);
  230. n.stopAllActions();
  231. cc.tween(n)
  232. .to(1, { y: 0 }, { easing: "backOut" })
  233. .call(() => {
  234. if (this._handAni && this._handAni.isValid) {
  235. this._handAni.setPosition(0, 0);
  236. this._handAni.active = true;
  237. let spAni = this._handAni.getComponent(sp.Skeleton);
  238. if (spAni) spAni.setAnimation(0, "animation", true);
  239. }
  240. })
  241. .delay(4)
  242. .call(() => {
  243. n.off(cc.Node.EventType.TOUCH_END, call, this)
  244. call();
  245. })
  246. .start();
  247. }
  248. }
  249. // 全屏轰炸动画
  250. effect_qpbz() {
  251. let pre = cocosz.resMgr.getRes("effect_qpbz", cc.Prefab);
  252. if (pre) {
  253. let node: cc.Node = cc.instantiate(pre);
  254. node.setPosition(gameMgr.playerTs.node.position);
  255. cc.director.getScene().getChildByName("Canvas").addChild(node);
  256. cc.tween(node)
  257. .delay(0.3)
  258. .call(() => {
  259. gameMgr.playEffect("QuanPingBaoZha");
  260. cc.game.emit(Constant.E_GAME_LOGIC, { type: Constant.E_Allzombie_Destory });
  261. })
  262. .union()
  263. .repeat(4)
  264. .call(() => { node.destroy(); })
  265. .start();
  266. }
  267. }
  268. private _onGameMessageHandler(event: any) {
  269. switch (event.type) { }
  270. }
  271. private async _onBtnClickHandler(event: cc.Event.EventTouch) {
  272. cocosz.audioMgr.playBtnEffect();
  273. switch (event.target.name) {
  274. case "rangedWeaponAd": {
  275. if (gameMgr.rangedWeaponAdMess) {
  276. let adIcon = gameMgr.rangedWeaponAdMess.getChildByName("adIcon");
  277. if (adIcon && adIcon.active) {
  278. utils.SendEvent("视频-高级武器-播放")
  279. cocosz.watchAD(() => {
  280. utils.SendEvent("视频-高级武器-成功")
  281. adIcon.active = false;
  282. gameMgr.useRangedWeaponAd();
  283. gameMgr.rangedWeaponAdMess.stopAllActions();
  284. }, () => {
  285. utils.SendEvent("视频-高级武器-失败")
  286. });
  287. } else {
  288. gameMgr.useRangedWeaponAd();
  289. }
  290. }
  291. break;
  292. }
  293. case "rangedWeapon": {
  294. gameMgr.useRangedWeapon();
  295. break;
  296. }
  297. case "BtnPause": {
  298. cocosz.uiMgr.openPanel(PanelName.UIPausePanel);
  299. break;
  300. }
  301. case "BtnBullet": {
  302. if (gameMgr.BtnBullet && gameMgr.playerTs && gameMgr.playerTs.curWeapon && gameMgr.playerTs.curWeapon.isRangeWeapon)
  303. gameMgr.playerTs.curWeapon.reloadBullet();
  304. break;
  305. }
  306. case "BtnShuxing": {
  307. gameMgr.model6_shuxing.active = !gameMgr.model6_shuxing.active;
  308. gameMgr.update_model6_shuxing();
  309. break;
  310. }
  311. case "BtnHideBanner": {
  312. utils.SendEvent("视频-游戏中去广告-播放")
  313. cocosz.watchAD(() => {
  314. utils.SendEvent("视频-游戏中去广告-成功")
  315. event.target.active = false;
  316. gameMgr.canSHowGameBanner = false;
  317. utils.adManager.HideBanner(BannerLocation.Game);
  318. }, () => {
  319. utils.SendEvent("视频-游戏中去广告-失败")
  320. });
  321. break;
  322. }
  323. case "BtnCt": {
  324. if (this._btnCt && this._btnCt.getChildByName("share") && this._btnCt.getChildByName("share").active) {
  325. utils.SendEvent("分享-磁铁")
  326. cocosz.share(() => {
  327. utils.SendEvent("分享-磁铁-成功")
  328. // 磁铁事件
  329. cc.game.emit(Constant.E_Skill_Citie);
  330. }, () => {
  331. utils.SendEvent("分享-磁铁-失败")
  332. });
  333. } else if (this._btnCt && this._btnCt.getChildByName("video") && this._btnCt.getChildByName("video").active) {
  334. utils.SendEvent("视频-磁铁-播放")
  335. cocosz.watchAD(() => {
  336. utils.SendEvent("视频-磁铁-成功")
  337. // 磁铁事件
  338. cc.game.emit(Constant.E_Skill_Citie);
  339. }, () => {
  340. utils.SendEvent("视频-磁铁-失败")
  341. });
  342. } else {
  343. // 磁铁事件
  344. cc.game.emit(Constant.E_Skill_Citie);
  345. }
  346. break;
  347. }
  348. case "BtnQpbz": {
  349. if (this._btnQpbz && this._btnQpbz.getChildByName("share") && this._btnQpbz.getChildByName("share").active) {
  350. utils.SendEvent("分享-全屏轰炸")
  351. cocosz.share(() => {
  352. utils.SendEvent("分享-全屏轰炸-成功")
  353. // 全屏轰炸动画
  354. this.effect_qpbz();
  355. }, () => {
  356. utils.SendEvent("分享-全屏轰炸-失败")
  357. });
  358. } else if (this._btnQpbz && this._btnQpbz.getChildByName("video") && this._btnQpbz.getChildByName("video").active) {
  359. // 注册方法 , this.ClickClose.bind(this));
  360. // GlobalManager.getInstance().registerMethod('event_duoBeiJieSuan', this.event_duoBeiJieSuan.bind(this));
  361. //cc.sys.localStorage.setItem(adKey, 'duoBeiJieSuan');//1==消除道具
  362. // if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  363. // console.log('zh:AD ready for idx2')
  364. // ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  365. // } else {
  366. // console.log('zh:AD not ready for idx2')
  367. // this.event_quanPinHongZha();
  368. // }
  369. // if (2 > 1) {
  370. // return;
  371. // }
  372. //下面是原先的
  373. utils.SendEvent("视频-全屏轰炸-播放11")
  374. cocosz.watchAD(() => {
  375. utils.SendEvent("视频-全屏轰炸-成功11")
  376. 0 // 全屏轰炸动画
  377. this.effect_qpbz();
  378. }, () => {
  379. utils.SendEvent("视频-全屏轰炸-失败22")
  380. });
  381. } else {
  382. // 全屏轰炸动画
  383. this.effect_qpbz();
  384. }
  385. break;
  386. }
  387. }
  388. }
  389. public event_quanPinHongZha() {
  390. // 全屏轰炸动画
  391. this.effect_qpbz();
  392. }
  393. }