|
- using System;
- using System.Diagnostics;
- using CIG;
- using CIG.Extensions;
- using CIG.Translation;
- using CIGEnums;
- using Engine.DependencyTree;
- using SUISS.Cloud;
- using SUISS.Core;
- using SUISSEngine;
- using Tweening;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class HUDView : GUIView
- {
- //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event HUDView.ViewStateChangedHandler viewStateChangedEvent;
-
- public HUDViewState ViewState
- {
- get
- {
- return this._viewState;
- }
- protected set
- {
- if (value != this._viewState)
- {
- HUDViewState viewState = this._viewState;
- this._viewState = value;
- if (this.viewStateChangedEvent != null)
- {
- this.viewStateChangedEvent(viewState, this._viewState);
- }
- }
- }
- }
-
- private void OnDestroy()
- {
- this.CancelInvoke(new Action(this.UpdateVideoUnlockTime));
- this.CancelInvoke(new Action(this.VideoButtonAnimation));
- this.CancelInvoke(new Action(this.ShowOrUpdateVideoUnlockPopup));
- this.CancelInvoke(new Action(this.HideArrow));
- }
-
- public void OnLikeClicked()
- {
- ((HUDState)this.State).Like();
- }
-
- public void OnAddCurrencyClicked()
- {
- ((HUDState)this.State).OpenCurrencyPopup(ShopMenuTabs.Cash);
- }
-
- public void OnAddGoldClicked()
- {
- ((HUDState)this.State).OpenCurrencyPopup(ShopMenuTabs.Gold);
- }
-
- public void OnAddCranesClicked()
- {
- ((HUDState)this.State).OpenCurrencyPopup(ShopMenuTabs.Cranes);
- }
-
- public void OnSettingsClicked()
- {
- ((HUDState)this.State).OpenSettingsPopup();
- }
-
- public void OnEyeClicked()
- {
- if (!this._showingCommercialTimers)
- {
- ((HUDState)this.State).ToggleBuildingsHidden();
- }
- }
-
- public void OnEyeLongPress()
- {
- this._showingCommercialTimers = true;
- foreach (CIGCommercialBuilding cigcommercialBuilding in UnityEngine.Object.FindObjectsOfType<CIGCommercialBuilding>())
- {
- cigcommercialBuilding.ShowCommercialTimerProgress();
- }
- base.Invoke("HideCommercialTimers", 5f);
- }
-
- private void HideCommercialTimers()
- {
- this._showingCommercialTimers = false;
- foreach (CIGCommercialBuilding cigcommercialBuilding in UnityEngine.Object.FindObjectsOfType<CIGCommercialBuilding>())
- {
- cigcommercialBuilding.HideCommercialTimerProgress();
- }
- }
-
- public void OnShowUpgradesClicked()
- {
- ((HUDState)this.State).ToggleUpgradeLevelView();
- }
-
- public void OnFacebookClicked()
- {
- ((HUDState)this.State).OpenFacebook();
- }
-
- public void OnGameFacebookClicked()
- {
- ((HUDState)this.State).OpenGameFacebook();
- }
-
- public void OnTelegramClicked()
- {
- ((HUDState)this.State).OpenTelegram();
- }
-
- public void OnLeaderboardsClicked()
- {
- ((HUDState)this.State).OpenLeaderboardsPopup();
- }
-
- public void OnWorldMapClicked()
- {
- ((HUDState)this.State).OpenWorldMap();
- this._worldMapExclamationBadge.SetActive(false);
- }
-
- public void OnShopClicked()
- {
- ((HUDState)this.State).OpenShopPopup();
- }
-
- public void OnBuildQueueClicked()
- {
- ((HUDState)this.State).OpenBuildDemolishPopup(BuildDemolishTabs.Build);
- }
-
- public void OnDemolishQueueClicked()
- {
- ((HUDState)this.State).OpenBuildDemolishPopup(BuildDemolishTabs.Demolish);
- }
-
- public void OnRoadsClicked()
- {
- ((HUDState)this.State).OpenRoadSelectionPopup();
- }
-
- public void OnDemolishClicked()
- {
- ((HUDState)this.State).StartDestroying();
- }
-
- public void OnRewardsClicked()
- {
- ((HUDState)this.State).OpenRewardsPopup();
- }
-
- public void OnDailyQuestsClicked()
- {
- ((HUDState)this.State).OpenDailyQuest();
- }
-
- public void OnCityAdvisorClicked()
- {
- ((HUDState)this.State).OpenCityAdvisorPopup();
- }
-
- public void OnSocialClicked()
- {
- ((HUDState)this.State).OpenSocialPopup();
- }
-
- public void OnQuitTutorialClicked()
- {
- ((HUDState)this.State).QuitTutorial();
- }
-
- public void OnHomeClicked()
- {
- ((HUDState)this.State).StopVisiting();
- }
-
- public void OnWatchVideoClicked()
- {
- ((HUDState)this.State).WatchVideo();
- }
-
- public void SetWatchVideoButtonVisible(bool visible)
- {
- this.CancelInvoke(new Action(this.UpdateVideoUnlockTime));
- VideoAds1Manager instance = SingletonMonobehaviour<VideoAds1Manager>.Instance;
- bool isUnlocked = instance.IsUnlocked;
- this._watchVideoButton.gameObject.SetActive(visible || !isUnlocked);
- if (isUnlocked)
- {
- this._watchVideoUnlockRemainingTimeLabel.gameObject.SetActive(false);
- this._watchVideoButton.interactable = true;
- if (!this.IsInvoking(new Action(this.VideoButtonAnimation)) && base.gameObject.activeInHierarchy)
- {
- this.InvokeRepeating(new Action(this.VideoButtonAnimation), 1f, 60f, false);
- }
- }
- else
- {
- this._watchVideoUnlockRemainingTimeLabel.gameObject.SetActive(true);
- this._watchVideoButton.interactable = false;
- this.UpdateVideoUnlockTime();
- if (base.gameObject.activeInHierarchy)
- {
- this.InvokeRepeating(new Action(this.UpdateVideoUnlockTime), 1f, 1f, true);
- this.CancelInvoke(new Action(this.VideoButtonAnimation));
- }
- }
- }
-
- public void SetViewState(HUDViewState viewState)
- {
- this.ViewState = viewState;
- }
-
- public void ShowWorldMapExclamationMark()
- {
- this._worldMapExclamationBadge.SetActive(true);
- }
-
- public void UpdateLevel(CIGGameState state)
- {
- this._levelLabel.LocalizedString = Localization.Integer(state.Level);
- this.UpdateLevelProgress(state);
- }
-
- public void UpdateBalance(CIGGameState state)
- {
- this.UpdateLevelProgress(state);
- }
-
- public void UpdateHappiness(int happiness, int housing)
- {
- float num;
- UISpriteType key;
- if (housing == 0)
- {
- num = 0f;
- key = UISpriteType.HappinessNeutral;
- }
- else
- {
- num = Mathf.Max(0f, (float)happiness / (float)housing);
- if (num < 0.75f)
- {
- key = UISpriteType.HappinessSad;
- }
- else if (num > 1f)
- {
- key = UISpriteType.HappinessHappy;
- }
- else
- {
- key = UISpriteType.HappinessNeutral;
- }
- }
- this._happinessLabel.LocalizedString = Localization.Percentage(num, 0);
- this._happinessIcon.sprite = SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(key);
- this._happinessProgressBar.value = num;
- }
-
- public void UpdatePopulation(float progress, int population, int housing)
- {
- this._residentialsLabel.LocalizedString = Localization.Format(Localization.Key("progress"), new ILocalizedString[]
- {
- Localization.Integer(population),
- Localization.Integer(housing)
- });
- this._residentialsProgressBar.value = progress;
- }
-
- public void UpdateEmployees(float progress, int employees, int jobs)
- {
- this._employeesLabel.LocalizedString = Localization.Format(Localization.Key("progress"), new ILocalizedString[]
- {
- Localization.Integer(employees),
- Localization.Integer(jobs)
- });
- this._employeesProgressBar.value = progress;
- }
-
- public void UpdateDailyQuestButtons()
- {
- int activeQuestsAmount = SingletonMonobehaviour<CIGDailyQuestManager>.Instance.ActiveQuestsAmount;
- int num = this._dailyQuestButtons.Length;
- for (int i = 0; i < num; i++)
- {
- DailyQuestButton dailyQuestButton = this._dailyQuestButtons[i];
- if (i < activeQuestsAmount)
- {
- Dependency activeQuestAt = SingletonMonobehaviour<CIGDailyQuestManager>.Instance.GetActiveQuestAt(i);
- dailyQuestButton.gameObject.SetActive(true);
- dailyQuestButton.Init(activeQuestAt);
- }
- else
- {
- dailyQuestButton.gameObject.SetActive(false);
- }
- }
- }
-
- public void ShowArrowAboveButtonIndex(int index, int duration)
- {
- if (index < 0 || index >= this._tutorialButtons.Length)
- {
- UnityEngine.Debug.LogWarning(string.Format("ShowArrowAboveButtonIndex: incorrect index {0}", index));
- this.HideArrow();
- return;
- }
- this._attentionArrow.gameObject.SetActive(true);
- this._attentionArrow.transform.position = this._tutorialButtons[index].transform.position;
- if (duration > 0)
- {
- this.Invoke(new Action(this.HideArrow), (float)duration, false);
- }
- }
-
- public void HideArrow()
- {
- this._attentionArrow.gameObject.SetActive(false);
- }
-
- public void ShowTutorialDialog(ILocalizedString tutorialText)
- {
- this._tutorialDialogLabel.LocalizedString = tutorialText;
- if (!this._tutorialDialogTweener.gameObject.activeSelf)
- {
- this._tutorialDialogTweener.gameObject.SetActive(true);
- this._tutorialDialogTweener.Reset(false);
- this._tutorialDialogTweener.Play();
- }
- }
-
- public void HideTutorialDialog()
- {
- this._tutorialDialogTweener.gameObject.SetActive(false);
- }
-
- public void SetTutorialButton(bool state)
- {
- this._quitTutorialButton.SetActive(state);
- }
-
- public void UpdateShopBadge()
- {
- if (SingletonMonobehaviour<CIGPurchasedBuildingsManager>.IsAvailable)
- {
- int totalUnconsumedBuildings = SingletonMonobehaviour<CIGPurchasedBuildingsManager>.Instance.TotalUnconsumedBuildings;
- this._shopBadgeLabel.LocalizedString = Localization.Integer(totalUnconsumedBuildings);
- this._shopBadge.SetActive(totalUnconsumedBuildings > 0);
- }
- }
-
- public void SetRewardBadge(bool active)
- {
- this._rewardBadge.SetActive(active);
- }
-
- public void UpdateBuildQueueButton()
- {
- int currentBuildCount = SingletonMonobehaviour<CIGBuilderManager>.Instance.CurrentBuildCount;
- bool flag = currentBuildCount > 0;
- this._buildQueueButton.SetActive(flag);
- if (flag)
- {
- this._buildQueueBadgeLabel.LocalizedString = Localization.Integer(currentBuildCount);
- }
- }
-
- public void UpdateDemolishQueueButton()
- {
- bool flag = IsometricIsland.Current != null && IsometricIsland.Current.destroyer.isDestroying;
- this._demolishQueueButton.SetActive(flag);
- if (flag)
- {
- this._demolishQueueBadgeLabel.LocalizedString = Localization.Integer(IsometricIsland.Current.destroyer.DemolishList.Count);
- }
- }
-
- public void SetVisitingInfo(LeaderboardEntry player)
- {
- float num = (float)player.QuaternaryScore / 100f;
- this._visitingLevelProgressBar.value = num;
- this._visitingLevelProgressLabel.LocalizedString = Localization.Percentage(num, 0);
- this._visitingLevelLabel.LocalizedString = Localization.Integer(player.PrimaryScore);
- this._visitingPlayerNameLabel.LocalizedString = Localization.Literal(player.Playername);
- this._visitingPopulationLabel.LocalizedString = Localization.Integer(player.SecondaryScore);
- this._visitingIslandCountLabel.LocalizedString = Localization.Integer(player.TertiaryScore);
- this.SetLikeButton();
- }
-
- public void SetLikeButton()
- {
- bool flag = false;
- CIGSparkSocServices instanceIfAvailable = SingletonMonobehaviour<CIGSparkSocServices>.InstanceIfAvailable;
- if (instanceIfAvailable != null)
- {
- flag = instanceIfAvailable.IsLogedInAndLinked();
- }
- this._visitingLoginBadge.SetActive(!flag);
- this._visitingVotesLeftBadge.SetActive(flag);
- if (!SingletonMonobehaviour<CIGIslandsManager>.IsAvailable)
- {
- UnityEngine.Debug.LogError("No CIGIslandsManager available");
- return;
- }
- if (!flag)
- {
- this._visitingLikeButton.Interactable = true;
- this._visitingUserLikedObject.SetActive(false);
- }
- else
- {
- this._visitingVotesLeftLabel.LocalizedString = Localization.Integer(LikeRegistrar.VotesLeft);
- bool flag2 = LikeRegistrar.HaveVotedFor(SingletonMonobehaviour<CIGIslandsManager>.Instance.VisitingPlayer.InstallUuid);
- this._visitingUserLikedObject.SetActive(flag2);
- if (flag2)
- {
- this._visitingLikeButton.Interactable = false;
- }
- else
- {
- bool interactable = LikeRegistrar.VotesLeft > 0;
- this._visitingLikeButton.Interactable = interactable;
- }
- }
- }
-
- public void SetSettingsAttention(bool visible)
- {
- this._settingsExclamationBadge.SetActive(visible);
- }
-
- public void UpdateDropChestButton(CIGDropChestManager manager)
- {
- this._dropChestButton.Init(manager);
- }
-
- public void SetEyeButtonToggle(bool active)
- {
- this._eyeButtonToggle.SetActive(active);
- }
-
- public void SetShowLevelsButtonToggle(bool active)
- {
- this._showLevelsButtonToggle.SetActive(active);
- }
-
- private void UpdateVideoUnlockTime()
- {
- this._watchVideoUnlockRemainingTimeLabel.LocalizedString = Localization.TimeSpan(TimeSpan.FromSeconds((double)SingletonMonobehaviour<VideoAds1Manager>.Instance.RemainingUnlockSeconds), false);
- }
-
- private void VideoButtonAnimation()
- {
- if (this._watchVideoButtonTweener.IsPlaying)
- {
- this._watchVideoButtonTweener.StopAndReset(false);
- }
- this._watchVideoButtonTweener.Play();
- }
-
- private void ShowOrUpdateVideoUnlockPopup()
- {
- VideoAds1Manager instance = SingletonMonobehaviour<VideoAds1Manager>.Instance;
- if (!instance.IsUnlocked)
- {
- ILocalizedString body = Localization.Format(Localization.Key("available_in_x_time"), new ILocalizedString[]
- {
- Localization.TimeSpan(TimeSpan.FromSeconds((double)instance.RemainingUnlockSeconds), false)
- });
- 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);
- }
- else
- {
- bool suppressQueue = SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue;
- SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue = true;
- SingletonMonobehaviour<PopupManager>.Instance.CloseRecursive(true);
- this.VideoUnlockPopupClosed();
- SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue = suppressQueue;
- }
- }
-
- private void VideoUnlockPopupClosed()
- {
- this.CancelInvoke(new Action(this.ShowOrUpdateVideoUnlockPopup));
- }
-
- protected void UpdateLevelProgress(CIGGameState state)
- {
- this._levelProgressBarContainer.SetActive(state.Level != Mathf.Max(state.MaxLevel, 150));
- }
-
- private static string[] ShareStrings
- {
- get
- {
- if (HUDView._shareStrings == null)
- {
- TextAsset textAsset = Resources.Load("share_lines") as TextAsset;
- if (textAsset != null)
- {
- HUDView._shareStrings = textAsset.text.Split(new char[]
- {
- '\n'
- });
- while (HUDView._shareStrings.Length > 0 && HUDView._shareStrings[HUDView._shareStrings.Length - 1].Length == 0)
- {
- Array.Resize<string>(ref HUDView._shareStrings, HUDView._shareStrings.Length - 1);
- }
- }
- else
- {
- UnityEngine.Debug.LogError("Unable to load asset at path share_lines.txt");
- HUDView._shareStrings = new string[]
- {
- "City Island 3"
- };
- }
- }
- return HUDView._shareStrings;
- }
- }
-
- private byte[] LoadIconFile()
- {
- TextAsset textAsset = Resources.Load("share_image_png") as TextAsset;
- return textAsset.bytes;
- }
-
- [SerializeField]
- [Header("TopLeft")]
- private LocalizedText _levelLabel;
-
- [SerializeField]
- private GameObject _levelProgressBarContainer;
-
- [SerializeField]
- private DropChestHUDButton _dropChestButton;
-
- [SerializeField]
- private DailyQuestButton[] _dailyQuestButtons;
-
- [SerializeField]
- private Button _watchVideoButton;
-
- [SerializeField]
- private Tweener _watchVideoButtonTweener;
-
- [SerializeField]
- private LocalizedText _watchVideoUnlockRemainingTimeLabel;
-
- [SerializeField]
- [Header("BottomLeft")]
- private GameObject _quitTutorialButton;
-
- [SerializeField]
- private GameObject _shopBadge;
-
- [SerializeField]
- private LocalizedText _shopBadgeLabel;
-
- [SerializeField]
- private GameObject _rewardBadge;
-
- [SerializeField]
- private GameObject _worldMapExclamationBadge;
-
- [SerializeField]
- [Header("TopRight")]
- private Image _happinessIcon;
-
- [SerializeField]
- private LocalizedText _happinessLabel;
-
- [SerializeField]
- private Slider _happinessProgressBar;
-
- [SerializeField]
- private LocalizedText _residentialsLabel;
-
- [SerializeField]
- private Slider _residentialsProgressBar;
-
- [SerializeField]
- private LocalizedText _employeesLabel;
-
- [SerializeField]
- private Slider _employeesProgressBar;
-
- [SerializeField]
- private GameObject _settingsExclamationBadge;
-
- [SerializeField]
- private GameObject _eyeButtonToggle;
-
- [SerializeField]
- private GameObject _showLevelsButtonToggle;
-
- [SerializeField]
- [Header("BottomRight")]
- private GameObject _buildQueueButton;
-
- [SerializeField]
- private LocalizedText _buildQueueBadgeLabel;
-
- [SerializeField]
- private GameObject _demolishQueueButton;
-
- [SerializeField]
- private LocalizedText _demolishQueueBadgeLabel;
-
- [SerializeField]
- [Header("Tutorial")]
- private RectTransform[] _tutorialButtons;
-
- [SerializeField]
- private RectTransform _attentionArrow;
-
- [SerializeField]
- private Tweener _tutorialDialogTweener;
-
- [SerializeField]
- private LocalizedText _tutorialDialogLabel;
-
- [SerializeField]
- [Header("Visiting")]
- private Slider _visitingLevelProgressBar;
-
- [SerializeField]
- private LocalizedText _visitingLevelProgressLabel;
-
- [SerializeField]
- private LocalizedText _visitingLevelLabel;
-
- [SerializeField]
- private LocalizedText _visitingPlayerNameLabel;
-
- [SerializeField]
- private LocalizedText _visitingPopulationLabel;
-
- [SerializeField]
- private LocalizedText _visitingIslandCountLabel;
-
- [SerializeField]
- private InteractableButton _visitingLikeButton;
-
- [SerializeField]
- private GameObject _visitingUserLikedObject;
-
- [SerializeField]
- private GameObject _visitingLoginBadge;
-
- [SerializeField]
- private GameObject _visitingVotesLeftBadge;
-
- [SerializeField]
- private LocalizedText _visitingVotesLeftLabel;
-
- private bool _showingCommercialTimers;
-
- protected HUDViewState _viewState;
-
- private static string[] _shareStrings;
-
- public delegate void ViewStateChangedHandler(HUDViewState oldState, HUDViewState newState);
- }
|