UECube.ts 4.6 KB

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