038c4e91-9c71-4544-be4e-7ca95e850592.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. "use strict";
  2. cc._RF.push(module, '038c46RnHFFRL5OfKlehQWS', 'TryGameNode');
  3. // common-plugin/Scripts/TryGameNode.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 YZ_Constant_1 = require("./YZ_Constant");
  27. var PlatUtils_1 = require("./PlatUtils");
  28. var CompatibleTool_1 = require("./CompatibleTool");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. var TryGameNode = /** @class */ (function (_super) {
  31. __extends(TryGameNode, _super);
  32. function TryGameNode() {
  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. TryGameNode.prototype.onLoad = function () {
  46. this._icon = cc.find("Mask/Icon", this.node).getComponent(cc.Sprite);
  47. this._mask = cc.find("Mask", this.node);
  48. // this._nameLabel = cc.find("NameLabel", this.node).getComponent(cc.Label);
  49. // this._nameLabel.string = "";
  50. };
  51. /**
  52. *
  53. * @param data 交叉推广数据
  54. * data:{
  55. "jump_list": [
  56. { // 交叉推广挂件内容信息
  57. "icon": "http://xcx.youletd.com/img/icon/fgdxc.png",
  58. "name": "翻滚的香肠大冒险",
  59. "path": "",
  60. "js_jump": "true",
  61. "qr_code": "http://xcx.youletd.com/img/qrcode/q_fgdxc.jpg",
  62. "appid": "wx2c4ed4218224b042"
  63. }
  64. ]
  65. * }
  66. *
  67. */
  68. TryGameNode.prototype.init = function (data) {
  69. this._data = data;
  70. if (this._data) {
  71. this._jumpInfo = this._data.jump_list;
  72. this._gameJumpInterval = this._data.jump_refresh_time;
  73. this._isFirst = true;
  74. this.node.active = false;
  75. }
  76. else {
  77. this.node.active = false;
  78. }
  79. };
  80. /**
  81. * 跳转成功过后显示下一个
  82. */
  83. TryGameNode.prototype.showNextItem = function () {
  84. this.unscheduleAllCallbacks();
  85. this.jump();
  86. this.schedule(this.jump, this._gameJumpInterval);
  87. };
  88. TryGameNode.prototype.onEnable = function () {
  89. var _this = this;
  90. this.jump();
  91. this.schedule(this.jump, this._gameJumpInterval);
  92. this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
  93. if (_this._jumpInfo[_this._index] && _this._jumpInfo[_this._index].appid) {
  94. Utils_1.utils.showLog("\u5C0F\u6E38\u620F\u8DF3\u8F6C! info=" + _this._jumpInfo[_this._index]);
  95. if (PlatUtils_1.default.IsDouyin) {
  96. Utils_1.utils.Tool_Douyin.showMoreGamesModal();
  97. }
  98. else if (PlatUtils_1.default.IsQQ) {
  99. Utils_1.utils.adManager.ShowAppBox(true);
  100. }
  101. else {
  102. var index_1 = _this._index;
  103. _this._postClickData(_this._jumpInfo[index_1].appid);
  104. Utils_1.utils.navigateToMiniGame(_this._jumpInfo[index_1], function (ret) {
  105. if (ret) {
  106. // 上报数据
  107. if (_this._jumpInfo && _this._jumpInfo[index_1] && _this._jumpInfo[index_1].appid) {
  108. _this._postData(_this._jumpInfo[index_1].appid);
  109. }
  110. }
  111. });
  112. }
  113. _this.showNextItem();
  114. }
  115. }, this);
  116. };
  117. TryGameNode.prototype.onDisable = function () {
  118. this.unscheduleAllCallbacks();
  119. this.node.targetOff(this);
  120. };
  121. TryGameNode.prototype.jump = function () {
  122. var _this = this;
  123. if (this._jumping)
  124. return;
  125. this._jumping = true;
  126. this._index = this._index + 1;
  127. if (this._index >= this._jumpInfo.length) {
  128. this._index = 0;
  129. }
  130. var contentSize = this._icon.node.getContentSize();
  131. if (this._jumpInfo[this._index] && this._jumpInfo[this._index].icon) {
  132. // this._setName(this._jumpInfo[this._index].name);
  133. var remoteUrl = this._jumpInfo[this._index].icon;
  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. }
  147. else {
  148. this._jumping = false;
  149. }
  150. };
  151. TryGameNode.prototype._setName = function (name) {
  152. if (!name) {
  153. this._nameLabel.string = "";
  154. }
  155. else {
  156. if (name.length > 5) {
  157. this._nameLabel.string = name.slice(0, 5) + "...";
  158. this._nameLabel.node.scale = 0.7;
  159. }
  160. else {
  161. this._nameLabel.string = name;
  162. }
  163. }
  164. };
  165. // _postData(appid: string) {
  166. // utils.postData(appid);
  167. // }
  168. /**
  169. * 上报跳转成功
  170. * @param appid
  171. */
  172. TryGameNode.prototype._postData = function (appid) {
  173. Utils_1.utils.postDataByLocation(appid, YZ_Constant_1.SubLocation.isTryGame, 1);
  174. };
  175. /**
  176. * 上报点击
  177. * @param appid
  178. */
  179. TryGameNode.prototype._postClickData = function (appid) {
  180. Utils_1.utils.postDataByLocation(appid, YZ_Constant_1.SubLocation.isTryGame, 0);
  181. };
  182. TryGameNode = __decorate([
  183. ccclass
  184. ], TryGameNode);
  185. return TryGameNode;
  186. }(cc.Component));
  187. exports.default = TryGameNode;
  188. cc._RF.pop();