ComboBox.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { _decorator, Component, Label, math, Node, ProgressBar, Sprite, tween, UIOpacity, v3, Vec3 } from 'cc';
  2. import { Global } from '../Global';
  3. import { CfgCombo } from '../config/CfgCombo';
  4. import { GameMgr } from '../manager/GameMgr';
  5. import { ResMgr } from '../manager/ResMgr';
  6. import { Bundle } from '../enum/Bundle';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('Game/ComboBox')
  9. export class ComboBox extends Component {
  10. @property(ProgressBar)
  11. private progressBar: ProgressBar = null
  12. @property(Label)
  13. private lbCombo: Label = null
  14. private curCombo: number = 0
  15. public get CurCombo(): number {
  16. return this.curCombo
  17. }
  18. public set CurCombo(v: number) {
  19. this.curCombo = math.clamp(v, 0, Global.Max_Combo)
  20. this.node.active = this.curCombo > 0
  21. if (this.curCombo <= 0) return
  22. this.lbCombo.string = `x${this.curCombo}`
  23. const comboData = CfgCombo[this.curCombo]
  24. const { durarion } = comboData
  25. this.speed = 1 / durarion
  26. this.progressBar.progress = 1
  27. }
  28. private speed: number = 0
  29. protected start(): void {
  30. this.CurCombo = 0
  31. }
  32. protected update(dt: number): void {
  33. if (GameMgr.Pause) return
  34. if (this.curCombo <= 0) return
  35. this.progressBar.progress = math.clamp(this.progressBar.progress - this.speed * dt, 0, 1)
  36. if (this.progressBar.progress <= 0) {
  37. this.CurCombo = 0
  38. }
  39. }
  40. public createFloatText(shelveWorldPos: Vec3): void {
  41. const floatText: Node = new Node()
  42. const sp: Sprite = floatText.addComponent(Sprite)
  43. const uiOpacity: UIOpacity = floatText.addComponent(UIOpacity)
  44. const comboData = CfgCombo[this.curCombo]
  45. const { icon } = comboData
  46. if(!icon) return
  47. sp.spriteFrame = ResMgr.getSpriteFrame(Bundle.Game, icon)
  48. this.node.parent.addChild(floatText)
  49. floatText.setWorldPosition(shelveWorldPos)
  50. const tw = tween(floatText)
  51. tw.set({ scale: v3(0.5, 0.5, 1) })
  52. tw.to(0.5, { scale: v3(1, 1, 1) }, { easing: 'backOut' })
  53. tw.by(0.5, { position: v3(0, 50, 0) }, { easing: 'sineOut' })
  54. tw.call(() => {
  55. floatText.destroy()
  56. })
  57. tw.start()
  58. tween(uiOpacity).delay(0.5).to(0.5, { opacity: 0 }, { easing: 'sineOut' }).start()
  59. }
  60. }