diff --git a/assets/script/game/map/HInfoComp.ts b/assets/script/game/map/HInfoComp.ts index c90d5eb6..6aa20b38 100644 --- a/assets/script/game/map/HInfoComp.ts +++ b/assets/script/game/map/HInfoComp.ts @@ -2,10 +2,14 @@ import { _decorator, Animation, AnimationClip, Component, instantiate, Label, No import { oops } from 'db://oops-framework/core/Oops'; import { getHeroList, HeroInfo, HType, HTypeName } from '../common/config/heroSet'; import { smc } from '../common/SingletonModuleComp'; +import { GameEvent } from '../common/config/GameEvent'; +import { CCComp } from 'db://oops-framework/module/common/CCComp'; +import { ecs } from 'db://oops-framework/libs/ecs/ECS'; const { ccclass, property } = _decorator; @ccclass('HInfoComp') -export class HInfoComp extends Component { +@ecs.register('HInfoComp', false) +export class HInfoComp extends CCComp { h_uuid:number=0 name_node:any=null type_node:any=null @@ -26,7 +30,14 @@ export class HInfoComp extends Component { 5:v3(-280,-109,0), 6:v3(-420,-109,0), // 不在屏幕内 } - + + // 动画锁定标志:防止快速点击导致的动画冲突 + private isMoving: boolean = false; + // 保存待处理的setTimeout句柄,用于取消前一个异步操作 + private moveTimeoutId: any = null; + protected onLoad(): void { + // this.on(GameEvent.MissionStart,this.mission_start,this) + } // 位置索引常量 private static center_pos = 3; @@ -105,7 +116,9 @@ export class HInfoComp extends Component { return node; } - + mission_start(){ + this.claear_hero() + } claear_hero(){ for (let i = 0; i < this.heroNodes.length; i++) { if (this.heroNodes[i]) { @@ -116,6 +129,9 @@ export class HInfoComp extends Component { } next_hero(){ + // 检查是否正在动画中,防止快速点击导致的冲突 + if (this.isMoving) return; + // 获取英雄列表 let heros = getHeroList(); let index = heros.indexOf(this.h_uuid); @@ -125,6 +141,7 @@ export class HInfoComp extends Component { // 更新数据 this.h_uuid = nextHero; + smc.updateFihgtHero(nextHero) this.update_data(nextHero); // 执行平滑移动动画 @@ -132,6 +149,9 @@ export class HInfoComp extends Component { } prev_hero(){ + // 检查是否正在动画中,防止快速点击导致的冲突 + if (this.isMoving) return; + // 获取英雄列表 let heros = getHeroList(); let index = heros.indexOf(this.h_uuid); @@ -141,6 +161,7 @@ export class HInfoComp extends Component { // 更新数据 this.h_uuid = prevHero; + smc.updateFihgtHero(prevHero) this.update_data(prevHero); // 执行平滑移动动画 @@ -148,6 +169,14 @@ export class HInfoComp extends Component { } moveHeroesLeft() { + // 取消前一个待处理的异步操作 + if (this.moveTimeoutId !== null) { + clearTimeout(this.moveTimeoutId); + } + + // 设置动画锁定 + this.isMoving = true; + // 在动画开始前,直接销毁hero_pos[6]上的节点 if (this.heroNodes[6]) { this.heroNodes[6].destroy(); @@ -162,13 +191,13 @@ export class HInfoComp extends Component { // 使用Tween执行平滑移动 tween(this.heroNodes[i]) - .to(0.3, { position: targetPos }) + .to(0.2, { position: targetPos }) .start(); } } // 延迟重排数组和创建新节点,等待动画完成 - setTimeout(() => { + this.moveTimeoutId = setTimeout(() => { // 移动数组元素(向后平移) for (let i = 6; i > 0; i--) { this.heroNodes[i] = this.heroNodes[i - 1]; @@ -185,10 +214,22 @@ export class HInfoComp extends Component { } this.heroNodes[0] = this.load_hui(heros[newIndex], 0); - }, 300); // 与动画时间保持一致 + + // 动画完成,解除锁定 + this.isMoving = false; + this.moveTimeoutId = null; + }, 200); // 与动画时间保持一致 } moveHeroesRight() { + // 取消前一个待处理的异步操作 + if (this.moveTimeoutId !== null) { + clearTimeout(this.moveTimeoutId); + } + + // 设置动画锁定 + this.isMoving = true; + // 在动画开始前,直接销毁hero_pos[0]上的节点 if (this.heroNodes[0]) { this.heroNodes[0].destroy(); @@ -203,13 +244,13 @@ export class HInfoComp extends Component { // 使用Tween执行平滑移动 tween(this.heroNodes[i]) - .to(0.3, { position: targetPos }) + .to(0.2, { position: targetPos }) .start(); } } // 延迟重排数组和创建新节点,等待动画完成 - setTimeout(() => { + this.moveTimeoutId = setTimeout(() => { // 移动数组元素(向前平移) for (let i = 0; i < 6; i++) { this.heroNodes[i] = this.heroNodes[i + 1]; @@ -226,7 +267,11 @@ export class HInfoComp extends Component { } this.heroNodes[6] = this.load_hui(heros[newIndex], 6); - }, 300); // 与动画时间保持一致 + + // 动画完成,解除锁定 + this.isMoving = false; + this.moveTimeoutId = null; + }, 200); // 与动画时间保持一致 } reset() { diff --git a/assets/script/game/map/MissionHeroComp.ts b/assets/script/game/map/MissionHeroComp.ts index fa5417d6..1f88e1f5 100644 --- a/assets/script/game/map/MissionHeroComp.ts +++ b/assets/script/game/map/MissionHeroComp.ts @@ -56,15 +56,11 @@ export class MissionHeroCompComp extends CCComp { } - - private zhao_huan(event: string, args: any){ // console.log("[MissionHeroComp]:zhaohuan",args) this.addHero(args.uuid,false) } - - /** 添加英雄 */ private addHero(uuid:number=1001,is_zhaohuan:boolean=false) { // console.log("[MissionHeroComp]:addHero",uuid,is_zhaohuan) diff --git a/assets/script/game/map/MissionHomeComp.ts b/assets/script/game/map/MissionHomeComp.ts index e6067bef..e7ea61cf 100644 --- a/assets/script/game/map/MissionHomeComp.ts +++ b/assets/script/game/map/MissionHomeComp.ts @@ -27,11 +27,11 @@ export class MissionHomeComp extends CCComp { start_mission() { - oops.message.dispatchEvent(GameEvent.MissionStart, {}) this.node.active=false; } mission_end(){ + console.log("[MissionHomeComp]=>mission_end") this.home_active() } home_active(){