|
- using System;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Cloud;
- using SUISS.Core;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class LeaderboardItem : MonoBehaviour
- {
- private void OnDestroy()
- {
- this.UnregisterDataDownloadedEvent();
- }
-
- private bool IsSelf
- {
- get
- {
- return this._record == null || this._record.InstallUuid == SingletonMonobehaviour<CIGSparkSocServices>.Instance.GetInstallUuid();
- }
- }
-
- public void Init(LeaderboardEntry record, Leaderboard board)
- {
- this._record = record;
- this._recordContainer.SetActive(true);
- this._spacerContainer.SetActive(false);
- this._background.sprite = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset((!this.IsSelf) ? UISpriteType.InsetFrameDarkBlueLeaderboard : UISpriteType.InsetFrameHighlightedLeaderboard);
- this._rankLabel.LocalizedString = Localization.Integer(board.GetRank(record));
- this._playerNameLabel.LocalizedString = Localization.Literal(record.Username);
- this._levelLabel.LocalizedString = Localization.Integer(record.PrimaryScore);
- this._levelProgressLabel.LocalizedString = Localization.Percentage(record.QuaternaryScore);
- this._levelProgress.value = (float)record.QuaternaryScore / 100f;
- this._citizensLabel.LocalizedString = Localization.Integer(record.SecondaryScore);
- this._islandsLabel.LocalizedString = Localization.Format(Localization.Key("progress"), new ILocalizedString[]
- {
- Localization.Integer(record.TertiaryScore),
- Localization.Integer(10)
- });
- this._visitButton.gameObject.SetActive((record.IslandReady || record.Votes > 0) && !this.IsSelf);
- this.UpdateLikesLabel();
- }
-
- public void InitFakeRecord()
- {
- CIGSparkSocServices instance = SingletonMonobehaviour<CIGSparkSocServices>.Instance;
- CIGGameState instance2 = SingletonMonobehaviour<CIGGameState>.Instance;
- this._record = null;
- this._recordContainer.SetActive(true);
- this._spacerContainer.SetActive(false);
- this._background.sprite = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(UISpriteType.InsetFrameHighlightedLeaderboard);
- this._rankLabel.LocalizedString = Localization.Literal("?");
- if (instance.IsLinkedToPlayername())
- {
- this._playerNameLabel.LocalizedString = Localization.Literal(instance.GetPlayerName());
- }
- else
- {
- this._playerNameLabel.LocalizedString = Localization.Key("battle_log.you");
- }
- this._levelLabel.LocalizedString = Localization.Integer(instance2.Level);
- this._levelProgressLabel.LocalizedString = Localization.Percentage(instance2.LevelProgress, 0);
- this._levelProgress.value = instance2.LevelProgress;
- this._citizensLabel.LocalizedString = Localization.Integer(instance2.GlobalPopulation);
- this._islandsLabel.LocalizedString = Localization.Format(Localization.Key("progress"), new ILocalizedString[]
- {
- Localization.Integer(instance2.GetIslandsUnlockedCount()),
- Localization.Integer(10)
- });
- this._visitButton.gameObject.SetActive(false);
- this.UpdateLikesLabel();
- }
-
- public void InitSeparator()
- {
- this._recordContainer.SetActive(false);
- this._spacerContainer.SetActive(true);
- }
-
- public void OnVisitIslandClicked()
- {
- CIGVisitingIslandsManager instanceIfAvailable = SingletonMonobehaviour<CIGVisitingIslandsManager>.InstanceIfAvailable;
- if (instanceIfAvailable != null)
- {
- if (instanceIfAvailable.VisitingIslandDataAvaible(Island.GoneGreenlands, this._record.InstallUuid) && instanceIfAvailable.IsUnlocked(Island.GoneGreenlands, this._record.InstallUuid))
- {
- this.StartVisiting();
- }
- else if (instanceIfAvailable.VisitingIslandDataAvaible(Island.GoneGreenlands, this._record.InstallUuid) && !instanceIfAvailable.IsUnlocked(Island.GoneGreenlands, this._record.InstallUuid))
- {
- this.ShowNoDataPopup();
- }
- else
- {
- this.RegisterDataDownloadedEvent();
- SingletonMonobehaviour<PopupManager>.Instance.ShowOrUpdateGenericPopup(null, Localization.Key("please_wait"), Localization.Key("social_loading"), null, Localization.Key("cancel"), null, new Action(this.CancelClicked), new Action(this.CancelClicked), true);
- instanceIfAvailable.DownloadAllIslandsData(this._record.InstallUuid);
- }
- }
- }
-
- private void UpdateLikesLabel()
- {
- if (this._record == null)
- {
- this._likesLabel.LocalizedString = Localization.Integer(1);
- }
- else
- {
- int numberOfLikes = LikeRegistrar.GetNumberOfLikes(this._record.InstallUuid);
- int num = Math.Max(numberOfLikes, Math.Max(this._record.Votes, 0));
- if (num >= 1000)
- {
- this._likesLabel.LocalizedString = Localization.Concat(new ILocalizedString[]
- {
- Localization.Integer(num / 1000),
- Localization.Literal("k")
- });
- }
- else
- {
- this._likesLabel.LocalizedString = Localization.Integer(num);
- }
- }
- }
-
- private void StartVisiting()
- {
- this.UnregisterDataDownloadedEvent();
- SingletonMonobehaviour<PopupManager>.Instance.CloseRecursive(true);
- SingletonMonobehaviour<CIGIslandsManager>.Instance.StartVisiting(this._record);
- }
-
- private void CancelClicked()
- {
- this.UnregisterDataDownloadedEvent();
- }
-
- private void RegisterDataDownloadedEvent()
- {
- if (!this._eventRegistered)
- {
- CIGVisitingIslandsManager instanceIfAvailable = SingletonMonobehaviour<CIGVisitingIslandsManager>.InstanceIfAvailable;
- if (instanceIfAvailable != null)
- {
- instanceIfAvailable.DataDownloadedEvent += this.OnDataDownloaded;
- this._eventRegistered = true;
- }
- }
- }
-
- private void ShowNoDataPopup()
- {
- SingletonMonobehaviour<PopupManager>.Instance.ShowOrUpdateGenericPopup(null, Localization.Key("oops_three_dots"), Localization.Key("building.cannot_build"), null, Localization.Key("ok"), null, new Action(this.CancelClicked), new Action(this.CancelClicked), true);
- this.UnregisterDataDownloadedEvent();
- }
-
- private void UnregisterDataDownloadedEvent()
- {
- if (this._eventRegistered)
- {
- CIGVisitingIslandsManager instanceIfAvailable = SingletonMonobehaviour<CIGVisitingIslandsManager>.InstanceIfAvailable;
- if (instanceIfAvailable != null)
- {
- instanceIfAvailable.DataDownloadedEvent -= this.OnDataDownloaded;
- this._eventRegistered = false;
- }
- }
- }
-
- private void OnDataDownloaded(Island island, string uid)
- {
- CIGVisitingIslandsManager instanceIfAvailable = SingletonMonobehaviour<CIGVisitingIslandsManager>.InstanceIfAvailable;
- if (instanceIfAvailable != null && island == Island.GoneGreenlands && uid == this._record.InstallUuid)
- {
- if (instanceIfAvailable.VisitingIslandDataAvaible(Island.GoneGreenlands, this._record.InstallUuid) && !instanceIfAvailable.IsUnlocked(Island.GoneGreenlands, this._record.InstallUuid))
- {
- this.ShowNoDataPopup();
- }
- else
- {
- this.StartVisiting();
- }
- }
- }
-
- [SerializeField]
- private GameObject _recordContainer;
-
- [SerializeField]
- private GameObject _spacerContainer;
-
- [SerializeField]
- [Header("Record")]
- private Image _background;
-
- [SerializeField]
- private LocalizedText _rankLabel;
-
- [SerializeField]
- private LocalizedText _levelLabel;
-
- [SerializeField]
- private LocalizedText _levelProgressLabel;
-
- [SerializeField]
- private Slider _levelProgress;
-
- [SerializeField]
- private LocalizedText _playerNameLabel;
-
- [SerializeField]
- private LocalizedText _citizensLabel;
-
- [SerializeField]
- private LocalizedText _islandsLabel;
-
- [SerializeField]
- private Button _visitButton;
-
- [SerializeField]
- private LocalizedText _likesLabel;
-
- private LeaderboardEntry _record;
-
- private bool _eventRegistered;
- }
|