UECube.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 { HcType } from "../../shared/hc/PtlHcInfo";
  6. import AssetMgr from "../../utils/AssetMgr";
  7. import UEHomeRole from "./UEHomeRole";
  8. const { ccclass, property } = cc._decorator;
  9. export interface I_CubeData {
  10. /** 物品类型 */
  11. type: HcType;
  12. /** 物品ID */
  13. id: number;
  14. /** 位置索引 */
  15. idx: 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. @property(cc.Node)
  31. private node_emitter_num: cc.Node = null!;
  32. cubeData: I_CubeData = null!;
  33. quality: number = 0;
  34. ueHomeRole: UEHomeRole = null!;
  35. Init(cubeData: I_CubeData) {
  36. this.cubeData = cubeData;
  37. this.SetZIndex(cubeData.idx);
  38. this.node_emitter_num.active = false;
  39. if (cubeData.type == HcType.emitter) {
  40. let mergePropCfg = Gamecfg.emitterInfo.getItem(cubeData.id.toString());
  41. this.sp_item.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg.icon}`);
  42. this.quality = mergePropCfg.quality;
  43. this.node_emitter_num.active = true;
  44. } else if (cubeData.type == HcType.material) {
  45. let mergePropCfg = Gamecfg.mergePropInfo.getItem(cubeData.id.toString());
  46. this.sp_item.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg.icon}`);
  47. this.quality = mergePropCfg.quality;
  48. } else if (cubeData.type == HcType.equip) {
  49. let mergePropCfg = Gamecfg.equipInfo.getItem(cubeData.id.toString());
  50. this.sp_item.setSpriteFrame('gridMap', `mergeEquip/${mergePropCfg.icon}`);
  51. this.quality = mergePropCfg.quality;
  52. } else if (cubeData.type == HcType.user) {
  53. this.ueHomeRole = AssetMgr.instantiateUE(UEHomeRole);
  54. this.itemNode.addChild(this.ueHomeRole.node);
  55. this.ueHomeRole.Init(cubeData);
  56. } else if (cubeData.type == HcType.monster) {
  57. this.ueHomeRole = AssetMgr.instantiateUE(UEHomeRole);
  58. this.itemNode.addChild(this.ueHomeRole.node);
  59. this.ueHomeRole.Init(cubeData);
  60. }
  61. // this.lbt_key.string = `${cubeData.type}_${cubeData.id}`;
  62. }
  63. /** 获取品质 */
  64. GetQuality() {
  65. return this.quality;
  66. }
  67. /** 触发点击 */
  68. TriggerClick() {
  69. if (this.cubeData.type == HcType.emitter) {
  70. CC_PREVIEW && console.log("触发点击发射器");
  71. GameDataCenter.gridMap.sendEmitter(this.cubeData.idx);
  72. } else if (this.cubeData.type == HcType.monster) {
  73. CC_PREVIEW && console.log("点击怪物开始战斗");
  74. GameDataCenter.gridMap.sendFightHc(this.cubeData.idx);
  75. } else if (this.cubeData.type == HcType.equip) {
  76. }
  77. }
  78. GetCubeData(): I_CubeData {
  79. return this.cubeData;
  80. }
  81. SetZIndex(zIndex: number) {
  82. this.node.zIndex = zIndex;
  83. this.cubeData.idx = zIndex;
  84. // this.lbt_num.string = zIndex.toString();
  85. }
  86. /** 是否有物品可以拖动 */
  87. CanDrag(): boolean {
  88. if (this.cubeData.type == HcType.monster) return false;
  89. return true;
  90. }
  91. StartDrag(): void {
  92. this.node.zIndex = 1000;
  93. }
  94. UpdateDragPosition(pos: cc.Vec3): void {
  95. this.node.position = pos.sub(this.node.position);
  96. }
  97. EndDrag(): void {
  98. this.node.zIndex = this.cubeData.idx;
  99. }
  100. ClearCell() {
  101. }
  102. /** 回到原来位置 */
  103. BackToOriginalPos(needMove: boolean) {
  104. let originalPos = GameDataCenter.gridMap.GetPosByIdx(this.cubeData.idx);
  105. if (needMove) {
  106. cc.tween(this.node)
  107. .to(0.15, { position: originalPos })
  108. .call(() => {
  109. this.EndDrag();
  110. this.PlayJellyAnim();
  111. })
  112. .start();
  113. } else {
  114. this.itemNode.setPosition(originalPos.clone());
  115. this.EndDrag();
  116. this.PlayJellyAnim();
  117. }
  118. }
  119. /** 播放果冻效果 */
  120. PlayJellyAnim() {
  121. cc.tween(this.itemNode)
  122. .to(0.1, { scale: 1.3 })
  123. .to(0.1, { scale: 0.9 })
  124. .to(0.08, { scale: 1 })
  125. .start();
  126. }
  127. /** 播放合成动画 */
  128. PlayMergeAnim() {
  129. cc.tween(this.itemNode)
  130. .by(0.1, { position: cc.v3(0, 40) })
  131. .by(0.1, { position: cc.v3(0, -40) })
  132. .by(0.1, { position: cc.v3(0, 10) })
  133. .by(0.1, { position: cc.v3(0, -10) })
  134. .start();
  135. }
  136. /** 移动到新的位置 */
  137. MoveToNewPos(newPos: cc.Vec3, duration: number = 0.1) {
  138. cc.tween(this.node)
  139. .to(duration, { position: newPos })
  140. .call(() => {
  141. this.EndDrag();
  142. })
  143. .start();
  144. }
  145. public unUse() {
  146. this.node.destroy();
  147. }
  148. }