UECell.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. @property(cc.Node)
  19. private node_select: cc.Node = null!;
  20. @property(cc.Node)
  21. private sp_item: cc.Node = null!;
  22. private originalPos: cc.Vec3 = cc.v3(0, 0);
  23. cellData: I_CellData = null!;
  24. Init(cellData: I_CellData, idx: number) {
  25. this.cellData = cellData;
  26. this.node.zIndex = cellData.zIndex;
  27. this.lbt_num.string = idx.toString();
  28. this.originalPos = this.node.position;
  29. }
  30. /** 是否有物品可以拖动 */
  31. CanDrag(): boolean {
  32. return true;
  33. }
  34. StartDrag(): void {
  35. this.node.zIndex = 1000;
  36. }
  37. SetSelect(isSelect: boolean) {
  38. this.node_select.active = isSelect;
  39. }
  40. UpdateDragPosition(pos: cc.Vec3): void {
  41. if (this.itemNode) {
  42. this.itemNode.position = pos.sub(this.node.position);
  43. }
  44. }
  45. EndDrag(): void {
  46. if (this.itemNode) {
  47. this.node.zIndex = this.cellData.zIndex;
  48. this.PlayJellyAnim();
  49. }
  50. }
  51. ClearCell() {
  52. }
  53. /** 播放果冻效果 */
  54. PlayJellyAnim() {
  55. cc.tween(this.itemNode)
  56. .to(0.15, { position: cc.Vec3.ZERO })
  57. .to(0.1, { scale: 1.3 })
  58. .to(0.1, { scale: 0.9 })
  59. .to(0.08, { scale: 1 })
  60. .start();
  61. }
  62. /** 播放合成动画 */
  63. PlayMergeAnim() {
  64. cc.tween(this.itemNode)
  65. .by(0.1, { position: cc.v3(0, 40) })
  66. .by(0.1, { position: cc.v3(0, -40) })
  67. .by(0.1, { position: cc.v3(0, 10) })
  68. .by(0.1, { position: cc.v3(0, -10) })
  69. .start();
  70. }
  71. private UpdateItemDisplay(): void {
  72. // 根据 itemType 和 itemLevel 更新物品显示
  73. if (this.itemNode) {
  74. this.itemNode.active = true;
  75. // TODO: 更新物品的具体显示效果
  76. }
  77. }
  78. }