1d525d65-f9d3-4553-9ffc-190d085b6e92.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. "use strict";
  2. cc._RF.push(module, '1d5251l+dNFU5/8GQ0IW26S', 'YZ_NativeInsert');
  3. // common-plugin/Scripts/YZ_NativeInsert.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 PlatUtils_1 = require("./PlatUtils");
  26. var Utils_1 = require("./Utils");
  27. var CompatibleTool_1 = require("./CompatibleTool");
  28. var YZ_Constant_1 = require("./YZ_Constant");
  29. var EventAdInfo_1 = require("./YouWanSDK/EventAdInfo");
  30. var YouWanAnalytics_1 = require("./YouWanSDK/YouWanAnalytics");
  31. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  32. var YZ_NativeInsert = /** @class */ (function (_super) {
  33. __extends(YZ_NativeInsert, _super);
  34. function YZ_NativeInsert() {
  35. var _this = _super !== null && _super.apply(this, arguments) || this;
  36. _this._panel = null;
  37. _this._sourceLable = null;
  38. _this._titleLabel = null;
  39. _this._desLabel = null;
  40. _this._icon = null;
  41. _this._mask = null;
  42. _this._btnLabel = null;
  43. _this._closeBtn = null;
  44. _this._img = null;
  45. _this._hideInstallBtn = null;
  46. _this._nativeAd = null;
  47. _this._data = null;
  48. _this._dataDirty = false;
  49. _this._btnDownLoad = null;
  50. _this._defaultCloseSize = 60;
  51. return _this;
  52. }
  53. Object.defineProperty(YZ_NativeInsert.prototype, "ServerConfig", {
  54. get: function () {
  55. return Utils_1.utils.ServerConfig;
  56. },
  57. enumerable: false,
  58. configurable: true
  59. });
  60. YZ_NativeInsert.prototype.onLoad = function () {
  61. if (Utils_1.utils.otherConfig && Utils_1.utils.otherConfig.group) {
  62. this.node.group = Utils_1.utils.otherConfig.group;
  63. }
  64. cc.game.addPersistRootNode(this.node);
  65. this._panel = this.node.getChildByName("Panel");
  66. this._icon = this._panel.getChildByName("Icon").getComponent(cc.Sprite);
  67. this._img = this._panel.getChildByName("Img").getComponent(cc.Sprite);
  68. this._titleLabel = this._panel.getChildByName("TitleLabel").getComponent(cc.Label);
  69. this._desLabel = this._panel.getChildByName("DesLabel").getComponent(cc.Label);
  70. this._mask = this.node.getChildByName("Mask");
  71. this._sourceLable = this._panel.getChildByName("Img").getChildByName("source").getComponent(cc.Label);
  72. this._btnDownLoad = this._panel.getChildByName("Btn_Download");
  73. this._btnLabel = this._btnDownLoad.getComponentInChildren(cc.Label);
  74. this._hideInstallBtn = this._panel.getChildByName("Btn_HideInstall");
  75. this._closeBtn = this._hideInstallBtn.getChildByName("Btn_Close");
  76. var self = this;
  77. var bg = this._panel.getChildByName("bg").getComponent(cc.Sprite);
  78. var bgUrl = Utils_1.utils.ServerConfig.native_intersititial_bg_img;
  79. if (bgUrl && !this.bgTexture) {
  80. CompatibleTool_1.default.LoadRes(bgUrl, function (err, texture) {
  81. if (!err && cc.isValid(self) && self._panel) {
  82. var size = self._panel.getChildByName("bg").getContentSize();
  83. self.bgTexture = new cc.SpriteFrame(texture);
  84. bg.spriteFrame = self.bgTexture;
  85. self._panel.getChildByName("bg").setContentSize(size);
  86. }
  87. });
  88. }
  89. var back = this._panel.getChildByName("Btn_Install").getChildByName("Background").getComponent(cc.Sprite);
  90. var backUrl = Utils_1.utils.ServerConfig.native_intersititial_btn_img;
  91. if (backUrl && !this.btnTexture) {
  92. CompatibleTool_1.default.LoadRes(backUrl, function (err, texture) {
  93. if (!err && cc.isValid(self) && self._panel) {
  94. var size = self._panel.getChildByName("Btn_Install").getContentSize();
  95. self.btnTexture = new cc.SpriteFrame(texture);
  96. back.spriteFrame = self.btnTexture;
  97. self._panel.getChildByName("Btn_Install").setContentSize(size);
  98. }
  99. });
  100. }
  101. var ratio = 1;
  102. if (cc.winSize.height < cc.winSize.width) {
  103. // 横屏游戏
  104. ratio = cc.winSize.width / 1920 * 0.7;
  105. // if (PlatUtils.IsVIVO) {
  106. // ratio = cc.winSize.width / 1920 * 0.7 * (1280 / utils.cur_tool.SysInfo.screenWidth);
  107. // } else {
  108. // if (!PlatUtils.IsHuaWei) {
  109. // this._panel.width = cc.winSize.width / 2;
  110. // this._panel.height = cc.winSize.height * 0.9;
  111. // this._desLabel.getComponent(cc.Widget).bottom = 200;
  112. // this._desLabel.getComponent(cc.Widget).updateAlignment();
  113. // this._panel.getChildByName("Btn_Install").getComponent(cc.Widget).bottom = 50;
  114. // this._panel.getChildByName("Btn_Install").getComponent(cc.Widget).updateAlignment();
  115. // this._img.node.getComponent(cc.Widget).top = (this._titleLabel.node.y - this._desLabel.node.y) / 3;
  116. // this._img.node.getComponent(cc.Widget).bottom = (this._titleLabel.node.y - this._desLabel.node.y) / 2
  117. // this._img.node.getComponent(cc.Widget).updateAlignment();
  118. // this._titleLabel.node.getComponent(cc.Widget).top = 70;
  119. // this._titleLabel.node.getComponent(cc.Widget).updateAlignment();
  120. // this._closeBtn.getComponent(cc.Widget).top = 65;
  121. // this._closeBtn.getComponent(cc.Widget).updateAlignment();
  122. // }else{
  123. this._panel.scale = ratio;
  124. // }
  125. }
  126. else {
  127. this._panel.getComponent(cc.Widget).isAlignBottom = true;
  128. this._panel.getComponent(cc.Widget).bottom = 378;
  129. this._panel.getComponent(cc.Widget).updateAlignment();
  130. ratio = cc.winSize.width / 1080;
  131. this._panel.scale = ratio;
  132. }
  133. /**
  134. if (PlatUtils.IsHuaWei) {
  135. let closeBtnRange = this.ServerConfig.intersititia_close_but_range ? this.ServerConfig.intersititia_close_but_range : this._closeBtn.getContentSize().height;
  136. let closeBtnSize = this.ServerConfig.intersititia_close_but_size ? this.ServerConfig.intersititia_close_but_size : this._closeBtn.getContentSize().height;
  137. this._closeBtn.setContentSize(cc.size(closeBtnRange, closeBtnRange));
  138. this._closeBtn.getChildByName("Background").setContentSize(cc.size(closeBtnSize, closeBtnSize));
  139. this._btnDownLoad.active = false;
  140. //@ts-ignore
  141. // qg.onShow(this._reportAdShow.bind(this));
  142. }
  143. */
  144. if (PlatUtils_1.default.IsXiaoMi) {
  145. this._panel.getChildByName("Xm_Mask").active = true;
  146. }
  147. // this._panel.scale = ratio;
  148. };
  149. YZ_NativeInsert.prototype.onEnable = function () {
  150. var _this = this;
  151. if (PlatUtils_1.default.IsHuaWei) {
  152. Utils_1.utils.showLog("注册原生插屏监听事件 >>>>>.");
  153. cc.game.targetOff(this);
  154. cc.game.on(cc.game.EVENT_SHOW, function () {
  155. console.log("HuaWeiOnShow >>>>>>");
  156. _this._reportAdShow();
  157. }, this);
  158. }
  159. if (PlatUtils_1.default.IsOPPO || PlatUtils_1.default.IsVIVO || PlatUtils_1.default.IsHuaWei || PlatUtils_1.default.IsXiaoMi) {
  160. this._panel.on(cc.Node.EventType.TOUCH_START, function (event) {
  161. _this._reportAdClick();
  162. }, this);
  163. cc.game.on(YZ_Constant_1.default.YZ_NativeAdClick, function () {
  164. _this._reportAdClick();
  165. }, this);
  166. }
  167. };
  168. YZ_NativeInsert.prototype.onDestroy = function () {
  169. if (PlatUtils_1.default.IsHuaWei) {
  170. cc.game.targetOff(this);
  171. Utils_1.utils.adManager.ShowBanner();
  172. }
  173. };
  174. YZ_NativeInsert.prototype.init = function (nativeAd, data) {
  175. this._nativeAd = nativeAd;
  176. this._data = data;
  177. this._dataDirty = true;
  178. };
  179. YZ_NativeInsert.prototype.update = function (dt) {
  180. if (this._data && this._dataDirty) {
  181. this._panel.active = true;
  182. this._mask.active = true;
  183. this._dataDirty = false;
  184. this._updateContent();
  185. }
  186. if (!this._data) {
  187. this._panel.active = false;
  188. this._mask.active = false;
  189. }
  190. };
  191. YZ_NativeInsert.prototype._updateContent = function () {
  192. var _this = this;
  193. // this.ServerConfig.intersititia_close_but_range = 10;
  194. // this.ServerConfig.intersititia_close_but_size = 90;
  195. if (this._data) {
  196. // 上报原生插屏广告
  197. this._reportAdShow();
  198. Utils_1.utils.nativeInsertShowCount++;
  199. if (this.ServerConfig.first_interstitial_delayed_level_close) {
  200. if (Utils_1.utils.nativeInsertShowCount > 3 && this.ServerConfig.interstitial_delayed_level_close) {
  201. Utils_1.utils.nativeInsertResizeCloseBtnShowCount++;
  202. if (Utils_1.utils.nativeInsertResizeCloseBtnShowCount % this.ServerConfig.interstitial_delayed_level_close == 0) {
  203. Utils_1.utils.showLog("\u539F\u751F\u63D2\u5C4F\u5173\u95ED\u6309\u94AE\u8BBE\u7F6E\u670D\u52A1\u5668\u914D\u7F6E\u5927\u5C0F" + this.ServerConfig.intersititia_close_but_size);
  204. var closeBtnSize = this.ServerConfig.intersititia_close_but_size ? this.ServerConfig.intersititia_close_but_size : this._defaultCloseSize;
  205. this._hideInstallBtn.setContentSize(cc.size(closeBtnSize, closeBtnSize));
  206. }
  207. }
  208. else {
  209. Utils_1.utils.showLog("\u539F\u751F\u63D2\u5C4F\u5173\u95ED\u6309\u94AE,\u4E0D\u6EE1\u8DB3\u670D\u52A1\u5668\u6761\u4EF6\uFF0C\u8BBE\u7F6E\u4E3A\u9ED8\u8BA4\u5927\u5C0F\uFF01");
  210. this._hideInstallBtn.setContentSize(cc.size(this._defaultCloseSize, this._defaultCloseSize));
  211. }
  212. }
  213. else {
  214. var closeBtnSize = this.ServerConfig.intersititia_close_but_size ? this.ServerConfig.intersititia_close_but_size : this._defaultCloseSize;
  215. this._hideInstallBtn.setContentSize(cc.size(closeBtnSize, closeBtnSize));
  216. }
  217. this._closeBtn.getChildByName("Background").opacity = CC_DEBUG ? 255 : 0;
  218. this._hideInstallBtn.opacity = this.ServerConfig.intersititia_close_but_alpha ? this.ServerConfig.intersititia_close_but_alpha : 255;
  219. var closeBtnRange = this.ServerConfig.intersititia_close_but_range ? this.ServerConfig.intersititia_close_but_range : this._defaultCloseSize;
  220. this._closeBtn.setContentSize(cc.size(closeBtnRange, closeBtnRange));
  221. this._titleLabel.string = this._data.title ? this._data.title : "";
  222. this._desLabel.string = this._data.desc ? this._data.desc : "";
  223. this._btnLabel.string = this._data.clickBtnTxt ? this._data.clickBtnTxt : "查看详情";
  224. if (this._data.imgUrlList && this._data.imgUrlList.length > 0) {
  225. // 有图片,优先显示图片
  226. this._titleLabel.node.active = true;
  227. this._icon.node.active = false;
  228. this._img.node.active = true;
  229. this._desLabel.node.active = true;
  230. CompatibleTool_1.default.LoadRes(this._data.imgUrlList[0], function (err, res) {
  231. Utils_1.utils.showLog("加载图片信息 ...." + err);
  232. if (!err && cc.isValid(_this) && _this._img) {
  233. _this._img.spriteFrame = new cc.SpriteFrame(res);
  234. }
  235. });
  236. }
  237. else if (PlatUtils_1.default.IsOPPO && this._data.iconUrlList && this._data.iconUrlList.length > 0) {
  238. // 有icon
  239. this._titleLabel.node.active = true;
  240. this._icon.node.active = true;
  241. this._img.node.active = false;
  242. this._desLabel.node.active = true;
  243. CompatibleTool_1.default.LoadRes(this._data.iconUrlList[0], function (err, res) {
  244. if (!err && cc.isValid(_this) && _this._icon) {
  245. _this._icon.spriteFrame = new cc.SpriteFrame(res);
  246. }
  247. });
  248. }
  249. else if ((PlatUtils_1.default.IsVIVO || PlatUtils_1.default.IsHuaWei) && this._data.icon) {
  250. // 有icon
  251. this._titleLabel.node.active = true;
  252. this._icon.node.active = true;
  253. this._img.node.active = false;
  254. this._desLabel.node.active = true;
  255. CompatibleTool_1.default.LoadRes(this._data.icon, function (err, res) {
  256. if (!err && cc.isValid(_this) && _this._icon) {
  257. _this._icon.spriteFrame = new cc.SpriteFrame(res);
  258. }
  259. });
  260. }
  261. this._hideInstallBtn.active = false;
  262. this._closeBtn.active = false;
  263. // if(this.ServerConfig.intersititia_close_delay_time == 0){
  264. // this._closeBtn.active = true;
  265. // this._hideInstallBtn.active = true;
  266. // }else{
  267. this.scheduleOnce(function () {
  268. _this._closeBtn.active = true;
  269. _this._hideInstallBtn.active = true;
  270. }, this.ServerConfig.intersititia_close_delay_time || 0);
  271. // }
  272. if (PlatUtils_1.default.IsHuaWei) {
  273. this._sourceLable.string = this._data.source ? this._data.source : "";
  274. }
  275. }
  276. };
  277. YZ_NativeInsert.prototype.onBtnClickHandler = function (event, data) {
  278. console.log("event.target.name:", event.target.name);
  279. switch (event.target.name) {
  280. case "Btn_Close": {
  281. this._panel.active = false;
  282. this._mask.active = false;
  283. break;
  284. }
  285. case "Btn_HideInstall":
  286. case "Img":
  287. case "Btn_Install":
  288. this._reportAdClick();
  289. break;
  290. case "Btn_Download": {
  291. if (Utils_1.utils.ServerConfig.native_intersititial_click_range && Utils_1.utils.ServerConfig.native_intersititial_click_range == 2) {
  292. Utils_1.utils.showLog("服务器native_intersititial_click_range配置为2,只能点击安装按钮算安装");
  293. return;
  294. }
  295. this._reportAdClick();
  296. break;
  297. }
  298. }
  299. };
  300. YZ_NativeInsert.prototype._reportAdShow = function () {
  301. if (this._data) {
  302. if (this._nativeAd && this._panel.active) {
  303. YouWanAnalytics_1.default.EventAdWithObj(EventAdInfo_1.YwAdType.NATIVE_INTERSITITIAL, EventAdInfo_1.YwAdStatus.SHOW_SUCCESS, new EventAdInfo_1.AdEventParameter(this._data.adId));
  304. Utils_1.utils.showLog("上报原生插屏广告展示! adId:" + this._data.adId + " #active=" + this.node.active);
  305. this._nativeAd.reportAdShow({
  306. adId: this._data.adId
  307. });
  308. }
  309. }
  310. };
  311. YZ_NativeInsert.prototype._reportAdClick = function () {
  312. if (this._data) {
  313. Utils_1.utils.showLog("上报原生插屏广告点击! adId:" + this._data.adId);
  314. if (this._nativeAd) {
  315. YouWanAnalytics_1.default.EventAdWithObj(EventAdInfo_1.YwAdType.NATIVE_INTERSITITIAL, EventAdInfo_1.YwAdStatus.CLICK, new EventAdInfo_1.AdEventParameter(this._data.adId));
  316. this._nativeAd.reportAdClick({
  317. adId: this._data.adId
  318. });
  319. // 服务器控制点击后是否关闭插屏广告
  320. if (this.ServerConfig.intersititial_click_close ? (this.ServerConfig.intersititial_click_close == "true") : true) {
  321. this._panel.active = false;
  322. this._mask.active = false;
  323. }
  324. // 点击后调整关闭按钮大小和触发按钮相同的大小
  325. this._closeBtn.active = true;
  326. this._hideInstallBtn.active = true;
  327. this._closeBtn.setContentSize(cc.size(this.ServerConfig.intersititia_close_but_range, this.ServerConfig.intersititia_close_but_range));
  328. if (PlatUtils_1.default.IsOPPO) {
  329. Utils_1.utils.oppoTool.countNativeInserClick();
  330. }
  331. else if (PlatUtils_1.default.IsVIVO) {
  332. Utils_1.utils.Tool_Vivo.countNativeInserClick();
  333. }
  334. if (PlatUtils_1.default.IsHuaWei) {
  335. this.node.destroy();
  336. this.downLoadAd();
  337. }
  338. }
  339. }
  340. };
  341. YZ_NativeInsert.prototype.downLoadAd = function () {
  342. return;
  343. var resultCode = this._nativeAd.startDownload({
  344. adId: this._data.adId
  345. });
  346. Utils_1.utils.showLog('原生广告主动下载 resumeDownloadresultCode = ' + resultCode);
  347. };
  348. YZ_NativeInsert = __decorate([
  349. ccclass
  350. ], YZ_NativeInsert);
  351. return YZ_NativeInsert;
  352. }(cc.Component));
  353. exports.default = YZ_NativeInsert;
  354. cc._RF.pop();