YZ_RecommendGamesBanner.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { utils } from "./Utils";
  2. import YZ_ListView from "./YZ_ListView";
  3. import PlatUtils from "./PlatUtils";
  4. import { SubLocation } from "./YZ_Constant";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class YZ_RecommendGamesBanner extends cc.Component {
  8. _listView: YZ_ListView = null;
  9. _isInit: boolean = false;
  10. closeBtn: cc.Node = null;
  11. onLoad() {
  12. if (utils.otherConfig && utils.otherConfig.group) {
  13. this.node.group = utils.otherConfig.group;
  14. }
  15. this._listView = this.getComponentInChildren("YZ_ListView");
  16. this._listView.node.active = false;
  17. this.closeBtn = cc.find("bg/close", this.node);
  18. }
  19. onEnable() {
  20. utils.registerServerInitEvent(() => {
  21. this._initWidget();
  22. this.closeBtn.on(cc.Node.EventType.TOUCH_START, (event) => {
  23. this.node.destroy();
  24. });
  25. }, this);
  26. }
  27. onDisable() {
  28. utils.unregisterServerInitEvent(this);
  29. this.closeBtn.targetOff(this);
  30. }
  31. _initWidget() {
  32. if (this._isInit) return;
  33. if (utils.isShowRecommondGamesBanner()) {
  34. let data: any = utils.getRecommondGameList();
  35. if (data) {
  36. if (data.length > 0) {
  37. if (data.length >= 6) {
  38. this._isInit = true;
  39. this._listView.init(data);
  40. this._listView.node.active = true;
  41. utils.postRecommentShowData(SubLocation.isYzBanner);
  42. if (PlatUtils.IsOPPO) {
  43. utils.oppoTool.countYzBannerShowCount();
  44. utils.adManager.hideKyxBanner();
  45. }
  46. } else {
  47. cc.warn("交叉推广数据长度小于6");
  48. }
  49. } else {
  50. cc.warn("交叉推广数据长度为0");
  51. }
  52. } else {
  53. cc.warn("交叉推广数据为null!");
  54. }
  55. } else {
  56. this.node.destroy();
  57. }
  58. }
  59. }