| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { _decorator, Component, Label, Animation, utils, EventHandler } from 'cc';
- import { CountDown } from '../../core/ui/CountDown';
- import { Utils } from '../../core/utils/Utils';
- const { ccclass, property } = _decorator;
- /**
- * 切磋列表红包倒计时
- */
- @ccclass('BattleItemRedPacket')
- export class BattleItemRedPacket extends Component {
- @property({ type: Label, tooltip: "可领取文本" })
- getLabel: Label;
- @property({ type: Label, tooltip: "倒计时文本" })
- timeLabel: Label;
- @property({ type: Animation, tooltip: "红包特效" })
- animation: Animation;
- @property({ type: CountDown, tooltip: "倒计时组件" })
- redCountDown: CountDown;
- @property({ type: EventHandler, tooltip: "红包可领取" })
- public finishHandler: EventHandler;
- start() {
- }
- update() {
- }
- public setData(time: number) {
- if (time > Date.now()) {
- this.redCountDown.value = Math.ceil((time - Date.now()) / 1000);
- this.timeLabel.string = Utils.formatCountDown(this.redCountDown.value * 1000);
- this.redCountDown.play();
- this.getLabel.node.active = false;
- this.timeLabel.node.active = true;
- } else {
- this.getLabel.node.active = true;
- this.timeLabel.node.active = false;
- }
- }
- /**倒计时回调 */
- public onInterval(progress) {
- this.timeLabel.string = Utils.formatCountDown(progress * 1000);
- }
- /**倒计时结束回调 */
- public onComplete() {
- this.redCountDown.stop();
- this.animation && this.animation.play();
- this.getLabel.node.active = true;
- this.timeLabel.node.active = false;
- this.finishHandler.emit([]);
- }
- }
|