HeroDragingHelper.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import { _decorator, Component } from 'cc';
  2. import { DragSource } from '../../core/ui/drag/DragSource';
  3. import List from '../../core/ui/virtualList/List';
  4. import { FormationHeroItem } from './FormationHeroItem';
  5. import { FormationOne } from './FormationOne';
  6. const { ccclass, property } = _decorator;
  7. /**
  8. * 英雄拖拽中辅助组件
  9. * @author 袁浩
  10. */
  11. @ccclass('HeroDragingHelper')
  12. export class HeroDragingHelper extends Component {
  13. @property({ tooltip: "武将列表", type: List })
  14. public list: List;
  15. @property({ tooltip: "阵位列表", type: [FormationOne] })
  16. public formationList: FormationOne[] = [];
  17. public onDraging(source: DragSource, inTarget: boolean) {
  18. let helper = (source.getComponent(FormationHeroItem) || source.getComponent(FormationOne)).helper;
  19. helper && (helper.node.active = inTarget);
  20. this.list.scrollView.enabled = !inTarget;
  21. this.checkSame(source, inTarget);
  22. }
  23. public onDrop(source: DragSource) {
  24. this.list.scrollView.enabled = true;
  25. this.checkSame(source, false);
  26. }
  27. private checkSame(dragSource: DragSource, isInTarget: boolean = false) {
  28. for (let i = 0; i < this.formationList.length; i++) {
  29. this.formationList[i].checkSame(dragSource, isInTarget);
  30. }
  31. }
  32. }