UECube.ts 4.8 KB

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