refactor(map): 重构小气泡提示逻辑,统一组件管理
1. 新增SmallTipComp组件封装气泡提示动画逻辑 2. 移除TalentsComp中切换阶位的解锁提示弹窗 3. 重构HerosListComp的小提示逻辑,复用通用组件 4. 修改顶部UI的资源监听路径为钻石数据
This commit is contained in:
61
assets/script/game/map/SmallTipComp.ts
Normal file
61
assets/script/game/map/SmallTipComp.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user