7c99396d-d68d-4494-b5b0-b52ca50c4f53.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. "use strict";
  2. cc._RF.push(module, '7c993lt1o1ElLWwtSylDE9T', 'YZ_NativeSplashView');
  3. // common-plugin/Scripts/YZ_NativeSplashView.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 CompatibleTool_1 = require("./CompatibleTool");
  26. var PlatUtils_1 = require("./PlatUtils");
  27. var Utils_1 = require("./Utils");
  28. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  29. var YZ_NativeSplashView = /** @class */ (function (_super) {
  30. __extends(YZ_NativeSplashView, _super);
  31. function YZ_NativeSplashView() {
  32. var _this = _super !== null && _super.apply(this, arguments) || this;
  33. _this._panel = null;
  34. _this._sourceLable = null;
  35. _this._titleLabel = null;
  36. _this._desLabel = null;
  37. _this._icon = null;
  38. // _mask: cc.Node = null;
  39. _this._btnLabel = null;
  40. _this._img = null;
  41. _this._timeLabel = null;
  42. _this._nativeAd = null;
  43. _this._data = null;
  44. _this._dataDirty = false;
  45. _this._btnDownLoad = null;
  46. _this.ratio = 1;
  47. _this.canSkip = true; //直接跳过
  48. return _this;
  49. }
  50. Object.defineProperty(YZ_NativeSplashView.prototype, "ServerConfig", {
  51. get: function () {
  52. return Utils_1.utils.ServerConfig;
  53. },
  54. enumerable: false,
  55. configurable: true
  56. });
  57. YZ_NativeSplashView.prototype.onLoad = function () {
  58. if (Utils_1.utils.otherConfig && Utils_1.utils.otherConfig.group) {
  59. this.node.group = Utils_1.utils.otherConfig.group;
  60. }
  61. if (cc.winSize.height < cc.winSize.width) {
  62. // 横屏游戏
  63. this.ratio = cc.winSize.width / 1920 * 0.75;
  64. this._panel = this.node.getChildByName("LandscapePanel");
  65. }
  66. else {
  67. this.ratio = cc.winSize.width / 1080;
  68. this._panel = this.node.getChildByName("PortraitPanel");
  69. }
  70. this._panel.active = true;
  71. // cc.game.addPersistRootNode(this.node);
  72. var canSkip = Utils_1.utils.getConfigByKey("native_splash_can_skip");
  73. if (canSkip == "false") {
  74. this.canSkip = false;
  75. }
  76. // this._panel = this.node.getChildByName("Panel");
  77. this._panel.scale = this.ratio;
  78. this._icon = this._panel.getChildByName("Icon").getComponent(cc.Sprite);
  79. this._img = this._panel.getChildByName("Img").getComponent(cc.Sprite);
  80. this._titleLabel = this._panel.getChildByName("TitleLabel").getComponent(cc.Label);
  81. this._desLabel = this._panel.getChildByName("DesLabel").getComponent(cc.Label);
  82. // this._mask = this.node.getChildByName("Mask");
  83. this._sourceLable = this._img.node.getChildByName("source").getComponent(cc.Label);
  84. this._btnDownLoad = this._panel.getChildByName("Btn_Download");
  85. this._btnLabel = this._btnDownLoad.getComponentInChildren(cc.Label);
  86. this._timeLabel = this._panel.getChildByName("time").children[0].getComponent(cc.Label);
  87. if (PlatUtils_1.default.IsHuaWei) {
  88. //@ts-ignore
  89. qg.onShow(this._reportAdShow.bind(this));
  90. }
  91. if (Utils_1.utils.getConfigByKey("native_splash_full_cilck") == "true") {
  92. this._btnDownLoad.active = true;
  93. }
  94. // this._panel.scale = ratio;
  95. };
  96. YZ_NativeSplashView.prototype.onDestroy = function () {
  97. if (PlatUtils_1.default.IsHuaWei) {
  98. //@ts-ignore
  99. qg.offShow(this._reportAdShow);
  100. this._nativeAd.destroy();
  101. cc.director.emit("SplashViewOff");
  102. }
  103. };
  104. YZ_NativeSplashView.prototype.init = function (nativeAd, data) {
  105. this._nativeAd = nativeAd;
  106. this._data = data;
  107. this._dataDirty = true;
  108. };
  109. YZ_NativeSplashView.prototype.update = function (dt) {
  110. if (this._data && this._dataDirty) {
  111. this._panel.active = true;
  112. // this._mask.active = true;
  113. this._dataDirty = false;
  114. this._updateContent();
  115. }
  116. if (!this._data) {
  117. this._panel.active = false;
  118. // this._mask.active = false;
  119. }
  120. };
  121. YZ_NativeSplashView.prototype._updateContent = function () {
  122. var _this = this;
  123. if (this._data) {
  124. // 上报原生插屏广告
  125. this._reportAdShow();
  126. if (PlatUtils_1.default.IsHuaWei) {
  127. this._data.icon = "";
  128. }
  129. // utils.nativeInsertShowCount++;
  130. Utils_1.utils.showLog("data:", JSON.stringify(this._data));
  131. this._titleLabel.string = this._data.title ? this._data.title : "";
  132. this._desLabel.string = this._data.desc ? this._data.desc : "";
  133. this._panel.getChildByName("Btn_Install").getComponentInChildren(cc.Label).string = this._data.clickBtnTxt ? this._data.clickBtnTxt : "查看详情";
  134. // this._btnLabel.string = this._data.clickBtnTxt ? this._data.clickBtnTxt : "查看详情";
  135. // utils.showLog("this._btnLabel.string" + this._btnLabel.string);
  136. if (this._data.imgUrlList && this._data.imgUrlList.length > 0) {
  137. // 有图片,优先显示图片
  138. this._titleLabel.node.active = true;
  139. this._icon.node.active = false;
  140. this._img.node.active = true;
  141. this._desLabel.node.active = true;
  142. var t_1 = 5;
  143. var task_1 = setInterval(function () {
  144. t_1--;
  145. if (t_1 == 0) {
  146. _this._timeLabel.string = "\u8DF3\u8FC7";
  147. }
  148. else if (t_1 == -1) {
  149. clearInterval(task_1);
  150. _this.node.destroy();
  151. }
  152. else {
  153. _this._timeLabel.string = "\u70B9\u51FB\u8DF3\u8FC7" + t_1 + "s";
  154. }
  155. }, 1000);
  156. Utils_1.utils.showLog("有图片,优先显示图片");
  157. CompatibleTool_1.default.LoadRes(this._data.imgUrlList[0], function (err, res) {
  158. Utils_1.utils.showLog("加载图片信息 ...." + err);
  159. if (!err && cc.isValid(_this) && _this._img) {
  160. _this._img.spriteFrame = new cc.SpriteFrame(res);
  161. }
  162. });
  163. }
  164. else if (PlatUtils_1.default.IsHuaWei && this._data.icon) {
  165. // 有icon
  166. Utils_1.utils.showLog("没有图片,显示icon");
  167. this._titleLabel.node.active = true;
  168. this._icon.node.active = true;
  169. this._img.node.active = false;
  170. this._desLabel.node.active = true;
  171. CompatibleTool_1.default.LoadRes(this._data.icon, function (err, res) {
  172. if (!err && cc.isValid(_this) && _this._icon) {
  173. _this._icon.spriteFrame = new cc.SpriteFrame(res);
  174. }
  175. });
  176. }
  177. else {
  178. Utils_1.utils.showLog("什么都没有!!!");
  179. }
  180. if (PlatUtils_1.default.IsHuaWei) {
  181. this._sourceLable.string = this._data.source ? this._data.source : "";
  182. }
  183. }
  184. };
  185. YZ_NativeSplashView.prototype.onBtnClickHandler = function (event, data) {
  186. switch (event.target.name) {
  187. case "time":
  188. if (this.canSkip) {
  189. this.node.destroy();
  190. }
  191. else {
  192. if (this._timeLabel.string == "跳过") {
  193. this.node.destroy();
  194. }
  195. }
  196. // this._panel.active = false;
  197. // this._mask.active = false;
  198. break;
  199. case "Btn_Close": {
  200. this.node.destroy();
  201. // this._panel.active = false;
  202. // this._mask.active = false;
  203. break;
  204. }
  205. case "Img":
  206. case "Icon":
  207. case "Btn_Install":
  208. this._reportAdClick();
  209. break;
  210. case "Btn_Download": {
  211. this._reportAdClick();
  212. break;
  213. }
  214. }
  215. };
  216. YZ_NativeSplashView.prototype._reportAdShow = function () {
  217. if (this._data) {
  218. if (this._nativeAd && this._panel.active) {
  219. Utils_1.utils.showLog("上报原生插屏广告展示! adId:" + this._data.adId + " #active=" + this.node.active);
  220. this._nativeAd.reportAdShow({
  221. adId: this._data.adId
  222. });
  223. }
  224. }
  225. };
  226. YZ_NativeSplashView.prototype._reportAdClick = function () {
  227. if (this._data) {
  228. Utils_1.utils.showLog("上报原生开屏广告点击! adId:" + this._data.adId);
  229. if (this._nativeAd) {
  230. this._nativeAd.reportAdClick({
  231. adId: this._data.adId
  232. });
  233. this._panel.active = false;
  234. // this._mask.active = false;
  235. if (PlatUtils_1.default.IsOPPO) {
  236. Utils_1.utils.oppoTool.countNativeInserClick();
  237. }
  238. else if (PlatUtils_1.default.IsVIVO) {
  239. Utils_1.utils.Tool_Vivo.countNativeInserClick();
  240. }
  241. if (PlatUtils_1.default.IsHuaWei) {
  242. this.node.destroy();
  243. this.downLoadAd();
  244. }
  245. }
  246. }
  247. };
  248. YZ_NativeSplashView.prototype.downLoadAd = function () {
  249. return;
  250. var resultCode = this._nativeAd.startDownload({
  251. adId: this._data.adId
  252. });
  253. Utils_1.utils.showLog('原生广告主动下载 resumeDownloadresultCode = ' + resultCode);
  254. };
  255. YZ_NativeSplashView = __decorate([
  256. ccclass
  257. ], YZ_NativeSplashView);
  258. return YZ_NativeSplashView;
  259. }(cc.Component));
  260. exports.default = YZ_NativeSplashView;
  261. cc._RF.pop();