e2d27230-950e-41e6-999e-2f4a7f0fee47.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. "use strict";
  2. cc._RF.push(module, 'e2d27IwlQ5B5pmeL0p/D+5H', 'GameItem');
  3. // common-plugin/Scripts/GameItem.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 YZ_Constant_1 = require("./YZ_Constant");
  28. var CompatibleTool_1 = require("./CompatibleTool");
  29. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  30. var GameItem = /** @class */ (function (_super) {
  31. __extends(GameItem, _super);
  32. function GameItem() {
  33. var _this = _super !== null && _super.apply(this, arguments) || this;
  34. /*
  35. {
  36. "icon": "http://ff.td68x.com/xcx/ylyxhz/451m.png",
  37. "name": "点亮它的色彩",
  38. "path": "",
  39. "qr_code": "",
  40. "appid": "wx35562d816d9ed9fb"
  41. }
  42. */
  43. _this.data = null;
  44. _this.icon = null;
  45. _this.labelName = null;
  46. _this.labelShadow = null;
  47. _this._dataDirty = false;
  48. _this._redPoint = null;
  49. _this._location = null;
  50. _this.mask = null;
  51. _this._subNameLength = 4;
  52. return _this;
  53. }
  54. GameItem.prototype.onLoad = function () {
  55. this.mask = this.node.getChildByName("Mask");
  56. this.icon = this.mask.getChildByName("Icon").getComponent(cc.Sprite);
  57. this.labelName = this.node.getChildByName("Label").getComponent(cc.Label);
  58. this.labelShadow = this.node.getChildByName("LabelShadow").getComponent(cc.Label);
  59. if (this._location && (this._location == YZ_Constant_1.SubLocation.isYzBanner || this._location == YZ_Constant_1.SubLocation.isScrollbar || this._location == YZ_Constant_1.SubLocation.isMoreGame || this._location == YZ_Constant_1.SubLocation.isBoxInsertAd || this._location == YZ_Constant_1.SubLocation.isBeforGameOverAd)) {
  60. this._redPoint = this.mask.getChildByName("redpoint");
  61. if (this.data && this.data.red && this.data.red != "0") {
  62. if (this.data.red == "1") {
  63. this._redPoint.getComponent("YZ_ActionScale").isRunAction = false;
  64. }
  65. }
  66. else {
  67. this._redPoint && this._redPoint.destroy();
  68. }
  69. }
  70. };
  71. GameItem.prototype.init = function (data, location) {
  72. this.data = data;
  73. this._dataDirty = true;
  74. this._location = location;
  75. var checkSubString = [YZ_Constant_1.SubLocation.isBoxInsertAd, YZ_Constant_1.SubLocation.isBeforGameOverAd, YZ_Constant_1.SubLocation.isVerticalPanel];
  76. if (checkSubString.indexOf(this._location) > -1) {
  77. this._subNameLength = 6;
  78. }
  79. else if (this._location == YZ_Constant_1.SubLocation.isMoreGame) {
  80. this._subNameLength = 8;
  81. }
  82. };
  83. GameItem.prototype.update = function (dt) {
  84. if (this._dataDirty) {
  85. this._dataDirty = false;
  86. this.updateItem();
  87. }
  88. };
  89. GameItem.prototype.onEnable = function () {
  90. var _this = this;
  91. if (!this.data)
  92. return;
  93. this.node.on(cc.Node.EventType.TOUCH_END, function (event) {
  94. if (PlatUtils_1.default.IsDouyin) {
  95. Utils_1.utils.Tool_Douyin.showMoreGamesModal();
  96. return;
  97. }
  98. _this._postClickData(_this.data.appid);
  99. if (_this.data.is_jump && _this.data.is_jump == "true" && _this.data.appid) {
  100. Utils_1.utils.showLog("直接跳转!", _this.data.appid);
  101. Utils_1.utils.navigateToMiniGame(_this.data, function (ret) {
  102. if (ret) {
  103. // 上报数据
  104. if (_this.data && _this.data.appid) {
  105. _this._postData(_this.data.appid);
  106. }
  107. }
  108. });
  109. }
  110. else if (_this.data.is_jump && _this.data.is_jump == "false" && _this.data.qr_code) {
  111. if (PlatUtils_1.default.IsWechat) {
  112. Utils_1.utils.showLog("二维码跳转!", _this.data.qr_code);
  113. Utils_1.utils.wechatTool.previewImage(_this.data.qr_code);
  114. // 上报数据
  115. if (_this.data && _this.data.appid) {
  116. _this._postData(_this.data.appid);
  117. }
  118. }
  119. else {
  120. Utils_1.utils.showLog("不支持二维码跳转!");
  121. }
  122. }
  123. else {
  124. Utils_1.utils.showLog("没有is_jump直接跳转!", _this.data.appid);
  125. if (_this.data.appid) {
  126. Utils_1.utils.navigateToMiniGame(_this.data, function (ret) {
  127. if (ret) {
  128. // 上报数据
  129. if (_this.data.appid) {
  130. _this._postData(_this.data.appid);
  131. }
  132. }
  133. });
  134. }
  135. }
  136. }, this);
  137. };
  138. GameItem.prototype.onDisable = function () {
  139. this.node.targetOff(this);
  140. };
  141. GameItem.prototype.updateItem = function () {
  142. var _this = this;
  143. if (this.data) {
  144. if (this.data.name) {
  145. var gameName = this.data.name;
  146. if (this.data.name.length > this._subNameLength) {
  147. gameName = gameName.slice(0, this._subNameLength);
  148. gameName += "...";
  149. }
  150. this.labelName.string = gameName;
  151. this.labelShadow.string = gameName;
  152. }
  153. if (this.data.icon) {
  154. CompatibleTool_1.default.LoadRes(this.data.icon, function (err, texture) {
  155. if (!err && cc.isValid(_this) && _this.icon && _this.icon.spriteFrame) {
  156. _this.icon.spriteFrame = new cc.SpriteFrame(texture);
  157. }
  158. });
  159. }
  160. }
  161. else {
  162. this.mask.active = false;
  163. }
  164. };
  165. /**
  166. * 上报跳转成功
  167. * @param appid
  168. */
  169. GameItem.prototype._postData = function (appid) {
  170. Utils_1.utils.postDataByLocation(appid, this._location, 1);
  171. };
  172. /**
  173. * 上报点击
  174. * @param appid
  175. */
  176. GameItem.prototype._postClickData = function (appid) {
  177. Utils_1.utils.postDataByLocation(appid, this._location, 0);
  178. };
  179. GameItem = __decorate([
  180. ccclass
  181. ], GameItem);
  182. return GameItem;
  183. }(cc.Component));
  184. exports.default = GameItem;
  185. cc._RF.pop();