mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交拖拽阵法
This commit is contained in:
@@ -5,6 +5,10 @@ import { GUI } from '../../UIConfig';
|
||||
import { sp } from 'cc';
|
||||
import { UIPetAnim } from '../../../consts/GData';
|
||||
import PlayerPetData from '../../../data/PlayerPetData';
|
||||
import { Vec3 } from 'cc';
|
||||
import { NodeEventType } from 'cc';
|
||||
import { EventTouch } from 'cc';
|
||||
import JNodeDrag from '../../../../../extensions/ngame/assets/ngame/util/components/JNodeDrag';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('PlayerTacticalItem')
|
||||
@@ -21,12 +25,20 @@ export class PlayerTacticalItem extends Component {
|
||||
@property(Node)
|
||||
havePet:Node;
|
||||
|
||||
//拖拽
|
||||
@property(JNodeDrag)
|
||||
drag:JNodeDrag;
|
||||
|
||||
//当前上阵的宠物
|
||||
petId:number;
|
||||
|
||||
//初始位置
|
||||
initPos:Vec3;
|
||||
|
||||
//初始化阵法
|
||||
onInit(index:number){
|
||||
this.index = index;
|
||||
this.initPos = this.node.position;
|
||||
}
|
||||
|
||||
protected start(): void {
|
||||
@@ -64,6 +76,10 @@ export class PlayerTacticalItem extends Component {
|
||||
|
||||
//打开选择阵法宠物
|
||||
onClick(){
|
||||
|
||||
//如果拖拽了则不生效点击事件
|
||||
if(this.drag.isMove) return;
|
||||
|
||||
//如果没有宠物则弹出选择宠物 负责 删除宠物
|
||||
if(this.petId){
|
||||
//移除宠物
|
||||
@@ -83,6 +99,24 @@ export class PlayerTacticalItem extends Component {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//交换阵法
|
||||
onExchange(item:PlayerTacticalItem){
|
||||
let rootIndex = this.index;
|
||||
this.index = item.index;
|
||||
item.index = rootIndex;
|
||||
|
||||
//更新拖拽位置
|
||||
let rootOriginal = this.drag.original;
|
||||
this.drag.onUpdateOriginal(item.drag.original);
|
||||
item.drag.onUpdateOriginal(rootOriginal);
|
||||
}
|
||||
|
||||
addMoveEvent(fun:Function){
|
||||
this.drag.addMoveEvent((e) => {
|
||||
fun(this,e);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,9 @@ import { _decorator, Component, Node } from 'cc';
|
||||
import { PlayerTacticalItem } from './PlayerTacticalItem';
|
||||
import { app } from '../../../App';
|
||||
import { PlayerTacticalEvent } from '../../../data/PlayerTacticalData';
|
||||
import JNodeDrag from '../../../../../extensions/ngame/assets/ngame/util/components/JNodeDrag';
|
||||
import { EventTouch } from 'cc';
|
||||
import { UITransform } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
@@ -20,6 +23,7 @@ export class PlayerTacticalView extends Component {
|
||||
this.items = this.node.getComponentsInChildren(PlayerTacticalItem);
|
||||
this.items.forEach((item,index) => {
|
||||
item.onInit(index); //初始化阵法下标
|
||||
item.addMoveEvent(this.onMoveItem.bind(this));
|
||||
});
|
||||
|
||||
this.onUpdateView();
|
||||
@@ -28,6 +32,27 @@ export class PlayerTacticalView extends Component {
|
||||
|
||||
}
|
||||
|
||||
//移动子节点
|
||||
onMoveItem(root:PlayerTacticalItem,e:EventTouch){
|
||||
|
||||
//获取接触的节点(除了自己)
|
||||
this.items.forEach(item => {
|
||||
|
||||
//排除自己
|
||||
if(item == root) return;
|
||||
//排除在移动的节点
|
||||
if(!(item.node.position.equals(item.drag.original))) return;
|
||||
|
||||
//检测接触
|
||||
if(item.getComponent(UITransform).isHit(e.getUILocation())){
|
||||
//如果手指接触了 则 将接触的阵法移动到自己
|
||||
item.onExchange(root);
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
protected onDestroy(): void {
|
||||
this.offEvent();
|
||||
}
|
||||
|
Reference in New Issue
Block a user