12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /** @format */
- import GameUI from '../zuma/FightCore'
- import {CardSkillConfig, ICardSkillConfig} from '../config/CardSkillConfig'
- import {Data} from '../GameControl'
- import {ICard} from '../interface/GlobalInterface'
- const {ccclass, property} = cc._decorator
- @ccclass
- export class SkillOptCell extends cc.Component {
- mask: cc.Sprite = null //技能精灵
- timeLb: cc.Label = null //显示技能冷却剩余时间的文字
- time: number = 1 //技能冷却时间
- countDown: number = 0
- showTime: boolean = false //是否显示文字
- isStop: boolean = true //是否停止
- iCard: ICard
- gameUI: GameUI
- onLoad() {
- this.mask = cc.find('mask', this.node).getComponent(cc.Sprite)
- this.timeLb = cc.find('timeLb', this.node).getComponent(cc.Label)
- this.timeLb.node.active = this.showTime
- this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchStart, this)
- }
- update(dt: number) {
- dt *= Data.game.gameSpeed
- if (!this.isStop && !this.gameUI.isStop) {
- this.countDown -= dt
- if (this.countDown <= 0) {
- this.countDown = 0
- this.isStop = true
- if (this.iCard) {
- this.showCreateAni()
- }
- }
- this.mask.fillRange = this.time > 0 ? this.countDown / this.time : 0 //恢复技能
- this.timeLb.string = this.countDown > 0 ? (this.mask.fillRange * this.time).toFixed(1) : '' //更新技能冷却时间
- }
- }
- init(iCard: ICard, gameUI: GameUI) {
- this.gameUI = gameUI
- this.iCard = iCard
- this.time = this.iCard.cfg.startCD
- this.countDown = this.time
- this.mask.fillRange = 0
- this.isStop = true
- this.resetNode()
- }
- startCD() {
- this.time = this.iCard.cfg.skillCDs[0]
- this.countDown = this.time
- this.isStop = false
- this.resetNode()
- }
- onTouchStart(e: cc.Event.EventTouch): void {
- if (!this.iCard) return
- this.gameUI.skillOptShow(this)
- cc.find('popChoose', this.node).active = true
- }
- resetNode() {
- this.node.stopAllActions()
- this.node.y = 0
- this.node.scale = 1
- cc.find('light', this.node).active = false
- cc.find('popChoose', this.node).active = false
- }
- showCreateAni() {
- cc.find('light', this.node).active = true
- let t = cc.tween
- t(this.node)
- .then(t().by(0.5, {y: 30}))
- .start()
- }
- }
|