GameBoxListItem.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { utils } from "./Utils";
  2. import PlatUtils from "./PlatUtils";
  3. import GameItem from "./GameItem";
  4. import GameBoxListGameItem from "./GameBoxListGameItem";
  5. const { ccclass, property } = cc._decorator;
  6. /**
  7. * 推荐列表节点
  8. */
  9. @ccclass
  10. export default class GameBoxListItem extends cc.Component {
  11. data: any = null;
  12. titleLabel: cc.RichText = null;
  13. _dataDirty: boolean = false;
  14. _gameList: cc.Node = null;
  15. _gameItems: GameBoxListGameItem[] = [];
  16. onLoad() {
  17. this.titleLabel = this.node.getChildByName("titleLabel").getComponent(cc.RichText);
  18. this._gameList = this.node.getChildByName("listLay");
  19. for (let i = 0; i < this._gameList.childrenCount; i++) {
  20. this._gameItems.push(this._gameList.children[i].getComponent("GameBoxListGameItem"));
  21. this._gameList.children[i].active = false;
  22. }
  23. }
  24. public init(data: any) {
  25. this.data = data;
  26. this._dataDirty = true;
  27. }
  28. update(dt: number) {
  29. if (this._dataDirty) {
  30. this._dataDirty = false;
  31. this.updateItem();
  32. }
  33. }
  34. updateItem() {
  35. if (this.data) {
  36. utils.showLog("boxList: ", this.data);
  37. if (this.data.title) {
  38. this.titleLabel.string = "<b>" + this.data.title + "</b>";
  39. }
  40. if (this.data.infos && this.data.infos.length > 0) {
  41. for (let i = 0; i < this.data.infos.length; i++) {
  42. if (this._gameItems[i]) {
  43. this._gameItems[i].init(this.data.infos[i]);
  44. this._gameItems[i].node.active = true;
  45. }
  46. }
  47. }
  48. }
  49. }
  50. }