UECube.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 { uiCommon } from "../../utils/UICommon";
  8. import { GridConstant } from "./GridConstant";
  9. import UEHomeRole from "./UEHomeRole";
  10. const { ccclass, property } = cc._decorator;
  11. export interface I_CubeData {
  12. /** 物品类型 */
  13. type: HcType;
  14. /** 物品ID */
  15. id: number;
  16. /** 位置索引 */
  17. idx: 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. @property(cc.Node)
  33. private node_emitter_num: cc.Node = null!;
  34. cubeData: I_CubeData = null!;
  35. quality: number = 0;
  36. ueHomeRole: UEHomeRole = null!;
  37. Init(cubeData: I_CubeData) {
  38. this.cubeData = cubeData;
  39. this.SetZIndex(cubeData.idx);
  40. this.node_emitter_num.active = false;
  41. if (cubeData.type == HcType.emitter) {
  42. let mergePropCfg = Gamecfg.emitterInfo.getItem(cubeData.id.toString());
  43. this.sp_item.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg.icon}`);
  44. this.quality = mergePropCfg.quality;
  45. this.node_emitter_num.active = true;
  46. } else if (cubeData.type == HcType.material) {
  47. let mergePropCfg = Gamecfg.mergePropInfo.getItem(cubeData.id.toString());
  48. this.sp_item.setSpriteFrame('gridMap', `mergeProp/${mergePropCfg.icon}`);
  49. this.quality = mergePropCfg.quality;
  50. } else if (cubeData.type == HcType.equip) {
  51. let mergePropCfg = Gamecfg.equipInfo.getItem(cubeData.id.toString());
  52. this.sp_item.setSpriteFrame('gridMap', `mergeEquip/${mergePropCfg.icon}`);
  53. this.quality = mergePropCfg.quality;
  54. } else if (cubeData.type == HcType.user) {
  55. this.ueHomeRole = AssetMgr.instantiateUE(UEHomeRole);
  56. this.itemNode.addChild(this.ueHomeRole.node);
  57. this.ueHomeRole.Init(cubeData);
  58. } else if (cubeData.type == HcType.monster) {
  59. this.ueHomeRole = AssetMgr.instantiateUE(UEHomeRole);
  60. this.itemNode.addChild(this.ueHomeRole.node);
  61. this.ueHomeRole.Init(cubeData);
  62. }
  63. // this.lbt_key.string = `${cubeData.type}_${cubeData.id}`;
  64. }
  65. /** 获取品质 */
  66. GetQuality() {
  67. return this.quality;
  68. }
  69. /** 触发点击 */
  70. TriggerClick() {
  71. if (this.cubeData.type == HcType.emitter) {
  72. CC_PREVIEW && console.log("触发点击发射器");
  73. GameDataCenter.gridMap.sendEmitter(this.cubeData.idx);
  74. } else if (this.cubeData.type == HcType.monster) {
  75. CC_PREVIEW && console.log("点击怪物开始战斗");
  76. GameDataCenter.gridMap.sendFightHc(this.cubeData.idx);
  77. } else if (this.cubeData.type == HcType.equip) {
  78. }
  79. }
  80. GetCubeData(): I_CubeData {
  81. return this.cubeData;
  82. }
  83. SetZIndex(zIndex: number) {
  84. this.node.zIndex = zIndex;
  85. this.cubeData.idx = zIndex;
  86. // this.lbt_num.string = zIndex.toString();
  87. }
  88. /** 是否有物品可以拖动 */
  89. CanDrag(): boolean {
  90. if (this.cubeData.type == HcType.monster) return false;
  91. return true;
  92. }
  93. StartDrag(): void {
  94. this.node.zIndex = 1000;
  95. }
  96. UpdateDragPosition(pos: cc.Vec3): void {
  97. this.node.position = pos.sub(this.node.position);
  98. }
  99. EndDrag(): void {
  100. this.node.zIndex = this.cubeData.idx;
  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. /** 吸附效果 */
  146. Adsorb(degree: number) {
  147. let pos = uiCommon.GetPointOnCircle(GridConstant.CELL_WIDTH * 0.1, degree, cc.v2(0, 0));
  148. cc.tween(this.itemNode)
  149. .to(0.1, { position: pos })
  150. .call(() => {
  151. })
  152. .start();
  153. }
  154. /** 取消吸附 */
  155. CancelAdsorb() {
  156. cc.tween(this.itemNode)
  157. .to(0.1, { position: cc.Vec3.ZERO })
  158. .start();
  159. }
  160. public unUse() {
  161. this.node.destroy();
  162. }
  163. }