import { _decorator, Component, Node, Label, Sprite, SpriteFrame, Color, Vec2, Enum } from 'cc'; import { WeaponConfig } from '../../Core/ConfigManager'; // 导入cc命名空间以支持旧版本API const cc = { Color, Vec2, Enum }; const { ccclass, property } = _decorator; /** * 方块信息组件 * 用于在属性检查器中显示和管理方块的各种信息 * 包括稀有度、价格、标签、武器配置等 */ @ccclass('BlockInfo') export class BlockInfo extends Component { // 方块基础信息 @property({ displayName: '方块名称', tooltip: '方块的显示名称' }) public blockName: string = ''; @property({ displayName: '方块ID', tooltip: '方块的唯一标识符' }) public blockId: string = ''; // 稀有度相关 @property({ type: cc.Enum({ common: 0, uncommon: 1, rare: 2, epic: 3 }), displayName: '稀有度', tooltip: '方块的稀有度等级' }) public rarity: number = 0; // 0: common, 1: uncommon, 2: rare, 3: epic @property({ displayName: '稀有度颜色', tooltip: '稀有度对应的颜色' }) public rarityColor: Color = Color.WHITE; // 武器相关 @property({ displayName: '武器类型', tooltip: '方块对应的武器类型' }) public weaponType: string = ''; @property({ displayName: '武器ID', tooltip: '武器的唯一标识符' }) public weaponId: string = ''; @property({ displayName: '伤害值', tooltip: '武器的伤害值' }) public damage: number = 0; @property({ displayName: '攻击范围', tooltip: '武器的攻击范围' }) public range: number = 0; @property({ displayName: '攻击速度', tooltip: '武器的攻击速度' }) public attackSpeed: number = 1.0; // 方块标签 @property({ displayName: '方块标签', tooltip: '方块的标签列表' }) public blockTags: string[] = []; // 形状相关 @property({ displayName: '形状ID', tooltip: '方块的形状标识符', readonly: true }) public shapeId: string = ''; @property({ displayName: '形状价格', tooltip: '从武器配置中读取的形状对应价格', readonly: true }) public shapePrice: number = 0; @property({ displayName: '形状大小', tooltip: '方块形状的尺寸(宽x高)' }) public shapeSize: Vec2 = new Vec2(1, 1); // 位置信息 @property({ displayName: '所在区域', tooltip: '方块当前所在的区域(kuang/block1/block2/block3/grid)' }) public currentLocation: string = 'kuang'; @property({ displayName: '网格位置', tooltip: '方块在网格中的位置' }) public gridPosition: Vec2 = new Vec2(-1, -1); // 状态信息 @property({ displayName: '是否已放置', tooltip: '方块是否已经放置在网格中' }) public isPlaced: boolean = false; @property({ displayName: '是否可拖拽', tooltip: '方块是否可以被拖拽' }) public isDraggable: boolean = true; @property({ displayName: '是否可合并', tooltip: '方块是否可以与其他方块合并' }) public isMergeable: boolean = true; // 引用节点 @property({ type: Sprite, displayName: '稀有度图标', tooltip: '显示稀有度的Sprite组件' }) public raritySprite: Sprite = null; @property({ type: Sprite, displayName: '武器图标', tooltip: '显示武器的Sprite组件' }) public weaponSprite: Sprite = null; @property({ type: [SpriteFrame], displayName: '稀有度图标数组', tooltip: '按稀有度顺序排列的图标数组:0-common, 1-uncommon, 2-rare, 3-epic' }) public rarityIcons: SpriteFrame[] = []; // 私有属性:武器配置 private weaponConfig: WeaponConfig = null; /** * 获取稀有度名称 */ public getRarityName(): string { const rarityNames = ['common', 'uncommon', 'rare', 'epic']; return rarityNames[this.rarity] || 'common'; } /** * 获取当前稀有度对应的图标 */ public getRarityIcon(): SpriteFrame | null { if (this.rarityIcons && this.rarityIcons.length > this.rarity && this.rarity >= 0) { return this.rarityIcons[this.rarity]; } return null; } /** * 设置武器配置 */ public setWeaponConfig(config: WeaponConfig): void { this.weaponConfig = config; if (config) { this.weaponType = config.name; this.weaponId = config.id || config.name; this.damage = config.stats?.damage || 0; this.range = config.stats?.range || 0; this.attackSpeed = config.stats?.fireRate || 1.0; // 如果配置中有稀有度信息,更新稀有度 if (config.rarity) { const rarityMap = { 'common': 0, 'uncommon': 1, 'rare': 2, 'epic': 3 }; this.rarity = rarityMap[config.rarity] || 0; } // 设置形状价格 if (config.inGameCostConfig && config.inGameCostConfig.shapeCosts && this.shapeId) { this.shapePrice = config.inGameCostConfig.shapeCosts[this.shapeId] || 0; } } } /** * 获取武器配置 */ public getWeaponConfig(): WeaponConfig { return this.weaponConfig; } /** * 更新价格显示 */ public updatePriceDisplay(): void { // 价格显示功能已移除 } /** * 更新稀有度显示 */ public updateRarityDisplay(): void { if (this.raritySprite) { // 根据稀有度设置颜色 this.raritySprite.color = this.rarityColor; } } /** * 设置方块标签 */ public setBlockTags(tags: string[]): void { this.blockTags = [...tags]; } /** * 添加方块标签 */ public addBlockTag(tag: string): void { if (this.blockTags.indexOf(tag) === -1) { this.blockTags.push(tag); } } /** * 移除方块标签 */ public removeBlockTag(tag: string): void { const index = this.blockTags.indexOf(tag); if (index > -1) { this.blockTags.splice(index, 1); } } /** * 检查是否有指定标签 */ public hasTag(tag: string): boolean { return this.blockTags.indexOf(tag) !== -1; } /** * 更新网格位置 */ public updateGridPosition(row: number, col: number): void { this.gridPosition.set(col, row); } /** * 设置放置状态 */ public setPlacedState(placed: boolean, location: string = ''): void { this.isPlaced = placed; if (location) { this.currentLocation = location; } } /** * 根据稀有度计算价格 */ /** * 获取方块信息摘要 */ public getBlockSummary(): string { return `${this.blockName} (${this.getRarityName()}) - 0金币 - ${this.weaponType}`; } start() { // 初始化时更新显示 this.updatePriceDisplay(); this.updateRarityDisplay(); } /** * 在编辑器中更新属性时调用 */ onLoad() { // 初始化组件 } }