UECube.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import Gamecfg from "../../common/gameCfg";
  2. import ResSprite from "../../frameWork/compment/ResSprite";
  3. import UEBase from "../../frameWork/compment/UEBase";
  4. const { ccclass, property } = cc._decorator;
  5. export interface I_CubeData {
  6. /** 物品类型 */
  7. type: number;
  8. /** 物品ID */
  9. id: number;
  10. /** 层级 */
  11. zIndex: number;
  12. /** 解锁条件 */
  13. unlock: number
  14. }
  15. @ccclass
  16. export default class UECube extends UEBase {
  17. static readonly BundleKey: string = "gridMap";
  18. static readonly PrefabUrl: string = "UECube";
  19. static readonly CLS: string = "UECube";
  20. @property(cc.Node)
  21. private itemNode: cc.Node = null!;
  22. @property(cc.Label)
  23. private lbt_num: cc.Label = null!;
  24. @property(ResSprite)
  25. private sp_item: ResSprite = null!;
  26. originalPos: cc.Vec3 = cc.Vec3.ZERO;
  27. cubeData: I_CubeData = null!;
  28. Init(cubeData: I_CubeData) {
  29. this.cubeData = cubeData;
  30. this.SetZIndex(cubeData.zIndex);
  31. this.originalPos = cc.v3(this.node.x, this.node.y);
  32. if (cubeData.type == 3) {
  33. let mergePropCfg = Gamecfg.mergePropInfo.getItem(cubeData.id.toString());
  34. this.sp_item.setSpriteFrame('gridMap', `equipIcon/${mergePropCfg.icon}`);
  35. }
  36. }
  37. getCubeData(): I_CubeData {
  38. return this.cubeData;
  39. }
  40. SetZIndex(zIndex: number) {
  41. this.node.zIndex = zIndex;
  42. this.cubeData.zIndex = zIndex;
  43. this.lbt_num.string = zIndex.toString();
  44. }
  45. /** 是否有物品可以拖动 */
  46. CanDrag(): boolean {
  47. return true;
  48. }
  49. StartDrag(): void {
  50. this.node.zIndex = 1000;
  51. }
  52. UpdateDragPosition(pos: cc.Vec3): void {
  53. this.node.position = pos.sub(this.node.position);
  54. }
  55. EndDrag(): void {
  56. this.node.zIndex = this.cubeData.zIndex;
  57. }
  58. ClearCell() {
  59. }
  60. /** 回到原来位置 */
  61. BackToOriginalPos(needMove: boolean) {
  62. if (needMove) {
  63. cc.tween(this.node)
  64. .to(0.15, { position: this.originalPos })
  65. .call(() => {
  66. this.EndDrag();
  67. this.PlayJellyAnim();
  68. })
  69. .start();
  70. } else {
  71. this.itemNode.setPosition(this.originalPos.clone());
  72. this.EndDrag();
  73. this.PlayJellyAnim();
  74. }
  75. }
  76. /** 播放果冻效果 */
  77. PlayJellyAnim() {
  78. cc.tween(this.itemNode)
  79. .to(0.1, { scale: 1.3 })
  80. .to(0.1, { scale: 0.9 })
  81. .to(0.08, { scale: 1 })
  82. .start();
  83. }
  84. /** 播放合成动画 */
  85. PlayMergeAnim() {
  86. cc.tween(this.itemNode)
  87. .by(0.1, { position: cc.v3(0, 40) })
  88. .by(0.1, { position: cc.v3(0, -40) })
  89. .by(0.1, { position: cc.v3(0, 10) })
  90. .by(0.1, { position: cc.v3(0, -10) })
  91. .start();
  92. }
  93. /** 移动到新的位置 */
  94. MoveToNewPos(newPos: cc.Vec3, duration: number = 0.2) {
  95. cc.tween(this.node)
  96. .to(duration, { position: newPos })
  97. .call(() => {
  98. this.EndDrag();
  99. this.PlayJellyAnim();
  100. })
  101. .start();
  102. this.originalPos = newPos.clone();
  103. }
  104. private UpdateItemDisplay(): void {
  105. // 根据 itemType 和 itemLevel 更新物品显示
  106. if (this.itemNode) {
  107. this.itemNode.active = true;
  108. // TODO: 更新物品的具体显示效果
  109. }
  110. }
  111. public unUse() {
  112. this.node.destroy();
  113. }
  114. }