Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

676 wiersze
17 KiB

  1. using System;
  2. using System.Diagnostics;
  3. using CIG;
  4. using CIG.Extensions;
  5. using CIG.Translation;
  6. using CIGEnums;
  7. using Engine.DependencyTree;
  8. using SUISS.Cloud;
  9. using SUISS.Core;
  10. using SUISSEngine;
  11. using Tweening;
  12. using UnityEngine;
  13. using UnityEngine.UI;
  14. public class HUDView : GUIView
  15. {
  16. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  17. public event HUDView.ViewStateChangedHandler viewStateChangedEvent;
  18. public HUDViewState ViewState
  19. {
  20. get
  21. {
  22. return this._viewState;
  23. }
  24. protected set
  25. {
  26. if (value != this._viewState)
  27. {
  28. HUDViewState viewState = this._viewState;
  29. this._viewState = value;
  30. if (this.viewStateChangedEvent != null)
  31. {
  32. this.viewStateChangedEvent(viewState, this._viewState);
  33. }
  34. }
  35. }
  36. }
  37. private void OnDestroy()
  38. {
  39. this.CancelInvoke(new Action(this.UpdateVideoUnlockTime));
  40. this.CancelInvoke(new Action(this.VideoButtonAnimation));
  41. this.CancelInvoke(new Action(this.ShowOrUpdateVideoUnlockPopup));
  42. this.CancelInvoke(new Action(this.HideArrow));
  43. }
  44. public void OnLikeClicked()
  45. {
  46. ((HUDState)this.State).Like();
  47. }
  48. public void OnAddCurrencyClicked()
  49. {
  50. ((HUDState)this.State).OpenCurrencyPopup(ShopMenuTabs.Cash);
  51. }
  52. public void OnAddGoldClicked()
  53. {
  54. ((HUDState)this.State).OpenCurrencyPopup(ShopMenuTabs.Gold);
  55. }
  56. public void OnAddCranesClicked()
  57. {
  58. ((HUDState)this.State).OpenCurrencyPopup(ShopMenuTabs.Cranes);
  59. }
  60. public void OnSettingsClicked()
  61. {
  62. ((HUDState)this.State).OpenSettingsPopup();
  63. }
  64. public void OnEyeClicked()
  65. {
  66. if (!this._showingCommercialTimers)
  67. {
  68. ((HUDState)this.State).ToggleBuildingsHidden();
  69. }
  70. }
  71. public void OnEyeLongPress()
  72. {
  73. this._showingCommercialTimers = true;
  74. foreach (CIGCommercialBuilding cigcommercialBuilding in UnityEngine.Object.FindObjectsOfType<CIGCommercialBuilding>())
  75. {
  76. cigcommercialBuilding.ShowCommercialTimerProgress();
  77. }
  78. base.Invoke("HideCommercialTimers", 5f);
  79. }
  80. private void HideCommercialTimers()
  81. {
  82. this._showingCommercialTimers = false;
  83. foreach (CIGCommercialBuilding cigcommercialBuilding in UnityEngine.Object.FindObjectsOfType<CIGCommercialBuilding>())
  84. {
  85. cigcommercialBuilding.HideCommercialTimerProgress();
  86. }
  87. }
  88. public void OnShowUpgradesClicked()
  89. {
  90. ((HUDState)this.State).ToggleUpgradeLevelView();
  91. }
  92. public void OnFacebookClicked()
  93. {
  94. ((HUDState)this.State).OpenFacebook();
  95. }
  96. public void OnGameFacebookClicked()
  97. {
  98. ((HUDState)this.State).OpenGameFacebook();
  99. }
  100. public void OnTelegramClicked()
  101. {
  102. ((HUDState)this.State).OpenTelegram();
  103. }
  104. public void OnLeaderboardsClicked()
  105. {
  106. ((HUDState)this.State).OpenLeaderboardsPopup();
  107. }
  108. public void OnWorldMapClicked()
  109. {
  110. ((HUDState)this.State).OpenWorldMap();
  111. this._worldMapExclamationBadge.SetActive(false);
  112. }
  113. public void OnShopClicked()
  114. {
  115. ((HUDState)this.State).OpenShopPopup();
  116. }
  117. public void OnBuildQueueClicked()
  118. {
  119. ((HUDState)this.State).OpenBuildDemolishPopup(BuildDemolishTabs.Build);
  120. }
  121. public void OnDemolishQueueClicked()
  122. {
  123. ((HUDState)this.State).OpenBuildDemolishPopup(BuildDemolishTabs.Demolish);
  124. }
  125. public void OnRoadsClicked()
  126. {
  127. ((HUDState)this.State).OpenRoadSelectionPopup();
  128. }
  129. public void OnDemolishClicked()
  130. {
  131. ((HUDState)this.State).StartDestroying();
  132. }
  133. public void OnRewardsClicked()
  134. {
  135. ((HUDState)this.State).OpenRewardsPopup();
  136. }
  137. public void OnDailyQuestsClicked()
  138. {
  139. ((HUDState)this.State).OpenDailyQuest();
  140. }
  141. public void OnCityAdvisorClicked()
  142. {
  143. ((HUDState)this.State).OpenCityAdvisorPopup();
  144. }
  145. public void OnSocialClicked()
  146. {
  147. ((HUDState)this.State).OpenSocialPopup();
  148. }
  149. public void OnQuitTutorialClicked()
  150. {
  151. ((HUDState)this.State).QuitTutorial();
  152. }
  153. public void OnHomeClicked()
  154. {
  155. ((HUDState)this.State).StopVisiting();
  156. }
  157. public void OnWatchVideoClicked()
  158. {
  159. ((HUDState)this.State).WatchVideo();
  160. }
  161. public void SetWatchVideoButtonVisible(bool visible)
  162. {
  163. this.CancelInvoke(new Action(this.UpdateVideoUnlockTime));
  164. VideoAds1Manager instance = SingletonMonobehaviour<VideoAds1Manager>.Instance;
  165. bool isUnlocked = instance.IsUnlocked;
  166. this._watchVideoButton.gameObject.SetActive(visible || !isUnlocked);
  167. if (isUnlocked)
  168. {
  169. this._watchVideoUnlockRemainingTimeLabel.gameObject.SetActive(false);
  170. this._watchVideoButton.interactable = true;
  171. if (!this.IsInvoking(new Action(this.VideoButtonAnimation)) && base.gameObject.activeInHierarchy)
  172. {
  173. this.InvokeRepeating(new Action(this.VideoButtonAnimation), 1f, 60f, false);
  174. }
  175. }
  176. else
  177. {
  178. this._watchVideoUnlockRemainingTimeLabel.gameObject.SetActive(true);
  179. this._watchVideoButton.interactable = false;
  180. this.UpdateVideoUnlockTime();
  181. if (base.gameObject.activeInHierarchy)
  182. {
  183. this.InvokeRepeating(new Action(this.UpdateVideoUnlockTime), 1f, 1f, true);
  184. this.CancelInvoke(new Action(this.VideoButtonAnimation));
  185. }
  186. }
  187. }
  188. public void SetViewState(HUDViewState viewState)
  189. {
  190. this.ViewState = viewState;
  191. }
  192. public void ShowWorldMapExclamationMark()
  193. {
  194. this._worldMapExclamationBadge.SetActive(true);
  195. }
  196. public void UpdateLevel(CIGGameState state)
  197. {
  198. this._levelLabel.LocalizedString = Localization.Integer(state.Level);
  199. this.UpdateLevelProgress(state);
  200. }
  201. public void UpdateBalance(CIGGameState state)
  202. {
  203. this.UpdateLevelProgress(state);
  204. }
  205. public void UpdateHappiness(int happiness, int housing)
  206. {
  207. float num;
  208. UISpriteType key;
  209. if (housing == 0)
  210. {
  211. num = 0f;
  212. key = UISpriteType.HappinessNeutral;
  213. }
  214. else
  215. {
  216. num = Mathf.Max(0f, (float)happiness / (float)housing);
  217. if (num < 0.75f)
  218. {
  219. key = UISpriteType.HappinessSad;
  220. }
  221. else if (num > 1f)
  222. {
  223. key = UISpriteType.HappinessHappy;
  224. }
  225. else
  226. {
  227. key = UISpriteType.HappinessNeutral;
  228. }
  229. }
  230. this._happinessLabel.LocalizedString = Localization.Percentage(num, 0);
  231. this._happinessIcon.sprite = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(key);
  232. this._happinessProgressBar.value = num;
  233. }
  234. public void UpdatePopulation(float progress, int population, int housing)
  235. {
  236. this._residentialsLabel.LocalizedString = Localization.Format(Localization.Key("progress"), new ILocalizedString[]
  237. {
  238. Localization.Integer(population),
  239. Localization.Integer(housing)
  240. });
  241. this._residentialsProgressBar.value = progress;
  242. }
  243. public void UpdateEmployees(float progress, int employees, int jobs)
  244. {
  245. this._employeesLabel.LocalizedString = Localization.Format(Localization.Key("progress"), new ILocalizedString[]
  246. {
  247. Localization.Integer(employees),
  248. Localization.Integer(jobs)
  249. });
  250. this._employeesProgressBar.value = progress;
  251. }
  252. public void UpdateDailyQuestButtons()
  253. {
  254. int activeQuestsAmount = SingletonMonobehaviour<CIGDailyQuestManager>.Instance.ActiveQuestsAmount;
  255. int num = this._dailyQuestButtons.Length;
  256. for (int i = 0; i < num; i++)
  257. {
  258. DailyQuestButton dailyQuestButton = this._dailyQuestButtons[i];
  259. if (i < activeQuestsAmount)
  260. {
  261. Dependency activeQuestAt = SingletonMonobehaviour<CIGDailyQuestManager>.Instance.GetActiveQuestAt(i);
  262. dailyQuestButton.gameObject.SetActive(true);
  263. dailyQuestButton.Init(activeQuestAt);
  264. }
  265. else
  266. {
  267. dailyQuestButton.gameObject.SetActive(false);
  268. }
  269. }
  270. }
  271. public void ShowArrowAboveButtonIndex(int index, int duration)
  272. {
  273. if (index < 0 || index >= this._tutorialButtons.Length)
  274. {
  275. UnityEngine.Debug.LogWarning(string.Format("ShowArrowAboveButtonIndex: incorrect index {0}", index));
  276. this.HideArrow();
  277. return;
  278. }
  279. this._attentionArrow.gameObject.SetActive(true);
  280. this._attentionArrow.transform.position = this._tutorialButtons[index].transform.position;
  281. if (duration > 0)
  282. {
  283. this.Invoke(new Action(this.HideArrow), (float)duration, false);
  284. }
  285. }
  286. public void HideArrow()
  287. {
  288. this._attentionArrow.gameObject.SetActive(false);
  289. }
  290. public void ShowTutorialDialog(ILocalizedString tutorialText)
  291. {
  292. this._tutorialDialogLabel.LocalizedString = tutorialText;
  293. if (!this._tutorialDialogTweener.gameObject.activeSelf)
  294. {
  295. this._tutorialDialogTweener.gameObject.SetActive(true);
  296. this._tutorialDialogTweener.Reset(false);
  297. this._tutorialDialogTweener.Play();
  298. }
  299. }
  300. public void HideTutorialDialog()
  301. {
  302. this._tutorialDialogTweener.gameObject.SetActive(false);
  303. }
  304. public void SetTutorialButton(bool state)
  305. {
  306. this._quitTutorialButton.SetActive(state);
  307. }
  308. public void UpdateShopBadge()
  309. {
  310. if (SingletonMonobehaviour<CIGPurchasedBuildingsManager>.IsAvailable)
  311. {
  312. int totalUnconsumedBuildings = SingletonMonobehaviour<CIGPurchasedBuildingsManager>.Instance.TotalUnconsumedBuildings;
  313. this._shopBadgeLabel.LocalizedString = Localization.Integer(totalUnconsumedBuildings);
  314. this._shopBadge.SetActive(totalUnconsumedBuildings > 0);
  315. }
  316. }
  317. public void SetRewardBadge(bool active)
  318. {
  319. this._rewardBadge.SetActive(active);
  320. }
  321. public void UpdateBuildQueueButton()
  322. {
  323. int currentBuildCount = SingletonMonobehaviour<CIGBuilderManager>.Instance.CurrentBuildCount;
  324. bool flag = currentBuildCount > 0;
  325. this._buildQueueButton.SetActive(flag);
  326. if (flag)
  327. {
  328. this._buildQueueBadgeLabel.LocalizedString = Localization.Integer(currentBuildCount);
  329. }
  330. }
  331. public void UpdateDemolishQueueButton()
  332. {
  333. bool flag = IsometricIsland.Current != null && IsometricIsland.Current.destroyer.isDestroying;
  334. this._demolishQueueButton.SetActive(flag);
  335. if (flag)
  336. {
  337. this._demolishQueueBadgeLabel.LocalizedString = Localization.Integer(IsometricIsland.Current.destroyer.DemolishList.Count);
  338. }
  339. }
  340. public void SetVisitingInfo(LeaderboardEntry player)
  341. {
  342. float num = (float)player.QuaternaryScore / 100f;
  343. this._visitingLevelProgressBar.value = num;
  344. this._visitingLevelProgressLabel.LocalizedString = Localization.Percentage(num, 0);
  345. this._visitingLevelLabel.LocalizedString = Localization.Integer(player.PrimaryScore);
  346. this._visitingPlayerNameLabel.LocalizedString = Localization.Literal(player.Playername);
  347. this._visitingPopulationLabel.LocalizedString = Localization.Integer(player.SecondaryScore);
  348. this._visitingIslandCountLabel.LocalizedString = Localization.Integer(player.TertiaryScore);
  349. this.SetLikeButton();
  350. }
  351. public void SetLikeButton()
  352. {
  353. bool flag = false;
  354. CIGSparkSocServices instanceIfAvailable = SingletonMonobehaviour<CIGSparkSocServices>.InstanceIfAvailable;
  355. if (instanceIfAvailable != null)
  356. {
  357. flag = instanceIfAvailable.IsLogedInAndLinked();
  358. }
  359. this._visitingLoginBadge.SetActive(!flag);
  360. this._visitingVotesLeftBadge.SetActive(flag);
  361. if (!SingletonMonobehaviour<CIGIslandsManager>.IsAvailable)
  362. {
  363. UnityEngine.Debug.LogError("No CIGIslandsManager available");
  364. return;
  365. }
  366. if (!flag)
  367. {
  368. this._visitingLikeButton.Interactable = true;
  369. this._visitingUserLikedObject.SetActive(false);
  370. }
  371. else
  372. {
  373. this._visitingVotesLeftLabel.LocalizedString = Localization.Integer(LikeRegistrar.VotesLeft);
  374. bool flag2 = LikeRegistrar.HaveVotedFor(SingletonMonobehaviour<CIGIslandsManager>.Instance.VisitingPlayer.InstallUuid);
  375. this._visitingUserLikedObject.SetActive(flag2);
  376. if (flag2)
  377. {
  378. this._visitingLikeButton.Interactable = false;
  379. }
  380. else
  381. {
  382. bool interactable = LikeRegistrar.VotesLeft > 0;
  383. this._visitingLikeButton.Interactable = interactable;
  384. }
  385. }
  386. }
  387. public void SetSettingsAttention(bool visible)
  388. {
  389. this._settingsExclamationBadge.SetActive(visible);
  390. }
  391. public void UpdateDropChestButton(CIGDropChestManager manager)
  392. {
  393. this._dropChestButton.Init(manager);
  394. }
  395. public void SetEyeButtonToggle(bool active)
  396. {
  397. this._eyeButtonToggle.SetActive(active);
  398. }
  399. public void SetShowLevelsButtonToggle(bool active)
  400. {
  401. this._showLevelsButtonToggle.SetActive(active);
  402. }
  403. private void UpdateVideoUnlockTime()
  404. {
  405. this._watchVideoUnlockRemainingTimeLabel.LocalizedString = Localization.TimeSpan(TimeSpan.FromSeconds((double)SingletonMonobehaviour<VideoAds1Manager>.Instance.RemainingUnlockSeconds), false);
  406. }
  407. private void VideoButtonAnimation()
  408. {
  409. if (this._watchVideoButtonTweener.IsPlaying)
  410. {
  411. this._watchVideoButtonTweener.StopAndReset(false);
  412. }
  413. this._watchVideoButtonTweener.Play();
  414. }
  415. private void ShowOrUpdateVideoUnlockPopup()
  416. {
  417. VideoAds1Manager instance = SingletonMonobehaviour<VideoAds1Manager>.Instance;
  418. if (!instance.IsUnlocked)
  419. {
  420. ILocalizedString body = Localization.Format(Localization.Key("available_in_x_time"), new ILocalizedString[]
  421. {
  422. Localization.TimeSpan(TimeSpan.FromSeconds((double)instance.RemainingUnlockSeconds), false)
  423. });
  424. SingletonMonobehaviour<PopupManager>.Instance.ShowOrUpdateGenericPopup(UISpriteType.Video, Localization.Key("watch_video"), body, Localization.Key("ok"), Localization.EmptyLocalizedString, new Action(this.VideoUnlockPopupClosed), null, new Action(this.VideoUnlockPopupClosed), true);
  425. }
  426. else
  427. {
  428. bool suppressQueue = SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue;
  429. SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue = true;
  430. SingletonMonobehaviour<PopupManager>.Instance.CloseRecursive(true);
  431. this.VideoUnlockPopupClosed();
  432. SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue = suppressQueue;
  433. }
  434. }
  435. private void VideoUnlockPopupClosed()
  436. {
  437. this.CancelInvoke(new Action(this.ShowOrUpdateVideoUnlockPopup));
  438. }
  439. protected void UpdateLevelProgress(CIGGameState state)
  440. {
  441. this._levelProgressBarContainer.SetActive(state.Level != Mathf.Max(state.MaxLevel, 150));
  442. }
  443. private static string[] ShareStrings
  444. {
  445. get
  446. {
  447. if (HUDView._shareStrings == null)
  448. {
  449. TextAsset textAsset = Resources.Load("share_lines") as TextAsset;
  450. if (textAsset != null)
  451. {
  452. HUDView._shareStrings = textAsset.text.Split(new char[]
  453. {
  454. '\n'
  455. });
  456. while (HUDView._shareStrings.Length > 0 && HUDView._shareStrings[HUDView._shareStrings.Length - 1].Length == 0)
  457. {
  458. Array.Resize<string>(ref HUDView._shareStrings, HUDView._shareStrings.Length - 1);
  459. }
  460. }
  461. else
  462. {
  463. UnityEngine.Debug.LogError("Unable to load asset at path share_lines.txt");
  464. HUDView._shareStrings = new string[]
  465. {
  466. "City Island 3"
  467. };
  468. }
  469. }
  470. return HUDView._shareStrings;
  471. }
  472. }
  473. private byte[] LoadIconFile()
  474. {
  475. TextAsset textAsset = Resources.Load("share_image_png") as TextAsset;
  476. return textAsset.bytes;
  477. }
  478. [SerializeField]
  479. [Header("TopLeft")]
  480. private LocalizedText _levelLabel;
  481. [SerializeField]
  482. private GameObject _levelProgressBarContainer;
  483. [SerializeField]
  484. private DropChestHUDButton _dropChestButton;
  485. [SerializeField]
  486. private DailyQuestButton[] _dailyQuestButtons;
  487. [SerializeField]
  488. private Button _watchVideoButton;
  489. [SerializeField]
  490. private Tweener _watchVideoButtonTweener;
  491. [SerializeField]
  492. private LocalizedText _watchVideoUnlockRemainingTimeLabel;
  493. [SerializeField]
  494. [Header("BottomLeft")]
  495. private GameObject _quitTutorialButton;
  496. [SerializeField]
  497. private GameObject _shopBadge;
  498. [SerializeField]
  499. private LocalizedText _shopBadgeLabel;
  500. [SerializeField]
  501. private GameObject _rewardBadge;
  502. [SerializeField]
  503. private GameObject _worldMapExclamationBadge;
  504. [SerializeField]
  505. [Header("TopRight")]
  506. private Image _happinessIcon;
  507. [SerializeField]
  508. private LocalizedText _happinessLabel;
  509. [SerializeField]
  510. private Slider _happinessProgressBar;
  511. [SerializeField]
  512. private LocalizedText _residentialsLabel;
  513. [SerializeField]
  514. private Slider _residentialsProgressBar;
  515. [SerializeField]
  516. private LocalizedText _employeesLabel;
  517. [SerializeField]
  518. private Slider _employeesProgressBar;
  519. [SerializeField]
  520. private GameObject _settingsExclamationBadge;
  521. [SerializeField]
  522. private GameObject _eyeButtonToggle;
  523. [SerializeField]
  524. private GameObject _showLevelsButtonToggle;
  525. [SerializeField]
  526. [Header("BottomRight")]
  527. private GameObject _buildQueueButton;
  528. [SerializeField]
  529. private LocalizedText _buildQueueBadgeLabel;
  530. [SerializeField]
  531. private GameObject _demolishQueueButton;
  532. [SerializeField]
  533. private LocalizedText _demolishQueueBadgeLabel;
  534. [SerializeField]
  535. [Header("Tutorial")]
  536. private RectTransform[] _tutorialButtons;
  537. [SerializeField]
  538. private RectTransform _attentionArrow;
  539. [SerializeField]
  540. private Tweener _tutorialDialogTweener;
  541. [SerializeField]
  542. private LocalizedText _tutorialDialogLabel;
  543. [SerializeField]
  544. [Header("Visiting")]
  545. private Slider _visitingLevelProgressBar;
  546. [SerializeField]
  547. private LocalizedText _visitingLevelProgressLabel;
  548. [SerializeField]
  549. private LocalizedText _visitingLevelLabel;
  550. [SerializeField]
  551. private LocalizedText _visitingPlayerNameLabel;
  552. [SerializeField]
  553. private LocalizedText _visitingPopulationLabel;
  554. [SerializeField]
  555. private LocalizedText _visitingIslandCountLabel;
  556. [SerializeField]
  557. private InteractableButton _visitingLikeButton;
  558. [SerializeField]
  559. private GameObject _visitingUserLikedObject;
  560. [SerializeField]
  561. private GameObject _visitingLoginBadge;
  562. [SerializeField]
  563. private GameObject _visitingVotesLeftBadge;
  564. [SerializeField]
  565. private LocalizedText _visitingVotesLeftLabel;
  566. private bool _showingCommercialTimers;
  567. protected HUDViewState _viewState;
  568. private static string[] _shareStrings;
  569. public delegate void ViewStateChangedHandler(HUDViewState oldState, HUDViewState newState);
  570. }