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:
File diff suppressed because it is too large
Load Diff
@@ -148,6 +148,8 @@ export const TooltipTypes = {
|
|||||||
addmp: 9,
|
addmp: 9,
|
||||||
shield: 10,
|
shield: 10,
|
||||||
miss: 11,
|
miss: 11,
|
||||||
|
/** 通用文字飘字(闪避/格挡/免疫等),文字与颜色由调用方传入 */
|
||||||
|
tip: 12,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { v3 } from "cc"
|
import { v3 } from "cc"
|
||||||
import { BoxSet, FacSet, FightSet } from "./GameSet"
|
import { BoxSet, FacSet, FightSet } from "./GameSet"
|
||||||
import { SkillOverrides, TGroup, SkillSet, FieldSkillSet, SkillConfig, SkillKind, FieldSkillConfig, FieldSkillType, mergeSkillParams } from "./SkillSet"
|
import { SkillOverrides, TGroup, SkillSet, FieldSkillSet, SkillConfig, SkillKind, FieldSkillConfig, FieldSkillType, mergeSkillParams } from "./SkillSet"
|
||||||
import { BuffList, BuffConfig, ModOp } from "./BuffSet"
|
import { BuffList, BuffConfig, ModOp } from "./BuffSet"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Vec3, _decorator, v3, Collider2D, Contact2DType, Node, Prefab, instantiate, tween, Tween, BoxCollider2D, UITransform } from "cc";
|
import { Vec3, _decorator, v3, Collider2D, Contact2DType, Node, Prefab, instantiate, tween, Tween, BoxCollider2D, UITransform, Color } from "cc";
|
||||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||||
import { mLogger } from "../common/Logger";
|
import { mLogger } from "../common/Logger";
|
||||||
@@ -222,7 +222,7 @@ export class HeroViewComp extends CCComp {
|
|||||||
Tooltip.load(pos, TooltipTypes.skill, value, s_uuid, this.node, 1, this.model?.fac ?? FacSet.MON);
|
Tooltip.load(pos, TooltipTypes.skill, value, s_uuid, this.node, 1, this.model?.fac ?? FacSet.MON);
|
||||||
}
|
}
|
||||||
/** 血量提示(伤害数字) */
|
/** 血量提示(伤害数字) */
|
||||||
private hp_tip(type: number = 1, value: string = "", s_uuid: number = 1001, y: number = 0, debuffIcon: string = "") {
|
private hp_tip(type: number = 1, value: string = "", s_uuid: number = 1001, y: number = 0, debuffIcon: string = "", tipColor: Color | null = null) {
|
||||||
let x = this.node.position.x;
|
let x = this.node.position.x;
|
||||||
// 获取怪物高度的一半,定位到中心点
|
// 获取怪物高度的一半,定位到中心点
|
||||||
let halfHeight = 0;
|
let halfHeight = 0;
|
||||||
@@ -234,15 +234,15 @@ export class HeroViewComp extends CCComp {
|
|||||||
// 起点设为怪物中心偏下位置,使其在血条下方
|
// 起点设为怪物中心偏下位置,使其在血条下方
|
||||||
let ny = this.node.position.y + halfHeight - 15;
|
let ny = this.node.position.y + halfHeight - 15;
|
||||||
let pos = v3(x, ny, 0);
|
let pos = v3(x, ny, 0);
|
||||||
Tooltip.load(pos, type, value, s_uuid, this.node.parent, 1, this.model?.fac ?? FacSet.MON, debuffIcon);
|
Tooltip.load(pos, type, value, s_uuid, this.node.parent, 1, this.model?.fac ?? FacSet.MON, debuffIcon, tipColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 护盾减免提示 */
|
/** 护盾吸收提示:蓝色 "吸收 N" */
|
||||||
shield_tip(absorbed: number) {
|
shield_tip(absorbed: number) {
|
||||||
this.hp_tip(TooltipTypes.shield, NumberFormatter.formatNumber(Math.max(0, Math.floor(absorbed))));
|
this.hp_tip(TooltipTypes.shield, NumberFormatter.formatNumber(Math.max(0, Math.floor(absorbed))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 闪避提示 */
|
/** 闪避提示:白色 "闪避" */
|
||||||
showMiss() {
|
showMiss() {
|
||||||
this.hp_tip(TooltipTypes.miss, "闪避");
|
this.hp_tip(TooltipTypes.miss, "闪避");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { BoxSet, FacSet } from "../common/config/GameSet";
|
|||||||
import { SkillSet } from "../common/config/SkillSet";
|
import { SkillSet } from "../common/config/SkillSet";
|
||||||
import { smc } from "../common/SingletonModuleComp";
|
import { smc } from "../common/SingletonModuleComp";
|
||||||
import { TooltipCom } from "./TooltipCom";
|
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 模块 */
|
/** Skill 模块 */
|
||||||
@ecs.register(`Tooltip`)
|
@ecs.register(`Tooltip`)
|
||||||
@@ -60,7 +60,7 @@ export class Tooltip extends ecs.Entity {
|
|||||||
this.remove(TooltipCom);
|
this.remove(TooltipCom);
|
||||||
super.destroy();
|
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;
|
let node: Node;
|
||||||
if (Tooltip.pool.size() > 0) {
|
if (Tooltip.pool.size() > 0) {
|
||||||
node = Tooltip.pool.get()!;
|
node = Tooltip.pool.get()!;
|
||||||
@@ -75,7 +75,7 @@ export class Tooltip extends ecs.Entity {
|
|||||||
node.active = true;
|
node.active = true;
|
||||||
|
|
||||||
var sv = node.getComponent(TooltipCom)!;
|
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); // 不要添加到单例实体上,否则会覆盖或导致单例被销毁
|
// this.add(sv); // 不要添加到单例实体上,否则会覆盖或导致单例被销毁
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ export class TooltipCom extends CCComp {
|
|||||||
fac: number = FacSet.MON;
|
fac: number = FacSet.MON;
|
||||||
/** DoT 飘字需激活的 debuff 图标节点名(loss_life/hp/debuff 下的子节点,如 FireDamage);空串=普通伤害 */
|
/** DoT 飘字需激活的 debuff 图标节点名(loss_life/hp/debuff 下的子节点,如 FireDamage);空串=普通伤害 */
|
||||||
debuffIcon: string = "";
|
debuffIcon: string = "";
|
||||||
|
/** 通用文字飘字(TooltipTypes.tip)的自定义颜色,null 表示使用预制体默认色 */
|
||||||
|
tipColor: Color | null = null;
|
||||||
|
|
||||||
// 动画参数配置
|
// 动画参数配置
|
||||||
private readonly popDuration = 0.15;
|
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.stype = type;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.s_uuid = uuid;
|
this.s_uuid = uuid;
|
||||||
this.fac = fac;
|
this.fac = fac;
|
||||||
this.debuffIcon = debuffIcon;
|
this.debuffIcon = debuffIcon;
|
||||||
|
this.tipColor = tipColor;
|
||||||
|
|
||||||
// 初始化或获取 UIOpacity 组件
|
// 初始化或获取 UIOpacity 组件
|
||||||
this._uiOpacity = this.node.getComponent(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.setPosition(v3(this.node.position.x, currentY - 60));
|
||||||
this.node.setSiblingIndex(topSiblingIndex);
|
this.node.setSiblingIndex(topSiblingIndex);
|
||||||
break;
|
break;
|
||||||
case TooltipTypes.shield: // 护盾减免
|
case TooltipTypes.shield: // 护盾吸收伤害:显示“吸收”+ 数值
|
||||||
this.node.setPosition(v3(this.node.position.x + offsetX, currentY));
|
this.node.setPosition(v3(this.node.position.x + offsetX, currentY));
|
||||||
this.node.setSiblingIndex(topSiblingIndex);
|
this.node.setSiblingIndex(topSiblingIndex);
|
||||||
this.setupLabel("add_life", "hp", "0");
|
this.setupTipLabel(`吸收 ${this.value}`, this.tipColor ?? new Color(79, 195, 247, 255)); // 默认蓝
|
||||||
isHeal = true;
|
isHeal = true; // 垂直上飘,区别于伤害随机横飘
|
||||||
break;
|
break;
|
||||||
case TooltipTypes.miss: // 闪避
|
case TooltipTypes.miss: // 闪避
|
||||||
this.node.setPosition(v3(this.node.position.x + offsetX, currentY));
|
this.node.setPosition(v3(this.node.position.x + offsetX, currentY));
|
||||||
this.node.setSiblingIndex(topSiblingIndex);
|
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;
|
isHeal = true;
|
||||||
break;
|
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 图标子节点。
|
* DoT 伤害飘字:激活 loss_life/hp/debuff 下指定的 debuff 图标子节点。
|
||||||
* 仅怪物普通伤害(loss_life)路径调用;debuffIcon 为空或未找到节点时静默跳过。
|
* 仅怪物普通伤害(loss_life)路径调用;debuffIcon 为空或未找到节点时静默跳过。
|
||||||
|
|||||||
Reference in New Issue
Block a user