c237b96b-47cb-456f-bad0-e849550114cc.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. "use strict";
  2. cc._RF.push(module, 'c237blrR8tFb7rQ6ElVARTM', 'NativeTryGameNode');
  3. // common-plugin/Scripts/NativeTryGameNode.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 Utils_1 = require("./Utils");
  26. var PlatUtils_1 = require("./PlatUtils");
  27. var NativeTryGamesWidget_1 = require("./NativeTryGamesWidget");
  28. var CompatibleTool_1 = require("./CompatibleTool");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. var NativeTryGameNode = /** @class */ (function (_super) {
  31. __extends(NativeTryGameNode, _super);
  32. function NativeTryGameNode() {
  33. var _this = _super !== null && _super.apply(this, arguments) || this;
  34. _this._data = null;
  35. _this._icon = null;
  36. _this._nameLabel = null;
  37. _this._gameJumpInterval = -1;
  38. _this._jumpInfo = null;
  39. _this._index = -1;
  40. _this._jumping = false; // 控制是否在跳转
  41. _this._isFirst = false;
  42. _this._mask = null;
  43. return _this;
  44. }
  45. NativeTryGameNode.prototype.onLoad = function () {
  46. this._icon = cc.find("Mask/Icon", this.node).getComponent(cc.Sprite);
  47. this._mask = cc.find("Mask", this.node);
  48. };
  49. /**
  50. *
  51. * @param data 交叉推广数据
  52. * data:[{"date":{
  53. "jump_list": [
  54. { // 交叉推广挂件内容信息
  55. "icon": "http://xcx.youletd.com/img/icon/fgdxc.png",
  56. "name": "翻滚的香肠大冒险",
  57. "path": "",
  58. "js_jump": "true",
  59. "qr_code": "http://xcx.youletd.com/img/qrcode/q_fgdxc.jpg",
  60. "appid": "wx2c4ed4218224b042"
  61. }
  62. ]
  63. }
  64. "tryGameAd":tryGameAd
  65. }
  66. ]
  67. *
  68. */
  69. NativeTryGameNode.prototype.init = function (data) {
  70. this._data = data;
  71. Utils_1.utils.showLog("原生抖动Node");
  72. if (this._data) {
  73. this._jumpInfo = this._data.jump_list;
  74. this._gameJumpInterval = this._data.jump_refresh_time;
  75. this._isFirst = true;
  76. this.node.active = true;
  77. if (PlatUtils_1.default.IsHuaWei) {
  78. this.node.getChildByName("source").getComponent(cc.Label).string = this._jumpInfo[this._index].date[0].source ? this._jumpInfo[this._index].date[0].source : "";
  79. }
  80. }
  81. else {
  82. this.node.active = false;
  83. }
  84. };
  85. /**
  86. * 跳转成功过后显示下一个
  87. */
  88. NativeTryGameNode.prototype.showNextItem = function () {
  89. this.unscheduleAllCallbacks();
  90. this.jump();
  91. this.schedule(this.jump, this._gameJumpInterval);
  92. };
  93. NativeTryGameNode.prototype.onEnable = function () {
  94. var _this = this;
  95. this.jump();
  96. this.schedule(this.jump, this._gameJumpInterval);
  97. this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
  98. if (_this.node.opacity == 0)
  99. return;
  100. var tryGameAd = _this._jumpInfo[_this._index].tryGameAd;
  101. var adid = _this._jumpInfo[_this._index].date[0].adId;
  102. if (tryGameAd) {
  103. tryGameAd.reportAdClick({
  104. adId: adid
  105. });
  106. Utils_1.utils.showLog("抖动试玩上报" + "tryGameAd:" + JSON.stringify(tryGameAd) + "adid:" + adid);
  107. }
  108. Utils_1.utils.nativeNeedChange = true;
  109. Utils_1.utils.tryGameDate.splice(_this._index, 1);
  110. if (Utils_1.utils._nativeTryGameNode) {
  111. Utils_1.utils._nativeTryGameNode.getComponent(NativeTryGamesWidget_1.default).init();
  112. }
  113. }, this);
  114. };
  115. NativeTryGameNode.prototype.onDisable = function () {
  116. this.unscheduleAllCallbacks();
  117. this.node.targetOff(this);
  118. };
  119. NativeTryGameNode.prototype.jump = function () {
  120. var _this = this;
  121. if (this._jumping)
  122. return;
  123. this._jumping = true;
  124. this._index = this._index + 1;
  125. if (this._index >= this._jumpInfo.length) {
  126. this._index = 0;
  127. }
  128. var contentSize = this._icon.node.getContentSize();
  129. if (this._jumpInfo[this._index]) {
  130. var remoteUrl = PlatUtils_1.default.IsOPPO ? this._jumpInfo[this._index].date[0].iconUrlList[0] : this._jumpInfo[this._index].date[0].icon;
  131. if (!remoteUrl || PlatUtils_1.default.IsHuaWei) {
  132. remoteUrl = this._jumpInfo[this._index].date[0].imgUrlList[0];
  133. }
  134. CompatibleTool_1.default.LoadRes(remoteUrl, function (err, texture) {
  135. if (!err && cc.isValid(_this) && _this._icon) {
  136. _this._icon.spriteFrame = new cc.SpriteFrame(texture);
  137. _this._icon.node.setContentSize(contentSize);
  138. if (_this._isFirst) {
  139. Utils_1.utils.showLog("当前试玩第一次加载!!!!!");
  140. _this._mask.active = true;
  141. _this._isFirst = false;
  142. }
  143. }
  144. _this._jumping = false;
  145. });
  146. var tryGameAd = this._jumpInfo[this._index].tryGameAd;
  147. var adid = this._jumpInfo[this._index].date[0].adId;
  148. if (tryGameAd && !tryGameAd.isReportShow) {
  149. tryGameAd.reportAdShow({
  150. adId: adid
  151. });
  152. tryGameAd.isReportShow = true;
  153. }
  154. }
  155. else {
  156. this._jumping = false;
  157. }
  158. this.node.opacity == 0 && (this.node.opacity = 255);
  159. };
  160. NativeTryGameNode = __decorate([
  161. ccclass
  162. ], NativeTryGameNode);
  163. return NativeTryGameNode;
  164. }(cc.Component));
  165. exports.default = NativeTryGameNode;
  166. cc._RF.pop();