ManageGolden.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. GoldenLabel: cc.Node,
  5. Diamondlabel: {
  6. default: null,
  7. type: cc.Node,
  8. },
  9. ManageUI: cc.Node,
  10. //5个神农呗兑1个cnt
  11. CNTNode: {
  12. default: null,
  13. type: cc.Node,
  14. },
  15. SNBNode: {
  16. default: null,
  17. type: cc.Node,
  18. },
  19. },
  20. InitManageGlodenUI() {
  21. this.GoldenLabel.getComponent(cc.Label).string = this.FormatMoney(
  22. GlobalD.GameData.GetGolden().toString()
  23. )
  24. this.Diamondlabel.getComponent(cc.Label).string = this.FormatMoney(
  25. GlobalD.GameData.GetDiamond().toString()
  26. )
  27. this.CNTNode.getComponent(cc.Label).string = this.FormatMoney(
  28. GlobalD.GameData.GetCNT().toString()
  29. )
  30. this.SNBNode.getComponent(cc.Label).string = this.FormatMoney(
  31. GlobalD.GameData.GetSNB().toString()
  32. )
  33. },
  34. FormatMoney(s, n) {
  35. n = n > 0 && n <= 20 ? n : 2
  36. s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(n) + ''
  37. var l = s.split('.')[0].split('').reverse(),
  38. r = s.split('.')[1]
  39. let t = ''
  40. for (let i = 0; i < l.length; i++) {
  41. t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? ',' : '')
  42. }
  43. return t.split('').reverse().join('') //+ "." + r;
  44. },
  45. })