| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import { _decorator, Component, Sprite, Label, SpriteFrame, Prefab, instantiate, Node } from 'cc';
- import { DataSystem } from '../../core/data/DataSystem';
- import { ResourceLoader } from '../../core/resourceManager/ResourceLoader';
- import { BitmapFont } from '../../core/ui/BitmapFont';
- import { DragSource } from '../../core/ui/drag/DragSource';
- import { DragSystem } from '../../core/ui/drag/DragSystem';
- import { UserHero, UserHeroData } from '../UserHeroData';
- import { FormationData } from './FormationData';
- import { HeroDragHelper } from './HeroDragHelper';
- const { ccclass, property, requireComponent } = _decorator;
- /**
- * 阵位英雄项
- * @author 袁浩
- */
- @ccclass('FormationHeroItem')
- @requireComponent(ResourceLoader)
- export class FormationHeroItem extends Component {
- @property({ tooltip: "统帅值", type: Label })
- public leaderLabel: Label;
- @property({ tooltip: "等级", type: Label })
- public lvLabel: Label;
- @property({ tooltip: "图标", type: Sprite })
- public avatorSprite: Sprite;
- @property({ tooltip: "星级", type: BitmapFont })
- public starBitmapLabel: BitmapFont;
- @property({ tooltip: "拖拽生成的预制体", type: Prefab })
- public dragPrefab: Prefab;
- @property({ tooltip: "品质框", type: Sprite })
- public qualityBorder: Sprite;
- @property({ tooltip: "所有品质框", type: [SpriteFrame] })
- public qualityBorderList: SpriteFrame[] = [];
- @property({ tooltip: "在阵上节点", type: Node })
- public inFormationNode: Node;
- public data: UserHero;
- public helper: HeroDragHelper;
- private dragSource: DragSource;
- start() {
- this.dragSource = this.getComponent(DragSource);
- }
- public async onDataChange(data: UserHero, index?: number) {
- if (!data) {
- this.node.active = false;
- return;
- }
- this.data = data;
- this.node.active = true;
- this.leaderLabel.string = data.client.commander + "";
- this.lvLabel.string = `Lv.${data.server.lv}`;
- let starString = "";
- for (let i = 0; i < data.server.star; i++) {
- starString += "0";
- }
- this.starBitmapLabel.string = starString;
- this.qualityBorder.spriteFrame = this.qualityBorderList[data.client.color - 1];
- let formation = DataSystem.getData(FormationData);
- this.inFormationNode.active = !!formation.getIDByHero(this.data.client.id);
- this.avatorSprite.spriteFrame = await this.getComponent(ResourceLoader).load(`images/general/texture/head_img/${data.client.hero_res}/spriteFrame`, SpriteFrame);
- }
- update() {
- if (this.data && DataSystem.watch(UserHeroData, this.data.client.id + "")) {
- this.onDataChange(this.data);
- }
- if (this.data && (
- DataSystem.watch(FormationData, "1") ||
- DataSystem.watch(FormationData, "2") ||
- DataSystem.watch(FormationData, "3") ||
- DataSystem.watch(FormationData, "4") ||
- DataSystem.watch(FormationData, "5")
- )) {
- this.onDataChange(this.data);
- }
- }
- public onDrag(isInTarget: boolean) {
- this.helper && this.helper.node.destroy();
- this.helper = null;
- let dragNode = instantiate(this.dragPrefab);
- dragNode.parent = DragSystem.touchNode;
- this.helper = dragNode.getComponent(HeroDragHelper);
- this.helper.data = this.data;
- this.helper.onDrag(this.dragSource, this.data);
- }
- public onDraging() {
- this.helper && (this.helper.onDraging(this.dragSource));
- }
- public onDrop() {
- this.helper && this.helper.node.destroy();
- this.helper = null;
- }
- }
|