FightRedbagUI.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { _decorator, Component, Label } from 'cc';
  2. import { HttpSystem } from '../../core/net/HttpSystem';
  3. import { CountDown } from '../../core/ui/CountDown';
  4. import { Window } from '../../core/ui/window/Window';
  5. import { Utils } from '../../core/utils/Utils';
  6. import { FightItemData } from '../FightData';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('FightRedbagUI')
  9. export class FightRedbagUI extends Component {
  10. @property({ type: Label, tooltip: "文本倒计时" })
  11. txtTime: Label = null;
  12. @property({ type: CountDown, tooltip: "倒计时组件" })
  13. countDown: CountDown = null;
  14. private remaindTime = 0;
  15. public onParam(param: FightItemData) {
  16. let curTime = HttpSystem.serverTime * 0.001;
  17. this.remaindTime = (param.itemType == 1 && param.redbagType != -1 && param.canOpenTime > curTime) ? param.canOpenTime - curTime : 0;
  18. this.txtTime.string = param.canOpenTime <= curTime ? "" : Utils.formatCountDown((param.canOpenTime - curTime) * 1000) + "";
  19. if (this.remaindTime > 0) { this.countDown.stop(); this.countDown.value = this.remaindTime; this.countDown.play() }
  20. }
  21. public updateTxtTime(progress) {
  22. this.txtTime.string = Utils.formatCountDown(progress * 1000);
  23. }
  24. public completeTime() {
  25. this.remaindTime = 0;
  26. this.txtTime.string = "";
  27. this.getComponent(Window).close();
  28. }
  29. }