|
- using System;
- using CIG;
- using CIG.Translation;
- using CIGEnums;
- using Engine.DependencyTree;
- using SUISS.Core;
- using SUISSEngine;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class QuestItem : MonoBehaviour
- {
- public void OnDestroy()
- {
- this.Deinit();
- }
-
- public void Initialize(Dependency quest)
- {
- this.Deinit();
- this._currencyAnimationSource.Init(this._currencyAnimationObject);
- this._quest = quest;
- if (this._quest != null)
- {
- this._quest.AchievedChangedEvent += this.OnAchievedChanged;
- }
- if (this.IsVideoQuest)
- {
- SingletonMonobehaviour<VideoAds1Manager>.Instance.AvailabilityChangedEvent += this.OnVideoAvailabilityChanged;
- }
- this.ShowQuest();
- }
-
- public void OnClaimRewardClicked()
- {
- if (this._level != null && !this._level.RewardClaimed && this._level.IsAchieved)
- {
- Currencies currencies = this._level.Reward;
- if (this._quest.IsAchieved && !this._quest.RewardClaimed)
- {
- currencies += this._quest.Reward;
- }
- if (!currencies.IsEmpty())
- {
- CIGGameState instance = SingletonMonobehaviour<CIGGameState>.Instance;
- instance.EarnCurrencies(currencies, this._currencyAnimationObject);
- ServiceLocator.Find<Messenger>().Invoke<InterestingRatingTriggerEvent<CIGInterestingRatingTriggerEventType>>(new InterestingRatingTriggerEvent<CIGInterestingRatingTriggerEventType>(CIGInterestingRatingTriggerEventType.ClaimedAchievementAward));
- SingletonMonobehaviour<CIGAudioManager>.Instance.PlayClip(Clip.Victory);
- }
- this._level.RewardClaimed = true;
- if (this._quest.IsAchieved)
- {
- this._quest.RewardClaimed = true;
- if (SingletonMonobehaviour<CIGDailyQuestManager>.Instance.IsActiveDailyQuest(this._quest))
- {
- }
- }
- if (this._quest.IsAchieved)
- {
- this.ShowQuest();
- }
- else
- {
- this.FindCurrentLevel();
- }
- }
- else if (this.IsVideoQuest)
- {
- SingletonMonobehaviour<VideoAds1Manager>.Instance.ShowVideoQuestAd();
- }
- }
-
- private void Deinit()
- {
- this._currencyAnimationSource.Deinit();
- if (this._quest != null)
- {
- this._quest.AchievedChangedEvent -= this.OnAchievedChanged;
- }
- if (this._level != null)
- {
- this._level.AchievedChangedEvent -= this.OnAchievedChanged;
- this._level.ProgressValueChangedEvent -= this.OnProgressChanged;
- }
- if (SingletonMonobehaviour<VideoAds1Manager>.IsAvailable)
- {
- SingletonMonobehaviour<VideoAds1Manager>.Instance.AvailabilityChangedEvent -= this.OnVideoAvailabilityChanged;
- }
- this._quest = null;
- this._level = null;
- }
-
- private void OnVideoAvailabilityChanged()
- {
- if (this.IsVideoQuest && (!this._level.IsAchieved || this._level.RewardClaimed))
- {
- this._claimRewardButton.interactable = SingletonMonobehaviour<VideoAds1Manager>.Instance.IsReady;
- }
- }
-
- private void FindCurrentLevel()
- {
- if (this._level != null)
- {
- this._level.AchievedChangedEvent -= this.OnAchievedChanged;
- this._level.ProgressValueChangedEvent -= this.OnProgressChanged;
- }
- this._level = null;
- if (this._quest != null)
- {
- foreach (Dependency dependency in this._quest.Children)
- {
- if (!dependency.IsAchieved || !dependency.RewardClaimed)
- {
- this._level = dependency;
- break;
- }
- }
- if (this._level == null && this._quest.Children.Count > 0)
- {
- this._level = this._quest.Children[this._quest.Children.Count - 1];
- }
- }
- if (this._level != null)
- {
- this._level.AchievedChangedEvent += this.OnAchievedChanged;
- this._level.ProgressValueChangedEvent += this.OnProgressChanged;
- }
- this.ShowLevel();
- }
-
- private void ShowQuest()
- {
- this._questIcon.sprite = SingletonMonobehaviour<QuestSpriteAssetCollection>.Instance.GetAsset(this._quest.SpriteName);
- this.FindCurrentLevel();
- }
-
- private void ShowLevel()
- {
- if (this._level != null)
- {
- Dependency dependency = this._level;
- if (!dependency.HasTitle)
- {
- dependency = this._quest;
- }
- string text;
- if (!dependency.HasTitle)
- {
- text = string.Empty;
- }
- else if (dependency.IsQuantityTitle)
- {
- text = ((!CIGUtilities.IsSingular(this._level.ProgressMaximumValue)) ? dependency.TitlePlural : dependency.TitleSingular);
- }
- else
- {
- text = dependency.Title;
- }
- this._nameText.LocalizedString = ((!string.IsNullOrEmpty(text)) ? Localization.Format(Localization.Key(text), this._level.TitleArguments) : Localization.EmptyLocalizedString);
- int num;
- int progressMaximumValue;
- if (this._level.IsAchieved)
- {
- num = this._level.ProgressMaximumValue;
- progressMaximumValue = this._level.ProgressMaximumValue;
- }
- else
- {
- num = this._level.ProgressValue;
- progressMaximumValue = this._level.ProgressMaximumValue;
- }
- this._progressBarSlider.value = (float)num / (float)progressMaximumValue;
- int i = Mathf.FloorToInt((float)num / this._level.ValueModifier);
- int i2 = Mathf.FloorToInt((float)progressMaximumValue / this._level.ValueModifier);
- this._progressText.LocalizedString = Localization.Format(Localization.Key("progress"), new ILocalizedString[]
- {
- Localization.Integer(i),
- Localization.Integer(i2)
- });
- this._progressBarFillImage.sprite = ((!this._level.IsAchieved) ? this._progressFillInProgress : this._progressFillCompleted);
- if (this._level.IsAchieved && !this._level.RewardClaimed)
- {
- this.EnableClaimButton();
- }
- else
- {
- this.DisableClaimButton();
- }
- this.UpdateReward(this._level.Reward);
- if (this._achievedQuestIcon != null)
- {
- this._achievedQuestIcon.gameObject.SetActive(this._level.IsAchieved && this._level.RewardClaimed);
- }
- }
- }
-
- private void UpdateReward(Currencies reward)
- {
- bool flag = CIGUtilities.HasCash(reward);
- bool flag2 = CIGUtilities.HasGold(reward);
- this._rewardText.LocalizedString = Localization.Integer(reward.GetValue((!flag) ? ((!flag2) ? "XP" : "Gold") : "Cash"));
- Sprite asset = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(UISpriteType.XPSmall);
- if (flag)
- {
- asset = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(UISpriteType.CashSmall);
- }
- else if (flag2)
- {
- asset = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(UISpriteType.GoldSmall);
- }
- this._rewardIcon.sprite = asset;
- }
-
- private void OnAchievedChanged(Dependency dependency, bool achieved)
- {
- if (dependency == this._quest)
- {
- this.ShowQuest();
- }
- else if (dependency == this._level)
- {
- this.ShowLevel();
- }
- }
-
- private void OnProgressChanged(Dependency dependency, int progress)
- {
- this.ShowLevel();
- }
-
- private void DisableClaimButton()
- {
- this._claimRewardObject.SetActive(false);
- this._rays.SetActive(false);
- this._claimRewardButton.interactable = (this.IsVideoQuest && SingletonMonobehaviour<VideoAds1Manager>.Instance.IsReady);
- }
-
- private void EnableClaimButton()
- {
- this._claimRewardObject.SetActive(true);
- this._rays.SetActive(true);
- this._claimRewardButton.interactable = true;
- }
-
- private bool IsVideoQuest
- {
- get
- {
- return this._quest != null && this._quest.Identifier.Contains("videos_gold");
- }
- }
-
- [Header("Customizations")]
- [SerializeField]
- private Sprite _progressFillInProgress;
-
- [SerializeField]
- private Sprite _progressFillCompleted;
-
- [Header("Links")]
- [SerializeField]
- private LocalizedText _nameText;
-
- [SerializeField]
- private LocalizedText _rewardText;
-
- [SerializeField]
- private Image _questIcon;
-
- [SerializeField]
- private Image _achievedQuestIcon;
-
- [SerializeField]
- private LocalizedText _progressText;
-
- [SerializeField]
- private Slider _progressBarSlider;
-
- [SerializeField]
- private Image _progressBarFillImage;
-
- [SerializeField]
- private Image _rewardIcon;
-
- [SerializeField]
- private GameObject _claimRewardObject;
-
- [SerializeField]
- private Button _claimRewardButton;
-
- [SerializeField]
- private GameObject _rays;
-
- [SerializeField]
- private CurrencyAnimationSource _currencyAnimationSource;
-
- private Dependency _quest;
-
- private Dependency _level;
-
- private object _currencyAnimationObject = new object();
- }
|