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();
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
import JNScrollViewItem from '../../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollViewItem';
|
||||
import { PlayerPetOV } from '../../../consts/API';
|
||||
import JNScrollViewItem from '../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollViewItem';
|
||||
import { PlayerPetOV } from '../../consts/API';
|
||||
import { sp } from 'cc';
|
||||
import { app } from '../../../App';
|
||||
import { UIPetAnim } from '../../../consts/GData';
|
||||
import { app } from '../../App';
|
||||
import { UIPetAnim } from '../../consts/GData';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('PetIconItem')
|
||||
export class PetIconItem extends JNScrollViewItem<PlayerPetOV> {
|
||||
@ccclass('IntoBattlePetIcon')
|
||||
export class IntoBattlePetIcon extends JNScrollViewItem<PlayerPetOV> {
|
||||
|
||||
@property(sp.Skeleton)
|
||||
spine:sp.Skeleton;
|
||||
@@ -16,11 +16,20 @@ export class PetIconItem extends JNScrollViewItem<PlayerPetOV> {
|
||||
@property(Node)
|
||||
select:Node;
|
||||
|
||||
//不可选中节点
|
||||
@property(Node)
|
||||
noselect:Node;
|
||||
|
||||
//是否被选中
|
||||
isSelect:boolean = false;
|
||||
|
||||
//是否不可选中
|
||||
isNoSelect:boolean = false;
|
||||
|
||||
onLoad(){
|
||||
this.onUpdateSelect();
|
||||
this.noselect.active = false;
|
||||
this.select.active = false;
|
||||
}
|
||||
|
||||
start(): void {
|
||||
@@ -34,6 +43,7 @@ export class PetIconItem extends JNScrollViewItem<PlayerPetOV> {
|
||||
onUpdateSelect(){
|
||||
|
||||
this.select.active = this.isSelect;
|
||||
this.noselect.active = this.isNoSelect;
|
||||
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ import JNLayerBase from '../../../../extensions/ngame/assets/ngame/ui/base/JNLay
|
||||
import { Prefab } from 'cc';
|
||||
import PlayerPetData from '../../data/PlayerPetData';
|
||||
import JNScrollView from '../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollView';
|
||||
import { PetIconItem } from '../Consts/Pet/PetIconItem';
|
||||
import { NodeEventType } from 'cc';
|
||||
import { sp } from 'cc';
|
||||
import { app } from '../../App';
|
||||
@@ -11,6 +10,7 @@ import { PlayerPetOV } from '../../consts/API';
|
||||
import { UIPetAnim } from '../../consts/GData';
|
||||
import { GUI } from '../UIConfig';
|
||||
import PlayerTacticalData from '../../data/PlayerTacticalData';
|
||||
import { IntoBattlePetIcon } from './IntoBattlePetIcon';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//上阵页面
|
||||
@@ -55,35 +55,49 @@ export class IntoBattleView extends JNLayerBase {
|
||||
this.pets = PlayerPetData.getIns().getData();
|
||||
this.views.refreshData(this.pets);
|
||||
|
||||
//设置不可选中
|
||||
this.views.getItems<IntoBattlePetIcon>().forEach(item => {
|
||||
if(PlayerTacticalData.getIns().getTacticalInfo().indexOf(item.data.petId) != -1)
|
||||
item.isNoSelect = true; //如果在阵法里则不可选中
|
||||
})
|
||||
|
||||
//向子节点添加点击事件
|
||||
this.views.addItemEvent(NodeEventType.TOUCH_START,this.onClickItem.bind(this));
|
||||
|
||||
this.onUpdateSelect();
|
||||
|
||||
}
|
||||
|
||||
//刷新选中
|
||||
onUpdateSelect(){
|
||||
|
||||
//默认都不选中
|
||||
this.views.getItems<PetIconItem>().forEach(item => {
|
||||
this.views.getItems<IntoBattlePetIcon>().forEach(item => {
|
||||
item.isSelect = false;
|
||||
item.onUpdateSelect();
|
||||
})
|
||||
|
||||
//设置选中
|
||||
if(this.index != -1){
|
||||
let current = this.views.getItems<PetIconItem>()[this.index]
|
||||
let current = this.views.getItems<IntoBattlePetIcon>()[this.index]
|
||||
current.isSelect = true;
|
||||
current.onUpdateSelect();
|
||||
}
|
||||
|
||||
//显示选中宠物
|
||||
this.spine.skeletonData = app.battleRes.roleSpine[this.pets[this.index].petTbId];
|
||||
this.spine.setAnimation(0,UIPetAnim.std,true);
|
||||
//显示选中宠物
|
||||
this.spine.skeletonData = app.battleRes.roleSpine[this.pets[this.index].petTbId];
|
||||
this.spine.setAnimation(0,UIPetAnim.std,true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//点击Item
|
||||
onClickItem(index:number){
|
||||
|
||||
//判断是否不可选中
|
||||
if(this.views.getItems<IntoBattlePetIcon>()[index].isNoSelect) {
|
||||
app.layer.Open(GUI.Tips,{text:"当前宠物已上阵"})
|
||||
return;
|
||||
}
|
||||
|
||||
//设置当前选中
|
||||
this.index = index;
|
||||
@@ -101,7 +115,7 @@ export class IntoBattleView extends JNLayerBase {
|
||||
}
|
||||
|
||||
//修改上阵信息
|
||||
await PlayerTacticalData.getIns().UpdateIndexTactical(this.index,this.pets[this.index].petId);
|
||||
await PlayerTacticalData.getIns().UpdateIndexTactical(this.tIndex,this.pets[this.index].petId);
|
||||
|
||||
//上阵完 关闭页面
|
||||
app.layer.CloseNode(this.node);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { v3 } from "cc";
|
||||
import { JNLayerAnim, JNLayerInfo } from "../../../extensions/ngame/assets/ngame/ui/JNLayer";
|
||||
import { JNLayerAnim, JNLayerAnimInfo, JNLayerInfo } from "../../../extensions/ngame/assets/ngame/ui/JNLayer";
|
||||
|
||||
export enum GLayer{
|
||||
View = "View",
|
||||
@@ -28,31 +28,29 @@ export enum GUI{
|
||||
}
|
||||
|
||||
|
||||
//常用动画
|
||||
const BackOutScale:JNLayerAnimInfo = {
|
||||
front:JNLayerAnim.BackOutOpen,
|
||||
back:JNLayerAnim.BackInClose
|
||||
}
|
||||
|
||||
|
||||
//系统UI
|
||||
const UISystemConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
[GUI.Tips]:{
|
||||
layer:GLayer.Tips,
|
||||
uri: "prefab/ui/系统页面/提示/TipsView",
|
||||
anims:{
|
||||
front:JNLayerAnim.BackOutOpen,
|
||||
back:JNLayerAnim.BackInClose
|
||||
}
|
||||
anims:BackOutScale
|
||||
},
|
||||
[GUI.SelectionBox]:{
|
||||
layer:GLayer.Tips,
|
||||
uri: "prefab/ui/系统页面/选择提示/SelectionBox",
|
||||
anims:{
|
||||
front:JNLayerAnim.BackOutOpen,
|
||||
back:JNLayerAnim.BackInClose
|
||||
},
|
||||
anims:BackOutScale,
|
||||
},
|
||||
[GUI.Login]:{
|
||||
layer:GLayer.Popup,
|
||||
uri: "prefab/ui/系统页面/LoginView",
|
||||
anims:{
|
||||
front:JNLayerAnim.BackOutOpen,
|
||||
back:JNLayerAnim.BackInClose
|
||||
}
|
||||
anims:BackOutScale
|
||||
},
|
||||
[GUI.Loading]:{
|
||||
layer:GLayer.View,
|
||||
@@ -67,7 +65,7 @@ const UISystemConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
//主页UI
|
||||
const UIMainConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
[GUI.MainChat]:{
|
||||
layer:GLayer.View,
|
||||
layer:GLayer.Popup,
|
||||
uri: "prefab/ui/主页/聊天/MainChatView",
|
||||
anims:{
|
||||
front:JNLayerAnim.Enlarge,
|
||||
@@ -76,6 +74,11 @@ const UIMainConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
backInfo:{key:"position",start:v3(0,0,0),end:v3(0,-1280,0)}
|
||||
}
|
||||
},
|
||||
[GUI.IntoBattleView]:{
|
||||
layer:GLayer.Popup,
|
||||
uri: "prefab/ui/阵法/阵法选择页面",
|
||||
anims:BackOutScale,
|
||||
},
|
||||
}
|
||||
|
||||
//新手引导页面
|
||||
@@ -84,18 +87,12 @@ const UINoviceConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
[GUI.NoviceNamingView]:{
|
||||
layer:GLayer.Popup,
|
||||
uri: "prefab/ui/新手引导页面/NoviceNamingView",
|
||||
anims:{
|
||||
front:JNLayerAnim.BackOutOpen,
|
||||
back:JNLayerAnim.BackInClose
|
||||
}
|
||||
anims:BackOutScale
|
||||
},
|
||||
[GUI.NoviceSelectPetView]:{
|
||||
layer:GLayer.Popup,
|
||||
uri: "prefab/ui/新手引导页面/NoviceSelectPetView",
|
||||
anims:{
|
||||
front:JNLayerAnim.BackOutOpen,
|
||||
back:JNLayerAnim.BackInClose
|
||||
}
|
||||
anims:BackOutScale
|
||||
},
|
||||
|
||||
}
|
||||
@@ -121,14 +118,6 @@ export const UIConfig:{ [key: string]: JNLayerInfo; } = {
|
||||
backInfo:{key:"position",start:v3(0,0,0),end:v3(-720,0,0)}
|
||||
},
|
||||
},
|
||||
[GUI.IntoBattleView]:{
|
||||
layer:GLayer.View,
|
||||
uri: "prefab/ui/阵法/IntoBattleView",
|
||||
anims:{
|
||||
front:JNLayerAnim.BackOutOpen,
|
||||
back:JNLayerAnim.BackInClose
|
||||
},
|
||||
},
|
||||
...UISystemConfig, //系统页面
|
||||
...UINoviceConfig, //新手引导页面
|
||||
...UIMainConfig, //主页面
|
||||
|
Reference in New Issue
Block a user