363eff2014ff2f9465f703c6d9fe1735dcfd3b1b.js 12 KB

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