SkillOptCell.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /** @format */
  2. import GameUI from '../zuma/FightCore'
  3. import {CardSkillConfig, ICardSkillConfig} from '../config/CardSkillConfig'
  4. import {Data} from '../GameControl'
  5. import {ICard} from '../interface/GlobalInterface'
  6. const {ccclass, property} = cc._decorator
  7. @ccclass
  8. export class SkillOptCell extends cc.Component {
  9. mask: cc.Sprite = null //技能精灵
  10. timeLb: cc.Label = null //显示技能冷却剩余时间的文字
  11. time: number = 1 //技能冷却时间
  12. countDown: number = 0
  13. showTime: boolean = false //是否显示文字
  14. isStop: boolean = true //是否停止
  15. iCard: ICard
  16. gameUI: GameUI
  17. onLoad() {
  18. this.mask = cc.find('mask', this.node).getComponent(cc.Sprite)
  19. this.timeLb = cc.find('timeLb', this.node).getComponent(cc.Label)
  20. this.timeLb.node.active = this.showTime
  21. this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchStart, this)
  22. }
  23. update(dt: number) {
  24. dt *= Data.game.gameSpeed
  25. if (!this.isStop && !this.gameUI.isStop) {
  26. this.countDown -= dt
  27. if (this.countDown <= 0) {
  28. this.countDown = 0
  29. this.isStop = true
  30. if (this.iCard) {
  31. this.showCreateAni()
  32. }
  33. }
  34. this.mask.fillRange = this.time > 0 ? this.countDown / this.time : 0 //恢复技能
  35. this.timeLb.string = this.countDown > 0 ? (this.mask.fillRange * this.time).toFixed(1) : '' //更新技能冷却时间
  36. }
  37. }
  38. init(iCard: ICard, gameUI: GameUI) {
  39. this.gameUI = gameUI
  40. this.iCard = iCard
  41. this.time = this.iCard.cfg.startCD
  42. this.countDown = this.time
  43. this.mask.fillRange = 0
  44. this.isStop = true
  45. this.resetNode()
  46. }
  47. startCD() {
  48. this.time = this.iCard.cfg.skillCDs[0]
  49. this.countDown = this.time
  50. this.isStop = false
  51. this.resetNode()
  52. }
  53. onTouchStart(e: cc.Event.EventTouch): void {
  54. if (!this.iCard) return
  55. this.gameUI.skillOptShow(this)
  56. cc.find('popChoose', this.node).active = true
  57. }
  58. resetNode() {
  59. this.node.stopAllActions()
  60. this.node.y = 0
  61. this.node.scale = 1
  62. cc.find('light', this.node).active = false
  63. cc.find('popChoose', this.node).active = false
  64. }
  65. showCreateAni() {
  66. cc.find('light', this.node).active = true
  67. let t = cc.tween
  68. t(this.node)
  69. .then(t().by(0.5, {y: 30}))
  70. .start()
  71. }
  72. }