ba907ee3b30856981d888e17fe9cc9d245e64503.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Label, math, _dec, _dec2, _class, _class2, _descriptor, _crd, ccclass, property, NumRaiseLable;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. return {
  8. setters: [function (_cc) {
  9. _cclegacy = _cc.cclegacy;
  10. __checkObsolete__ = _cc.__checkObsolete__;
  11. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  12. _decorator = _cc._decorator;
  13. Label = _cc.Label;
  14. math = _cc.math;
  15. }],
  16. execute: function () {
  17. _crd = true;
  18. _cclegacy._RF.push({}, "3f43dXREG5P1LIco7w9mkJo", "NumRaiseLable", undefined);
  19. __checkObsolete__(['_decorator', 'Component', 'Label', 'math', 'Node']);
  20. ({
  21. ccclass,
  22. property
  23. } = _decorator);
  24. /**
  25. * 调用事例
  26. * this.combatLable.startCounting(data.total);
  27. */
  28. //数字自增长
  29. _export("NumRaiseLable", NumRaiseLable = (_dec = ccclass('NumRaiseLable'), _dec2 = property({
  30. tooltip: '数字增长动画持续时间(秒)'
  31. }), _dec(_class = (_class2 = class NumRaiseLable extends Label {
  32. constructor() {
  33. super(...arguments);
  34. // 动画持续时间(秒)
  35. _initializerDefineProperty(this, "_duration", _descriptor, this);
  36. // 当前显示的数字
  37. this._currentValue = 0;
  38. // 目标数字
  39. this._targetValue = 0;
  40. // 是否正在播放动画
  41. this._isAnimating = false;
  42. // 每帧增量
  43. this._incrementPerFrame = 0;
  44. }
  45. get duration() {
  46. return this._duration;
  47. }
  48. set duration(value) {
  49. this._duration = math.clamp(value, 0.1, 5);
  50. }
  51. /**
  52. * 开始数字增长动画
  53. * @param targetValue 目标数值
  54. * @param duration 可选,动画持续时间(秒),默认使用组件设置的duration
  55. */
  56. startCounting(targetValue, duration) {
  57. if (this._isAnimating) {
  58. this.stopCounting();
  59. } //使用传入的duration或默认值
  60. var animDuration = duration != null ? duration : this._duration;
  61. this._targetValue = targetValue;
  62. this._currentValue = 0;
  63. this._isAnimating = true; //计算每帧增量(假设60FPS)
  64. this._incrementPerFrame = this._targetValue / (animDuration * 60); //取消之前的调度
  65. this.unschedule(this.updateNumber); //开始新的调度
  66. this.schedule(this.updateNumber, 1 / 60);
  67. }
  68. /**
  69. * 停止数字增长动画
  70. */
  71. stopCounting() {
  72. this._isAnimating = false;
  73. this.unschedule(this.updateNumber);
  74. this._currentValue = this._targetValue;
  75. this.updateDisplay();
  76. }
  77. /**
  78. * 立即完成动画
  79. */
  80. completeCounting() {
  81. this.stopCounting();
  82. this._currentValue = this._targetValue;
  83. this.updateDisplay();
  84. }
  85. /**
  86. * 每帧更新数字
  87. */
  88. updateNumber() {
  89. if (!this._isAnimating) return;
  90. this._currentValue += this._incrementPerFrame; //确保不超过目标值
  91. if (this._currentValue >= this._targetValue) {
  92. this._currentValue = this._targetValue;
  93. this._isAnimating = false;
  94. this.unschedule(this.updateNumber);
  95. }
  96. this.updateDisplay();
  97. }
  98. /**
  99. * 更新显示文本
  100. */
  101. updateDisplay() {
  102. this.string = Math.floor(this._currentValue).toString();
  103. } //组件销毁时清理
  104. onDestroy() {
  105. this.unschedule(this.updateNumber);
  106. }
  107. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "_duration", [_dec2], {
  108. configurable: true,
  109. enumerable: true,
  110. writable: true,
  111. initializer: function initializer() {
  112. return 0.5;
  113. }
  114. }), _applyDecoratedDescriptor(_class2.prototype, "duration", [property], Object.getOwnPropertyDescriptor(_class2.prototype, "duration"), _class2.prototype)), _class2)) || _class));
  115. _cclegacy._RF.pop();
  116. _crd = false;
  117. }
  118. };
  119. });
  120. //# sourceMappingURL=ba907ee3b30856981d888e17fe9cc9d245e64503.js.map