UECube.ts 4.7 KB

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