YZ_StatementRecommentAd.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { utils } from "./Utils";
  2. import QCrossWidgetItem from "./QCrossWidgetItem";
  3. import AldUtils from "./AldUtils";
  4. import PlatUtils from "./PlatUtils";
  5. import YZ_NativeItem from "./YZ_NativeItem";
  6. import { SubLocation, BannerLocation } from "./YZ_Constant";
  7. import List from "./List";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class YZ_StatementRecommentAd extends cc.Component {
  11. private _jumpList: any = null;
  12. private _items: QCrossWidgetItem[] = [];
  13. listView: List = null;
  14. _pageItem: cc.Node = null;
  15. _pageRecItem: cc.Node = null;
  16. _recListNode: cc.Node = null;
  17. public nativeData: any = null;
  18. private _nativeAd: cc.Node = null;
  19. public showNativeAd: boolean = true; //是否显示原生广告
  20. public yzItem: YZ_NativeItem = null;
  21. _nativeIsShow: boolean = false;
  22. onLoad() {
  23. this._recListNode = this.node.getChildByName("RecList");
  24. this.listView = this._recListNode.getChildByName("ScrollView").getComponent(List);
  25. this._nativeAd = this.node.getChildByName("nativeAd");
  26. AldUtils.SendEvent("显示结算推荐组件");
  27. }
  28. start() {
  29. if (this.showNativeAd) {
  30. this._recListNode.active = false;
  31. this.yzItem = this._nativeAd.getComponent("YZ_NativeItem");
  32. this.yzItem.showType = 1;
  33. utils.adManager.createNativeAd(null,this.yzItem);
  34. utils.showLog("交叉推广调用原生广告《《《《《《《");
  35. } else {
  36. this._recListNode.active = true;
  37. this._jumpList = utils.getRecommondGameList();
  38. if (this._jumpList && this._jumpList.length > 0) {
  39. this._initWidget();
  40. this.listView.numItems = this._jumpList.length;
  41. } else {
  42. cc.warn("交叉推广数据为null, 6元素交叉推广组件不显示!");
  43. this.node.destroy();
  44. }
  45. }
  46. }
  47. hideLastNode() {
  48. for (let i = 5; i > 2; i--) {
  49. this._items[i].node.active = false;
  50. }
  51. }
  52. update(dt) {
  53. if (this.yzItem && this.yzItem.content && this.yzItem.content.active && !this._nativeIsShow) {
  54. this._nativeIsShow = false;
  55. this._recListNode.active = false;
  56. }
  57. if (this.autoScorll && !this.listView.scrollView.isScrolling()) {
  58. this.listView.content.y += dt * 150;
  59. this.listView._onScrolling();
  60. }
  61. }
  62. onListRender(item: cc.Node, idx: number) {
  63. let qcrossWidgetItem: QCrossWidgetItem = item.getComponent("QCrossWidgetItem");
  64. qcrossWidgetItem._location = SubLocation.isStatement;
  65. qcrossWidgetItem.getComponent("QCrossWidgetItem").init(this._jumpList[idx]);
  66. }
  67. autoScorll: boolean = false;
  68. private _initWidget() {
  69. if (utils.ServerConfig.st_recomment_is_hide_banner && utils.ServerConfig.st_recomment_is_hide_banner == "true") {
  70. utils.showLog("服务器配置显示结算互推后隐藏banner >>>");
  71. utils.adManager.HideBanner(BannerLocation.Game);
  72. utils.adManager.HideBanner(BannerLocation.Over);
  73. }
  74. this.scheduleOnce(() => {
  75. this.autoScorll = true;
  76. }, 1);
  77. utils.postRecommentShowData(SubLocation.isStatement);
  78. }
  79. }