UserBuffList.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { _decorator, Component, Node } from 'cc';
  2. import { BuffData } from '../battle/BuffData';
  3. import { DataSystem } from '../core/data/DataSystem';
  4. import { BuffItem } from './BuffItem';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('UserBuffList')
  7. export class UserBuffList extends Component {
  8. @property({ type: Node, tooltip: "内容节点" }) contentNode: Node;
  9. @property({ tooltip: "宝箱红包", type: [BuffItem] }) buffList: BuffItem[] = [];
  10. start() {
  11. this.setView();
  12. }
  13. update() {
  14. DataSystem.watch(BuffData, 'curBuffs') && this.setView();
  15. DataSystem.watch(BuffData, 'canUseCombination') && this.setView();
  16. }
  17. private async setView() {
  18. let buffData = DataSystem.getData(BuffData);
  19. let index = 0;
  20. if (buffData.canUseCombination) {
  21. this.buffList[0].setData(110004, true);
  22. index = 1;
  23. }
  24. for (let i = 0; i < buffData.curBuffs.length; i++) {
  25. if (index < this.buffList.length) {
  26. this.buffList[index++].setData(buffData.curBuffs[i]);
  27. }
  28. }
  29. for (let i = index; i < this.buffList.length; i++) {
  30. this.buffList[i].node.active = false;
  31. }
  32. }
  33. }