refactor(map): 提取动画方法以消除重复代码

- 将 playButtonPressAnim、playButtonClickAnim 和 playButtonResetAnim 中的动画逻辑提取为通用方法 playNodeScaleTo 和 playNodeScalePop
- 调整 playCoinChangeAnim 以使用新的动画方法,并分别对图标和数字应用动画
- 清理属性声明顺序,移除已弃用的 tooltip 注释
This commit is contained in:
panw
2026-03-27 10:54:45 +08:00
parent 1ef38ce595
commit 8c3a142d9f

View File

@@ -22,13 +22,12 @@ export class MissionCardComp extends CCComp {
private readonly buttonNormalScale: number = 1;
private readonly buttonPressScale: number = 0.94;
private readonly buttonClickScale: number = 1.06;
@property({ tooltip: "每次刷新卡牌消耗金币" })
refreshCost: number = 1;
cardsPanelMoveDuration: number = 0.2;
/** 四个插卡槽位固定顺序分发1~4 */
@property(Node)
cards_node:Node = null!
@property({ tooltip: "卡牌面板位移动画时长" })
cardsPanelMoveDuration: number = 0.2;
@property(Node)
card1:Node = null!
@property(Node)
@@ -51,6 +50,7 @@ export class MissionCardComp extends CCComp {
hero_info_prefab:Prefab=null! //场上英雄信息面板Prefab
@property(Node)
hero_num_node:Node=null!
/** 预留图集缓存(后续接入按钮/卡面图标时复用) */
private uiconsAtlas: SpriteAtlas | null = null;
/** 四个槽位对应的单卡控制器缓存 */
@@ -148,7 +148,7 @@ export class MissionCardComp extends CCComp {
this.on(GameEvent.MissionEnd, this.onMissionEnd, this);
this.on(GameEvent.NewWave, this.onNewWave, this);
this.on(GameEvent.FightStart, this.onFightStart, this);
this.on(GameEvent.CoinAdd, this.onCoinAdd, this);
oops.message.on(GameEvent.CoinAdd, this.onCoinAdd, this);
oops.message.on(GameEvent.MasterCalled, this.onMasterCalled, this);
oops.message.on(GameEvent.HeroDead, this.onHeroDead, this);
oops.message.on(GameEvent.UseHeroCard, this.onUseHeroCard, this);
@@ -187,6 +187,7 @@ export class MissionCardComp extends CCComp {
/** 解除按钮监听,避免节点销毁后回调泄漏 */
private unbindEvents() {
oops.message.off(GameEvent.CoinAdd, this.onCoinAdd, this);
oops.message.off(GameEvent.MasterCalled, this.onMasterCalled, this);
oops.message.off(GameEvent.HeroDead, this.onHeroDead, this);
oops.message.off(GameEvent.UseHeroCard, this.onUseHeroCard, this);
@@ -395,13 +396,7 @@ export class MissionCardComp extends CCComp {
}
private playButtonPressAnim(node: Node | null) {
if (!node || !node.isValid) return;
Tween.stopAllByTarget(node);
tween(node)
.to(0.06, {
scale: new Vec3(this.buttonPressScale, this.buttonPressScale, 1)
})
.start();
this.playNodeScaleTo(node, this.buttonPressScale, 0.06);
}
private playButtonClickAnim(node: Node | null, onComplete: () => void) {
@@ -409,26 +404,11 @@ export class MissionCardComp extends CCComp {
onComplete();
return;
}
Tween.stopAllByTarget(node);
tween(node)
.to(0.05, {
scale: new Vec3(this.buttonClickScale, this.buttonClickScale, 1)
})
.call(onComplete)
.to(0.08, {
scale: new Vec3(this.buttonNormalScale, this.buttonNormalScale, 1)
})
.start();
this.playNodeScalePop(node, this.buttonClickScale, 0.05, 0.08, onComplete);
}
private playButtonResetAnim(node: Node | null) {
if (!node || !node.isValid) return;
Tween.stopAllByTarget(node);
tween(node)
.to(0.08, {
scale: new Vec3(this.buttonNormalScale, this.buttonNormalScale, 1)
})
.start();
this.playNodeScaleTo(node, this.buttonNormalScale, 0.08);
}
private resetButtonScale(node: Node | null) {
@@ -491,15 +471,13 @@ export class MissionCardComp extends CCComp {
private playCoinChangeAnim(isIncrease: boolean) {
if (!this.coins_node || !this.coins_node.isValid) return;
const target = this.coins_node.getChildByName("num") || this.coins_node;
if (!target || !target.isValid) return;
const peak = isIncrease ? 1.16 : 1.08;
Tween.stopAllByTarget(target);
target.setScale(1, 1, 1);
tween(target)
.to(0.08, { scale: new Vec3(peak, peak, 1) })
.to(0.1, { scale: new Vec3(1, 1, 1) })
.start();
const icon = this.coins_node.getChildByName("icon");
if (!icon || !icon.isValid ) return;
const peak = isIncrease ? 1.2 : 1.2;
this.playHeroNumNodePop(icon, peak);
const num= this.coins_node.getChildByName("num");
if (!num || !num.isValid) return;
this.playHeroNumNodePop(num, peak);
}
private getUpgradeCost(lv: number): number {
@@ -648,25 +626,42 @@ export class MissionCardComp extends CCComp {
if (!this.hero_num_node || !this.hero_num_node.isValid) return;
const iconNode = this.hero_num_node.getChildByName("icon");
const numNode = this.hero_num_node.getChildByName("num");
this.playHeroNumNodePop(iconNode, 1.16);
this.playHeroNumNodePop(numNode, 1.16);
this.playHeroNumNodePop(iconNode, 1.2);
this.playHeroNumNodePop(numNode, 1.2);
}
private playHeroNumDeniedAnim() {
if (!this.hero_num_node || !this.hero_num_node.isValid) return;
const iconNode = this.hero_num_node.getChildByName("icon");
const numNode = this.hero_num_node.getChildByName("num");
this.playHeroNumNodePop(iconNode, 1.1);
this.playHeroNumNodePop(numNode, 1.1);
this.playHeroNumNodePop(iconNode, 1.2);
this.playHeroNumNodePop(numNode, 1.2);
}
private playHeroNumNodePop(node: Node | null, scalePeak: number) {
this.playNodeScalePop(node, scalePeak, 0.08, 0.1);
}
private playNodeScaleTo(node: Node | null, scale: number, duration: number) {
if (!node || !node.isValid) return;
Tween.stopAllByTarget(node);
tween(node)
.to(duration, {
scale: new Vec3(scale, scale, 1)
})
.start();
}
private playNodeScalePop(node: Node | null, scalePeak: number, toPeakDuration: number, toNormalDuration: number, onPeak?: () => void) {
if (!node || !node.isValid) return;
Tween.stopAllByTarget(node);
node.setScale(1, 1, 1);
tween(node)
.to(0.08, { scale: new Vec3(scalePeak, scalePeak, 1) })
.to(0.1, { scale: new Vec3(1, 1, 1) })
const seq = tween(node)
.to(toPeakDuration, { scale: new Vec3(scalePeak, scalePeak, 1) });
if (onPeak) {
seq.call(onPeak);
}
seq.to(toNormalDuration, { scale: new Vec3(1, 1, 1) })
.start();
}