UECell.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import UEBase from "../../frameWork/compment/UEBase";
  2. const { ccclass, property } = cc._decorator;
  3. export interface I_CellData {
  4. }
  5. @ccclass
  6. export default class UECell extends UEBase {
  7. static readonly BundleKey: string = "gridMap";
  8. static readonly PrefabUrl: string = "UECell";
  9. static readonly CLS: string = "UECell";
  10. @property(cc.Node)
  11. private itemNode: cc.Node = null!;
  12. @property(cc.Label)
  13. private lbt_num: cc.Label = null!;
  14. private itemType: number = 0; // 物品类型
  15. private itemLevel: number = 0; // 物品等级
  16. private originalPos: cc.Vec3 = cc.v3(0, 0);
  17. Init(idx: number) {
  18. this.lbt_num.string = idx.toString();
  19. this.originalPos = this.node.position;
  20. }
  21. hasItem(): boolean {
  22. return this.itemType !== 0;
  23. }
  24. startDrag(): void {
  25. if (this.itemNode) {
  26. this.itemNode.zIndex = 100;
  27. this.itemNode.opacity = 180;
  28. }
  29. }
  30. updateDragPosition(pos: cc.Vec3): void {
  31. if (this.itemNode) {
  32. this.itemNode.position = pos.sub(this.node.position);
  33. }
  34. }
  35. endDrag(): void {
  36. if (this.itemNode) {
  37. this.itemNode.zIndex = 1;
  38. this.itemNode.opacity = 255;
  39. this.itemNode.position = cc.Vec3.ZERO;
  40. }
  41. }
  42. canMergeWith(other: UECell): boolean {
  43. return this.itemType === other.itemType && this.itemLevel === other.itemLevel;
  44. }
  45. mergeFrom(other: UECell): void {
  46. if (this.canMergeWith(other)) {
  47. this.itemLevel++;
  48. // 更新显示
  49. this.updateItemDisplay();
  50. // 清空原来的格子
  51. other.clearItem();
  52. }
  53. }
  54. clearItem(): void {
  55. this.itemType = 0;
  56. this.itemLevel = 0;
  57. if (this.itemNode) {
  58. this.itemNode.active = false;
  59. }
  60. }
  61. private updateItemDisplay(): void {
  62. // 根据 itemType 和 itemLevel 更新物品显示
  63. if (this.itemNode) {
  64. this.itemNode.active = true;
  65. // TODO: 更新物品的具体显示效果
  66. }
  67. }
  68. }