dc9deb680982b07a88d6963f42597a8fe8e6598f.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, LabelNumber, _dec, _dec2, _class, _class2, _descriptor, _crd, ccclass, property, menu, LabelChange;
  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. function _reportPossibleCrUseOfLabelNumber(extras) {
  8. _reporterNs.report("LabelNumber", "./LabelNumber", _context.meta, extras);
  9. }
  10. return {
  11. setters: [function (_unresolved_) {
  12. _reporterNs = _unresolved_;
  13. }, function (_cc) {
  14. _cclegacy = _cc.cclegacy;
  15. __checkObsolete__ = _cc.__checkObsolete__;
  16. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  17. _decorator = _cc._decorator;
  18. }, function (_unresolved_2) {
  19. LabelNumber = _unresolved_2.default;
  20. }],
  21. execute: function () {
  22. _crd = true;
  23. _cclegacy._RF.push({}, "fff0fLwVNhNe59VirWTCPFJ", "LabelChange", undefined);
  24. /*
  25. * @Author: dgflash
  26. * @Date: 2022-04-14 17:08:01
  27. * @LastEditors: dgflash
  28. * @LastEditTime: 2023-08-11 10:00:51
  29. */
  30. __checkObsolete__(['_decorator']);
  31. ({
  32. ccclass,
  33. property,
  34. menu
  35. } = _decorator);
  36. /** 数值变化动画标签组件 */
  37. _export("LabelChange", LabelChange = (_dec = ccclass("LabelChange"), _dec2 = menu('OopsFramework/Label/LabelChange (数值变化动画标签)'), _dec(_class = _dec2(_class = (_class2 = class LabelChange extends (_crd && LabelNumber === void 0 ? (_reportPossibleCrUseOfLabelNumber({
  38. error: Error()
  39. }), LabelNumber) : LabelNumber) {
  40. constructor(...args) {
  41. super(...args);
  42. _initializerDefineProperty(this, "isInteger", _descriptor, this);
  43. this.duration = 0;
  44. // 持续时间
  45. this.callback = void 0;
  46. // 完成回调
  47. this.isBegin = false;
  48. // 是否开始
  49. this.speed = 0;
  50. // 变化速度
  51. this.end = 0;
  52. }
  53. // 最终值
  54. /**
  55. * 变化到某值,如果从当前开始的begin传入null
  56. * @param {number} duration
  57. * @param {number} end
  58. * @param {Function} [callback]
  59. */
  60. changeTo(duration, end, callback) {
  61. if (duration == 0) {
  62. if (callback) callback();
  63. return;
  64. }
  65. this.playAnim(duration, this.num, end, callback);
  66. }
  67. /**
  68. * 变化值,如果从当前开始的begin传入null
  69. * @param {number} duration
  70. * @param {number} value
  71. * @param {Function} [callback]
  72. * @memberof LabelChange
  73. */
  74. changeBy(duration, value, callback) {
  75. if (duration == 0) {
  76. if (callback) callback();
  77. return;
  78. }
  79. this.playAnim(duration, this.num, this.num + value, callback);
  80. }
  81. /** 立刻停止 */
  82. stop(excCallback = true) {
  83. this.num = this.end;
  84. this.isBegin = false;
  85. if (excCallback && this.callback) this.callback();
  86. }
  87. /** 播放动画 */
  88. playAnim(duration, begin, end, callback) {
  89. this.duration = duration;
  90. this.end = end;
  91. this.callback = callback;
  92. this.speed = (end - begin) / duration;
  93. this.num = begin;
  94. this.isBegin = true;
  95. }
  96. /** 是否已经结束 */
  97. isEnd(num) {
  98. if (this.speed > 0) {
  99. return num >= this.end;
  100. } else {
  101. return num <= this.end;
  102. }
  103. }
  104. update(dt) {
  105. if (this.isBegin) {
  106. if (this.num == this.end) {
  107. this.isBegin = false;
  108. if (this.callback) this.callback();
  109. return;
  110. }
  111. let num = this.num + dt * this.speed;
  112. if (this.isInteger) {
  113. if (this.end < this.num) {
  114. num = Math.floor(num);
  115. } else {
  116. num = Math.ceil(num);
  117. }
  118. }
  119. /** 变化完成 */
  120. if (this.isEnd(num)) {
  121. num = this.end;
  122. this.isBegin = false;
  123. if (this.callback) this.callback();
  124. }
  125. this.num = num;
  126. }
  127. }
  128. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "isInteger", [property], {
  129. configurable: true,
  130. enumerable: true,
  131. writable: true,
  132. initializer: function () {
  133. return false;
  134. }
  135. })), _class2)) || _class) || _class));
  136. _cclegacy._RF.pop();
  137. _crd = false;
  138. }
  139. };
  140. });
  141. //# sourceMappingURL=dc9deb680982b07a88d6963f42597a8fe8e6598f.js.map