Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

103 righe
2.6 KiB

  1. using System;
  2. using CIG.Translation;
  3. using CIGEnums;
  4. using SUISS.Core;
  5. using SUISSEngine;
  6. using Tweening;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. namespace CIG
  10. {
  11. public class CurrencyBar : CurrencyTweenHelper
  12. {
  13. private void OnEnable()
  14. {
  15. CIGGameState instance = SingletonMonobehaviour<CIGGameState>.Instance;
  16. instance.BalanceChangedEvent += this.OnBalanceChanged;
  17. switch (this._currencyType)
  18. {
  19. case CurrencyType.Cash:
  20. this._currencyTypeString = "Cash";
  21. break;
  22. case CurrencyType.Gold:
  23. this._currencyTypeString = "Gold";
  24. break;
  25. case CurrencyType.XP:
  26. this._currencyTypeString = "XP";
  27. break;
  28. default:
  29. UnityEngine.Debug.LogFormat("Can't create a CurrencyBar animation for unknown currencyType: {0}", new object[]
  30. {
  31. this._currencyType
  32. });
  33. break;
  34. }
  35. this._endValue = instance.Balance.GetValue(this._currencyTypeString);
  36. this.UpdateValue(this._endValue);
  37. }
  38. private void OnDisable()
  39. {
  40. if (SingletonMonobehaviour<CIGGameState>.IsAvailable)
  41. {
  42. SingletonMonobehaviour<CIGGameState>.Instance.BalanceChangedEvent -= this.OnBalanceChanged;
  43. }
  44. }
  45. protected override void UpdateValue(decimal value)
  46. {
  47. this._currentValue = value;
  48. if (this._currencyType == CurrencyType.XP)
  49. {
  50. float levelProgress = SingletonMonobehaviour<CIGGameState>.Instance.LevelProgress;
  51. this._currencyLabel.LocalizedString = Localization.Percentage(levelProgress, 0);
  52. this._currencyProgressBar.value = levelProgress;
  53. }
  54. else
  55. {
  56. this._currencyLabel.LocalizedString = Localization.Integer((long)this._currentValue);
  57. }
  58. }
  59. private void OnBalanceChanged(Currencies oldBalance, Currencies newBalance, object earnSource)
  60. {
  61. decimal num = newBalance.GetValue(this._currencyTypeString) - oldBalance.GetValue(this._currencyTypeString);
  62. if (num < 0m)
  63. {
  64. this._endValue += num;
  65. base.TweenTo(this._currentValue, this._endValue);
  66. }
  67. }
  68. public override void FlyingCurrencyFinishedPlaying(CurrencyValue earnedCurrency)
  69. {
  70. this._endValue += earnedCurrency.Value;
  71. base.TweenTo(this._currentValue, this._endValue);
  72. if (this._iconTweener.IsPlaying)
  73. {
  74. this._iconTweener.Stop();
  75. }
  76. this._iconTweener.Play();
  77. }
  78. [SerializeField]
  79. private Tweener _iconTweener;
  80. [SerializeField]
  81. private CurrencyType _currencyType;
  82. [SerializeField]
  83. private LocalizedText _currencyLabel;
  84. [SerializeField]
  85. private Slider _currencyProgressBar;
  86. private string _currencyTypeString;
  87. private decimal _currentValue;
  88. private decimal _endValue;
  89. }
  90. }