Files
pixelheros/assets/script/game/map/SmallTipComp.ts
pan 8e1c81adb0 refactor(map): 重构小气泡提示逻辑,统一组件管理
1. 新增SmallTipComp组件封装气泡提示动画逻辑
2. 移除TalentsComp中切换阶位的解锁提示弹窗
3. 重构HerosListComp的小提示逻辑,复用通用组件
4. 修改顶部UI的资源监听路径为钻石数据
2026-09-01 16:26:41 +08:00

62 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file SmallTipComp.ts
* @description smalltip 气泡提示组件(UI 通用层)
*
* 职责:
* 封装 smalltip.prefab 气泡的弹出/消失动画与文案填充,供各页面复用。
* 调用方通过 getComponent(SmallTipComp) 获取实例后调 show(text) 即可,
* 无需关心节点显隐与 Tween 生命周期。
*
* 用法:
* 1. 编辑器侧将本组件挂在 smalltip 节点上(或运行时 addComponent 兜底)。
* 2. 默认隐藏节点(active = false),调用 show() 自动弹出并在停留后缩小隐藏。
*/
import { _decorator, Component, Label, Tween, Vec3, tween } from "cc";
const { ccclass } = _decorator;
/** 气泡停留时长(秒) */
const STAY_DURATION = 1;
/** SmallTipComp —— smalltip 气泡提示(弹出 → 停留 → 缩小隐藏) */
@ccclass('SmallTipComp')
export class SmallTipComp extends Component {
protected onLoad(): void {
// 初始隐藏,避免遮挡挂载点的触摸事件
this.node.active = false;
}
/**
* 弹出气泡提示(重复调用时打断当前动画,从头播放)
* @param text 提示文案
* @param stay 停留时长(秒),默认 1 秒
*/
public show(text: string, stay: number = STAY_DURATION): void {
// 覆盖气泡文字
const label = this.getComponentInChildren(Label);
if (label) label.string = text;
this.node.active = true;
Tween.stopAllByTarget(this.node);
this.node.setScale(0, 0, 1);
tween(this.node)
// 弹出动画(微放大再回弹)
.to(0.15, { scale: new Vec3(1.1, 1.1, 1) }, { easing: 'quadOut' })
.to(0.05, { scale: new Vec3(1, 1, 1) })
// 停留
.delay(stay)
// 缩小消失
.to(0.15, { scale: new Vec3(0, 0, 1) }, { easing: 'quadIn' })
.call(() => {
if (this.node && this.node.isValid) this.node.active = false;
})
.start();
}
protected onDestroy(): void {
Tween.stopAllByTarget(this.node);
}
}