You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

229 lines
7.5 KiB

  1. using System;
  2. using CIG.Translation;
  3. using CIGEnums;
  4. using SUISS.Cloud;
  5. using SUISS.Core;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. public class LeaderboardItem : MonoBehaviour
  9. {
  10. private void OnDestroy()
  11. {
  12. this.UnregisterDataDownloadedEvent();
  13. }
  14. private bool IsSelf
  15. {
  16. get
  17. {
  18. return this._record == null || this._record.InstallUuid == SingletonMonobehaviour<CIGSparkSocServices>.Instance.GetInstallUuid();
  19. }
  20. }
  21. public void Init(LeaderboardEntry record, Leaderboard board)
  22. {
  23. this._record = record;
  24. this._recordContainer.SetActive(true);
  25. this._spacerContainer.SetActive(false);
  26. this._background.sprite = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset((!this.IsSelf) ? UISpriteType.InsetFrameDarkBlueLeaderboard : UISpriteType.InsetFrameHighlightedLeaderboard);
  27. this._rankLabel.LocalizedString = Localization.Integer(board.GetRank(record));
  28. this._playerNameLabel.LocalizedString = Localization.Literal(record.Username);
  29. this._levelLabel.LocalizedString = Localization.Integer(record.PrimaryScore);
  30. this._levelProgressLabel.LocalizedString = Localization.Percentage(record.QuaternaryScore);
  31. this._levelProgress.value = (float)record.QuaternaryScore / 100f;
  32. this._citizensLabel.LocalizedString = Localization.Integer(record.SecondaryScore);
  33. this._islandsLabel.LocalizedString = Localization.Format(Localization.Key("progress"), new ILocalizedString[]
  34. {
  35. Localization.Integer(record.TertiaryScore),
  36. Localization.Integer(10)
  37. });
  38. this._visitButton.gameObject.SetActive((record.IslandReady || record.Votes > 0) && !this.IsSelf);
  39. this.UpdateLikesLabel();
  40. }
  41. public void InitFakeRecord()
  42. {
  43. CIGSparkSocServices instance = SingletonMonobehaviour<CIGSparkSocServices>.Instance;
  44. CIGGameState instance2 = SingletonMonobehaviour<CIGGameState>.Instance;
  45. this._record = null;
  46. this._recordContainer.SetActive(true);
  47. this._spacerContainer.SetActive(false);
  48. this._background.sprite = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(UISpriteType.InsetFrameHighlightedLeaderboard);
  49. this._rankLabel.LocalizedString = Localization.Literal("?");
  50. if (instance.IsLinkedToPlayername())
  51. {
  52. this._playerNameLabel.LocalizedString = Localization.Literal(instance.GetPlayerName());
  53. }
  54. else
  55. {
  56. this._playerNameLabel.LocalizedString = Localization.Key("battle_log.you");
  57. }
  58. this._levelLabel.LocalizedString = Localization.Integer(instance2.Level);
  59. this._levelProgressLabel.LocalizedString = Localization.Percentage(instance2.LevelProgress, 0);
  60. this._levelProgress.value = instance2.LevelProgress;
  61. this._citizensLabel.LocalizedString = Localization.Integer(instance2.GlobalPopulation);
  62. this._islandsLabel.LocalizedString = Localization.Format(Localization.Key("progress"), new ILocalizedString[]
  63. {
  64. Localization.Integer(instance2.GetIslandsUnlockedCount()),
  65. Localization.Integer(10)
  66. });
  67. this._visitButton.gameObject.SetActive(false);
  68. this.UpdateLikesLabel();
  69. }
  70. public void InitSeparator()
  71. {
  72. this._recordContainer.SetActive(false);
  73. this._spacerContainer.SetActive(true);
  74. }
  75. public void OnVisitIslandClicked()
  76. {
  77. CIGVisitingIslandsManager instanceIfAvailable = SingletonMonobehaviour<CIGVisitingIslandsManager>.InstanceIfAvailable;
  78. if (instanceIfAvailable != null)
  79. {
  80. if (instanceIfAvailable.VisitingIslandDataAvaible(Island.GoneGreenlands, this._record.InstallUuid) && instanceIfAvailable.IsUnlocked(Island.GoneGreenlands, this._record.InstallUuid))
  81. {
  82. this.StartVisiting();
  83. }
  84. else if (instanceIfAvailable.VisitingIslandDataAvaible(Island.GoneGreenlands, this._record.InstallUuid) && !instanceIfAvailable.IsUnlocked(Island.GoneGreenlands, this._record.InstallUuid))
  85. {
  86. this.ShowNoDataPopup();
  87. }
  88. else
  89. {
  90. this.RegisterDataDownloadedEvent();
  91. 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);
  92. instanceIfAvailable.DownloadAllIslandsData(this._record.InstallUuid);
  93. }
  94. }
  95. }
  96. private void UpdateLikesLabel()
  97. {
  98. if (this._record == null)
  99. {
  100. this._likesLabel.LocalizedString = Localization.Integer(1);
  101. }
  102. else
  103. {
  104. int numberOfLikes = LikeRegistrar.GetNumberOfLikes(this._record.InstallUuid);
  105. int num = Math.Max(numberOfLikes, Math.Max(this._record.Votes, 0));
  106. if (num >= 1000)
  107. {
  108. this._likesLabel.LocalizedString = Localization.Concat(new ILocalizedString[]
  109. {
  110. Localization.Integer(num / 1000),
  111. Localization.Literal("k")
  112. });
  113. }
  114. else
  115. {
  116. this._likesLabel.LocalizedString = Localization.Integer(num);
  117. }
  118. }
  119. }
  120. private void StartVisiting()
  121. {
  122. this.UnregisterDataDownloadedEvent();
  123. SingletonMonobehaviour<PopupManager>.Instance.CloseRecursive(true);
  124. SingletonMonobehaviour<CIGIslandsManager>.Instance.StartVisiting(this._record);
  125. }
  126. private void CancelClicked()
  127. {
  128. this.UnregisterDataDownloadedEvent();
  129. }
  130. private void RegisterDataDownloadedEvent()
  131. {
  132. if (!this._eventRegistered)
  133. {
  134. CIGVisitingIslandsManager instanceIfAvailable = SingletonMonobehaviour<CIGVisitingIslandsManager>.InstanceIfAvailable;
  135. if (instanceIfAvailable != null)
  136. {
  137. instanceIfAvailable.DataDownloadedEvent += this.OnDataDownloaded;
  138. this._eventRegistered = true;
  139. }
  140. }
  141. }
  142. private void ShowNoDataPopup()
  143. {
  144. 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);
  145. this.UnregisterDataDownloadedEvent();
  146. }
  147. private void UnregisterDataDownloadedEvent()
  148. {
  149. if (this._eventRegistered)
  150. {
  151. CIGVisitingIslandsManager instanceIfAvailable = SingletonMonobehaviour<CIGVisitingIslandsManager>.InstanceIfAvailable;
  152. if (instanceIfAvailable != null)
  153. {
  154. instanceIfAvailable.DataDownloadedEvent -= this.OnDataDownloaded;
  155. this._eventRegistered = false;
  156. }
  157. }
  158. }
  159. private void OnDataDownloaded(Island island, string uid)
  160. {
  161. CIGVisitingIslandsManager instanceIfAvailable = SingletonMonobehaviour<CIGVisitingIslandsManager>.InstanceIfAvailable;
  162. if (instanceIfAvailable != null && island == Island.GoneGreenlands && uid == this._record.InstallUuid)
  163. {
  164. if (instanceIfAvailable.VisitingIslandDataAvaible(Island.GoneGreenlands, this._record.InstallUuid) && !instanceIfAvailable.IsUnlocked(Island.GoneGreenlands, this._record.InstallUuid))
  165. {
  166. this.ShowNoDataPopup();
  167. }
  168. else
  169. {
  170. this.StartVisiting();
  171. }
  172. }
  173. }
  174. [SerializeField]
  175. private GameObject _recordContainer;
  176. [SerializeField]
  177. private GameObject _spacerContainer;
  178. [SerializeField]
  179. [Header("Record")]
  180. private Image _background;
  181. [SerializeField]
  182. private LocalizedText _rankLabel;
  183. [SerializeField]
  184. private LocalizedText _levelLabel;
  185. [SerializeField]
  186. private LocalizedText _levelProgressLabel;
  187. [SerializeField]
  188. private Slider _levelProgress;
  189. [SerializeField]
  190. private LocalizedText _playerNameLabel;
  191. [SerializeField]
  192. private LocalizedText _citizensLabel;
  193. [SerializeField]
  194. private LocalizedText _islandsLabel;
  195. [SerializeField]
  196. private Button _visitButton;
  197. [SerializeField]
  198. private LocalizedText _likesLabel;
  199. private LeaderboardEntry _record;
  200. private bool _eventRegistered;
  201. }