UECube.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 { HcType } from "../../shared/hc/PtlHcInfo";
  7. import { GridEvent } from "./GridEvent";
  8. const { ccclass, property } = cc._decorator;
  9. export interface I_CubeData {
  10. /** 物品类型 */
  11. type: HcType;
  12. /** 物品ID */
  13. id: number;
  14. /** 层级 */
  15. zIndex: number;
  16. }
  17. @ccclass
  18. export default class UECube extends UEBase {
  19. static readonly BundleKey: string = "gridMap";
  20. static readonly PrefabUrl: string = "UECube";
  21. static readonly CLS: string = "UECube";
  22. @property(cc.Node)
  23. private itemNode: cc.Node = null!;
  24. @property(cc.Label)
  25. private lbt_num: cc.Label = null!;
  26. @property(cc.Label)
  27. private lbt_key: cc.Label = null!;
  28. @property(ResSprite)
  29. private sp_item: ResSprite = null!;
  30. cubeData: I_CubeData = null!;
  31. quality: number = 0;
  32. Init(cubeData: I_CubeData) {
  33. this.cubeData = cubeData;
  34. this.SetZIndex(cubeData.zIndex);
  35. if (cubeData.type == HcType.emitter) {
  36. let mergePropCfg = Gamecfg.emitterInfo.getItem(cubeData.id.toString());
  37. this.sp_item.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg.icon}`);
  38. // this.quality = mergePropCfg.
  39. } else if (cubeData.type == HcType.material) {
  40. let mergePropCfg = Gamecfg.mergePropInfo.getItem(cubeData.id.toString());
  41. this.sp_item.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg.icon}`);
  42. this.quality = mergePropCfg.quality;
  43. } else if (cubeData.type == HcType.equip) {
  44. let mergePropCfg = Gamecfg.equipInfo.getItem(cubeData.id.toString());
  45. this.sp_item.setSpriteFrame('gridMap', `mergeEquip/${mergePropCfg.icon}`);
  46. // this.quality = mergePropCfg.quality;
  47. }
  48. this.lbt_key.string = `${cubeData.type}_${cubeData.id}`;
  49. }
  50. /** 获取品质 */
  51. GetQuality() {
  52. return this.quality;
  53. }
  54. /** 触发点击 */
  55. TriggerClick() {
  56. if (this.cubeData.type == HcType.emitter) {
  57. CC_PREVIEW && console.log("触发点击发射器");
  58. GameDataCenter.gridMap.sendEmitter(this.cubeData.zIndex);
  59. } else if (this.cubeData.type == HcType.monster) {
  60. CC_PREVIEW && console.log("点击怪物开始战斗");
  61. } else if (this.cubeData.type == HcType.equip) {
  62. }
  63. }
  64. GetCubeData(): I_CubeData {
  65. return this.cubeData;
  66. }
  67. SetZIndex(zIndex: number) {
  68. this.node.zIndex = zIndex;
  69. this.cubeData.zIndex = zIndex;
  70. this.lbt_num.string = zIndex.toString();
  71. }
  72. /** 是否有物品可以拖动 */
  73. CanDrag(): boolean {
  74. return true;
  75. }
  76. StartDrag(): void {
  77. this.node.zIndex = 1000;
  78. }
  79. UpdateDragPosition(pos: cc.Vec3): void {
  80. this.node.position = pos.sub(this.node.position);
  81. }
  82. EndDrag(): void {
  83. this.node.zIndex = this.cubeData.zIndex;
  84. }
  85. ClearCell() {
  86. }
  87. /** 回到原来位置 */
  88. BackToOriginalPos(needMove: boolean) {
  89. let originalPos = GameDataCenter.gridMap.GetPosByIdx(this.cubeData.zIndex);
  90. if (needMove) {
  91. cc.tween(this.node)
  92. .to(0.15, { position: originalPos })
  93. .call(() => {
  94. this.EndDrag();
  95. this.PlayJellyAnim();
  96. })
  97. .start();
  98. } else {
  99. this.itemNode.setPosition(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. }
  131. private UpdateItemDisplay(): void {
  132. // 根据 itemType 和 itemLevel 更新物品显示
  133. if (this.itemNode) {
  134. this.itemNode.active = true;
  135. // TODO: 更新物品的具体显示效果
  136. }
  137. }
  138. public unUse() {
  139. this.node.destroy();
  140. }
  141. }