CountDownLab.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. e =
  5. (this && this.__decorate) ||
  6. function(t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. };
  16. Object.defineProperty(i, "__esModule", { value: !0 });
  17. const s = t("App"),
  18. o = t("GameText"),
  19. a = t("LocalizedLabel"),
  20. { ccclass: n, property: r, menu: l, executeInEditMode: h } = cc._decorator;
  21. t = class extends a.default {
  22. constructor() {
  23. super(...arguments), (this.timeBaseStr = ""), (this._time = -1), (this.isBref = !1);
  24. }
  25. onLoad() {
  26. super.onLoad();
  27. }
  28. setEndTime(t) {
  29. this._time = t;
  30. }
  31. updateLabel() {
  32. var t;
  33. this.label ?
  34. this.dataID ?
  35. ((t = o.GameText.getTextByStr(this.dataID)), (this.timeBaseStr = t || "{0}")) :
  36. (this.timeBaseStr = "{0}") :
  37. cc.error("Failed to update localized label, label component is invalid!");
  38. }
  39. startCount() {
  40. s.default.TimerManager.doTimer(1e3, 0, this.routine, this), this.routine();
  41. }
  42. stopCount() {
  43. s.default.TimerManager.remove(this.routine, this);
  44. }
  45. onDestroy() {
  46. s.default.TimerManager.remove(this.routine, this);
  47. }
  48. routine() {
  49. let t = this._time - s.default.DateUtils.Now();
  50. t < 0 ?
  51. ((t = 0), s.default.TimerManager.remove(this.routine, this), (this.label.string = "00:00:00")) :
  52. (this.label.string = this.timeBaseStr.format(s.default.CommonUtils.getFormatTime(t, this.isBref)));
  53. }
  54. };
  55. e([r()], t.prototype, "isBref", void 0), (t = e([n, h], t)), (i.default = t);