BuffItem.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { _decorator, Component, Node, Sprite, Label, RichText, SpriteFrame } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
  4. import { StringUtils } from '../core/utils/StringUtils';
  5. import { ConfigData } from '../data/ConfigData';
  6. import { Config } from '../launch/Config';
  7. const { ccclass, property, requireComponent } = _decorator;
  8. @ccclass('BuffItem')
  9. @requireComponent(ResourceLoader)
  10. export class BuffItem extends Component {
  11. @property({ type: Node, tooltip: "技能背景" }) skillNode: Node;
  12. @property({ type: Node, tooltip: "buff背景" }) buffNode: Node;
  13. @property({ type: Sprite, tooltip: "icon图标" }) iconSprite: Sprite;
  14. @property({ type: Label, tooltip: "icon图标" }) nameLabel: Label;
  15. @property({ type: RichText, tooltip: "描述" }) desRichText: RichText;
  16. start() {
  17. }
  18. public async setData(id: number, isSkill: boolean = false) {
  19. this.skillNode.active = isSkill;
  20. this.buffNode.active = !isSkill;
  21. let configData = isSkill ? DataSystem.getData(ConfigData).get('skill') : DataSystem.getData(ConfigData).get('buff');
  22. if (isSkill) {
  23. this.desRichText.string = '<outline color=#000000 width=1>' + StringUtils.getRichText(configData[id].des1) + '</outline>';
  24. this.iconSprite.spriteFrame = await this.getComponent(ResourceLoader).load<SpriteFrame>('image/skillIcons/skill04/spriteFrame', SpriteFrame);
  25. this.node.active = true;
  26. } else if (configData[id].icon) {
  27. this.desRichText.string = '<outline color=#000000 width=1>' + StringUtils.getRichText(configData[id].des) + '</outline>';
  28. this.iconSprite.spriteFrame = await this.getComponent(ResourceLoader).load<SpriteFrame>('image/skillIcons/' + configData[id].icon + '/spriteFrame', SpriteFrame);
  29. this.node.active = true;
  30. }
  31. this.nameLabel.string = configData[id].name || '';
  32. }
  33. }