6cb5a116-271e-445b-babc-c7b028c1b6d6.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. "use strict";
  2. cc._RF.push(module, '6cb5aEWJx5EW7q8x7AowbbW', 'AdAgentQQ');
  3. // common-plugin/Scripts/AdAgentQQ.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var AdAgent_1 = require("./AdAgent");
  26. var YZ_Constant_1 = require("./YZ_Constant");
  27. var PlatUtils_1 = require("./PlatUtils");
  28. var Utils_1 = require("./Utils");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. var AdAgentQQ = /** @class */ (function (_super) {
  31. __extends(AdAgentQQ, _super);
  32. function AdAgentQQ() {
  33. var _this = _super !== null && _super.apply(this, arguments) || this;
  34. _this._sysData = null;
  35. _this._curBannerAd = null;
  36. _this._videoAd = null;
  37. _this._insertAd = null;
  38. _this._oldAd = null;
  39. _this._appBox = null; //游戏盒子广告
  40. _this._videoCallback = null;
  41. _this._isVideoLoaded = false;
  42. _this._isVideoShow = false;
  43. //@ts-ignore
  44. _this.qq = window.qq;
  45. _this._bannerShow = false;
  46. _this._bannerSizePercent = 0.5;
  47. _this._bannerBottom = 0;
  48. _this._oldBannerLocation = YZ_Constant_1.BannerLocation.None;
  49. _this._curBannerHeight = 240;
  50. _this._moveBtn = null;
  51. _this._cur_level = null;
  52. _this._showBannerTimerId = 0;
  53. _this._isShow = false;
  54. _this._blockAd = null;
  55. return _this;
  56. }
  57. AdAgentQQ.prototype.Init = function () {
  58. var _this = this;
  59. if (PlatUtils_1.default.IsQQ) {
  60. Utils_1.utils.registerServerInitEvent(function () {
  61. _this._sysData = Utils_1.utils.Tool_QQ.getSystemInfo();
  62. _this._initVideoAd();
  63. }, this);
  64. }
  65. };
  66. Object.defineProperty(AdAgentQQ.prototype, "ServerConfig", {
  67. get: function () {
  68. return Utils_1.utils.Tool_QQ.ServerConfig;
  69. },
  70. enumerable: false,
  71. configurable: true
  72. });
  73. // /**
  74. // * 初始化游戏盒子
  75. // */
  76. // _initAppBox() {
  77. // let checkVersion: boolean = utils.Tool_QQ.isOverMinVersion("1.7.1");
  78. // if (checkVersion) {
  79. // this._appBox = qq.createAppBox({
  80. // adUnitId: utils.config.qqconfig.appBoxId
  81. // });
  82. // this._appBox.load().then(() => {
  83. // utils.showLog("游戏盒子加载成功!")
  84. // }).catch(() => {
  85. // utils.showLog("游戏盒子加载失败!");
  86. // });
  87. // } else {
  88. // cc.warn("当前基础库版本低于1.7.1,不显示盒子广告");
  89. // }
  90. // }
  91. AdAgentQQ.prototype._initVideoAd = function () {
  92. var _this = this;
  93. if (!this._videoAd) {
  94. Utils_1.utils.showLog("初始化视频!");
  95. if (!Utils_1.utils.config.qqconfig.videoId) {
  96. Utils_1.utils.showLog("视频ID配置错误!");
  97. if (this._videoCallback) {
  98. this._videoCallback(false, "暂无视频广告!");
  99. this._videoCallback = null;
  100. }
  101. return;
  102. }
  103. // if (!utils.Tool_QQ.isOverMinVersion("0.1.26")) {
  104. // utils.showLog("当前版本不支持视频广告!");
  105. // if (this._videoCallback) {
  106. // this._videoCallback(false, "暂无视频广告!");
  107. // this._videoCallback = null;
  108. // }
  109. // return;
  110. // }
  111. Utils_1.utils.showLog("视频广告ID:", Utils_1.utils.config.qqconfig.videoId.trim());
  112. this._videoAd = this.qq.createRewardedVideoAd({
  113. adUnitId: Utils_1.utils.config.qqconfig.videoId
  114. });
  115. if (this._videoAd) {
  116. Utils_1.utils.showLog("初始化注册视频回调!");
  117. this._videoAd.onLoad(function () {
  118. Utils_1.utils.showLog("激励视频加载成功");
  119. _this._isVideoLoaded = true;
  120. if (_this._isVideoShow) {
  121. _this._videoAd.show().then(function () {
  122. }).catch(function () {
  123. Utils_1.utils.showLog("视频播放失败!");
  124. if (_this._videoCallback) {
  125. _this._videoCallback("暂无视频广告!");
  126. _this._videoCallback = null;
  127. }
  128. });
  129. }
  130. });
  131. this._videoAd.onError(function (err) {
  132. Utils_1.utils.showLog("激励视频加载失败!", err.code, err.msg);
  133. _this._isVideoLoaded = false;
  134. if (_this._videoCallback) {
  135. _this._videoCallback(false, "暂无视频广告!");
  136. _this._videoCallback = null;
  137. }
  138. });
  139. this._videoAd.onClose(function (res) {
  140. _this._isVideoShow = false;
  141. if (res && res.isEnded || res === undefined) {
  142. // 正常播放结束,可以下发游戏奖励
  143. Utils_1.utils.showLog('激励视频广告完成,发放奖励');
  144. if (_this._videoCallback) {
  145. _this._videoCallback(true, "");
  146. _this._videoCallback = null;
  147. }
  148. }
  149. else {
  150. // 播放中途退出,不下发游戏奖励
  151. Utils_1.utils.showLog('激励视频广告取消关闭,不发放奖励');
  152. if (_this._videoCallback) {
  153. _this._videoCallback(false, "观看完视频才能获得奖励!");
  154. _this._videoCallback = null;
  155. }
  156. }
  157. });
  158. }
  159. else {
  160. Utils_1.utils.showLog("激励视频初始化失败!");
  161. if (this._videoCallback) {
  162. this._videoCallback(false, "暂无视频广告!");
  163. this._videoCallback = null;
  164. }
  165. }
  166. }
  167. };
  168. AdAgentQQ.prototype._createBanner = function (location, args) {
  169. var _this = this;
  170. if (args === void 0) { args = null; }
  171. if (PlatUtils_1.default.IsQQ) {
  172. if (!Utils_1.utils.config.qqconfig.bannerId) {
  173. Utils_1.utils.showLog("banner广告ID不存在");
  174. return;
  175. }
  176. var argsTmp = args;
  177. this._bannerShow = false;
  178. if (argsTmp && argsTmp.width) {
  179. this._bannerSizePercent = argsTmp.width < 0 ? 0 : argsTmp.width;
  180. this._bannerSizePercent = argsTmp.width > 1 ? 1 : this._bannerSizePercent;
  181. }
  182. if (argsTmp && argsTmp.bottom) {
  183. this._bannerBottom = argsTmp.bottom / this._sysData.pixelRatio;
  184. this._bannerBottom = this._bannerBottom < 0 ? 0 : this._bannerBottom;
  185. this._bannerBottom = this._bannerBottom > this._sysData.screenHeight ? this._sysData.screenHeight : this._bannerBottom;
  186. }
  187. // IOS平台不支持onResize更改尺寸,所以这里宽度固定最小值
  188. // let width = this._sysData.screenWidth * this._bannerSizePercent;
  189. var width = 300;
  190. var height = 72;
  191. var left = (this._sysData.screenWidth - width) / 2;
  192. var top = this._sysData.screenHeight - height - this._bannerBottom;
  193. var params = {
  194. adUnitId: Utils_1.utils.config.qqconfig.bannerId,
  195. style: {
  196. left: left,
  197. width: width,
  198. top: top,
  199. height: height,
  200. }
  201. };
  202. var bannerAd_1 = null;
  203. var oldBannerAd_1 = this._curBannerAd;
  204. bannerAd_1 = this.qq.createBannerAd(params);
  205. Utils_1.utils.showLog("bannerAd ", bannerAd_1);
  206. if (bannerAd_1) {
  207. bannerAd_1.onError(function (err) {
  208. Utils_1.utils.showLog("广告条加载失败! ", JSON.stringify(err));
  209. _this._bannerShow = false;
  210. // if (location == BannerLocation.Game && this.ServerConfig.banner_first_ad && this.ServerConfig.banner_first_ad == "1") {
  211. // utils.showLog("服务器配置banner广告优先级为默认banner,游戏页面备用显示积木广告!");
  212. // this.showBlockAd({ bottom: 0 });
  213. // }
  214. });
  215. bannerAd_1.onLoad(function () {
  216. if (_this._bannerShow) {
  217. return;
  218. }
  219. _this._bannerShow = true;
  220. try {
  221. bannerAd_1.show().then(function () {
  222. Utils_1.utils.showLog("Banner广告显示成功!");
  223. if (_this.ServerConfig.banner_move_btn_interval && _this._cur_level && _this._cur_level % _this.ServerConfig.banner_move_btn_interval == 0) {
  224. _this.moveBtnToBannerTop();
  225. }
  226. if (oldBannerAd_1) {
  227. oldBannerAd_1.destroy();
  228. }
  229. _this._curBannerAd = bannerAd_1;
  230. }).catch(function (err) {
  231. Utils_1.utils.showLog("Banner广告出错", JSON.stringify(err));
  232. _this._bannerShow = false;
  233. });
  234. }
  235. catch (error) {
  236. if (_this.ServerConfig.banner_move_btn_interval && _this._cur_level && _this._cur_level % _this.ServerConfig.banner_move_btn_interval == 0) {
  237. _this.moveBtnToBannerTop();
  238. }
  239. Utils_1.utils.showLog("Banner ad Show erro", error);
  240. }
  241. });
  242. bannerAd_1.onResize(function (res) {
  243. if (res) {
  244. _this._curBannerHeight = res.height * _this._sysData.pixelRatio;
  245. }
  246. });
  247. }
  248. }
  249. };
  250. AdAgentQQ.prototype._showBannerTimer = function (location, args) {
  251. var _this = this;
  252. var locationTmp = location;
  253. var argsTmp = args;
  254. Utils_1.utils.showLog("\u663E\u793ABanner\u5E7F\u544Axxx\uFF01location:" + locationTmp + "; \u95F4\u9694\u65F6\u95F4:" + Utils_1.utils.Tool_QQ.ServerConfig.refresh_ad_time + ":\u4F18\u5148\u7EA7\uFF1A" + this.ServerConfig.banner_first_ad);
  255. // if (this.ServerConfig.banner_first_ad) {
  256. // switch (this.ServerConfig.banner_first_ad) {
  257. // case "default":
  258. // this._createBanner(locationTmp, argsTmp);
  259. // break;
  260. // case "box":
  261. // if (!utils.Tool_QQ.isOverMinVersion("1.15.0")) {
  262. // utils.showLog("当前版本不支持积木广告,显示默认banner");
  263. // this._createBanner(locationTmp, argsTmp);
  264. // return;
  265. // }
  266. // this.showBlockAd();
  267. // break;
  268. // // case "3":
  269. // // this._createBanner(locationTmp, argsTmp);
  270. // // this.showBlockAd();
  271. // // break;
  272. // }
  273. // } else {
  274. var banner_delay_time = this.ServerConfig.banner_delay_time ? this.ServerConfig.banner_delay_time : 0;
  275. Utils_1.utils.showLog("\u5EF6\u8FDF" + banner_delay_time + "\u79D2\u663E\u793Abanner");
  276. if (!this.ServerConfig.banner_move_btn_interval || !this._cur_level || this._cur_level % this.ServerConfig.banner_move_btn_interval != 0) {
  277. Utils_1.utils.showLog("当前关卡不做延迟移动!");
  278. this.moveBtnToBannerTop();
  279. }
  280. this._showBannerTimerId = setTimeout(function () {
  281. _this._createBanner(locationTmp, argsTmp);
  282. }, banner_delay_time * 1000);
  283. // }
  284. };
  285. AdAgentQQ.prototype.ShowBanner = function (location, args) {
  286. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  287. if (args === void 0) { args = null; }
  288. if (PlatUtils_1.default.IsQQ) {
  289. if (Utils_1.utils.Tool_QQ.ServerConfig) {
  290. var locationTmp = location;
  291. var argsTmp = args;
  292. this._moveBtn = args ? args.moveBtn : null;
  293. this._cur_level = args ? args.cur_level : null;
  294. this._showBannerTimer(locationTmp, argsTmp);
  295. }
  296. else {
  297. Utils_1.utils.showLog("服务器配置数据未初始化!");
  298. }
  299. }
  300. };
  301. AdAgentQQ.prototype.HideBanner = function (location) {
  302. if (location === void 0) { location = YZ_Constant_1.BannerLocation.Home; }
  303. if (PlatUtils_1.default.IsQQ) {
  304. Utils_1.utils.showLog("隐藏广告条");
  305. this._bannerShow = false;
  306. clearInterval(this._showBannerTimerId);
  307. if (this._curBannerAd) {
  308. this._curBannerAd.hide();
  309. }
  310. }
  311. };
  312. AdAgentQQ.prototype.ShowVideo = function (callback) {
  313. var _this = this;
  314. if (PlatUtils_1.default.IsQQ) {
  315. this._videoCallback = callback;
  316. this._isVideoShow = true;
  317. if (!this._videoAd) {
  318. this._initVideoAd();
  319. }
  320. else {
  321. this._videoAd.show().then(function () {
  322. Utils_1.utils.showLog("视频显示成功!");
  323. }).catch(function (err) {
  324. Utils_1.utils.showLog("视频未加载!");
  325. _this._videoAd.load();
  326. });
  327. }
  328. }
  329. };
  330. /**
  331. * 显示插屏
  332. * 2001 触发频率限制 小程序启动一定时间内不允许展示插屏广告
  333. * 2002 触发频率限制 距离小程序插屏广告或者激励视频广告上次播放时间间隔不足,不允许展示插屏广告
  334. * 2003 触发频率限制 当前正在播放激励视频广告或者插屏广告,不允许再次展示插屏广告
  335. * 2004 广告渲染失败 该项错误不是开发者的异常情况,或因小程序页面切换导致广告渲染失败
  336. * 2005 广告调用异常 插屏广告实例不允许跨页面调用
  337. * 销毁插屏广告后才能重新创建
  338. * @param location
  339. */
  340. AdAgentQQ.prototype.ShowInterstitial = function (location) {
  341. if (location === void 0) { location = null; }
  342. if (PlatUtils_1.default.IsQQ) {
  343. if (!Utils_1.utils.Tool_QQ.isOverMinVersion("1.12.0")) {
  344. Utils_1.utils.showLog("当前版本" + Utils_1.utils.Tool_QQ._sysInfo.SDKVersion + "不支持插屏广告和盒子广告!");
  345. return;
  346. }
  347. if (this.ServerConfig) {
  348. if (this.ServerConfig.intersititial_first_ad) {
  349. Utils_1.utils.showLog("\u670D\u52A1\u5668\u63D2\u5C4F\u4F18\u5148\u7EA7>>>" + this.ServerConfig.intersititial_first_ad);
  350. switch (this.ServerConfig.intersititial_first_ad) {
  351. case "default":
  352. Utils_1.utils.delayCall(this._createInsterstitial.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  353. break;
  354. case "box":
  355. if (!Utils_1.utils.Tool_QQ.isOverMinVersion("1.7.1")) {
  356. Utils_1.utils.showLog("当前版本" + Utils_1.utils.Tool_QQ._sysInfo.SDKVersion + "不支持盒子广告,显示插屏");
  357. Utils_1.utils.delayCall(this._createInsterstitial.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  358. return;
  359. }
  360. Utils_1.utils.delayCall(this.ShowAppBox.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  361. break;
  362. case "onlydefault":
  363. Utils_1.utils.delayCall(this._createInsterstitial.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  364. break;
  365. }
  366. }
  367. else {
  368. Utils_1.utils.showLog("服务器未配置优先级,显示默认插屏");
  369. Utils_1.utils.delayCall(this._createInsterstitial.bind(this), this.ServerConfig.intersititia_delay_show_time || 0);
  370. }
  371. }
  372. }
  373. };
  374. AdAgentQQ.prototype._createInsterstitial = function () {
  375. var _this = this;
  376. Utils_1.utils.showLog("_createInsterstitial >>> 222");
  377. // if (this._insertAd) {
  378. // this._insertAd.destroy();
  379. // }
  380. // let insertId;
  381. if (!this._insertAd) {
  382. this._insertAd = this.qq.createInterstitialAd({ adUnitId: Utils_1.utils.config.qqconfig.insertId });
  383. this._insertAd.onError(function (err) {
  384. switch (err.errCode) {
  385. case 2001:
  386. Utils_1.utils.showLog("小程序启动一定时间内不允许展示插屏广告");
  387. break;
  388. case 2002:
  389. Utils_1.utils.showLog("距离小程序插屏广告或者激励视频广告上次播放时间间隔不足,不允许展示插屏广告");
  390. break;
  391. case 2003:
  392. Utils_1.utils.showLog("当前正在播放激励视频广告或者插屏广告,不允许再次展示插屏广告");
  393. break;
  394. case 2004:
  395. Utils_1.utils.showLog("该项错误不是开发者的异常情况,或因小程序页面切换导致广告渲染失败");
  396. break;
  397. case 2005:
  398. Utils_1.utils.showLog("插屏广告实例不允许跨页面调用");
  399. break;
  400. default:
  401. Utils_1.utils.showLog("插屏加载失败! ", JSON.stringify(err));
  402. break;
  403. }
  404. if (_this.ServerConfig.intersititial_first_ad && _this.ServerConfig.intersititial_first_ad == "default") {
  405. Utils_1.utils.showLog("优先显示的是插屏广告,备用显示盒子广告!");
  406. var show_level = _this.ServerConfig.insert_show_appBox_level ? _this.ServerConfig.insert_show_appBox_level : 0;
  407. if (Utils_1.utils.currentLevel > show_level) {
  408. _this.ShowAppBox();
  409. }
  410. else {
  411. Utils_1.utils.showLog("备用显示盒子广告未达到关卡限制要求");
  412. }
  413. }
  414. });
  415. // this._insertAd.onLoad(() => {
  416. // utils.showLog("插屏加载成功! ");
  417. // })
  418. this._insertAd.onClose(function () {
  419. Utils_1.utils.showLog("插屏广告关闭成功!");
  420. });
  421. }
  422. if (this._insertAd) {
  423. this._insertAd.load().then(function () {
  424. Utils_1.utils.showLog("插屏加载成功! ");
  425. _this._insertAd.show().then(function () {
  426. Utils_1.utils.showLog("插屏广告显示成功!");
  427. }).catch(function (err) {
  428. Utils_1.utils.showLog("插屏广告出错", JSON.stringify(err));
  429. });
  430. }).catch(function () {
  431. Utils_1.utils.showLog("插屏加载失败! ");
  432. });
  433. if (!this._isShow) {
  434. this._insertAd.show().then(function () {
  435. Utils_1.utils.showLog("插屏广告显示成功!");
  436. }).catch(function (err) {
  437. Utils_1.utils.showLog("插屏广告出错", JSON.stringify(err));
  438. });
  439. this._isShow = true;
  440. }
  441. }
  442. };
  443. /**
  444. * 显示游戏盒子
  445. */
  446. AdAgentQQ.prototype.ShowAppBox = function (isMoreGame) {
  447. var _this = this;
  448. if (PlatUtils_1.default.IsQQ) {
  449. if (!Utils_1.utils.Tool_QQ.isOverMinVersion("1.7.1")) {
  450. Utils_1.utils.showLog("当前版本" + Utils_1.utils.Tool_QQ._sysInfo.SDKVersion + "不支持游戏盒子!");
  451. return;
  452. }
  453. Utils_1.utils.showLog(">>>>>ShowAppBox");
  454. if (this._appBox) {
  455. this._appBox.destroy().then(function () {
  456. Utils_1.utils.showLog("游戏盒子id为:", Utils_1.utils.config.qqconfig.boxId);
  457. _this._appBox = _this.qq.createAppBox({
  458. adUnitId: Utils_1.utils.config.qqconfig.boxId
  459. });
  460. _this._appBox.load().then(function () {
  461. Utils_1.utils.showLog("游戏盒子加载成功!");
  462. _this._appBox.show().then(function () {
  463. Utils_1.utils.showLog("游戏盒子显示成功!");
  464. }).catch(function (err) {
  465. Utils_1.utils.showLog("游戏盒子未加载!#err=", JSON.stringify(err));
  466. });
  467. }).catch(function (err) {
  468. Utils_1.utils.showLog("游戏盒子加载失败! #err=", JSON.stringify(err));
  469. if (!isMoreGame && _this.ServerConfig.intersititial_first_ad && _this.ServerConfig.intersititial_first_ad == "box") {
  470. Utils_1.utils.showLog("优先显示的是盒子广告,备用显示插屏");
  471. _this._createInsterstitial();
  472. }
  473. });
  474. }).catch(function (err) {
  475. Utils_1.utils.showLog("游戏盒子销毁失败! #err=", JSON.stringify(err));
  476. });
  477. ;
  478. }
  479. else {
  480. Utils_1.utils.showLog("游戏盒子id为:", Utils_1.utils.config.qqconfig.boxId);
  481. this._appBox = this.qq.createAppBox({
  482. adUnitId: Utils_1.utils.config.qqconfig.boxId
  483. });
  484. this._appBox.load().then(function () {
  485. Utils_1.utils.showLog("游戏盒子加载成功!");
  486. _this._appBox.show().then(function () {
  487. Utils_1.utils.showLog("游戏盒子显示成功!");
  488. }).catch(function (err) {
  489. Utils_1.utils.showLog("游戏盒子未加载!#err=", JSON.stringify(err));
  490. });
  491. }).catch(function (err) {
  492. Utils_1.utils.showLog("游戏盒子加载失败! #err=", JSON.stringify(err));
  493. if (!isMoreGame && _this.ServerConfig.intersititial_first_ad && _this.ServerConfig.intersititial_first_ad == "box") {
  494. Utils_1.utils.showLog("优先显示的是盒子广告,备用显示插屏");
  495. _this._createInsterstitial();
  496. }
  497. });
  498. }
  499. }
  500. };
  501. /**
  502. * 隐藏游戏盒子
  503. */
  504. AdAgentQQ.prototype.HideAppbox = function () {
  505. if (PlatUtils_1.default.IsQQ) {
  506. if (this._appBox) {
  507. this._appBox.destroy().then(function () {
  508. Utils_1.utils.showLog("游戏盒子销毁成功!");
  509. }).catch(function () {
  510. cc.warn("游戏盒子销毁失败!");
  511. });
  512. }
  513. }
  514. };
  515. /**
  516. * 显示积木广告
  517. */
  518. AdAgentQQ.prototype.showBlockAd = function (parme) {
  519. var _this = this;
  520. if (!this.ServerConfig) {
  521. Utils_1.utils.showLog("组件未初始化!");
  522. return;
  523. }
  524. if (!Utils_1.utils.config.qqconfig.bannerBoxId) {
  525. Utils_1.utils.showLog("积木广告ID不存在");
  526. return;
  527. }
  528. if (this.ServerConfig.is_banner_box == "false") {
  529. Utils_1.utils.showLog("服务器配置积木广告不展示!");
  530. return;
  531. }
  532. if (this._blockAd) {
  533. this._blockAd.offLoad();
  534. this._blockAd.offResize();
  535. this._blockAd.offError();
  536. this._blockAd.destroy();
  537. }
  538. if (PlatUtils_1.default.IsIOS && this._sysData.screenHeight < 736) {
  539. var top = 16;
  540. var left_1 = 16;
  541. var width_1 = 65;
  542. if (parme.top) {
  543. // top = parme.top
  544. top = parme.top / cc.winSize.height * this._sysData.screenHeight;
  545. }
  546. else {
  547. // top = this._sysData.screenHeight - 65.5 - parme.bottom
  548. top = this._sysData.screenHeight - 65.5 - parme.bottom / cc.winSize.height * this._sysData.screenHeight;
  549. }
  550. this._blockAd = this.qq.createBlockAd({
  551. adUnitId: Utils_1.utils.config.qqconfig.bannerBoxId,
  552. style: {
  553. left: left_1,
  554. top: top
  555. },
  556. size: parme.showNum ? parme.showNum : 5,
  557. orientation: "landscape"
  558. });
  559. this._blockAd.onResize(function (res) {
  560. _this._blockAd.offResize();
  561. Utils_1.utils.showLog("this._sysData", JSON.stringify(_this._sysData));
  562. Utils_1.utils.showLog("onresize >>", JSON.stringify(res));
  563. _this._blockAd.show().then(function () {
  564. Utils_1.utils.showLog("显示成功!");
  565. }).catch(function (res) {
  566. Utils_1.utils.showLog("显示异常", JSON.stringify(res));
  567. });
  568. if (parme.showNum == 1) {
  569. width_1 = 0;
  570. }
  571. else {
  572. width_1 = res.width;
  573. }
  574. if (parme.left) {
  575. // left = width + parme.left;
  576. left_1 = parme.left / cc.winSize.width * _this._sysData.screenWidth;
  577. }
  578. else if (parme.right) {
  579. left_1 = _this._sysData.screenWidth - res.width - parme.right / cc.winSize.width * _this._sysData.screenWidth;
  580. }
  581. else {
  582. left_1 = (_this._sysData.screenWidth - width_1) / 2;
  583. }
  584. _this._blockAd.style.left = left_1;
  585. Utils_1.utils.showLog("onresize end>>", _this._blockAd.style.top, "<<", _this._blockAd.style.left, "<<");
  586. });
  587. }
  588. else {
  589. this._blockAd = this.qq.createBlockAd({
  590. adUnitId: Utils_1.utils.config.qqconfig.bannerBoxId,
  591. style: {
  592. left: 16,
  593. top: 16
  594. },
  595. size: parme.showNum ? parme.showNum : 5,
  596. orientation: "landscape"
  597. });
  598. // if (parme.top) {
  599. // console.log("实际位置:", parme.top / cc.winSize.height * this._sysData.screenHeight, cc.winSize.height, parme.top)
  600. // }
  601. // else if (parme.bottom) {
  602. // console.log("实际位置:", this._sysData.screenHeight - 60 - parme.bottom / cc.winSize.height * this._sysData.screenHeight,cc.winSize.height,parme.bottom)
  603. // }
  604. this._blockAd.onResize(function (res) {
  605. _this._blockAd.offResize();
  606. Utils_1.utils.showLog("this._sysData", JSON.stringify(_this._sysData));
  607. Utils_1.utils.showLog("onresize >>", JSON.stringify(res));
  608. if (parme) {
  609. Utils_1.utils.showLog("parme:" + JSON.stringify(parme));
  610. if (parme.top) {
  611. Utils_1.utils.showLog("积木广告TOP位置:", parme.top);
  612. _this._blockAd.style.top = parme.top / cc.winSize.height * _this._sysData.screenHeight;
  613. }
  614. else if (parme.bottom) {
  615. // let bottom = this._sysData.screenHeight - res.height;
  616. // this._blockAd.style.top = bottom - parme.bottom;
  617. _this._blockAd.style.top = _this._sysData.screenHeight - res.height - parme.bottom / cc.winSize.height * _this._sysData.screenHeight;
  618. }
  619. if (parme.left) {
  620. // this._blockAd.style.left = parme.left;
  621. _this._blockAd.style.left = parme.left / cc.winSize.width * _this._sysData.screenWidth;
  622. }
  623. else if (parme.right) {
  624. // this._blockAd.style.left = this._sysData.screenWidth - res.width - parme.right;
  625. _this._blockAd.style.left = _this._sysData.screenWidth - res.width - parme.right / cc.winSize.width * _this._sysData.screenWidth;
  626. }
  627. else {
  628. _this._blockAd.style.left = (_this._sysData.screenWidth - res.width) / 2;
  629. }
  630. }
  631. else {
  632. _this._blockAd.style.top = _this._sysData.screenHeight - res.height;
  633. _this._blockAd.style.left = (_this._sysData.screenWidth - res.width) / 2;
  634. }
  635. _this._blockAd.show().then(function () {
  636. Utils_1.utils.showLog("显示成功!");
  637. }).catch(function (res) {
  638. Utils_1.utils.showLog("显示异常", JSON.stringify(res));
  639. });
  640. Utils_1.utils.showLog("onresize end>>", _this._blockAd.style.top, "<<", _this._blockAd.style.left, "<<");
  641. });
  642. }
  643. this._blockAd.onLoad(function () {
  644. Utils_1.utils.showLog("积木广告加载成功!");
  645. });
  646. this._blockAd.onError(function (res) {
  647. Utils_1.utils.showLog("积木广告加载失败!", res.errMsg, ">>", res.errCode);
  648. });
  649. };
  650. /**
  651. * 隐藏积木广告
  652. */
  653. AdAgentQQ.prototype.hideBlockAd = function () {
  654. Utils_1.utils.showLog("隐藏积木广告");
  655. if (this._blockAd)
  656. this._blockAd.hide();
  657. };
  658. AdAgentQQ.prototype.moveBtnToBannerTop = function () {
  659. var _this = this;
  660. Utils_1.utils.showLog("moveBtnToBannerTop >>>>>>>>>.");
  661. if (this.ServerConfig && this._moveBtn && cc.isValid(this._moveBtn)) {
  662. var moveBtnTime = 0;
  663. var btn_1 = this._moveBtn;
  664. if (this.ServerConfig.banner_move_btn_interval && this._cur_level && this._cur_level % this.ServerConfig.banner_move_btn_interval == 0) {
  665. if (this.ServerConfig.banner_move_btn_time) {
  666. moveBtnTime = this.ServerConfig.banner_move_btn_time;
  667. }
  668. }
  669. Utils_1.utils.showLog(moveBtnTime == 0 ? "按钮直接显示在banner上面" : "\u6309\u94AE\u5C45\u5E95\u90E8\u4E14" + moveBtnTime + "\u79D2\u540E\u79FB\u52A8");
  670. setTimeout(function () {
  671. if (btn_1 && cc.isValid(btn_1)) {
  672. if (_this._sysData.screenHeight < 600) {
  673. btn_1.getComponent(cc.Widget).bottom = 250;
  674. }
  675. else {
  676. btn_1.getComponent(cc.Widget).bottom = 220;
  677. }
  678. btn_1.getComponent(cc.Widget).updateAlignment();
  679. }
  680. }, moveBtnTime * 1000);
  681. }
  682. };
  683. AdAgentQQ = __decorate([
  684. ccclass
  685. ], AdAgentQQ);
  686. return AdAgentQQ;
  687. }(AdAgent_1.default));
  688. exports.default = AdAgentQQ;
  689. cc._RF.pop();