|
- using System;
- using CIG;
- using CIG.Extensions;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using Tweening;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class DailyRewardPopupView : PopupBaseView
- {
- protected void OnDestroy()
- {
- this._valueCounterDisplay.FinishedTweeningEvent -= this.OnTodayItemCountDownFinished;
- }
-
- public void UpdateView(DailyRewardsManager.Streak streak, int currentIndex)
- {
- this.ClearItems();
- this._collectButton.interactable = true;
- this._dailyRewardItems = new DailyRewardItem[streak.TotalDays];
- int i = 0;
- int num = this._dailyRewardItems.Length;
- while (i < num)
- {
- DailyRewardItem dailyRewardItem = UnityEngine.Object.Instantiate<DailyRewardItem>(this._dailyRewardItemPrefab, this._dailyRewardItemsHolder);
- this._dailyRewardItems[i] = dailyRewardItem;
- DailyReward dailyReward = streak.GetDailyReward(i);
- dailyRewardItem.Display(dailyReward, i, currentIndex);
- if (i == currentIndex)
- {
- this._todaysReward = dailyReward;
- ILocalizedString localizedString = Localization.Integer(this._todaysReward.Value);
- if (this._todaysReward.Currency == "LevelUp")
- {
- localizedString = Localization.Format(Localization.Key("iap.title.levels$n"), new ILocalizedString[]
- {
- localizedString
- });
- this._todayRewardValueText.gameObject.SetActive(true);
- this._todayRewardValueText.LocalizedString = dailyRewardItem.GetCurrentValueDisplay();
- }
- else
- {
- this._todayRewardValueText.gameObject.SetActive(false);
- }
- this._todayValueText.LocalizedString = localizedString;
- this._todayRewardDisplayImage.sprite = dailyRewardItem.GetCurrencyDisplaySprite();
- this._todayRewardIcon.sprite = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(this._todaysReward.Currency);
- }
- i++;
- }
- }
-
- public void Init(object _rewardCurrencySourceObject)
- {
- this._rewardCurrencyAnimationSource.Init(_rewardCurrencySourceObject);
- }
-
- public void Deinit()
- {
- this._rewardCurrencyAnimationSource.Deinit();
- }
-
- public override void Close()
- {
- this.ClearItems();
- base.Close();
- }
-
- public void OnCollectClicked()
- {
- if (this._collectButton.interactable)
- {
- this._collectButton.interactable = false;
- if (this._todaysReward != null && this._todaysReward.Currency != "LevelUp")
- {
- this._valueCounterDisplay.FinishedTweeningEvent += this.OnTodayItemCountDownFinished;
- this._valueCounterDisplay.PlayValueCounter(this._todaysReward.Value, 0m);
- }
- else
- {
- this.OnTodayItemCountDownFinished();
- }
- SingletonMonobehaviour<CIGAudioManager>.Instance.PlayClip(Clip.Victory);
- }
- }
-
- private void ClosePopup()
- {
- base.PopupState.ClosePopup();
- }
-
- private void ClearItems()
- {
- if (this._dailyRewardItems != null)
- {
- int i = 0;
- int num = this._dailyRewardItems.Length;
- while (i < num)
- {
- UnityEngine.Object.Destroy(this._dailyRewardItems[i].gameObject);
- i++;
- }
- }
- this._dailyRewardItems = null;
- }
-
- private void OnTodayItemCountDownFinished()
- {
- this._valueCounterDisplay.FinishedTweeningEvent -= this.OnTodayItemCountDownFinished;
- ((DailyRewardPopupState)this.State).Collect();
- this._rewardIconClaimedTweener.Play();
- this.Invoke(new Action(base.PopupState.ClosePopup), 1f, false);
- }
-
- [Header("Today Reward")]
- [SerializeField]
- private LocalizedText _todayValueText;
-
- [SerializeField]
- private Image _todayRewardIcon;
-
- [SerializeField]
- private LocalizedText _todayRewardValueText;
-
- [SerializeField]
- private Image _todayRewardDisplayImage;
-
- [SerializeField]
- private ValueCounterDisplay _valueCounterDisplay;
-
- [SerializeField]
- private CurrencyAnimationSource _rewardCurrencyAnimationSource;
-
- [SerializeField]
- private Tweener _rewardIconClaimedTweener;
-
- [Header("Day Reward Items")]
- [SerializeField]
- private DailyRewardItem _dailyRewardItemPrefab;
-
- [SerializeField]
- private RectTransform _dailyRewardItemsHolder;
-
- [Header("Lower Section")]
- [SerializeField]
- private Button _collectButton;
-
- private DailyRewardItem[] _dailyRewardItems = new DailyRewardItem[0];
-
- private DailyReward _todaysReward;
- }
|