提交捕捉

This commit is contained in:
PC-20230316NUNE\Administrator
2023-11-17 18:29:39 +08:00
parent 62b72bdcfc
commit cb64a6c25f
59 changed files with 4757 additions and 953 deletions

View File

@@ -25,10 +25,12 @@ import { StorageData, StorageEnum } from "./consts/GData";
import { JAPI, JAPIConfig } from "../../extensions/ngame/assets/ngame/util/JAPI";
import { AppData } from "./AppData";
let APIPath = `http://localhost:8080`
let WsPath = `ws://localhost:8080/websocket`
// let APIPath = `https://api.pet.jisol.cn`
// let WsPath = `wss://api.pet.jisol.cn/websocket`
// let APIPath = `http://localhost:8080`
// let WsPath = `ws://localhost:8080/websocket`
// let APIPath = `http://192.168.0.123:8080`
// let WsPath = `ws://192.168.0.123:8080/websocket`
let APIPath = `https://api.pet.jisol.cn`
let WsPath = `wss://api.pet.jisol.cn/websocket`
//重写UI
class JNGLayer extends JNLayer{

View File

@@ -2,6 +2,7 @@ import { _decorator, Component, director, instantiate, Node, Prefab } from 'cc';
import { app } from './App';
import { Env, JNGame } from '../../extensions/ngame/assets/ngame/JNGame';
import { JNSyncAction } from '../../extensions/ngame/assets/ngame/sync/JNSyncAction';
import { GOnHookPets } from '../../extensions/ngame/assets/ngame/message/proto';
const { ccclass, property } = _decorator;
@ccclass('Main')

View File

@@ -1,6 +1,7 @@
import { _decorator, Component, Node, Prefab } from 'cc';
import { Camera } from 'cc';
import GBattleModeManager from './battle/GBattleModeManager';
import { GData } from './consts/GData';
const { ccclass, property } = _decorator;
@ccclass('WorldCanvas')
@@ -18,6 +19,8 @@ export class WorldCanvas extends Component {
async onLoad(){
GData.WorldCanvas = this;
//重置相机位置
this.camera.node.setWorldPosition(0,0,1000);

View File

@@ -58,7 +58,7 @@ export default abstract class GRoleBase<T> extends GObject<T>{
//攻击回调
attackCallbacks:Function[] = [];
//添加击回调
//添加击回调
addAttackCallback(fun:Function){this.attackCallbacks.push(fun)};
get():this{
@@ -147,7 +147,7 @@ export default abstract class GRoleBase<T> extends GObject<T>{
onHit(){
// return;
this.blood -= 10;
this.hitCallbacks.forEach(fun => fun());
this.hitCallbacks.forEach(fun => fun(this,10));
//检测是否死亡
if(this.blood <= 0){
//关闭状态机

View File

@@ -0,0 +1,18 @@
import { _decorator } from "cc";
import GRoleExpandBase from "../GRoleExpandBase";
import { GOnHookPet } from "../../../../../../../extensions/ngame/assets/ngame/message/proto";
const { ccclass, property } = _decorator;
/**
* 无限模式 野怪 扩展类
*/
@ccclass('GRoleOnHookCreepsExpand')
export default class GRoleOnHookCreepsExpand extends GRoleExpandBase<{}>{
//野怪
creeps:GOnHookPet;
}

View File

@@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "edf60f56-5d3e-48d1-90b4-6deef4b5635c",
"uuid": "3a21518a-766b-4f61-a59f-3e8825cf08f0",
"files": [],
"subMetas": {},
"userData": {}

View File

@@ -1,13 +1,12 @@
import { _decorator } from "cc";
import GRoleDefault from "../../GRoleDefault";
import GRoleExpandBase from "../GRoleExpandBase";
const { ccclass, property } = _decorator;
/**
*
*
*/
@ccclass('GRoleDefault')
export default class GRoleOnHookExpand extends GRoleExpandBase<{}>{
@ccclass('GRoleOnHookPlayerExpand')
export default class GRoleOnHookPlayerExpand extends GRoleExpandBase<{}>{
//角色Id
petId:number;

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "3c2ff03b-a7e4-4afb-bb3c-ceacb17300ae",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -17,11 +17,13 @@ import { v2 } from "cc";
import GFSMOnHookMode from "./OnHook/GFSMOnHookMode";
import { TB } from "../../../resources/config/data/schema";
import PlayerTacticalData, { PlayerTacticalEvent } from "../../data/PlayerTacticalData";
import GRoleOnHookExpand from "../base/role/expand/OnHook/GRoleOnHookExpand";
import GRoleOnHookPlayerExpand from "../base/role/expand/OnHook/GRoleOnHookPlayerExpand";
import PlayerPetData from "../../data/PlayerPetData";
import { GUI } from "../../ui/UIConfig";
import { GAction } from "../../consts/GAction";
import { GActionType } from "../../consts/GActionType";
import { GOnHookPet, GOnHookPets } from "../../../../extensions/ngame/assets/ngame/message/proto";
import GOnHookManager from "../../manager/battle/mode/GOnHookManager";
import GRoleOnHookCreepsExpand from "../base/role/expand/OnHook/GRoleOnHookCreepsExpand";
import { ModeRenderEvent } from "../../ui/Consts/Game/ModeRender";
const { ccclass, property } = _decorator;
//挂机模式状态
@@ -45,18 +47,8 @@ export interface GOnHookInfo{
roles: TB.TbGRole[];
}
//野怪
interface GOnHookPet{
key:string; //野怪唯一Id
petTbId:number; //野怪配置表Id
}
//野怪列表
interface GOnHookPets{
pets:GOnHookPet[];
}
/**
* 挂机模式 无限出现小怪 (不是联机模式 该模式支持使用本地数据)
* 挂机模式 无限出现小怪 (不是联机模式 该模式支持使用本地数据 和 API)
*/
@ccclass('GOnHookMode')
export default class GOnHookMode extends GBaseMode<{}>{
@@ -115,21 +107,6 @@ export default class GOnHookMode extends GBaseMode<{}>{
//是否允许攻击
isAllowAttack:boolean = false;
//野怪列表
_wildlifes:GOnHookPets;
get wildlifes(){
//如果没有野怪了 则 向服务器生成
if(!this._wildlifes || !(this._wildlifes.pets.length)){
//生成
this.onSpawnWildlife();
return null;
}
return this._wildlifes;
}
set wildlifes(data:GOnHookPets){
this._wildlifes = data;
}
//添加监听事件
addEvent(){
app.event.on(PlayerTacticalEvent.UPDATE_TACTICAL,this.onUpdatePlayerPet,this);
@@ -185,18 +162,7 @@ export default class GOnHookMode extends GBaseMode<{}>{
// this.onResetGenerateEnemy();
}
//生成野怪
onSpawnWildlife(){
//获取服务器野怪
app.socket.SendBack(GAction.MODE_ON_HOOK_SPAWN_PET,{
type:GActionType.GOnHookPets,
fun:(info:GOnHookPets) => {
this.wildlifes = info;
}
})
}
//更新玩家宠物
onUpdatePlayerPet(){
//获取玩家阵容
@@ -205,7 +171,7 @@ export default class GOnHookMode extends GBaseMode<{}>{
//移除不再阵容中的宠物
let roles = [...this.getOnesRoleAlive(GOnHookModePlayerEnum.PLAYER)]
roles.forEach(role => {
let expand = role.getComponent(GRoleOnHookExpand);
let expand = role.getComponent(GRoleOnHookPlayerExpand);
//如果宠物不再阵容中 则 移除宠物
if(infos.indexOf(expand.petId) < 0){
//移除宠物
@@ -267,7 +233,7 @@ export default class GOnHookMode extends GBaseMode<{}>{
//如果场上有这个宠物则更新阵法位置
let passRole:GRoleDefault;
this.playerRoles.forEach(role => {
if(role.getComponent(GRoleOnHookExpand).petId == petId)
if(role.getComponent(GRoleOnHookPlayerExpand).petId == petId)
passRole = role;
})
if(passRole){
@@ -285,10 +251,21 @@ export default class GOnHookMode extends GBaseMode<{}>{
}
let role = this.onGenRole(GOnHookModePlayerEnum.PLAYER,index,TD.TbGRole.get(info.petTbId));
//向宠物添加 OnHook 扩展
let expand = role.node.addComponent(GRoleOnHookExpand);
let expand = role.node.addComponent(GRoleOnHookPlayerExpand);
expand.petId = petId;
}
//生成野怪
onGenCreeps(index:number,creeps:GOnHookPet){
let role = this.onGenRole(GOnHookModePlayerEnum.ENEMY,index,TD.TbGRole.get(creeps.petTbId));
//向野怪添加扩展
let expand = role.node.addComponent(GRoleOnHookCreepsExpand);
expand.creeps = creeps;
}
//生成宠物
onGenRole(type: GOnHookModePlayerEnum,index:number,info:TB.TbGRole):GRoleDefault {
@@ -308,6 +285,8 @@ export default class GOnHookMode extends GBaseMode<{}>{
//绑定死亡回调
entity.addKillBackEvent(this.onRoleKillBack.bind(this))
//绑定受击回调
entity.addHitCallback(this.onHitBack.bind(this));
this.addGObject(entity,tactical.getPosition(index));
@@ -364,11 +343,10 @@ export default class GOnHookMode extends GBaseMode<{}>{
//生成敌人
onResetGenerateEnemy(){
this.enemyRoles = [];
if(!this.wildlifes) return;
//获取敌人
let wildlife = this.wildlifes.pets.shift();
this.onGenRole(GOnHookModePlayerEnum.ENEMY,2,GRoleUtil.getGRole(wildlife.petTbId));
let creeps = GOnHookManager.getIns().getNextCreeps();
if(!creeps) return; //没有获取到野怪则返回
this.onGenCreeps(2,creeps);
// this.enemyInfo.roles.forEach((info,index) => this.onGenRole(GOnHookModePlayerEnum.ENEMY,index + 1,info));
}
@@ -380,14 +358,22 @@ export default class GOnHookMode extends GBaseMode<{}>{
role.node.destroy()
},3000)
//如果死亡的是野怪则通知野怪死亡
if(role.getComponent(GRoleOnHookCreepsExpand)){
GOnHookManager.getIns().onKillSreeps(role.getComponent(GRoleOnHookCreepsExpand).creeps);
}
//清理
this.onClearCache();
// //如果没有敌人则生成敌人
// if(this.getOnesRole(GOnHookModePlayerEnum.ENEMY).filter(role => !!role.get()).length <= 0){
// //生成敌人
// this.onResetGenerateEnemy();
// }
}
//角色受击回调
onHitBack(role:GRoleDefault,hit:number){
//添加受击显示
app.event.emit(ModeRenderEvent.HIT,role,hit);
}
//清理缓存

View File

@@ -1,7 +1,8 @@
import { app } from "../App";
import { GUI } from "../ui/UIConfig";
const RData = (data:any,isTips:boolean = true) => {
//接受到JSON消息
export const RData = (data:any,isTips:boolean = true) => {
if(data.data.state == 200){
return data.data.data;
}else{
@@ -12,6 +13,18 @@ const RData = (data:any,isTips:boolean = true) => {
return data.data.data;
}
}
//接受到Protobuf
export const RProto = (data:any,type:string) => {
try{
return app.proto
.getType(type)
.decode(new Uint8Array(data.data)) as any;;
}catch{
app.layer.Open(GUI.Tips,{text:"Protobuf 解析失败"});
}
}
/************** 请求类 *******************/
export interface NewsContext{

View File

@@ -0,0 +1,14 @@
import { GOnHookPets } from "../../../extensions/ngame/assets/ngame/message/proto";
import { app } from "../App";
import { PlayerPetOV, RData, RProto } from "./API";
import { GActionType } from "./GActionType";
export const GAPI = {
/************** 无限模式接口 ********************/
//生成野怪
GOnHookSpawnCreeps : async () => RProto(await app.api.get(`/game/mode/onHook/onSpawnCreeps`,{responseType:'arraybuffer'}),GActionType.GOnHookPets) as GOnHookPets,
//捕捉野怪
GOnHookCatchCreeps : async (creepId) => RData(await app.api.post(`/game/mode/onHook/onCatchCreeps/${creepId}`)) as PlayerPetOV,
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "4ecc480c-6d05-4b57-bc01-1605ae0c1512",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -8,9 +8,5 @@ export enum GAction {
/*************** 游戏模式 : 无尽模式(OnHook) **************/
MODE_ON_HOOK_SPAWN_PET = 3001, //生成宠物
MODE_ON_HOOK_CAPTURE_PET = 3002, //捕捉宠物
MODE_ON_HOOK_SELL_PET = 3003, //卖出宠物
}

View File

@@ -1,13 +1,14 @@
import { sys } from "cc";
import { WorldCanvas } from "../WorldCanvas";
//UI 动画
export enum UIPetAnim{
std = "std",
}
//存储Key
export enum StorageEnum{
Token = "Storage_Token", // Token
}
export class StorageData {
@@ -26,10 +27,13 @@ export class StorageData {
}
export const GData = {
export class GData {
//层级
layer: {
static layer = {
World: 1,
}
};
//世界画布节点
static WorldCanvas: WorldCanvas;
}

View File

@@ -38,6 +38,11 @@ export default class PlayerPetData extends BaseData{
return this.datas.filter(item => item.petId == petId)[0]
}
//添加宠物
addPet(pet:PlayerPetOV){
this.datas.push(pet);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "d92a44bc-1e3c-44d4-b3e5-a3b2f1324e98",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "ec650551-a3f2-4b5c-a9bb-a4fd649dbdbd",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,100 @@
import { GOnHookPet } from "../../../../../extensions/ngame/assets/ngame/message/proto";
import Singleton from "../../../../../extensions/ngame/assets/ngame/util/Singleton";
import { app } from "../../../App";
import { PlayerPetOV } from "../../../consts/API";
import { GAPI } from "../../../consts/GAPI";
import PlayerPetData from "../../../data/PlayerPetData";
import { GUI } from "../../../ui/UIConfig";
export enum GOnHookManagerEvent{
//添加死亡野怪
ADD_KILL_SREEP = "GOnHookManagerEvent_ADD_KILL_SREEP",
//删除死亡野怪
DEL_KILL_SREEP = "GOnHookManagerEvent_DEL_KILL_SREEP"
}
//游戏模式 OnHook 管理器
export default class GOnHookManager extends Singleton{
//野怪列表
_sreeps:Map<string,GOnHookPet> = new Map();
get sreeps(){
//如果没有野怪了 则 向服务器生成
if(!this._sreeps || !(this._sreeps.size)){
//生成
this.onSpawnSreeps();
return null;
}
return this._sreeps;
}
set sreeps(data:Map<string,GOnHookPet>){
this._sreeps = data;
}
//已经死亡的野怪列表
killSreeps:GOnHookPet[] = [];
//生成野怪
onSpawnSreeps(){
GAPI.GOnHookSpawnCreeps().then(data => {
data.pets.forEach(pet => {
this._sreeps.set(pet.key,pet as GOnHookPet);
})
});
}
//获取下一只野怪
getNextCreeps(){
if(!this.sreeps) return;
let creeps = this.sreeps.get(this.sreeps.keys().next()?.value)
return creeps;
}
//野怪死亡
onKillSreeps(creeps:GOnHookPet){
this.sreeps.delete(creeps.key);
//记入死亡
//判断是否在死亡中如果在则跳出
if(this.killSreeps.indexOf(creeps) > -1){
return;
}
this.killSreeps.push(creeps);
//通知添加死亡野怪
app.event.emit(GOnHookManagerEvent.ADD_KILL_SREEP,creeps);
console.log(`GOnHookManager : ${creeps.key} 宠物死亡 可进行捕捉 出售`);
}
//捕捉野怪
async onCatchCreeps(creeps:GOnHookPet):Promise<boolean>{
let index;
if((index = this.killSreeps.indexOf(creeps)) < 0){
app.layer.Open(GUI.Tips,{text:"不可捕捉该宠物"});
return false;
}
//删除
this.killSreeps.splice(index,1);
//通知添加野怪被删除
app.event.emit(GOnHookManagerEvent.DEL_KILL_SREEP,creeps);
let pet:PlayerPetOV = await GAPI.GOnHookCatchCreeps(creeps.key);
//保存宠物
if(pet){
PlayerPetData.getIns().addPet(pet);
}
return !!pet;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "3e881d0a-dd68-4ca6-9043-73e2d45318bd",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a0bd4b57-3c54-4d36-a0b5-20728f53f17b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,54 @@
import { _decorator, Component, Node } from 'cc';
import { app } from '../../../App';
import GRoleDefault from '../../../battle/base/role/GRoleDefault';
import { GData } from '../../../consts/GData';
import { v2 } from 'cc';
import { Prefab } from 'cc';
import { instantiate } from 'cc';
import { v3 } from 'cc';
import { ModeRenderHitText } from './ModeRenderHitText';
const { ccclass, property } = _decorator;
export enum ModeRenderEvent{
//受击
HIT = "ModeRenderEvent_HIT"
}
@ccclass('ModeRender')
export class ModeRender extends Component {
//受击预制体
@property(Prefab)
hitPrefab:Prefab;
onLoad(){
app.event.on(ModeRenderEvent.HIT,this.onHit,this);
}
protected onDestroy(): void {
app.event.off(ModeRenderEvent.HIT,this.onHit,this);
}
//受击
onHit(role:GRoleDefault,hit:number){
if(!role.get()) return;
let rolePos = GData.WorldCanvas.camera.worldToScreen(role.node.worldPosition);
let hitNode = instantiate(this.hitPrefab);
this.node.addChild(hitNode);
hitNode.position = rolePos.add(v3(0,100,0));
hitNode.getComponent(ModeRenderHitText).setText(hit);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "00e93335-8301-435f-83b1-b83f29e48e8b",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,39 @@
import { tween } from 'cc';
import { v3 } from 'cc';
import { Label } from 'cc';
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('ModeRenderHitText')
export class ModeRenderHitText extends Component {
@property(Label)
hitLabel:Label;
setText(hit:number){
this.hitLabel.string = `${hit}`;
this.setAnimation();
}
//设置动画
setAnimation(){
this.node.scale = v3(0,0,0);
tween(this.node)
.to(.5,{position:this.node.position.clone().add(v3(0,100,0)),scale:v3(1,1,1)},{
onComplete:() => {
this.node.destroy();
},
easing:"quadInOut"
})
.start();
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "fad17282-4ea6-418f-89c6-09bff1b47c62",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,24 @@
import { sp } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { app } from '../../../App';
import { UIPetAnim } from '../../../consts/GData';
import { v3 } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('PetIcon')
export class PetIcon extends Component {
@property(sp.Skeleton)
spine:sp.Skeleton;
//设置icon
setIcon(petTbId:number){
this.spine.skeletonData = app.battleRes.roleSpine[petTbId];
this.spine.setAnimation(0,UIPetAnim.std,true);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b380916e-5ab8-41da-8bc4-08376a3133ac",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,62 @@
import { _decorator, Component, Node } from 'cc';
import { PetIcon } from './PetIcon';
const { ccclass, property } = _decorator;
@ccclass('PetIconSelect')
export class PetIconSelect extends Component {
@property(PetIcon)
petIcon:PetIcon;
//选中节点
@property(Node)
select:Node;
//不可选中节点
@property(Node)
noselect:Node;
//是否被选中
_isSelect:boolean = false;
get isSelect(){
return this._isSelect;
}
set isSelect(data:boolean){
this._isSelect = data;
this.onUpdateSelect();
}
//是否不可选中
_isNoSelect:boolean = false;
get isNoSelect(){
return this._isNoSelect;
}
set isNoSelect(data:boolean){
this._isNoSelect = data;
this.onUpdateSelect();
}
onLoad(){
this.onUpdateSelect();
this.noselect.active = false;
this.select.active = false;
}
//设置icon
setIcon(petTbId:number){
this.petIcon.setIcon(petTbId);
}
onUpdateSelect(){
this.select.active = this.isSelect;
this.noselect.active = this.isNoSelect;
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "7c6657dc-bcb4-460e-ace3-860bd4238a0d",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -24,6 +24,7 @@ export class MainView extends JNGLayerBase {
});
this.onUpdateView();
}
//更新UI界面

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "45b68a51-740e-4ff5-91b1-ba79c76ede3d",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,20 @@
import { _decorator, Component, Node } from 'cc';
import JNScrollViewItem from '../../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollViewItem';
import { GOnHookPet } from '../../../../../extensions/ngame/assets/ngame/message/proto';
import { PetIcon } from '../../Consts/Pet/PetIcon';
import { PetIconSelect } from '../../Consts/Pet/PetIconSelect';
const { ccclass, property } = _decorator;
@ccclass('MainSreepsIcon')
export class MainSreepsIcon extends JNScrollViewItem<GOnHookPet> {
@property(PetIconSelect)
icon:PetIconSelect;
start(){
this.icon.setIcon(this.data.petTbId);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "590f92c6-d3f3-4143-9de4-e47a1257257a",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,93 @@
import { _decorator, Component, Node } from 'cc';
import JNScrollView from '../../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollView';
import { app } from '../../../App';
import GOnHookManager, { GOnHookManagerEvent } from '../../../manager/battle/mode/GOnHookManager';
import { GOnHookPet } from '../../../../../extensions/ngame/assets/ngame/message/proto';
import { MainSreepsIcon } from './MainSreepsIcon';
import { NodeEventType } from 'cc';
import { GUI } from '../../UIConfig';
const { ccclass, property } = _decorator;
@ccclass('MainSreepsList')
export class MainSreepsList extends Component {
//野怪列表
@property(JNScrollView)
views:JNScrollView;
//默认选择
index:number = 0;
onLoad(){
//监听 野怪死亡
app.event.on(GOnHookManagerEvent.ADD_KILL_SREEP,this.onAddSreep,this);
//监听 野怪删除
app.event.on(GOnHookManagerEvent.DEL_KILL_SREEP,this.onDelSreep,this);
//添加子节点事件
this.views.addItemEvent(NodeEventType.TOUCH_END,this.onClickItem.bind(this));
}
protected onDestroy(): void {
//取消监听
app.event.off(GOnHookManagerEvent.ADD_KILL_SREEP,this.onAddSreep,this);
app.event.on(GOnHookManagerEvent.DEL_KILL_SREEP,this.onDelSreep,this);
}
//添加野怪
onAddSreep(sreep:GOnHookPet){
this.views.addData(sreep);
}
//删除野怪
onDelSreep(sreep:GOnHookPet){
this.views.delData(sreep);
}
//刷新
onUpdateView(){
let items = this.views.getItems<MainSreepsIcon>();
if(items.length <= 0) return;
//取消选中
items.forEach(item => item.icon.isSelect = false)
//选中index
if(items[this.index]) items[this.index].icon.isSelect = true;
}
//点击子节点
onClickItem(index:number){
this.index = index;
this.onUpdateView();
}
//捕捉野怪
async onClickCatch(){
//获取选中的野怪
let item = this.views.getItems<MainSreepsIcon>()[this.index];
if(!item){
app.layer.Open(GUI.Tips,{text:"请选择需要捕捉的宠物"});
return;
}
if(await GOnHookManager.getIns().onCatchCreeps(item.data))
app.layer.Open(GUI.Tips,{text:"捕捉成功!"});
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "fe2ad307-ecc6-45e4-a5e0-4782b0bf0257",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,50 +1,17 @@
import { _decorator, Component, Node } from 'cc';
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 JNScrollViewItem from '../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollViewItem';
import { PetIconSelect } from '../Consts/Pet/PetIconSelect';
const { ccclass, property } = _decorator;
@ccclass('IntoBattlePetIcon')
export class IntoBattlePetIcon extends JNScrollViewItem<PlayerPetOV> {
@property(sp.Skeleton)
spine:sp.Skeleton;
//选中节点
@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 {
//显示角色
this.spine.skeletonData = app.battleRes.roleSpine[this.data.petTbId];
this.spine.setAnimation(0,UIPetAnim.std,true);
}
onUpdateSelect(){
this.select.active = this.isSelect;
this.noselect.active = this.isNoSelect;
@property(PetIconSelect)
select:PetIconSelect;
protected start(): void {
this.select.setIcon(this.data.petTbId);
}
}

View File

@@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "7c6657dc-bcb4-460e-ace3-860bd4238a0d",
"uuid": "0d7f0c4b-80b2-49fb-baab-f4c7131b9dda",
"files": [],
"subMetas": {},
"userData": {}

View File

@@ -21,9 +21,6 @@ export class IntoBattleView extends JNLayerBase {
@property(JNScrollView)
views:JNScrollView; //宠物列表
@property(Prefab)
petIconPrefab; //宠物Icon预制体
@property(sp.Skeleton)
spine:sp.Skeleton; //当前选中的宠物
@@ -58,7 +55,7 @@ export class IntoBattleView extends JNLayerBase {
//设置不可选中
this.views.getItems<IntoBattlePetIcon>().forEach(item => {
if(PlayerTacticalData.getIns().getTacticalInfo().indexOf(item.data.petId) != -1)
item.isNoSelect = true; //如果在阵法里则不可选中
item.select.isNoSelect = true; //如果在阵法里则不可选中
})
//向子节点添加点击事件
@@ -73,15 +70,13 @@ export class IntoBattleView extends JNLayerBase {
//默认都不选中
this.views.getItems<IntoBattlePetIcon>().forEach(item => {
item.isSelect = false;
item.onUpdateSelect();
item.select.isSelect = false;
})
//设置选中
if(this.index != -1){
let current = this.views.getItems<IntoBattlePetIcon>()[this.index]
current.isSelect = true;
current.onUpdateSelect();
current.select.isSelect = true;
//显示选中宠物
this.spine.skeletonData = app.battleRes.roleSpine[this.pets[this.index].petTbId];
@@ -94,7 +89,7 @@ export class IntoBattleView extends JNLayerBase {
onClickItem(index:number){
//判断是否不可选中
if(this.views.getItems<IntoBattlePetIcon>()[index].isNoSelect) {
if(this.views.getItems<IntoBattlePetIcon>()[index].select.isNoSelect) {
app.layer.Open(GUI.Tips,{text:"当前宠物已上阵"})
return;
}