feat(config,skill): 新增通用文字飘字提示功能
1. 新增TooltipTypes.tip枚举类型,支持调用方自定义文字和颜色 2. 扩展Tooltip.load和hp_tip方法,增加tipColor参数传递自定义颜色 3. 新增setupTipLabel工具方法,处理通用文字飘字的UI设置 4. 优化现有tip类型的注释和默认颜色逻辑,修复对象池复用颜色残留问题 5. 修复heroSet.ts导入多余空格问题
This commit is contained in:
@@ -4,7 +4,7 @@ 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";
|
||||
import { instantiate, Node, Prefab, Vec3 ,tween, v3,animation,Label,resources,SpriteFrame,Sprite, NodePool, Color} from "cc";
|
||||
|
||||
/** Skill 模块 */
|
||||
@ecs.register(`Tooltip`)
|
||||
@@ -60,7 +60,7 @@ export class Tooltip extends ecs.Entity {
|
||||
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,debuffIcon:string="") {
|
||||
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,debuffIcon:string="",tipColor:Color|null=null) {
|
||||
let node: Node;
|
||||
if (Tooltip.pool.size() > 0) {
|
||||
node = Tooltip.pool.get()!;
|
||||
@@ -75,7 +75,7 @@ export class Tooltip extends ecs.Entity {
|
||||
node.active = true;
|
||||
|
||||
var sv = node.getComponent(TooltipCom)!;
|
||||
sv.init(type, vaule, s_uuid, fac, debuffIcon);
|
||||
sv.init(type, vaule, s_uuid, fac, debuffIcon, tipColor);
|
||||
|
||||
// this.add(sv); // 不要添加到单例实体上,否则会覆盖或导致单例被销毁
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ export class TooltipCom extends CCComp {
|
||||
fac: number = FacSet.MON;
|
||||
/** DoT 飘字需激活的 debuff 图标节点名(loss_life/hp/debuff 下的子节点,如 FireDamage);空串=普通伤害 */
|
||||
debuffIcon: string = "";
|
||||
/** 通用文字飘字(TooltipTypes.tip)的自定义颜色,null 表示使用预制体默认色 */
|
||||
tipColor: Color | null = null;
|
||||
|
||||
// 动画参数配置
|
||||
private readonly popDuration = 0.15;
|
||||
@@ -31,12 +33,13 @@ export class TooltipCom extends CCComp {
|
||||
}
|
||||
|
||||
/** 初始化并播放动画 */
|
||||
init(type: number, value: string, uuid: number, fac: number = FacSet.MON, debuffIcon: string = "") {
|
||||
init(type: number, value: string, uuid: number, fac: number = FacSet.MON, debuffIcon: string = "", tipColor: Color | null = null) {
|
||||
this.stype = type;
|
||||
this.value = value;
|
||||
this.s_uuid = uuid;
|
||||
this.fac = fac;
|
||||
this.debuffIcon = debuffIcon;
|
||||
this.tipColor = tipColor;
|
||||
|
||||
// 初始化或获取 UIOpacity 组件
|
||||
this._uiOpacity = this.node.getComponent(UIOpacity);
|
||||
@@ -132,16 +135,22 @@ export class TooltipCom extends CCComp {
|
||||
this.node.setPosition(v3(this.node.position.x, currentY - 60));
|
||||
this.node.setSiblingIndex(topSiblingIndex);
|
||||
break;
|
||||
case TooltipTypes.shield: // 护盾减免
|
||||
case TooltipTypes.shield: // 护盾吸收伤害:显示“吸收”+ 数值
|
||||
this.node.setPosition(v3(this.node.position.x + offsetX, currentY));
|
||||
this.node.setSiblingIndex(topSiblingIndex);
|
||||
this.setupLabel("add_life", "hp", "0");
|
||||
isHeal = true;
|
||||
this.setupTipLabel(`吸收 ${this.value}`, this.tipColor ?? new Color(79, 195, 247, 255)); // 默认蓝
|
||||
isHeal = true; // 垂直上飘,区别于伤害随机横飘
|
||||
break;
|
||||
case TooltipTypes.miss: // 闪避
|
||||
this.node.setPosition(v3(this.node.position.x + offsetX, currentY));
|
||||
this.node.setSiblingIndex(topSiblingIndex);
|
||||
this.setupLabel("add_life", "hp", "闪避");
|
||||
this.setupTipLabel(this.value || "闪避", this.tipColor ?? new Color(255, 255, 255, 255)); // 默认白
|
||||
isHeal = true;
|
||||
break;
|
||||
case TooltipTypes.tip: // 通用文字飘字
|
||||
this.node.setPosition(v3(this.node.position.x + offsetX, currentY));
|
||||
this.node.setSiblingIndex(topSiblingIndex);
|
||||
this.setupTipLabel(this.value, this.tipColor);
|
||||
isHeal = true;
|
||||
break;
|
||||
}
|
||||
@@ -158,6 +167,22 @@ export class TooltipCom extends CCComp {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用文字飘字:激活 words 节点并设置文字与颜色
|
||||
* 预制体需包含 words/name 结构(Label);与 skill 节点区分,走漂移上飘动画而非原地淡出
|
||||
* 对象池复用安全:未传色时恢复默认白,避免上次自定义色残留
|
||||
*/
|
||||
private setupTipLabel(text: string, color: Color | null = null) {
|
||||
const words = this.node.getChildByName("words");
|
||||
if (!words) return;
|
||||
words.active = true;
|
||||
const label = words.getChildByName("name")?.getComponent(Label);
|
||||
if (label) {
|
||||
label.string = text;
|
||||
label.color = color ?? Color.WHITE.clone();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DoT 伤害飘字:激活 loss_life/hp/debuff 下指定的 debuff 图标子节点。
|
||||
* 仅怪物普通伤害(loss_life)路径调用;debuffIcon 为空或未找到节点时静默跳过。
|
||||
|
||||
Reference in New Issue
Block a user