refactor(missionCard): 重构刷新按钮UI逻辑,新增刷新石消耗支持

1. 新增初始刷新石常量配置
2. 重构多刷新按钮UI更新逻辑为通用方法
3. 调整按钮预制件UI结构,添加刷新石显示节点
4. 重构代码排版与注释,移除废弃引用
This commit is contained in:
panFD
2026-07-30 16:44:38 +08:00
parent 42c63e6482
commit 69b75b72c6
4 changed files with 2497 additions and 1145 deletions

View File

@@ -49,6 +49,7 @@ export enum FightSet {
REFRESH_COST = 2,
BASE_COST = 5,
INIT_COIN = 7, // 初始金币数
INIT_REFRESH_STONE = 3, // 初始刷新石数量
}
/**

View File

@@ -94,9 +94,6 @@ export class MissionCardComp extends CCComp {
/** 卡牌槽位预制体(动态实例化 3 个) */
@property(Prefab)
cardPrefab: Prefab = null!
/** 抽卡(刷新)按钮节点 */
@property(Node)
cards_chou: Node = null!
@property(Node)
closeCards: Node = null!
@@ -143,35 +140,33 @@ export class MissionCardComp extends CCComp {
shopBoxNode: Node = null!
@property(Prefab)
itemPrefab: Prefab = null!
/** 卡池升级按钮节点(已废弃,保留节点引用防止 editor 报错) */
@property(Node)
cards_up: Node = null!
/** 金币显示节点(含 icon + num 子节点) */
@property(Node)
coins_node: Node = null!
/** 卡池等级显示节点(已废弃,保留节点引用) */
@property(Node)
pool_lv_node: Node = null!
/** 英雄数量显示节点(含 icon + num 子节点) */
@property(Node)
hero_num_node: Node = null!
/** 技能刷新按钮节点 */
@property(Node)
skill_refresh: Node = null!
/** 槽位水平坐标(屏幕 720 三等分,卡片 230列宽 240 */
private readonly slotPosX: number[] = [-240, 0, 240];
/** 装备刷新按钮节点 */
@property(Node)
equip_refresh: Node = null!;
/** 药品刷新按钮节点 */
@property(Node)
shop_refresh: Node = null!;
/** 抽卡(刷新)按钮节点 */
@property(Node)
cards_chou: Node = null!
/** 金币显示节点(含 icon + num 子节点) */
@property(Node)
coins_node: Node = null!
/** 英雄数量显示节点(含 icon + num 子节点) */
@property(Node)
hero_num_node: Node = null!
// ======================== 运行时状态 ========================
/** 槽位水平坐标(屏幕 720 三等分,卡片 230列宽 240 */
private readonly slotPosX: number[] = [-240, 0, 240];
/** 三个槽位对应的 CHeroComp 控制器缓存(有序数组) */
private cardComps: CHeroComp[] = [];
/** 英雄面板 HeroBoxComp 控制器缓存(与场上英雄一一对应,最多 3 个) */
@@ -1712,52 +1707,62 @@ export class MissionCardComp extends CCComp {
}
private updateDrawCostUI() {
// 战斗阶段也允许抽卡nobg 统一按"金币是否足够"判断
if (this.cards_chou) {
const nobg = this.cards_chou.getChildByName("nobg");
if (nobg) {
nobg.active = !this.canDrawCards();
}
const coinNode = this.cards_chou.getChildByName("coin");
const numLabel = coinNode?.getChildByName("num")?.getComponent(Label);
if (numLabel) {
numLabel.string = `${MissionEconomy.getRefreshCost(this.refreshCost)}`;
const stones = MissionEconomy.getRefreshStone();
this.updateOneRefreshBtnUI(this.cards_chou, stones);
this.updateOneRefreshBtnUI(this.equip_refresh, stones);
this.updateOneRefreshBtnUI(this.shop_refresh, stones);
this.updateOneRefreshBtnUI(this.skill_refresh, stones);
}
/**
* 更新单个刷新按钮的费用显示与可用状态。
*
* 统一 UI 结构(按钮节点下):
* - 背景 :按钮底图
* - nobg :置灰遮罩,不可刷新时激活
* - Node/ :费用容器,下含 Label + coin + stone
* - coin/ :金币费用(含 num 子节点 Label刷新石=0 时显示
* - stone/ :刷新石费用(含 num 子节点 Label刷新石>0 时显示
*
* @param btnNode 刷新按钮节点
* @param stones 当前刷新石数量(外部统一读取,避免 4 次重复访问)
*/
private updateOneRefreshBtnUI(btnNode: Node | null, stones: number) {
if (!btnNode || !btnNode.isValid) return;
const useStone = stones > 0;
// 置灰遮罩:有刷新石必定可刷新,否则按金币判断
const nobg = btnNode.getChildByName("nobg");
if (nobg) {
nobg.active = useStone ? false : !this.canDrawCards();
}
// 费用容器:按钮下的 Node 子节点(统一结构:背景 + Node[Label/coin/stone]
const container = btnNode.getChildByName("Node");
if (!container) return;
// 金币费用节点
const coinNode = container.getChildByName("coin");
if (coinNode) {
coinNode.active = !useStone;
if (!useStone) {
const numLabel = coinNode.getChildByName("num")?.getComponent(Label);
if (numLabel) {
numLabel.string = `${MissionEconomy.getRefreshCost(this.refreshCost)}`;
}
}
}
if (this.equip_refresh) {
const nobg = this.equip_refresh.getChildByName("nobg");
if (nobg) {
nobg.active = !this.canDrawCards();
}
const coinNode = this.equip_refresh.getChildByName("coin");
const numLabel = coinNode?.getChildByName("num")?.getComponent(Label);
if (numLabel) {
numLabel.string = `${MissionEconomy.getRefreshCost(this.refreshCost)}`;
}
}
if (this.shop_refresh) {
const nobg = this.shop_refresh.getChildByName("nobg");
if (nobg) {
nobg.active = !this.canDrawCards();
}
const coinNode = this.shop_refresh.getChildByName("coin");
const numLabel = coinNode?.getChildByName("num")?.getComponent(Label);
if (numLabel) {
numLabel.string = `${MissionEconomy.getRefreshCost(this.refreshCost)}`;
}
}
if (this.skill_refresh) {
const nobg = this.skill_refresh.getChildByName("nobg");
if (nobg) {
nobg.active = !this.canDrawCards();
}
const coinNode = this.skill_refresh.getChildByName("coin");
const numLabel = coinNode?.getChildByName("num")?.getComponent(Label);
if (numLabel) {
numLabel.string = `${MissionEconomy.getRefreshCost(this.refreshCost)}`;
// 刷新石费用节点(显示当前持有数量)
const stoneNode = container.getChildByName("stone");
if (stoneNode) {
stoneNode.active = useStone;
if (useStone) {
const numLabel = stoneNode.getChildByName("num")?.getComponent(Label);
if (numLabel) {
numLabel.string = `${stones}`;
}
}
}
}