UECell.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import UEBase from "../../frameWork/compment/UEBase";
  2. const { ccclass, property } = cc._decorator;
  3. export interface I_CellData {
  4. id: number;
  5. type: number;
  6. level?: number;
  7. zIndex: number;
  8. }
  9. @ccclass
  10. export default class UECell extends UEBase {
  11. static readonly BundleKey: string = "gridMap";
  12. static readonly PrefabUrl: string = "UECell";
  13. static readonly CLS: string = "UECell";
  14. @property(cc.Node)
  15. private itemNode: cc.Node = null!;
  16. @property(cc.Label)
  17. private lbt_num: cc.Label = null!;
  18. private originalPos: cc.Vec3 = cc.v3(0, 0);
  19. cellData: I_CellData = null!;
  20. Init(cellData: I_CellData, idx: number) {
  21. this.cellData = cellData;
  22. this.node.zIndex = cellData.zIndex;
  23. this.lbt_num.string = idx.toString();
  24. this.originalPos = this.node.position;
  25. }
  26. /** 是否有物品可以拖动 */
  27. CanDrag(): boolean {
  28. return true;
  29. }
  30. StartDrag(): void {
  31. this.node.zIndex = 1000;
  32. }
  33. UpdateDragPosition(pos: cc.Vec3): void {
  34. if (this.itemNode) {
  35. this.itemNode.position = pos.sub(this.node.position);
  36. }
  37. }
  38. EndDrag(): void {
  39. if (this.itemNode) {
  40. this.node.zIndex = this.cellData.zIndex;
  41. cc.tween(this.itemNode)
  42. .to(0.15, { position: cc.Vec3.ZERO })
  43. .call(() => {
  44. this.itemNode.scale = 1.3;
  45. })
  46. .to(0.3, { scale: 1 })
  47. .to(0.2, { scale: 1.1 })
  48. .to(0.2, { scale: 1 })
  49. .start();
  50. }
  51. }
  52. private UpdateItemDisplay(): void {
  53. // 根据 itemType 和 itemLevel 更新物品显示
  54. if (this.itemNode) {
  55. this.itemNode.active = true;
  56. // TODO: 更新物品的具体显示效果
  57. }
  58. }
  59. }