UECube.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import Gamecfg from "../../common/gameCfg";
  2. import ResSprite from "../../frameWork/compment/ResSprite";
  3. import UEBase from "../../frameWork/compment/UEBase";
  4. const { ccclass, property } = cc._decorator;
  5. export interface I_CubeData {
  6. /** 物品类型 */
  7. type: number;
  8. /** 物品ID */
  9. id: number;
  10. /** 层级 */
  11. zIndex: number;
  12. /** 解锁条件 */
  13. unlock: number
  14. }
  15. @ccclass
  16. export default class UECube extends UEBase {
  17. static readonly BundleKey: string = "gridMap";
  18. static readonly PrefabUrl: string = "UECube";
  19. static readonly CLS: string = "UECube";
  20. @property(cc.Node)
  21. private itemNode: cc.Node = null!;
  22. @property(cc.Label)
  23. private lbt_num: cc.Label = null!;
  24. @property(ResSprite)
  25. private sp_item: ResSprite = null!;
  26. private originalPos: cc.Vec3 = cc.v3(0, 0);
  27. cellData: I_CubeData = null!;
  28. Init(cellData: I_CubeData, idx: number) {
  29. this.cellData = cellData;
  30. this.node.zIndex = cellData.zIndex;
  31. this.lbt_num.string = idx.toString();
  32. this.originalPos = this.node.position;
  33. if (cellData.type == 3) {
  34. let mergePropCfg = Gamecfg.mergePropInfo.getItem(cellData.id.toString());
  35. this.sp_item.setSpriteFrame('gridMap', `equipIcon/${mergePropCfg.icon}`);
  36. }
  37. }
  38. /** 是否有物品可以拖动 */
  39. CanDrag(): boolean {
  40. return true;
  41. }
  42. StartDrag(): void {
  43. this.node.zIndex = 1000;
  44. }
  45. UpdateDragPosition(pos: cc.Vec3): void {
  46. if (this.itemNode) {
  47. this.itemNode.position = pos.sub(this.node.position);
  48. }
  49. }
  50. EndDrag(): void {
  51. if (this.itemNode) {
  52. this.node.zIndex = this.cellData.zIndex;
  53. this.PlayJellyAnim();
  54. }
  55. }
  56. ClearCell() {
  57. }
  58. /** 播放果冻效果 */
  59. PlayJellyAnim() {
  60. cc.tween(this.itemNode)
  61. .to(0.15, { position: cc.Vec3.ZERO })
  62. .to(0.1, { scale: 1.3 })
  63. .to(0.1, { scale: 0.9 })
  64. .to(0.08, { scale: 1 })
  65. .start();
  66. }
  67. /** 播放合成动画 */
  68. PlayMergeAnim() {
  69. cc.tween(this.itemNode)
  70. .by(0.1, { position: cc.v3(0, 40) })
  71. .by(0.1, { position: cc.v3(0, -40) })
  72. .by(0.1, { position: cc.v3(0, 10) })
  73. .by(0.1, { position: cc.v3(0, -10) })
  74. .start();
  75. }
  76. private UpdateItemDisplay(): void {
  77. // 根据 itemType 和 itemLevel 更新物品显示
  78. if (this.itemNode) {
  79. this.itemNode.active = true;
  80. // TODO: 更新物品的具体显示效果
  81. }
  82. }
  83. }