using System; using System.Collections.Generic; using CIG; using CIG.Extensions; using CIG.Translation; using CIGEnums; using SUISS.Cloud; using SUISS.Core; using UnityEngine; using UnityEngine.UI; public class LeaderboardsPopupView : PopupBaseView { private void OnDestroy() { this._tabView.TabIndexChangedEvent -= this.OnTabIndexChanged; } private int ItemCount { get { if (this._currentLocal.Records.Count == 0) { return this._currentTop.Records.Count + ((!this._isInTop) ? 2 : 0); } return this._currentTop.Records.Count + 1 + this._currentLocal.Records.Count; } } public override void Init() { base.Init(); this._tabView.TabIndexChangedEvent += this.OnTabIndexChanged; } public override void Open() { base.Open(); SingletonMonobehaviour.Instance.PushUnlimitedFPSRequest(this); } public override void Close() { this._recyclerView.PushInstances(); SingletonMonobehaviour.Instance.PopUnlimitedFPSRequest(this); base.Close(); } public override void OnCloseClicked() { this._lastScrollPositionsPerTab[this._tabView.ActiveTabIndex] = this._scrollRect.verticalNormalizedPosition; base.OnCloseClicked(); } public void SwitchTab(LeaderboardTabs leaderboardTab, Leaderboard top, Leaderboard personal) { this._recyclerView.PushInstances(); this._tabView.ActiveTabIndex = (int)leaderboardTab; if (leaderboardTab != LeaderboardTabs.Global) { if (leaderboardTab != LeaderboardTabs.Country) { this._leaderboardNameLabel.LocalizedString = Localization.EmptyLocalizedString; UnityEngine.Debug.LogWarningFormat("Missing leaderboard name for '{0}'", new object[] { leaderboardTab }); } else { this._leaderboardNameLabel.LocalizedString = Localization.Key("leaderboard.local_ranking"); } } else { this._leaderboardNameLabel.LocalizedString = Localization.Key("leaderboard.global_ranking"); } this._sagid = SingletonMonobehaviour.Instance.GetInstallUuid(); this._currentTop = top; this._currentLocal = personal; this._isInTop = this._currentTop.Records.Exists((LeaderboardEntry x) => x.InstallUuid == this._sagid); if (SingletonMonobehaviour.Instance.IsLogedInAndLinked()) { this._loginFirstContainer.SetActive(false); if (this._isInTop || this._currentLocal.Records.Count > 0) { this._rankBeingProcessedContainer.SetActive(false); } else { this._rankBeingProcessedContainer.SetActive(true); } } else { this._loginFirstContainer.SetActive(true); this._rankBeingProcessedContainer.SetActive(false); } this._recyclerView.Init(this.ItemCount, new Func(this.InitLeaderboardItem)); this.InvokeNextFrame(delegate { float verticalNormalizedPosition; if (!this._lastScrollPositionsPerTab.TryGetValue(this._tabView.ActiveTabIndex, out verticalNormalizedPosition)) { verticalNormalizedPosition = 1f; } this._scrollRect.verticalNormalizedPosition = verticalNormalizedPosition; }); } public void OnLoginClicked() { ((LeaderboardsPopupState)this.State).OpenLoginPopup(); } private bool InitLeaderboardItem(GameObject go, int index) { if (this._currentTop == null || this._currentLocal == null || index < 0 || index >= this.ItemCount) { return false; } int count = this._currentTop.Records.Count; int num = count + 1; LeaderboardItem leaderboardItem = this.GetLeaderboardItem(go); if (index < count) { LeaderboardEntry record = this._currentTop.Records[index]; leaderboardItem.Init(record, this._currentTop); } else if (index == count) { leaderboardItem.InitSeparator(); } else if (this._currentLocal.Records.Count > 0) { LeaderboardEntry record2 = this._currentLocal.Records[index - num]; leaderboardItem.Init(record2, this._currentLocal); } else { leaderboardItem.InitFakeRecord(); } return true; } private LeaderboardItem GetLeaderboardItem(GameObject go) { if (!this._leaderboardItems.ContainsKey(go)) { this._leaderboardItems[go] = go.GetComponent(); } return this._leaderboardItems[go]; } private void OnTabIndexChanged(int oldIndex, int newIndex) { this._lastScrollPositionsPerTab[oldIndex] = this._scrollRect.verticalNormalizedPosition; ((LeaderboardsPopupState)this.State).SwitchTab((LeaderboardTabs)newIndex); } [SerializeField] private TabView _tabView; [SerializeField] private LocalizedText _leaderboardNameLabel; [SerializeField] private ScrollRect _scrollRect; [SerializeField] private RecyclerGridLayoutGroup _recyclerView; [SerializeField] private GameObject _loginFirstContainer; [SerializeField] private GameObject _rankBeingProcessedContainer; private bool _isInTop; private string _sagid = string.Empty; private Leaderboard _currentTop; private Leaderboard _currentLocal; private readonly Dictionary _lastScrollPositionsPerTab = new Dictionary(); private Dictionary _leaderboardItems = new Dictionary(); }