62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
|
import { Label } from 'cc';
|
||
|
import { tween } from 'cc';
|
||
|
import { Sprite } from 'cc';
|
||
|
import { _decorator, Component, Node } from 'cc';
|
||
|
import { UmUtil } from '../../../../cc-common/cc-util/UmUtil';
|
||
|
import { Button } from 'cc';
|
||
|
import { SpecialSkillInfo } from '../../global/GameInterface';
|
||
|
import { UmClientEvent } from '../../../../cc-common/cc-util/UmOneToMultiListener';
|
||
|
import { GameDefine } from '../../config/GameDefine';
|
||
|
import { GameGlobalData } from '../../global/GameGlobalData';
|
||
|
const { ccclass, property } = _decorator;
|
||
|
|
||
|
@ccclass('SkillSpecialItemUI')
|
||
|
export class SkillSpecialItemUI extends Component {
|
||
|
@property(Button) btnUse: Button = null!;
|
||
|
@property(Sprite) icon: Sprite = null!;
|
||
|
@property(Sprite) progress: Sprite = null!;
|
||
|
@property(Label) nameTxt: Label = null!;
|
||
|
skillItemInfo: SpecialSkillInfo = null;
|
||
|
isUsing = false;
|
||
|
_tween: any = null;
|
||
|
|
||
|
protected start(): void {
|
||
|
this.btnUse?.node.on(Button.EventType.CLICK, this.startUseSkill, this);
|
||
|
}
|
||
|
|
||
|
protected onDestroy(): void {
|
||
|
this._tween?.stop();
|
||
|
this._tween = null;
|
||
|
}
|
||
|
|
||
|
protected onDisable(): void {
|
||
|
this.isUsing = false;
|
||
|
}
|
||
|
|
||
|
|
||
|
setData(skillItemInfo: SpecialSkillInfo)
|
||
|
{
|
||
|
this.skillItemInfo = skillItemInfo;
|
||
|
this.nameTxt.string = skillItemInfo.skillName;
|
||
|
}
|
||
|
|
||
|
startUseSkill()
|
||
|
{
|
||
|
if (this.isUsing || !GameGlobalData.Instance.isHeroManaReady) return;
|
||
|
this.isUsing = true;
|
||
|
UmClientEvent.dispatchEvent(GameDefine.EVENT_START_USE_SPECIAL_SKILL, this.skillItemInfo.skillId);
|
||
|
this._tween = UmUtil.tweenValue(1, 0, this.skillItemInfo.skillTime, (value) => {
|
||
|
this.progress.fillRange = value;
|
||
|
}, () => {
|
||
|
this.progress.fillRange = 0;
|
||
|
this.endUseSkill();
|
||
|
})
|
||
|
}
|
||
|
|
||
|
endUseSkill() {
|
||
|
this.isUsing = false;
|
||
|
UmClientEvent.dispatchEvent(GameDefine.EVENT_END_USE_SPECIAL_SKILL, this.skillItemInfo.skillId);
|
||
|
}
|
||
|
}
|
||
|
|