|
- using System;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using SUISSEngine;
- using Tweening;
- using UnityEngine;
- using UnityEngine.UI;
-
- namespace CIG
- {
- public class CurrencyBar : CurrencyTweenHelper
- {
- private void OnEnable()
- {
- CIGGameState instance = SingletonMonobehaviour<CIGGameState>.Instance;
- instance.BalanceChangedEvent += this.OnBalanceChanged;
- switch (this._currencyType)
- {
- case CurrencyType.Cash:
- this._currencyTypeString = "Cash";
- break;
- case CurrencyType.Gold:
- this._currencyTypeString = "Gold";
- break;
- case CurrencyType.XP:
- this._currencyTypeString = "XP";
- break;
- default:
- UnityEngine.Debug.LogFormat("Can't create a CurrencyBar animation for unknown currencyType: {0}", new object[]
- {
- this._currencyType
- });
- break;
- }
- this._endValue = instance.Balance.GetValue(this._currencyTypeString);
- this.UpdateValue(this._endValue);
- }
-
- private void OnDisable()
- {
- if (SingletonMonobehaviour<CIGGameState>.IsAvailable)
- {
- SingletonMonobehaviour<CIGGameState>.Instance.BalanceChangedEvent -= this.OnBalanceChanged;
- }
- }
-
- protected override void UpdateValue(decimal value)
- {
- this._currentValue = value;
- if (this._currencyType == CurrencyType.XP)
- {
- float levelProgress = SingletonMonobehaviour<CIGGameState>.Instance.LevelProgress;
- this._currencyLabel.LocalizedString = Localization.Percentage(levelProgress, 0);
- this._currencyProgressBar.value = levelProgress;
- }
- else
- {
- this._currencyLabel.LocalizedString = Localization.Integer((long)this._currentValue);
- }
- }
-
- private void OnBalanceChanged(Currencies oldBalance, Currencies newBalance, object earnSource)
- {
- decimal num = newBalance.GetValue(this._currencyTypeString) - oldBalance.GetValue(this._currencyTypeString);
- if (num < 0m)
- {
- this._endValue += num;
- base.TweenTo(this._currentValue, this._endValue);
- }
- }
-
- public override void FlyingCurrencyFinishedPlaying(CurrencyValue earnedCurrency)
- {
- this._endValue += earnedCurrency.Value;
- base.TweenTo(this._currentValue, this._endValue);
- if (this._iconTweener.IsPlaying)
- {
- this._iconTweener.Stop();
- }
- this._iconTweener.Play();
- }
-
- [SerializeField]
- private Tweener _iconTweener;
-
- [SerializeField]
- private CurrencyType _currencyType;
-
- [SerializeField]
- private LocalizedText _currencyLabel;
-
- [SerializeField]
- private Slider _currencyProgressBar;
-
- private string _currencyTypeString;
-
- private decimal _currentValue;
-
- private decimal _endValue;
- }
- }
|