Item.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import { _decorator, Component, Node, Skeleton, sp, Sprite, SpriteAtlas, Vec3 } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. import { GameConstant } from './GameConstant';
  4. import { ResourceLoader } from './ResourceLoader';
  5. @ccclass('Item')
  6. export class Item extends Component {
  7. @property(Node)
  8. icon: Node = null;
  9. @property(Node)
  10. iconSpine: Node = null;
  11. @property(Node)
  12. wildTimesIcon: Node = null;
  13. @property(Node)
  14. wildTimesIconSpine: Node = null;
  15. @property(SpriteAtlas)
  16. iconSpriteFrame: SpriteAtlas[] = [];
  17. public iconType = 0;
  18. public isActive = false;
  19. public wildTimes = 1;
  20. public lineCount = 0;
  21. start() {
  22. this.iconType = 0;
  23. this.isActive = false;
  24. }
  25. setIconType(iconType, isNormal, wildTimes = 1) {
  26. // 设置图标类型
  27. this.iconType = iconType;
  28. this.wildTimes = wildTimes;
  29. // 设置图标图片
  30. let spriteAtlasName = `${(iconType + 1).toString().padStart(2, '0')}_default`;
  31. let spriteFrameName = isNormal ? GameConstant.ICON_NORMAL_SPRITE_NAME[iconType] : GameConstant.ICON_BLURRED_SPRITE_NAME[iconType]
  32. let spriteFrame = ResourceLoader.instance.getResource<SpriteAtlas>(spriteAtlasName).getSpriteFrame(spriteFrameName);
  33. // console.log(spriteFrame);
  34. this.icon.getComponent(Sprite).spriteFrame = spriteFrame;
  35. // 设置图标spine动画
  36. let spineName = `S${(iconType + 1).toString().padStart(2, '0')}`;
  37. this.iconSpine.getComponent(sp.Skeleton).skeletonData = ResourceLoader.instance.getResource(spineName);
  38. this.makeItem();
  39. }
  40. getIconType() {
  41. return this.iconType;
  42. }
  43. makeItem() {
  44. this.icon.scale = new Vec3(1, 1, 1);//new Vec3(0.95, 0.95, 0.95);
  45. this.icon.x = 0;
  46. this.icon.y = 0;
  47. this.iconSpine.scale = new Vec3(1, 1, 1);//new Vec3(0.95, 0.95, 0.95);
  48. this.iconSpine.x = 0;
  49. this.iconSpine.y = 0;
  50. this.wildTimesIcon.active = false;
  51. this.wildTimesIconSpine.active = false;
  52. if (this.iconType <= GameConstant.ICON_TYPE.SYMBOL_FREE) {
  53. // this.iconBg.node.scale = 0.9;
  54. // this.normalBG.scale = 0.9;
  55. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_WILD) {
  56. this.iconSpine.position = new Vec3(-4.5, -18, 0);
  57. let wildTimesSpriteFrameName = this.wildTimes > 1 ? ("02_x" + this.wildTimes) : "02_wild";
  58. let wildTimesSpriteFrame = ResourceLoader.instance.getResource<SpriteAtlas>("02_default").getSpriteFrame(wildTimesSpriteFrameName);
  59. this.wildTimesIcon.getComponent(Sprite).spriteFrame = wildTimesSpriteFrame;
  60. let wildTimesSpineName = this.wildTimes > 1 ? ("S02_x" + this.wildTimes) : "S02_wild";
  61. this.wildTimesIconSpine.getComponent(sp.Skeleton).skeletonData = ResourceLoader.instance.getResource(wildTimesSpineName);
  62. this.wildTimesIcon.active = true;
  63. if (this.wildTimes == 1) {
  64. this.wildTimesIcon.position = new Vec3(0, -60, 0);
  65. this.wildTimesIconSpine.position = new Vec3(-3, 55.5, 0);
  66. } else if (this.wildTimes == 2) {
  67. this.wildTimesIcon.position = new Vec3(0, -50, 0);
  68. this.wildTimesIconSpine.position = new Vec3(-4, 34, 0);
  69. } else if (this.wildTimes >= 3) {
  70. this.wildTimesIcon.position = new Vec3(0, -54, 0);
  71. this.wildTimesIconSpine.position = new Vec3(-4, 36, 0);
  72. }
  73. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_COW) {
  74. this.iconSpine.position = new Vec3(1.5, -20.5, 0)
  75. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_EAGLE) {
  76. this.iconSpine.position = new Vec3(4.5, -13, 0)
  77. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_LEOPARD) {
  78. this.iconSpine.position = new Vec3(1, -2.5, 0)
  79. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_WOLF) {
  80. this.iconSpine.scale = new Vec3(0.5, 0.5, 0.5);
  81. this.iconSpine.position = new Vec3(5, -113.5, 0)
  82. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_ELK) {
  83. this.iconSpine.position = new Vec3(-1.5, -94, 0)
  84. } else if (this.iconType >= GameConstant.ICON_TYPE.SYMBOL_A) {
  85. // this.iconSpine.position = new Vec3(1, 3, 0)
  86. // this.iconSpine.scale = new Vec3(0.5, 0.5, 0.5);
  87. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_K) {
  88. this.iconSpine.scale = new Vec3(0.8, 0.8, 0.8);
  89. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_Q) {
  90. this.iconSpine.scale = new Vec3(0.8, 0.8, 0.8);
  91. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_J) {
  92. this.iconSpine.scale = new Vec3(0.8, 0.8, 0.8);
  93. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_10) {
  94. this.iconSpine.scale = new Vec3(0.8, 0.8, 0.8);
  95. } else if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_9) {
  96. this.iconSpine.scale = new Vec3(0.8, 0.8, 0.8);
  97. }
  98. }
  99. // showDefault() {
  100. // // 设置图标图片
  101. // let spriteAtlasName = `${(this.iconType + 1).toString().padStart(2, '0')}_default`;
  102. // let spriteFrameName = GameConstant.ICON_NORMAL_SPRITE_NAME[this.iconType]
  103. // let spriteFrame = ResourceLoader.instance.getResource<SpriteAtlas>(spriteAtlasName).getSpriteFrame(spriteFrameName);
  104. // // console.log(spriteFrame);
  105. // this.icon.getComponent(Sprite).spriteFrame = spriteFrame;
  106. // }
  107. showNormal() {
  108. console.log("showNormal")
  109. this.iconSpine.getComponent(sp.Skeleton).clearTracks();
  110. this.iconSpine.getComponent(sp.Skeleton).setToSetupPose()
  111. this.iconSpine.active = false;
  112. this.icon.active = true;
  113. this.wildTimesIconSpine.getComponent(sp.Skeleton).clearTracks();
  114. this.wildTimesIconSpine.getComponent(sp.Skeleton).setToSetupPose()
  115. this.wildTimesIconSpine.active = false;
  116. }
  117. showLightAni() {
  118. // console.log("showLightAni")
  119. this.iconSpine.active = true;
  120. this.icon.active = false;
  121. this.iconSpine.getComponent(sp.Skeleton).clearTracks();
  122. this.iconSpine.getComponent(sp.Skeleton).setAnimation(0, "win", false);
  123. if (this.iconType == GameConstant.ICON_TYPE.SYMBOL_WILD) {
  124. this.wildTimesIconSpine.active = true;
  125. this.wildTimesIconSpine.getComponent(sp.Skeleton).clearTracks();
  126. let wildSpineName = "wild";
  127. if (this.wildTimes == 2)
  128. wildSpineName = "x2";
  129. else if (this.wildTimes == 3)
  130. wildSpineName = "x3";
  131. else if (this.wildTimes == 5)
  132. wildSpineName = "x5";
  133. this.wildTimesIconSpine.getComponent(sp.Skeleton).setAnimation(0, wildSpineName, false);
  134. }
  135. }
  136. showSpecialAni() {
  137. if(this.iconType != GameConstant.SPECIAL_ICON) {
  138. return;
  139. }
  140. this.icon.active = false;
  141. this.iconSpine.active = true;
  142. this.iconSpine.getComponent(sp.Skeleton).clearTracks();
  143. this.iconSpine.getComponent(sp.Skeleton).setAnimation(0, "win", false);
  144. }
  145. update(deltaTime: number) {
  146. }
  147. }