refactor(config,map): 统一抽离卡片背景颜色配置
将多处硬编码的卡片等级背景颜色数组移至公共配置文件, 同时重构英雄列表组件的等级显示逻辑,替换为标签直接赋值。
This commit is contained in:
@@ -195,3 +195,9 @@ export function getLvColor(lv: number): Color {
|
||||
default: return Color.WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* card_lv → 背景颜色节点名映射:1=green 2=blue 3=purple 4=yellow 5=red
|
||||
* 用于 BG_node 下子节点的显隐切换
|
||||
*/
|
||||
export const CARD_LV_BG_COLORS: string[] = ["green", "blue", "purple", "yellow", "red"];
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import { _decorator, Component } from "cc";
|
||||
import { CARD_LV_BG_COLORS } from "../common/config/GameSet";
|
||||
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
const POOL_COLORS = ["green", "blue", "purple", "yellow", "red"];
|
||||
|
||||
@ccclass('CardBgComp')
|
||||
export class CardBgComp extends Component {
|
||||
|
||||
apply(poolLv: number) {
|
||||
const color = POOL_COLORS[Math.min(poolLv, 5) - 1];
|
||||
apply(card_lv: number) {
|
||||
const color = CARD_LV_BG_COLORS[Math.min(card_lv, 5) - 1];
|
||||
this.node.children.forEach(c => c.active = c.name === color);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,12 @@ import { CardConfig, CardType, SpecialRefreshCardList, SpecialUpgradeCardList, C
|
||||
import { SkillCardList } from "../common/config/SCardSet";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { getLvColor } from "../common/config/GameSet";
|
||||
import { getLvColor, CARD_LV_BG_COLORS } from "../common/config/GameSet";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** card_lv → BG_node 子节点(颜色)名映射:1=green 2=blue 3=purple 4=yellow 5=red */
|
||||
const BG_COLORS = ["green", "blue", "purple", "yellow", "red"];
|
||||
/** card_lv → BG_node 子节点(颜色)名映射已移至 GameSet.CARD_LV_BG_COLORS */
|
||||
|
||||
/**
|
||||
* CardLiteComp —— 单张卡牌简单视图组件
|
||||
@@ -225,7 +224,7 @@ export class CardLiteComp extends CCComp {
|
||||
// 背景:按 card_lv 切换颜色底框(BG_node 下为 green/blue/purple/yellow/red 子节点)
|
||||
if (this.BG_node) {
|
||||
const bgLv = Math.min(Math.max(this.cardData.base_card_lv ?? this.cardData.card_lv ?? 1, 1), 5);
|
||||
const color = BG_COLORS[bgLv - 1];
|
||||
const color = CARD_LV_BG_COLORS[bgLv - 1];
|
||||
this.BG_node.children.forEach(child => child.active = (child.name === color));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,10 @@ import { _decorator, Animation, AnimationClip, Node, Sprite, Vec3, resources } f
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { CARD_LV_BG_COLORS } from "../common/config/GameSet";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** card_lv → BG_node 子节点(颜色)名映射:1=green 2=blue 3=purple 4=yellow 5=red */
|
||||
const BG_COLORS = ["green", "blue", "purple", "yellow", "red"];
|
||||
|
||||
/**
|
||||
* ChipComp —— 单张英雄卡图标/背景视图组件
|
||||
*
|
||||
@@ -58,7 +56,7 @@ export class ChipComp extends CCComp {
|
||||
|
||||
// 背景:按 card_lv 切换颜色底框(green/blue/purple/yellow/red)
|
||||
if (this.BG_node) {
|
||||
const color = BG_COLORS[Math.min(Math.max(hero.card_lv ?? 1, 1), 5) - 1];
|
||||
const color = CARD_LV_BG_COLORS[Math.min(Math.max(hero.card_lv ?? 1, 1), 5) - 1];
|
||||
this.BG_node.children.forEach(child => child.active = (child.name === color));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,8 @@ import { oops } from "db://oops-framework/core/Oops";
|
||||
import { mLogger } from "../common/Logger";
|
||||
import { HeroInfo, HeroList } from "../common/config/heroSet";
|
||||
import { buildSkillDesc } from "../common/config/HeroSkillDesc";
|
||||
import { CKind } from "../common/config/CardSet";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { HERO_UPGRADE_NEED_FRAGMENTS } from "../common/config/GameSet";
|
||||
import { CardBgComp } from "./CardBgComp";
|
||||
import { HERO_UPGRADE_NEED_FRAGMENTS, CARD_LV_BG_COLORS } from "../common/config/GameSet";
|
||||
import { CardLiteComp } from "./CardLiteComp";
|
||||
import { ChipComp } from "./ChipComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
@@ -70,8 +68,9 @@ export class HerosListComp extends CCComp {
|
||||
@property(Prefab)
|
||||
card_lite_prefab = null!
|
||||
|
||||
@property(Node)
|
||||
lv_node = null!
|
||||
/** 卡池等级 Label,直接显示 lv.X */
|
||||
@property(Label)
|
||||
lv_label = null!
|
||||
|
||||
@property(Node)
|
||||
type_node = null!
|
||||
@@ -270,14 +269,13 @@ export class HerosListComp extends CCComp {
|
||||
this.updateGrowthPanel(uuid)
|
||||
}
|
||||
|
||||
private updatePoolLvBg(poolLv: number) {
|
||||
private updatePoolLvBg(card_lv: number) {
|
||||
if (!this.BG_node) return
|
||||
const kindName = CKind[CKind.Hero];
|
||||
// BG_node 下直接放置颜色节点(green/blue/purple/yellow/red),按卡池等级激活对应颜色
|
||||
const color = CARD_LV_BG_COLORS[Math.min(card_lv, 5) - 1]
|
||||
this.BG_node.children.forEach(child => {
|
||||
child.active = (child.name === kindName);
|
||||
const bg = child.getComponent(CardBgComp);
|
||||
if (bg) child.active ? bg.apply(poolLv) : bg.clear();
|
||||
});
|
||||
child.active = (child.name === color)
|
||||
})
|
||||
}
|
||||
|
||||
private updateCdDisplay(hero: typeof HeroInfo[number]) {
|
||||
@@ -291,20 +289,8 @@ export class HerosListComp extends CCComp {
|
||||
}
|
||||
|
||||
private updateLvDisplay(hero: typeof HeroInfo[number]) {
|
||||
if (!this.lv_node) return
|
||||
const cardLvStr = `lv${hero.card_lv ?? 1}`
|
||||
this.lv_node.active = true
|
||||
this.lv_node.children.forEach(child => {
|
||||
|
||||
child.active = (child.name === cardLvStr)
|
||||
|
||||
})
|
||||
const widget = this.lv_node.getComponent(Widget)
|
||||
if (widget) widget.updateAlignment()
|
||||
this.lv_node.children.forEach(child => {
|
||||
const childWidget = child.getComponent(Widget)
|
||||
if (childWidget) childWidget.updateAlignment()
|
||||
})
|
||||
if (!this.lv_label) return
|
||||
this.lv_label.string = `lv.${hero.card_lv ?? 1}`
|
||||
}
|
||||
|
||||
private updateTypeDisplay(hero: typeof HeroInfo[number]) {
|
||||
|
||||
Reference in New Issue
Block a user