6ece2b74-f75a-4509-9f8a-47552bcba0b7.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. "use strict";
  2. cc._RF.push(module, '6ece2t091pFCZ+KR1Ury6C3', 'GameBox');
  3. // common-plugin/Scripts/GameBox.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 _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  27. /**
  28. * 游戏盒子
  29. */
  30. var GameBox = /** @class */ (function (_super) {
  31. __extends(GameBox, _super);
  32. function GameBox() {
  33. var _this = _super !== null && _super.apply(this, arguments) || this;
  34. // onLoad () {}
  35. _this.slidePageView = null;
  36. _this.listContent = null;
  37. _this.topSlideNode = null;
  38. _this.recommentNode = null;
  39. _this.recommentBanner = null;
  40. _this._boxInfo = null;
  41. _this._dataDirty = false;
  42. _this._slideList = null;
  43. _this._appIdList = [];
  44. /**
  45. * 初始化监听事件
  46. */
  47. _this.newPage = null;
  48. return _this;
  49. }
  50. GameBox.prototype.onLoad = function () {
  51. this.initListener();
  52. };
  53. GameBox.prototype.onEnable = function () {
  54. var _this = this;
  55. this.postData();
  56. Utils_1.utils.registerServerInitEvent(function () {
  57. _this._setNodeVisible();
  58. }, this);
  59. };
  60. GameBox.prototype.onDisable = function () {
  61. Utils_1.utils.unregisterServerInitEvent(this);
  62. };
  63. GameBox.prototype._setNodeVisible = function () {
  64. this.initData();
  65. if (this._boxInfo) {
  66. this.initUi();
  67. }
  68. else {
  69. this.node.destroy();
  70. }
  71. };
  72. /**
  73. * 初始化UI
  74. */
  75. GameBox.prototype.initUi = function () {
  76. this.slidePageView.removeAllPages();
  77. this.listContent.removeAllChildren();
  78. Utils_1.utils.showLog("gamebox initUi");
  79. if (!this._boxInfo)
  80. return;
  81. var slideData = this._boxInfo.banners;
  82. var listData = this._boxInfo.infos;
  83. for (var i = 0; i < slideData.length; i++) {
  84. var slideNode = cc.instantiate(this.topSlideNode);
  85. var slideItem = slideNode.getComponent("GameBoxSlideItem");
  86. slideNode.active = true;
  87. slideItem.initData(slideData[i]);
  88. this.slidePageView.addPage(slideNode);
  89. }
  90. for (var i = 0; i < listData.length; i++) {
  91. var listNode = cc.instantiate(this.recommentNode);
  92. var listItem = listNode.getComponent("GameBoxListItem");
  93. var data = listData[i];
  94. listItem.init(data);
  95. this.listContent.addChild(listNode);
  96. if (data.banner) {
  97. var banner = cc.instantiate(this.recommentBanner);
  98. var slideItem = banner.getComponent("GameBoxSlideItem");
  99. banner.active = true;
  100. slideItem.initData(data.banner);
  101. this.listContent.addChild(banner);
  102. }
  103. }
  104. this.startAutoChange();
  105. };
  106. /**
  107. * 开启轮播
  108. */
  109. GameBox.prototype.startAutoChange = function () {
  110. var _this = this;
  111. this.schedule(function () {
  112. var count = _this.slidePageView.getPages().length;
  113. var index = _this.slidePageView.getCurrentPageIndex();
  114. index = ((index < count) && (index + 1 !== count)) ? (index + 1) : 0;
  115. _this.slidePageView.scrollToPage(index, 2);
  116. }, 3); //3秒一换
  117. };
  118. GameBox.prototype.initListener = function () {
  119. // var _pool = new cc.NodePool();
  120. // this.slidePageView.node.on('scroll-began', () => {
  121. // if (this.slidePageView.getCurrentPageIndex() == this.slidePageView.content.childrenCount - 1) {
  122. // if (!this.newPage) {
  123. // this.newPage = cc.instantiate(this.slidePageView.getPages()[0]);
  124. // }
  125. // this.slidePageView.addPage(this.newPage);
  126. // }
  127. // });
  128. // this.slidePageView.node.on('scroll-ended', () => {
  129. // if (this.slidePageView.getPages().length == 4) {
  130. // _pool.put(this.slidePageView.content.children[1]);
  131. // this.newPage = _pool.get();
  132. // this.slidePageView.getPages().splice(1, 1);
  133. // }
  134. // })
  135. };
  136. /**
  137. * 初始化数据
  138. * @param {boxInfo} 游戏盒子的json数据
  139. */
  140. GameBox.prototype.initData = function () {
  141. Utils_1.utils.showLog("gamebox initData");
  142. this._boxInfo = Utils_1.utils._wechatTool.gameBoxServerConfig;
  143. if (this._boxInfo) {
  144. Utils_1.utils.showLog("Gamebox 游戏盒子数据:", JSON.stringify(this._boxInfo));
  145. }
  146. else {
  147. Utils_1.utils.showLog("Gamebox 游戏盒子数据获取失败!", this._boxInfo);
  148. }
  149. };
  150. GameBox.prototype.postData = function () {
  151. var url = "https://apps.youlesp.com/gbs?m=rclickV2&app_id=100000000001&game_id=" + Utils_1.utils.config.wechatconfig.appID;
  152. Utils_1.utils.showLog("上报数据, url=", url);
  153. Utils_1.utils.commomHttpRequest(url, function (ret, data) {
  154. if (ret) {
  155. Utils_1.utils.showLog("数据上报成功!");
  156. }
  157. else {
  158. Utils_1.utils.showLog("数据上报失败!");
  159. }
  160. });
  161. };
  162. GameBox.prototype.update = function (dt) {
  163. if (this._dataDirty) {
  164. this._dataDirty = false;
  165. this.node.active = true;
  166. }
  167. };
  168. __decorate([
  169. property({ type: cc.PageView, tooltip: "顶部滚动视图" })
  170. ], GameBox.prototype, "slidePageView", void 0);
  171. __decorate([
  172. property({ type: cc.Node, tooltip: "推荐列表" })
  173. ], GameBox.prototype, "listContent", void 0);
  174. __decorate([
  175. property({ type: cc.Node, tooltip: "顶部的幻灯片节点" })
  176. ], GameBox.prototype, "topSlideNode", void 0);
  177. __decorate([
  178. property({ type: cc.Node, tooltip: "推荐列表节点" })
  179. ], GameBox.prototype, "recommentNode", void 0);
  180. __decorate([
  181. property({ type: cc.Node, tooltip: "推荐列表Banner节点" })
  182. ], GameBox.prototype, "recommentBanner", void 0);
  183. GameBox = __decorate([
  184. ccclass
  185. ], GameBox);
  186. return GameBox;
  187. }(cc.Component));
  188. exports.default = GameBox;
  189. cc._RF.pop();