import { _decorator, Component, Label } from 'cc'; import { HttpSystem } from '../../core/net/HttpSystem'; import { CountDown } from '../../core/ui/CountDown'; import { Window } from '../../core/ui/window/Window'; import { Utils } from '../../core/utils/Utils'; import { FightItemData } from '../FightData'; const { ccclass, property } = _decorator; @ccclass('FightRedbagUI') export class FightRedbagUI extends Component { @property({ type: Label, tooltip: "文本倒计时" }) txtTime: Label = null; @property({ type: CountDown, tooltip: "倒计时组件" }) countDown: CountDown = null; private remaindTime = 0; public onParam(param: FightItemData) { let curTime = HttpSystem.serverTime * 0.001; this.remaindTime = (param.itemType == 1 && param.redbagType != -1 && param.canOpenTime > curTime) ? param.canOpenTime - curTime : 0; this.txtTime.string = param.canOpenTime <= curTime ? "" : Utils.formatCountDown((param.canOpenTime - curTime) * 1000) + ""; if (this.remaindTime > 0) { this.countDown.stop(); this.countDown.value = this.remaindTime; this.countDown.play() } } public updateTxtTime(progress) { this.txtTime.string = Utils.formatCountDown(progress * 1000); } public completeTime() { this.remaindTime = 0; this.txtTime.string = ""; this.getComponent(Window).close(); } }