Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

192 rader
5.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using CIG;
  4. using CIG.Extensions;
  5. using CIG.Translation;
  6. using CIGEnums;
  7. using SUISS.Cloud;
  8. using SUISS.Core;
  9. using UnityEngine;
  10. using UnityEngine.UI;
  11. public class LeaderboardsPopupView : PopupBaseView
  12. {
  13. private void OnDestroy()
  14. {
  15. this._tabView.TabIndexChangedEvent -= this.OnTabIndexChanged;
  16. }
  17. private int ItemCount
  18. {
  19. get
  20. {
  21. if (this._currentLocal.Records.Count == 0)
  22. {
  23. return this._currentTop.Records.Count + ((!this._isInTop) ? 2 : 0);
  24. }
  25. return this._currentTop.Records.Count + 1 + this._currentLocal.Records.Count;
  26. }
  27. }
  28. public override void Init()
  29. {
  30. base.Init();
  31. this._tabView.TabIndexChangedEvent += this.OnTabIndexChanged;
  32. }
  33. public override void Open()
  34. {
  35. base.Open();
  36. SingletonMonobehaviour<FPSLimiter>.Instance.PushUnlimitedFPSRequest(this);
  37. }
  38. public override void Close()
  39. {
  40. this._recyclerView.PushInstances();
  41. SingletonMonobehaviour<FPSLimiter>.Instance.PopUnlimitedFPSRequest(this);
  42. base.Close();
  43. }
  44. public override void OnCloseClicked()
  45. {
  46. this._lastScrollPositionsPerTab[this._tabView.ActiveTabIndex] = this._scrollRect.verticalNormalizedPosition;
  47. base.OnCloseClicked();
  48. }
  49. public void SwitchTab(LeaderboardTabs leaderboardTab, Leaderboard top, Leaderboard personal)
  50. {
  51. this._recyclerView.PushInstances();
  52. this._tabView.ActiveTabIndex = (int)leaderboardTab;
  53. if (leaderboardTab != LeaderboardTabs.Global)
  54. {
  55. if (leaderboardTab != LeaderboardTabs.Country)
  56. {
  57. this._leaderboardNameLabel.LocalizedString = Localization.EmptyLocalizedString;
  58. UnityEngine.Debug.LogWarningFormat("Missing leaderboard name for '{0}'", new object[]
  59. {
  60. leaderboardTab
  61. });
  62. }
  63. else
  64. {
  65. this._leaderboardNameLabel.LocalizedString = Localization.Key("leaderboard.local_ranking");
  66. }
  67. }
  68. else
  69. {
  70. this._leaderboardNameLabel.LocalizedString = Localization.Key("leaderboard.global_ranking");
  71. }
  72. this._sagid = SingletonMonobehaviour<CIGSparkSocServices>.Instance.GetInstallUuid();
  73. this._currentTop = top;
  74. this._currentLocal = personal;
  75. this._isInTop = this._currentTop.Records.Exists((LeaderboardEntry x) => x.InstallUuid == this._sagid);
  76. if (SingletonMonobehaviour<CIGSparkSocServices>.Instance.IsLogedInAndLinked())
  77. {
  78. this._loginFirstContainer.SetActive(false);
  79. if (this._isInTop || this._currentLocal.Records.Count > 0)
  80. {
  81. this._rankBeingProcessedContainer.SetActive(false);
  82. }
  83. else
  84. {
  85. this._rankBeingProcessedContainer.SetActive(true);
  86. }
  87. }
  88. else
  89. {
  90. this._loginFirstContainer.SetActive(true);
  91. this._rankBeingProcessedContainer.SetActive(false);
  92. }
  93. this._recyclerView.Init(this.ItemCount, new Func<GameObject, int, bool>(this.InitLeaderboardItem));
  94. this.InvokeNextFrame(delegate
  95. {
  96. float verticalNormalizedPosition;
  97. if (!this._lastScrollPositionsPerTab.TryGetValue(this._tabView.ActiveTabIndex, out verticalNormalizedPosition))
  98. {
  99. verticalNormalizedPosition = 1f;
  100. }
  101. this._scrollRect.verticalNormalizedPosition = verticalNormalizedPosition;
  102. });
  103. }
  104. public void OnLoginClicked()
  105. {
  106. ((LeaderboardsPopupState)this.State).OpenLoginPopup();
  107. }
  108. private bool InitLeaderboardItem(GameObject go, int index)
  109. {
  110. if (this._currentTop == null || this._currentLocal == null || index < 0 || index >= this.ItemCount)
  111. {
  112. return false;
  113. }
  114. int count = this._currentTop.Records.Count;
  115. int num = count + 1;
  116. LeaderboardItem leaderboardItem = this.GetLeaderboardItem(go);
  117. if (index < count)
  118. {
  119. LeaderboardEntry record = this._currentTop.Records[index];
  120. leaderboardItem.Init(record, this._currentTop);
  121. }
  122. else if (index == count)
  123. {
  124. leaderboardItem.InitSeparator();
  125. }
  126. else if (this._currentLocal.Records.Count > 0)
  127. {
  128. LeaderboardEntry record2 = this._currentLocal.Records[index - num];
  129. leaderboardItem.Init(record2, this._currentLocal);
  130. }
  131. else
  132. {
  133. leaderboardItem.InitFakeRecord();
  134. }
  135. return true;
  136. }
  137. private LeaderboardItem GetLeaderboardItem(GameObject go)
  138. {
  139. if (!this._leaderboardItems.ContainsKey(go))
  140. {
  141. this._leaderboardItems[go] = go.GetComponent<LeaderboardItem>();
  142. }
  143. return this._leaderboardItems[go];
  144. }
  145. private void OnTabIndexChanged(int oldIndex, int newIndex)
  146. {
  147. this._lastScrollPositionsPerTab[oldIndex] = this._scrollRect.verticalNormalizedPosition;
  148. ((LeaderboardsPopupState)this.State).SwitchTab((LeaderboardTabs)newIndex);
  149. }
  150. [SerializeField]
  151. private TabView _tabView;
  152. [SerializeField]
  153. private LocalizedText _leaderboardNameLabel;
  154. [SerializeField]
  155. private ScrollRect _scrollRect;
  156. [SerializeField]
  157. private RecyclerGridLayoutGroup _recyclerView;
  158. [SerializeField]
  159. private GameObject _loginFirstContainer;
  160. [SerializeField]
  161. private GameObject _rankBeingProcessedContainer;
  162. private bool _isInTop;
  163. private string _sagid = string.Empty;
  164. private Leaderboard _currentTop;
  165. private Leaderboard _currentLocal;
  166. private readonly Dictionary<int, float> _lastScrollPositionsPerTab = new Dictionary<int, float>();
  167. private Dictionary<GameObject, LeaderboardItem> _leaderboardItems = new Dictionary<GameObject, LeaderboardItem>();
  168. }