扩展 Tooltip 系统以支持根据伤害来源的阵营(英雄或怪物)显示不同的文本标签。修改 HeroViewComp 调用时传递阵营信息,TooltipCom 根据阵营选择对应的本地化键名。同时调整了工具提示预制件的默认激活状态和文本颜色。
83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { BoxSet, FacSet } from "../common/config/GameSet";
|
|
import { SkillSet } from "../common/config/SkillSet";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
import { TooltipCom } from "./TooltipCom";
|
|
import { instantiate, Node, Prefab, Vec3 ,tween, v3,animation,Label,resources,SpriteFrame,Sprite, NodePool} from "cc";
|
|
|
|
/** Skill 模块 */
|
|
@ecs.register(`Tooltip`)
|
|
export class Tooltip extends ecs.Entity {
|
|
/** 对象池 */
|
|
static pool: NodePool = new NodePool();
|
|
static readonly MAX_POOL_SIZE: number = 80;
|
|
|
|
/** 回收节点 */
|
|
static put(node: Node) {
|
|
if (!node || !node.isValid) return;
|
|
if (this.pool.size() >= this.MAX_POOL_SIZE) {
|
|
node.destroy();
|
|
return;
|
|
}
|
|
node.active = false;
|
|
node.parent = null;
|
|
this.pool.put(node);
|
|
}
|
|
static clearPool() {
|
|
while (this.pool.size() > 0) {
|
|
const node = this.pool.get();
|
|
if (node && node.isValid) {
|
|
node.destroy();
|
|
}
|
|
}
|
|
this.pool.clear();
|
|
}
|
|
static getPoolStats() {
|
|
return {
|
|
total: this.pool.size(),
|
|
max: this.MAX_POOL_SIZE
|
|
};
|
|
}
|
|
|
|
/** ---------- 数据层 ---------- */
|
|
// SkillModel!: SkillModelComp;
|
|
|
|
/** ---------- 业务层 ---------- */
|
|
// SkillBll!: SkillBllComp;
|
|
|
|
/** ---------- 视图层 ---------- */
|
|
TooltipView!: TooltipCom;
|
|
|
|
/** 实始添加的数据层组件 */
|
|
protected init() {
|
|
|
|
}
|
|
|
|
/** 模块资源释放 */
|
|
destroy() {
|
|
// 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放
|
|
this.remove(TooltipCom);
|
|
super.destroy();
|
|
}
|
|
static load(pos: Vec3 = Vec3.ZERO,type:number=1,vaule:string="",s_uuid:number=1001,parent:any=null,cd:number=1,fac:number=FacSet.MON) {
|
|
let node: Node;
|
|
if (Tooltip.pool.size() > 0) {
|
|
node = Tooltip.pool.get()!;
|
|
} else {
|
|
var path = "game/skill/buff/tooltip";
|
|
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|
node = instantiate(prefab);
|
|
}
|
|
|
|
node.parent = parent;
|
|
node.setPosition(pos);
|
|
node.active = true;
|
|
|
|
var sv = node.getComponent(TooltipCom)!;
|
|
sv.init(type, vaule, s_uuid, fac);
|
|
|
|
// this.add(sv); // 不要添加到单例实体上,否则会覆盖或导致单例被销毁
|
|
}
|
|
}
|