UECube.ts 4.6 KB

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