feat(地图): 添加卡片类型枚举并支持多种卡片数据
扩展MissionCardComp以支持多种卡片类型,添加CardType枚举 修改卡片数据处理逻辑,使其不局限于天赋类型 为后续添加技能和药水卡片类型预留扩展点
This commit is contained in:
@@ -7,6 +7,12 @@ import { talConf, ItalConf } from "../common/config/TalSet";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
export enum CardType {
|
||||
Talent = 1,
|
||||
Skill = 2,
|
||||
Potion = 3
|
||||
}
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('MissionCardComp')
|
||||
@ecs.register('MissionCard', false)
|
||||
@@ -21,10 +27,13 @@ export class MissionCardComp extends CCComp {
|
||||
@property(Node)
|
||||
card4:Node = null!
|
||||
|
||||
card1_data:ItalConf = null!
|
||||
card2_data:ItalConf = null!
|
||||
card3_data:ItalConf = null!
|
||||
card4_data:ItalConf = null!
|
||||
card1_data:any = null!
|
||||
card2_data:any = null!
|
||||
card3_data:any = null!
|
||||
card4_data:any = null!
|
||||
|
||||
// 当前卡片类型
|
||||
curCardType: CardType = CardType.Talent;
|
||||
|
||||
onLoad() {
|
||||
oops.message.on(GameEvent.TalentSelect, this.onTalentSelect, this);
|
||||
@@ -57,15 +66,23 @@ export class MissionCardComp extends CCComp {
|
||||
private onTalentSelect(event: string, args: any) {
|
||||
this.node.active = true;
|
||||
this.hasSelected = false; // 重置选择状态
|
||||
this.curCardType = CardType.Talent; // 记录当前类型为天赋
|
||||
this.resetCardStates(); // 每次刷新前重置卡片状态
|
||||
this.refCards();
|
||||
}
|
||||
|
||||
refCards(){
|
||||
// 随机获取4个不一样的天赋
|
||||
const allTalents = Object.values(talConf);
|
||||
const result: ItalConf[] = [];
|
||||
const temp = [...allTalents];
|
||||
// 根据当前类型获取数据
|
||||
let allData: any[] = [];
|
||||
|
||||
if (this.curCardType === CardType.Talent) {
|
||||
allData = Object.values(talConf);
|
||||
}
|
||||
// 后续扩展其他类型
|
||||
// else if (this.curCardType === CardType.Skill) { ... }
|
||||
|
||||
const result: any[] = [];
|
||||
const temp = [...allData];
|
||||
|
||||
// 简单的随机抽取算法
|
||||
for (let i = 0; i < 4 && temp.length > 0; i++) {
|
||||
@@ -81,7 +98,7 @@ export class MissionCardComp extends CCComp {
|
||||
if (result.length > 3) this.updateCardData(4, result[3]);
|
||||
}
|
||||
|
||||
updateCardInfo(card:Node, data:ItalConf){
|
||||
updateCardInfo(card:Node, data:any){
|
||||
if(!card) return
|
||||
card.active = true;
|
||||
// 隐藏选中状态
|
||||
@@ -94,11 +111,12 @@ export class MissionCardComp extends CCComp {
|
||||
}
|
||||
let info = card.getChildByName("info")?.getChildByName("Label")
|
||||
if(info){
|
||||
info.getComponent(Label)!.string = data.desc
|
||||
// 根据类型显示不同描述,目前天赋用desc
|
||||
info.getComponent(Label)!.string = data.desc || "";
|
||||
}
|
||||
}
|
||||
|
||||
updateCardData(index:number, data:ItalConf){
|
||||
updateCardData(index:number, data:any){
|
||||
switch (index) {
|
||||
case 1:
|
||||
this.card1_data = data
|
||||
@@ -125,38 +143,41 @@ export class MissionCardComp extends CCComp {
|
||||
// 如果已经选择过,则不再处理
|
||||
if(this.hasSelected) return;
|
||||
|
||||
let selectedTalent: ItalConf | null = null;
|
||||
let selectedData: any = null;
|
||||
let selectedCardNode: Node | null = null;
|
||||
|
||||
switch (_index) {
|
||||
case 1:
|
||||
selectedTalent = this.card1_data;
|
||||
selectedData = this.card1_data;
|
||||
selectedCardNode = this.card1;
|
||||
break;
|
||||
case 2:
|
||||
selectedTalent = this.card2_data;
|
||||
selectedData = this.card2_data;
|
||||
selectedCardNode = this.card2;
|
||||
break;
|
||||
case 3:
|
||||
selectedTalent = this.card3_data;
|
||||
selectedData = this.card3_data;
|
||||
selectedCardNode = this.card3;
|
||||
break;
|
||||
case 4:
|
||||
selectedTalent = this.card4_data;
|
||||
selectedData = this.card4_data;
|
||||
selectedCardNode = this.card4;
|
||||
break;
|
||||
}
|
||||
|
||||
if (selectedTalent && selectedCardNode) {
|
||||
if (selectedData && selectedCardNode) {
|
||||
this.hasSelected = true;
|
||||
console.log("选择天赋:", selectedTalent.name);
|
||||
console.log("选择卡片:", selectedData.name, "类型:", this.curCardType);
|
||||
|
||||
// 显示当前选中的 selected 节点
|
||||
const selected = selectedCardNode.getChildByName("selected");
|
||||
if(selected) selected.active = true;
|
||||
|
||||
// 发送事件
|
||||
oops.message.dispatchEvent(GameEvent.UseTalentCard, selectedTalent.uuid);
|
||||
// 根据类型发送不同事件
|
||||
if (this.curCardType === CardType.Talent) {
|
||||
oops.message.dispatchEvent(GameEvent.UseTalentCard, selectedData.uuid);
|
||||
}
|
||||
// 后续扩展其他类型事件
|
||||
|
||||
// 延迟关闭界面,让玩家看到选中效果
|
||||
// this.scheduleOnce(() => {
|
||||
|
||||
Reference in New Issue
Block a user