feat: 新增英雄出售功能并优化UI交互

- 在 Hero 类中添加 removeByEid 静态方法,用于安全移除英雄实体
- 在 HInfoComp 中集成出售按钮逻辑,点击可移除对应英雄并关闭信息面板
- 为 card.prefab 和 hnode.prefab 添加召唤/出售按钮及相关UI组件
- 调整 role_controller.prefab 面板高度并禁用部分组件
- 移除未使用的 hit-flash-white 场景资源文件
- 暂时注释 CardComp 中的触摸事件绑定以进行调试
This commit is contained in:
walkpan
2026-03-28 12:04:41 +08:00
parent 47b8aeb789
commit a638f473a0
9 changed files with 753 additions and 1623 deletions

View File

@@ -45,6 +45,17 @@ export class Hero extends ecs.Entity {
super.destroy();
}
static removeByEid(eid: number): boolean {
const targetEid = Math.floor(eid);
if (!targetEid) return false;
const entity = ecs.getEntityByEid(targetEid);
if (!entity) return false;
const model = entity.get(HeroAttrsComp);
if (!model || model.fac !== FacSet.HERO) return false;
entity.destroy();
return true;
}
/**
* 加载并初始化英雄

View File

@@ -1,9 +0,0 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "e091410c-c7b6-4416-ae99-38697c103286",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,11 +0,0 @@
{
"ver": "1.1.50",
"importer": "scene",
"imported": true,
"uuid": "5e1d3eb2-c300-4627-94c7-2ee03b8314f1",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

View File

@@ -277,22 +277,22 @@ export class CardComp extends CCComp {
/** 绑定触控:卡面点击使用,锁按钮点击切换锁定 */
private bindEvents() {
this.node.on(NodeEventType.TOUCH_START, this.onCardTouchStart, this);
this.node.on(NodeEventType.TOUCH_MOVE, this.onCardTouchMove, this);
this.node.on(NodeEventType.TOUCH_END, this.onCardTouchEnd, this);
this.node.on(NodeEventType.TOUCH_CANCEL, this.onCardTouchCancel, this);
this.Lock?.on(NodeEventType.TOUCH_END, this.onToggleLock, this);
this.unLock?.on(NodeEventType.TOUCH_END, this.onToggleLock, this);
// this.node.on(NodeEventType.TOUCH_START, this.onCardTouchStart, this);
// this.node.on(NodeEventType.TOUCH_MOVE, this.onCardTouchMove, this);
// this.node.on(NodeEventType.TOUCH_END, this.onCardTouchEnd, this);
// this.node.on(NodeEventType.TOUCH_CANCEL, this.onCardTouchCancel, this);
// this.Lock?.on(NodeEventType.TOUCH_END, this.onToggleLock, this);
// this.unLock?.on(NodeEventType.TOUCH_END, this.onToggleLock, this);
}
/** 解绑触控,防止节点销毁后残留回调 */
private unbindEvents() {
this.node.off(NodeEventType.TOUCH_START, this.onCardTouchStart, this);
this.node.off(NodeEventType.TOUCH_MOVE, this.onCardTouchMove, this);
this.node.off(NodeEventType.TOUCH_END, this.onCardTouchEnd, this);
this.node.off(NodeEventType.TOUCH_CANCEL, this.onCardTouchCancel, this);
this.Lock?.off(NodeEventType.TOUCH_END, this.onToggleLock, this);
this.unLock?.off(NodeEventType.TOUCH_END, this.onToggleLock, this);
// this.node.off(NodeEventType.TOUCH_START, this.onCardTouchStart, this);
// this.node.off(NodeEventType.TOUCH_MOVE, this.onCardTouchMove, this);
// this.node.off(NodeEventType.TOUCH_END, this.onCardTouchEnd, this);
// this.node.off(NodeEventType.TOUCH_CANCEL, this.onCardTouchCancel, this);
// this.Lock?.off(NodeEventType.TOUCH_END, this.onToggleLock, this);
// this.unLock?.off(NodeEventType.TOUCH_END, this.onToggleLock, this);
}
private onCardTouchStart(event: EventTouch) {

View File

@@ -1,10 +1,12 @@
import { _decorator, Animation, AnimationClip, Label, Node, NodeEventType, Sprite, resources } from "cc";
import { _decorator, Animation, AnimationClip, Button, Event, Label, Node, NodeEventType, Sprite, resources } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { HeroInfo } from "../common/config/heroSet";
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
import { Hero } from "../hero/Hero";
import { oops } from "db://oops-framework/core/Oops";
import { UIID } from "../common/config/GameUIConfig";
import { mLogger } from "../common/Logger";
const {property, ccclass } = _decorator;
@@ -22,14 +24,14 @@ export class HInfoComp extends CCComp {
private hpLabel: Label | null = null;
private iconVisualToken: number = 0;
private iconHeroUuid: number = 0;
private debugMode: boolean = true;
onLoad() {
this.cacheLabels();
this.bindEvents();
// this.bindEvents();
}
onDestroy() {
this.unbindEvents();
// this.unbindEvents();
}
bindData(eid: number, model: HeroAttrsComp) {
@@ -125,16 +127,19 @@ export class HInfoComp extends CCComp {
[...clips].forEach(clip => anim.removeClip(clip, true));
}
private bindEvents() {
this.node.on(NodeEventType.TOUCH_END, this.onOpenIBox, this);
}
// private bindEvents() {
// this.sell_node?.on(Button.EventType.CLICK, this.onSellHero, this);
// this.node.on(NodeEventType.TOUCH_END, this.onOpenIBox, this);
// }
private unbindEvents() {
this.node.off(NodeEventType.TOUCH_END, this.onOpenIBox, this);
}
// private unbindEvents() {
// this.sell_node?.off(Button.EventType.CLICK, this.onSellHero, this);
// this.node.off(NodeEventType.TOUCH_END, this.onOpenIBox, this);
// }
private onOpenIBox() {
if (!this.model) return;
if (!this.isModelAlive()) return;
const heroUuid = this.model.hero_uuid ?? 0;
if (!heroUuid || !HeroInfo[heroUuid]) return;
const heroLv = Math.max(1, Math.floor(this.model.lv ?? 1));
@@ -146,6 +151,18 @@ export class HInfoComp extends CCComp {
});
}
private onSellHero(event?: Event) {
if (!this.eid) return;
const removed = Hero.removeByEid(this.eid);
mLogger.log(this.debugMode, "HInfoComp", "onSellHero", {
eid: this.eid,
isAlive: this.isModelAlive(),
removed
});
if (!removed) return;
oops.gui.remove(UIID.IBox);
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.clearIconAnimation(this.icon_node);