445a599b04e622a25bb42ce16a5b4d2e086a5e93.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, Enum, Label, lerp, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _crd, ccclass, property, menu, VALUE_TYPE, BhvRollNumber;
  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. /** 时间格式转换 */
  8. function parseTimer(timer = 0, isFullTimer = true) {
  9. let t = Math.floor(timer);
  10. let hours = Math.floor(t / 3600);
  11. let mins = Math.floor(t % 3600 / 60);
  12. let secs = t % 60;
  13. let m = '' + mins;
  14. let s = '' + secs;
  15. if (secs < 10) s = '0' + secs; // full timer 按小时算,无论有没有小时
  16. if (isFullTimer) {
  17. if (mins < 10) m = '0' + mins;
  18. return hours + ':' + m + ':' + s;
  19. } else {
  20. m = '' + (mins + hours * 60);
  21. if (mins < 10) m = '0' + mins;
  22. return m + ':' + s;
  23. }
  24. }
  25. return {
  26. setters: [function (_cc) {
  27. _cclegacy = _cc.cclegacy;
  28. __checkObsolete__ = _cc.__checkObsolete__;
  29. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  30. _decorator = _cc._decorator;
  31. Component = _cc.Component;
  32. Enum = _cc.Enum;
  33. Label = _cc.Label;
  34. lerp = _cc.lerp;
  35. }],
  36. execute: function () {
  37. _crd = true;
  38. _cclegacy._RF.push({}, "72d13dwmG9LS4gkJhSuAp3F", "BhvRollNumber", undefined);
  39. __checkObsolete__(['_decorator', 'Component', 'Enum', 'Label', 'lerp']);
  40. ({
  41. ccclass,
  42. property,
  43. menu
  44. } = _decorator);
  45. VALUE_TYPE = /*#__PURE__*/function (VALUE_TYPE) {
  46. VALUE_TYPE[VALUE_TYPE["INTEGER"] = 0] = "INTEGER";
  47. VALUE_TYPE[VALUE_TYPE["FIXED_2"] = 1] = "FIXED_2";
  48. VALUE_TYPE[VALUE_TYPE["TIMER"] = 2] = "TIMER";
  49. VALUE_TYPE[VALUE_TYPE["PERCENTAGE"] = 3] = "PERCENTAGE";
  50. VALUE_TYPE[VALUE_TYPE["KMBT_FIXED2"] = 4] = "KMBT_FIXED2";
  51. VALUE_TYPE[VALUE_TYPE["CUSTOMER"] = 5] = "CUSTOMER";
  52. return VALUE_TYPE;
  53. }(VALUE_TYPE || {});
  54. /**
  55. * 滚动数字
  56. * 将会使用 lerp 自动滚动数字到目标数值
  57. */
  58. _export("BhvRollNumber", BhvRollNumber = (_dec = menu("OopsFramework/UI/Roll Number (滚动数字)"), _dec2 = property({
  59. type: Label,
  60. tooltip: '需要滚动的 Label 组件,如果不进行设置,就会从自己的节点自动查找'
  61. }), _dec3 = property({
  62. tooltip: '当前的滚动值(开始的滚动值)'
  63. }), _dec4 = property({
  64. tooltip: '是否显示正负符号'
  65. }), _dec5 = property({
  66. tooltip: '滚动的目标值'
  67. }), _dec6 = property({
  68. tooltip: '滚动的线性差值',
  69. step: 0.01,
  70. max: 1,
  71. min: 0
  72. }), _dec7 = property({
  73. tooltip: '是否在开始时就播放'
  74. }), _dec8 = property({
  75. tooltip: '在滚动之前会等待几秒',
  76. step: 0.1,
  77. max: 1,
  78. min: 0
  79. }), _dec9 = property({
  80. type: Enum(VALUE_TYPE),
  81. tooltip: '是否在开始时就播放'
  82. }), ccclass(_class = _dec(_class = (_class2 = class BhvRollNumber extends Component {
  83. constructor(...args) {
  84. super(...args);
  85. _initializerDefineProperty(this, "label", _descriptor, this);
  86. _initializerDefineProperty(this, "value", _descriptor2, this);
  87. _initializerDefineProperty(this, "showPlusSymbol", _descriptor3, this);
  88. _initializerDefineProperty(this, "_targetValue", _descriptor4, this);
  89. /** 滚动的线性差值 0 ~ 1 */
  90. _initializerDefineProperty(this, "lerp", _descriptor5, this);
  91. _initializerDefineProperty(this, "playAtStart", _descriptor6, this);
  92. _initializerDefineProperty(this, "runWaitTimer", _descriptor7, this);
  93. _initializerDefineProperty(this, "valueType", _descriptor8, this);
  94. /** 自定义string 处理函数 */
  95. this.onCustom = null;
  96. this.isScrolling = false;
  97. }
  98. get targetValue() {
  99. return this._targetValue;
  100. }
  101. set targetValue(v) {
  102. this._targetValue = v;
  103. this.scroll(); //数据变动了就开始滚动
  104. }
  105. onLoad() {
  106. if (this.label == undefined) {
  107. this.label = this.node.getComponent(Label);
  108. }
  109. if (this.playAtStart) {
  110. this.updateLabel();
  111. this.scroll();
  112. }
  113. }
  114. /** 开始滚动数字 */
  115. scroll() {
  116. if (this.isScrolling) return; // 已经在滚动了就返回
  117. if (this.runWaitTimer > 0) {
  118. this.scheduleOnce(() => {
  119. this.isScrolling = true;
  120. }, this.runWaitTimer);
  121. } else {
  122. this.isScrolling = true;
  123. }
  124. }
  125. /** 停止滚动数字 */
  126. stop() {
  127. this.value = this.targetValue;
  128. this.isScrolling = false;
  129. this.updateLabel();
  130. }
  131. /** 初始化数值,不填写则全部按默认值处理 */
  132. init(value, target, lerp) {
  133. this.targetValue = target || 0;
  134. this.value = value || 0;
  135. this.lerp = lerp || 0.1;
  136. }
  137. /** 滚动到指定数字 */
  138. scrollTo(target) {
  139. if (target === null || target === undefined) return;
  140. this.targetValue = target;
  141. }
  142. /** 更新文本 */
  143. updateLabel() {
  144. let value = this.value;
  145. let string = '';
  146. switch (this.valueType) {
  147. case VALUE_TYPE.INTEGER:
  148. // 最终显示整数类型
  149. string = Math.round(value) + '';
  150. break;
  151. case VALUE_TYPE.FIXED_2:
  152. // 最终显示两位小数类型
  153. string = value.toFixed(2);
  154. break;
  155. case VALUE_TYPE.TIMER:
  156. // 最终显示 计时器类型
  157. string = parseTimer(value);
  158. break;
  159. case VALUE_TYPE.PERCENTAGE:
  160. // 最终显示 百分比
  161. string = Math.round(value * 100) + '%';
  162. break;
  163. case VALUE_TYPE.KMBT_FIXED2:
  164. // 长单位缩放,只计算到 KMBT
  165. if (value >= Number.MAX_VALUE) {
  166. string = 'MAX';
  167. } else if (value > 1000000000000) {
  168. string = (value / 1000000000000).toFixed(2) + 'T';
  169. } else if (value > 1000000000) {
  170. string = (value / 1000000000).toFixed(2) + 'B';
  171. } else if (value > 1000000) {
  172. string = (value / 1000000).toFixed(2) + 'M';
  173. } else if (value > 1000) {
  174. string = (value / 1000).toFixed(2) + "K";
  175. } else {
  176. string = Math.round(value).toString();
  177. }
  178. break;
  179. case VALUE_TYPE.CUSTOMER:
  180. // 自定义设置模式 (通过给定的自定义函数..处理)
  181. if (this.onCustom) {
  182. string = this.onCustom(this.value, this.targetValue);
  183. }
  184. break;
  185. default:
  186. break;
  187. } // 显示正负符号
  188. if (this.showPlusSymbol) {
  189. if (value > 0) {
  190. string = '+' + string;
  191. } else if (value < 0) {
  192. string = '-' + string;
  193. }
  194. }
  195. if (this.label) {
  196. if (string === this.label.string) return; // 保证效率,如果上次赋值过,就不重复赋值
  197. this.label.string = string;
  198. }
  199. }
  200. update(dt) {
  201. if (this.isScrolling == false) return;
  202. this.value = lerp(this.value, this.targetValue, this.lerp);
  203. this.updateLabel();
  204. if (Math.abs(this.value - this.targetValue) <= 0.0001) {
  205. this.value = this.targetValue;
  206. this.isScrolling = false; //this.node.emit('roll-hit-target'); // 滚动数字击中了目标
  207. return;
  208. }
  209. }
  210. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "label", [_dec2], {
  211. configurable: true,
  212. enumerable: true,
  213. writable: true,
  214. initializer: function () {
  215. return null;
  216. }
  217. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "value", [_dec3], {
  218. configurable: true,
  219. enumerable: true,
  220. writable: true,
  221. initializer: function () {
  222. return 0;
  223. }
  224. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "showPlusSymbol", [_dec4], {
  225. configurable: true,
  226. enumerable: true,
  227. writable: true,
  228. initializer: function () {
  229. return false;
  230. }
  231. }), _applyDecoratedDescriptor(_class2.prototype, "targetValue", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "targetValue"), _class2.prototype), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "_targetValue", [property], {
  232. configurable: true,
  233. enumerable: true,
  234. writable: true,
  235. initializer: function () {
  236. return 100;
  237. }
  238. }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "lerp", [_dec6], {
  239. configurable: true,
  240. enumerable: true,
  241. writable: true,
  242. initializer: function () {
  243. return 0.1;
  244. }
  245. }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "playAtStart", [_dec7], {
  246. configurable: true,
  247. enumerable: true,
  248. writable: true,
  249. initializer: function () {
  250. return true;
  251. }
  252. }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "runWaitTimer", [_dec8], {
  253. configurable: true,
  254. enumerable: true,
  255. writable: true,
  256. initializer: function () {
  257. return 0;
  258. }
  259. }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "valueType", [_dec9], {
  260. configurable: true,
  261. enumerable: true,
  262. writable: true,
  263. initializer: function () {
  264. return VALUE_TYPE.INTEGER;
  265. }
  266. })), _class2)) || _class) || _class));
  267. _cclegacy._RF.pop();
  268. _crd = false;
  269. }
  270. };
  271. });
  272. //# sourceMappingURL=445a599b04e622a25bb42ce16a5b4d2e086a5e93.js.map