UserBuffInfo.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { _decorator, Component, Node, Sprite, SpriteFrame, Vec3, Button } from 'cc';
  2. import { BuffData } from '../battle/BuffData';
  3. import { DataSystem } from '../core/data/DataSystem';
  4. import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
  5. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  6. import { WindowSystem } from '../core/ui/window/WindowSystem';
  7. import { ConfigData } from '../data/ConfigData';
  8. import { BuffInfo } from './BuffInfo';
  9. import { UserInfo } from './UserInfo';
  10. const { ccclass, property, requireComponent } = _decorator;
  11. /**用户当前BUFF */
  12. @ccclass('UserBuffInfo')
  13. @requireComponent(ResourceLoader)
  14. export class UserBuffInfo extends Component {
  15. @property({ type: Node, tooltip: "玩家当前BUFF" }) contentNode: Node;
  16. @property({ type: Button, tooltip: "BUFF按钮" }) buffBtn: Button;
  17. private buffConfig: any;
  18. start() {
  19. this.buffConfig = DataSystem.getData(ConfigData).get('buff');
  20. for (let i = 0; i < 5; i++) {
  21. let node = new Node();
  22. node.setScale(new Vec3(0.5, 0.5, 0.5));
  23. node.addComponent(Sprite);
  24. node.addComponent(BuffInfo);
  25. this.contentNode.addChild(node);
  26. node.active = false;
  27. }
  28. }
  29. update() {
  30. DataSystem.watch(BuffData, 'curBuffs') && this.setBuffIcons();
  31. DataSystem.watch(BuffData, 'canUseCombination') && this.setBuffIcons();
  32. }
  33. private async setBuffIcons() {
  34. let buffData = DataSystem.getData(BuffData);
  35. let curBuffs = buffData.curBuffs.concat();
  36. for (let i = 0; i < curBuffs.length; i++) {
  37. if (!this.buffConfig[curBuffs[i]].icon) {
  38. curBuffs.splice(i, 1);
  39. }
  40. }
  41. for (let i = 0; i < this.contentNode.children.length; i++) {
  42. let node = this.contentNode.children[i];
  43. if (i < curBuffs.length) {
  44. if (node.getComponent(BuffInfo).buffId != curBuffs[i] && curBuffs[i] && this.buffConfig[curBuffs[i]].icon) {
  45. node.active = true;
  46. node.getComponent(BuffInfo).buffId = curBuffs[i];
  47. node.getComponent(Sprite)!.spriteFrame = await this.getComponent(ResourceLoader).load<SpriteFrame>('image/skillIcons/' + this.buffConfig[curBuffs[i]].icon + '/spriteFrame', SpriteFrame);
  48. }
  49. } else if (i == curBuffs.length && buffData.canUseCombination) {
  50. if (node.getComponent(BuffInfo).buffId != 999) {
  51. node.getComponent(BuffInfo).buffId = 999;
  52. node.active = true;
  53. node.getComponent(Sprite)!.spriteFrame = await this.getComponent(ResourceLoader).load<SpriteFrame>('image/skillIcons/skill04/spriteFrame', SpriteFrame);
  54. }
  55. } else {
  56. node.getComponent(BuffInfo).buffId = -1;
  57. node.active = false;
  58. }
  59. }
  60. if (DataSystem.getData(BuffData).curBuffs.length > 0 || DataSystem.getData(BuffData).canUseCombination) {
  61. this.contentNode.active = true;
  62. } else {
  63. this.contentNode.active = false;
  64. }
  65. }
  66. private openBuffList() {
  67. WindowSystem.open('prefabs/ui/buff/buff', WindowOpenMode.NotCloseAndCover, []);
  68. }
  69. }