BlockInfo.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import { _decorator, Component, Node, Label, Sprite, SpriteFrame, Color, Vec2, Enum } from 'cc';
  2. import { WeaponConfig } from '../../Core/ConfigManager';
  3. // 导入cc命名空间以支持旧版本API
  4. const cc = { Color, Vec2, Enum };
  5. const { ccclass, property } = _decorator;
  6. /**
  7. * 方块信息组件
  8. * 用于在属性检查器中显示和管理方块的各种信息
  9. * 包括稀有度、价格、标签、武器配置等
  10. */
  11. @ccclass('BlockInfo')
  12. export class BlockInfo extends Component {
  13. // 方块基础信息
  14. @property({
  15. displayName: '方块名称',
  16. tooltip: '方块的显示名称'
  17. })
  18. public blockName: string = '';
  19. @property({
  20. displayName: '方块ID',
  21. tooltip: '方块的唯一标识符'
  22. })
  23. public blockId: string = '';
  24. // 稀有度相关
  25. @property({
  26. type: cc.Enum({
  27. common: 0,
  28. uncommon: 1,
  29. rare: 2,
  30. epic: 3
  31. }),
  32. displayName: '稀有度',
  33. tooltip: '方块的稀有度等级'
  34. })
  35. public rarity: number = 0; // 0: common, 1: uncommon, 2: rare, 3: epic
  36. @property({
  37. displayName: '稀有度颜色',
  38. tooltip: '稀有度对应的颜色'
  39. })
  40. public rarityColor: Color = Color.WHITE;
  41. // 武器相关
  42. @property({
  43. displayName: '武器类型',
  44. tooltip: '方块对应的武器类型'
  45. })
  46. public weaponType: string = '';
  47. @property({
  48. displayName: '武器ID',
  49. tooltip: '武器的唯一标识符'
  50. })
  51. public weaponId: string = '';
  52. @property({
  53. displayName: '伤害值',
  54. tooltip: '武器的伤害值'
  55. })
  56. public damage: number = 0;
  57. @property({
  58. displayName: '攻击范围',
  59. tooltip: '武器的攻击范围'
  60. })
  61. public range: number = 0;
  62. @property({
  63. displayName: '攻击速度',
  64. tooltip: '武器的攻击速度'
  65. })
  66. public attackSpeed: number = 1.0;
  67. // 方块标签
  68. @property({
  69. displayName: '方块标签',
  70. tooltip: '方块的标签列表'
  71. })
  72. public blockTags: string[] = [];
  73. // 形状相关
  74. @property({
  75. displayName: '形状ID',
  76. tooltip: '方块的形状标识符'
  77. })
  78. public shapeId: string = '';
  79. @property({
  80. displayName: '形状大小',
  81. tooltip: '方块形状的尺寸(宽x高)'
  82. })
  83. public shapeSize: Vec2 = new Vec2(1, 1);
  84. // 位置信息
  85. @property({
  86. displayName: '所在区域',
  87. tooltip: '方块当前所在的区域(kuang/block1/block2/block3/grid)'
  88. })
  89. public currentLocation: string = 'kuang';
  90. @property({
  91. displayName: '网格位置',
  92. tooltip: '方块在网格中的位置'
  93. })
  94. public gridPosition: Vec2 = new Vec2(-1, -1);
  95. // 状态信息
  96. @property({
  97. displayName: '是否已放置',
  98. tooltip: '方块是否已经放置在网格中'
  99. })
  100. public isPlaced: boolean = false;
  101. @property({
  102. displayName: '是否可拖拽',
  103. tooltip: '方块是否可以被拖拽'
  104. })
  105. public isDraggable: boolean = true;
  106. @property({
  107. displayName: '是否可合并',
  108. tooltip: '方块是否可以与其他方块合并'
  109. })
  110. public isMergeable: boolean = true;
  111. // 引用节点
  112. @property({
  113. type: Sprite,
  114. displayName: '稀有度图标',
  115. tooltip: '显示稀有度的Sprite组件'
  116. })
  117. public raritySprite: Sprite = null;
  118. @property({
  119. type: Sprite,
  120. displayName: '武器图标',
  121. tooltip: '显示武器的Sprite组件'
  122. })
  123. public weaponSprite: Sprite = null;
  124. @property({
  125. type: [SpriteFrame],
  126. displayName: '稀有度图标数组',
  127. tooltip: '按稀有度顺序排列的图标数组:0-common, 1-uncommon, 2-rare, 3-epic'
  128. })
  129. public rarityIcons: SpriteFrame[] = [];
  130. // 私有属性:武器配置
  131. private weaponConfig: WeaponConfig = null;
  132. /**
  133. * 获取稀有度名称
  134. */
  135. public getRarityName(): string {
  136. const rarityNames = ['common', 'uncommon', 'rare', 'epic'];
  137. return rarityNames[this.rarity] || 'common';
  138. }
  139. /**
  140. * 获取当前稀有度对应的图标
  141. */
  142. public getRarityIcon(): SpriteFrame | null {
  143. if (this.rarityIcons && this.rarityIcons.length > this.rarity && this.rarity >= 0) {
  144. return this.rarityIcons[this.rarity];
  145. }
  146. return null;
  147. }
  148. /**
  149. * 设置武器配置
  150. */
  151. public setWeaponConfig(config: WeaponConfig): void {
  152. this.weaponConfig = config;
  153. if (config) {
  154. this.weaponType = config.name;
  155. this.weaponId = config.id || config.name;
  156. this.damage = config.stats?.damage || 0;
  157. this.range = config.stats?.range || 0;
  158. this.attackSpeed = config.stats?.fireRate || 1.0;
  159. // 如果配置中有稀有度信息,更新稀有度
  160. if (config.rarity) {
  161. const rarityMap = { 'common': 0, 'uncommon': 1, 'rare': 2, 'epic': 3 };
  162. this.rarity = rarityMap[config.rarity] || 0;
  163. }
  164. }
  165. }
  166. /**
  167. * 获取武器配置
  168. */
  169. public getWeaponConfig(): WeaponConfig {
  170. return this.weaponConfig;
  171. }
  172. /**
  173. * 更新价格显示
  174. */
  175. public updatePriceDisplay(): void {
  176. // 价格显示功能已移除
  177. }
  178. /**
  179. * 更新稀有度显示
  180. */
  181. public updateRarityDisplay(): void {
  182. if (this.raritySprite) {
  183. // 根据稀有度设置颜色
  184. this.raritySprite.color = this.rarityColor;
  185. }
  186. }
  187. /**
  188. * 设置方块标签
  189. */
  190. public setBlockTags(tags: string[]): void {
  191. this.blockTags = [...tags];
  192. }
  193. /**
  194. * 添加方块标签
  195. */
  196. public addBlockTag(tag: string): void {
  197. if (this.blockTags.indexOf(tag) === -1) {
  198. this.blockTags.push(tag);
  199. }
  200. }
  201. /**
  202. * 移除方块标签
  203. */
  204. public removeBlockTag(tag: string): void {
  205. const index = this.blockTags.indexOf(tag);
  206. if (index > -1) {
  207. this.blockTags.splice(index, 1);
  208. }
  209. }
  210. /**
  211. * 检查是否有指定标签
  212. */
  213. public hasTag(tag: string): boolean {
  214. return this.blockTags.indexOf(tag) !== -1;
  215. }
  216. /**
  217. * 更新网格位置
  218. */
  219. public updateGridPosition(row: number, col: number): void {
  220. this.gridPosition.set(col, row);
  221. }
  222. /**
  223. * 设置放置状态
  224. */
  225. public setPlacedState(placed: boolean, location: string = ''): void {
  226. this.isPlaced = placed;
  227. if (location) {
  228. this.currentLocation = location;
  229. }
  230. }
  231. /**
  232. * 根据稀有度计算价格
  233. */
  234. /**
  235. * 获取方块信息摘要
  236. */
  237. public getBlockSummary(): string {
  238. return `${this.blockName} (${this.getRarityName()}) - 0金币 - ${this.weaponType}`;
  239. }
  240. start() {
  241. // 初始化时更新显示
  242. this.updatePriceDisplay();
  243. this.updateRarityDisplay();
  244. }
  245. /**
  246. * 在编辑器中更新属性时调用
  247. */
  248. onLoad() {
  249. // 初始化组件
  250. }
  251. }