SkillBox.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { _decorator, Component, Label, macro, Node, Sprite, SpriteFrame, tween, v3, Vec3 } from 'cc';
  2. import { SkillMgr } from '../manager/SkillMgr';
  3. import { SkillType } from '../enum/SkillType';
  4. import { Debug } from '../util/Debug';
  5. import { UIMgr } from '../manager/UIMgr';
  6. import { UI } from '../enum/UI';
  7. import { EventMgr } from '../manager/EventMgr';
  8. import { EventType } from '../enum/EventType';
  9. import { ResMgr } from '../manager/ResMgr';
  10. import { Bundle } from '../enum/Bundle';
  11. import { CfgSkillInfo } from '../config/CfgSkillInfo';
  12. import { GameMgr } from '../manager/GameMgr';
  13. import { Shake } from '../misc/Shake';
  14. import { Breath } from '../misc/Breath';
  15. const { ccclass, property } = _decorator;
  16. const Tag: string = 'SkillBox'
  17. @ccclass('Game/SkillBox')
  18. export class SkillBox extends Component {
  19. @property([Label])
  20. private skillCntTips: Label[] = []
  21. @property(Breath)
  22. private tipBreath: Breath = null
  23. @property(Shake)
  24. private iconShake: Shake = null
  25. protected onLoad(): void {
  26. EventMgr.on(EventType.UpdateSkillCnt, this.onUpdateSkillCnt, this)
  27. EventMgr.on(EventType.AddSkill, this.onAddSkill, this)
  28. }
  29. protected start(): void {
  30. for (let i = 0; i < this.skillCntTips.length; i++) {
  31. const skillCntTip: Label = this.skillCntTips[i]
  32. const cnt: number = SkillMgr.skillCnt(i)
  33. skillCntTip.string = `${cnt}`
  34. skillCntTip.node.parent.active = cnt > 0
  35. }
  36. this.schedule(this.onCheckStuck, 1, macro.REPEAT_FOREVER)
  37. }
  38. protected onDestroy(): void {
  39. EventMgr.off(EventType.UpdateSkillCnt, this.onUpdateSkillCnt, this)
  40. EventMgr.off(EventType.AddSkill, this.onAddSkill, this)
  41. }
  42. protected onCheckStuck(): void {
  43. const isStucked: boolean = GameMgr.isStucked
  44. this.tipBreath.node.active = isStucked
  45. this.tipBreath.enabled = isStucked
  46. this.iconShake.enabled = isStucked
  47. }
  48. protected onUpdateSkillCnt(skill: SkillType, cnt: number): void {
  49. const skillCntTip: Label = this.skillCntTips[skill]
  50. skillCntTip.string = `${cnt}`
  51. skillCntTip.node.parent.active = cnt > 0
  52. }
  53. protected onAddSkill(skill: SkillType): void {
  54. const flySkillNode: Node = new Node()
  55. const sp: Sprite = flySkillNode.addComponent(Sprite)
  56. sp.spriteFrame = ResMgr.getSpriteFrame(Bundle.Icon, CfgSkillInfo[skill].icon)
  57. this.node.parent.addChild(flySkillNode)
  58. const btnSkillNode: Node = this.node.children[skill]
  59. const tw = tween(flySkillNode)
  60. tw.set({ scale: v3(0, 0, 0) })
  61. tw.to(0.2, { scale: v3(1, 1, 1) }, { easing: 'backOut' })
  62. tw.delay(0.1)
  63. tw.parallel(
  64. tween(flySkillNode).to(0.5, { worldPosition: btnSkillNode.worldPosition }),
  65. tween(flySkillNode).to(0.5, { scale: v3(0.5, 0.5, 0.5) }),
  66. )
  67. tw.call(() => {
  68. flySkillNode.destroy()
  69. tween(btnSkillNode).to(0.2, { scale: v3(1.2, 1.2, 1) }).to(0.2, { scale: v3(1, 1, 1) }).start()
  70. })
  71. tw.start()
  72. }
  73. protected onBtnFreezeTimeClick(): void {
  74. if (SkillMgr.hasSkill(SkillType.FreezeTime)) {
  75. SkillMgr.useSkill(SkillType.FreezeTime)
  76. } else {
  77. UIMgr.open(UI.GetSkill, SkillType.FreezeTime)
  78. Debug.Warn(Tag, '冰冻道具数量不足,使用失败')
  79. }
  80. }
  81. protected onBtnEraseOneGroupClick(): void {
  82. if (SkillMgr.hasSkill(SkillType.EraseGroup)) {
  83. SkillMgr.useSkill(SkillType.EraseGroup)
  84. } else {
  85. UIMgr.open(UI.GetSkill, SkillType.EraseGroup)
  86. Debug.Warn(Tag, '移除道具数量不足,使用失败')
  87. }
  88. }
  89. protected onBtnRefreshPositionClick(): void {
  90. if (SkillMgr.hasSkill(SkillType.RefreshPosition)) {
  91. SkillMgr.useSkill(SkillType.RefreshPosition)
  92. } else {
  93. UIMgr.open(UI.GetSkill, SkillType.RefreshPosition)
  94. Debug.Warn(Tag, '刷新位置道具数量不足,使用失败')
  95. }
  96. }
  97. protected onBtnDoubleCoinClick(): void {
  98. if (SkillMgr.hasSkill(SkillType.DoubleCoin)) {
  99. SkillMgr.useSkill(SkillType.DoubleCoin)
  100. } else {
  101. UIMgr.open(UI.GetSkill, SkillType.DoubleCoin)
  102. Debug.Warn(Tag, '双倍金币道具数量不足,使用失败')
  103. }
  104. }
  105. }