BaguaItem.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { _decorator, Component, Label, Sprite, Animation, SpriteFrame, Color, color } from "cc";
  2. import { DataSystem } from "../../core/data/DataSystem";
  3. import { ResourceLoader } from "../../core/resourceManager/ResourceLoader";
  4. import { ConfigData } from "../../data/ConfigData";
  5. import { Formation } from "./Formation";
  6. import { FormationData } from "./FormationData";
  7. const { ccclass, property, requireComponent } = _decorator;
  8. /**
  9. * 八卦信息
  10. * @author 袁浩
  11. */
  12. @ccclass('BaguaItem')
  13. @requireComponent(ResourceLoader)
  14. export class BaguaItem extends Component {
  15. @property({ tooltip: "八卦图标", type: Sprite })
  16. public baguaIcon: Sprite;
  17. @property({ tooltip: "八卦动画", type: Animation })
  18. public baguaAni: Animation;
  19. @property({ tooltip: "太极动画", type: Animation })
  20. public taiji: Animation;
  21. @property({ tooltip: "描述文本", type: Label })
  22. public desLabel: Label;
  23. @property({ tooltip: "攻击加成文本", type: Label })
  24. public attackLabel: Label;
  25. @property({ tooltip: "暴击加成文本", type: Label })
  26. public criLabel: Label;
  27. @property({ tooltip: "未激活文本颜色", type: Color })
  28. public noActiveColor: Color = color(255, 255, 255, 255);
  29. start() {
  30. }
  31. /**
  32. * 当列表项渲染
  33. * @param item 项节点
  34. * @param index 项索引
  35. */
  36. public async onDataChange(data: any) {
  37. let buffConfig = DataSystem.getData(ConfigData).get("buff");
  38. let buffList = data.activeBuff.split(",");
  39. let attackPer = 0;
  40. let cri = 0;
  41. for (let i = 0; i < buffList.length; i++) {
  42. attackPer += (buffConfig[buffList[i]].attackPer || 0);
  43. cri += (buffConfig[buffList[i]].cri || 0);
  44. }
  45. this.taiji.node.active = this.baguaAni.node.active = data.isActive;
  46. this.desLabel.string = data.des;
  47. this.attackLabel.string = `+${attackPer / 100}%`;
  48. this.criLabel.string = `+${cri / 100}%`;
  49. if (!data.isActive) {
  50. this.desLabel.color = this.criLabel.color = this.attackLabel.color = this.noActiveColor;
  51. }
  52. this.baguaIcon.spriteFrame = await this.getComponent(ResourceLoader).load(`images/general/texture/${data.icon}/spriteFrame`, SpriteFrame);
  53. this.baguaIcon.grayscale = !data.isActive;
  54. }
  55. }