import { _decorator, Component, Node, Sprite, SpriteFrame, Vec3, Button } from 'cc'; import { BuffData } from '../battle/BuffData'; import { DataSystem } from '../core/data/DataSystem'; import { ResourceLoader } from '../core/resourceManager/ResourceLoader'; import { WindowOpenMode } from '../core/ui/window/WindowOpenMode'; import { WindowSystem } from '../core/ui/window/WindowSystem'; import { ConfigData } from '../data/ConfigData'; import { BuffInfo } from './BuffInfo'; import { UserInfo } from './UserInfo'; const { ccclass, property, requireComponent } = _decorator; /**用户当前BUFF */ @ccclass('UserBuffInfo') @requireComponent(ResourceLoader) export class UserBuffInfo extends Component { @property({ type: Node, tooltip: "玩家当前BUFF" }) contentNode: Node; @property({ type: Button, tooltip: "BUFF按钮" }) buffBtn: Button; private buffConfig: any; start() { this.buffConfig = DataSystem.getData(ConfigData).get('buff'); for (let i = 0; i < 5; i++) { let node = new Node(); node.setScale(new Vec3(0.5, 0.5, 0.5)); node.addComponent(Sprite); node.addComponent(BuffInfo); this.contentNode.addChild(node); node.active = false; } } update() { DataSystem.watch(BuffData, 'curBuffs') && this.setBuffIcons(); DataSystem.watch(BuffData, 'canUseCombination') && this.setBuffIcons(); } private async setBuffIcons() { let buffData = DataSystem.getData(BuffData); let curBuffs = buffData.curBuffs.concat(); for (let i = 0; i < curBuffs.length; i++) { if (!this.buffConfig[curBuffs[i]].icon) { curBuffs.splice(i, 1); } } for (let i = 0; i < this.contentNode.children.length; i++) { let node = this.contentNode.children[i]; if (i < curBuffs.length) { if (node.getComponent(BuffInfo).buffId != curBuffs[i] && curBuffs[i] && this.buffConfig[curBuffs[i]].icon) { node.active = true; node.getComponent(BuffInfo).buffId = curBuffs[i]; node.getComponent(Sprite)!.spriteFrame = await this.getComponent(ResourceLoader).load('image/skillIcons/' + this.buffConfig[curBuffs[i]].icon + '/spriteFrame', SpriteFrame); } } else if (i == curBuffs.length && buffData.canUseCombination) { if (node.getComponent(BuffInfo).buffId != 999) { node.getComponent(BuffInfo).buffId = 999; node.active = true; node.getComponent(Sprite)!.spriteFrame = await this.getComponent(ResourceLoader).load('image/skillIcons/skill04/spriteFrame', SpriteFrame); } } else { node.getComponent(BuffInfo).buffId = -1; node.active = false; } } if (DataSystem.getData(BuffData).curBuffs.length > 0 || DataSystem.getData(BuffData).canUseCombination) { this.contentNode.active = true; } else { this.contentNode.active = false; } } private openBuffList() { WindowSystem.open('prefabs/ui/buff/buff', WindowOpenMode.NotCloseAndCover, []); } }