< Summary

Class:ExploreV2MenuComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/MainMenu/ExploreV2Menu/ExploreV2MenuComponentView.cs
Covered lines:82
Uncovered lines:74
Coverable lines:156
Total lines:367
Line coverage:52.5% (82 of 156)
Covered branches:0
Total branches:0
Covered methods:20
Total methods:46
Method coverage:43.4% (20 of 46)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Dispose()0%220100%
Awake()0%110100%
Start()0%110100%
Update()0%2100%
OnDestroy()0%220100%
Create()0%2100%
IsInitialized_OnChange(...)0%2.032080%
CreateSectionSelectorMappingsAfterDelay()0%5.673033.33%
CreateSectionSelectorMappings()0%440100%
OpenCurrentWalletSection()0%12300%
OpenMyAccountSection(...)0%20400%
OnSectionSelected(...)0%110100%
SelectSection(...)0%7.336066.67%
ResetSectionOpenLock()0%5.673033.33%
SetVisible(...)0%4.024090%
GoToFirstActiveSection()0%20400%
GoToSection(...)0%220100%
SetSectionActive(...)0%220100%
SetSectionAsNew(...)0%6200%
IsSectionActive(...)0%6200%
OnAfterShowAnimationCompleted(...)0%12300%
ConfigureEncapsulatedSection(...)0%220100%
RefreshControl()0%12300%
RemoveSectionSelectorMappings()0%440100%
IsSomeModalOpen_OnChange(...)0%220100%
CheckIfProfileCardShouldBeClosed()0%72800%
ConfigureCloseButton()0%110100%
OnCloseActionTriggered(...)0%220100%
ShowRealmSelectorModal()0%2100%
ConfigureRealmSelectorModal()0%220100%
HideMapOnEnteringWorld()0%2100%
SetWalletActive(...)0%2100%
HideAllSections()0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/MainMenu/ExploreV2Menu/ExploreV2MenuComponentView.cs

#LineLine coverage
 1using DCL;
 2using DCL.Wallet;
 3using System;
 4using System.Collections;
 5using System.Collections.Generic;
 6using UnityEngine;
 7using UnityEngine.Events;
 8
 9public class ExploreV2MenuComponentView : BaseComponentView, IExploreV2MenuComponentView
 10{
 11    internal const string REALM_SELECTOR_MODAL_ID = "RealmSelector_Modal";
 12
 13    [Header("Assets References")]
 14    [SerializeField] internal RealmSelectorComponentView realmSelectorModalPrefab;
 15
 16    [Header("Top Menu")]
 17    [SerializeField] internal SectionSelectorComponentView sectionSelector;
 18    [SerializeField] internal WalletCardHUDComponentView walletCard;
 19    [SerializeField] internal ProfileCardComponentView profileCard;
 20    [SerializeField] internal RealmViewerComponentView realmViewer;
 21    [SerializeField] internal ButtonComponentView closeMenuButton;
 22    [SerializeField] internal InputAction_Trigger closeAction;
 23
 24    [Header("Sections")]
 25    [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection;
 26    [SerializeField] internal FeatureEncapsulatorComponentView backpackSection;
 27    [SerializeField] internal FeatureEncapsulatorComponentView cameraReelSection;
 28    [SerializeField] internal FeatureEncapsulatorComponentView mapSection;
 29    [SerializeField] internal FeatureEncapsulatorComponentView questSection;
 30    [SerializeField] internal FeatureEncapsulatorComponentView settingsSection;
 31    [SerializeField] internal FeatureEncapsulatorComponentView walletSection;
 32    [SerializeField] internal FeatureEncapsulatorComponentView myAccountSection;
 33
 34    [Header("Tutorial References")]
 35    [SerializeField] internal RectTransform profileCardTooltipReference;
 36
 37    private DataStore_Camera cameraDataStore;
 38
 39    private Dictionary<ExploreSection, FeatureEncapsulatorComponentView> exploreSectionsById;
 40    private HUDCanvasCameraModeController hudCanvasCameraModeController;
 41
 42    private RectTransform profileCardRectTransform;
 43    private RealmSelectorComponentView realmSelectorModal;
 44    private bool isOpeningSectionThisFrame;
 45
 046    public IRealmViewerComponentView currentRealmViewer => realmViewer;
 047    public IRealmSelectorComponentView currentRealmSelectorModal => realmSelectorModal;
 5848    public IWalletCardHUDComponentView currentWalletCard => walletCard;
 049    public IProfileCardComponentView currentProfileCard => profileCard;
 050    public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection;
 51
 052    public RectTransform currentTopMenuTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explore).pivot
 053    public RectTransform currentPlacesAndEventsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explor
 054    public RectTransform currentBackpackTooltipReference => sectionSelector.GetSection((int)ExploreSection.Backpack).piv
 055    public RectTransform currentMapTooltipReference => sectionSelector.GetSection((int)ExploreSection.Map).pivot;
 056    public RectTransform currentQuestTooltipReference => sectionSelector.GetSection((int)ExploreSection.Quest).pivot;
 057    public RectTransform currentSettingsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Settings).piv
 058    public RectTransform cameraReelTooltipReference => sectionSelector.GetSection((int)ExploreSection.CameraReel).pivot;
 059    public RectTransform currentProfileCardTooltipReference => profileCardTooltipReference;
 60
 61    public event Action<bool> OnCloseButtonPressed;
 62    public event Action<ExploreSection> OnSectionOpen;
 63    public event Action OnAfterShowAnimation;
 64
 65    public override void Dispose()
 66    {
 2967        base.Dispose();
 68
 2969        RemoveSectionSelectorMappings();
 2970        closeMenuButton.onClick.RemoveAllListeners();
 2971        currentWalletCard.OnWalletCardClicked -= OpenCurrentWalletSection;
 2972        closeAction.OnTriggered -= OnCloseActionTriggered;
 2973        DataStore.i.exploreV2.isSomeModalOpen.OnChange -= IsSomeModalOpen_OnChange;
 2974        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 2975        DataStore.i.myAccount.myAccountSectionOpenFromProfileHUD.OnChange -= OpenMyAccountSection;
 76
 2977        if (realmSelectorModal != null)
 2978            realmSelectorModal.Dispose();
 2979    }
 80
 81    public override void Awake()
 82    {
 2983        base.Awake();
 2984        showHideAnimator.OnWillFinishStart += OnAfterShowAnimationCompleted;
 85
 2986        profileCardRectTransform = profileCard.GetComponent<RectTransform>();
 2987        realmSelectorModal = ConfigureRealmSelectorModal();
 2988        hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud
 89
 2990        exploreSectionsById = new Dictionary<ExploreSection, FeatureEncapsulatorComponentView>
 91        {
 92            { ExploreSection.Explore, null },
 93            { ExploreSection.Quest, questSection },
 94            { ExploreSection.Backpack, backpackSection },
 95            { ExploreSection.CameraReel, cameraReelSection },
 96            { ExploreSection.Map, mapSection },
 97            { ExploreSection.Settings, settingsSection },
 98            { ExploreSection.Wallet, walletSection },
 99            { ExploreSection.MyAccount, myAccountSection },
 100        };
 29101    }
 102
 103    public void Start()
 104    {
 29105        DataStore.i.exploreV2.isInitialized.OnChange += IsInitialized_OnChange;
 29106        DataStore.i.myAccount.myAccountSectionOpenFromProfileHUD.OnChange += OpenMyAccountSection;
 29107        IsInitialized_OnChange(DataStore.i.exploreV2.isInitialized.Get(), false);
 108
 29109        ConfigureCloseButton();
 110
 29111        currentWalletCard.OnWalletCardClicked += OpenCurrentWalletSection;
 29112    }
 113
 114    public void Update() =>
 0115        CheckIfProfileCardShouldBeClosed();
 116
 117    public void OnDestroy() =>
 29118        hudCanvasCameraModeController?.Dispose();
 119
 120    internal static ExploreV2MenuComponentView Create()
 121    {
 0122        ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get
 0123        exploreV2View.name = "_ExploreV2";
 124
 0125        return exploreV2View;
 126    }
 127
 128    private void IsInitialized_OnChange(bool current, bool previous)
 129    {
 29130        if (!current)
 0131            return;
 132
 29133        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 29134        StartCoroutine(CreateSectionSelectorMappingsAfterDelay());
 29135    }
 136
 137    private IEnumerator CreateSectionSelectorMappingsAfterDelay()
 138    {
 29139        yield return null;
 0140        CreateSectionSelectorMappings();
 0141    }
 142
 143    internal void CreateSectionSelectorMappings()
 144    {
 180145        foreach (ExploreSection sectionId in Enum.GetValues(typeof(ExploreSection)))
 80146            sectionSelector.GetSection((int)sectionId)
 147                          ?.onSelect.AddListener(OnSectionSelected(sectionId));
 10148    }
 149
 150    private void OpenCurrentWalletSection()
 151    {
 0152        HideAllSections();
 153
 0154        foreach (ISectionToggle section in sectionSelector.GetAllSections())
 0155            section?.SetUnselectedVisuals();
 156
 0157        SelectSection(ExploreSection.Wallet, true);
 0158    }
 159
 160    private void OpenMyAccountSection(bool current, bool previous)
 161    {
 0162        if (!current)
 0163            return;
 164
 0165        HideAllSections();
 166
 0167        foreach (ISectionToggle section in sectionSelector.GetAllSections())
 0168            section?.SetUnselectedVisuals();
 169
 0170        SelectSection(ExploreSection.MyAccount, true);
 0171    }
 172
 173    private UnityAction<bool> OnSectionSelected(ExploreSection sectionId) =>
 60174        isOn =>
 175        {
 5176            if (exploreSectionsById[ExploreSection.Wallet].isVisible)
 0177                exploreSectionsById[ExploreSection.Wallet].Hide();
 178
 5179            if (exploreSectionsById[ExploreSection.MyAccount].isVisible)
 0180                exploreSectionsById[ExploreSection.MyAccount].Hide();
 181
 5182            SelectSection(sectionId, isOn);
 5183        };
 184
 185    private void SelectSection(ExploreSection sectionId, bool isOn)
 186    {
 5187        FeatureEncapsulatorComponentView sectionView = exploreSectionsById[sectionId];
 188
 5189        if (isOn)
 190        {
 5191            if (isOpeningSectionThisFrame)
 0192                return;
 193
 5194            isOpeningSectionThisFrame = true;
 5195            StartCoroutine(ResetSectionOpenLock());
 196
 197            // If not an explorer Section, because we do not Show/Hide it
 5198            if (sectionView != null)
 4199                sectionView.Show();
 200
 5201            OnSectionOpen?.Invoke(sectionId);
 202        }
 0203        else if (sectionView != null) // If not an explorer Section, because we do not Show/Hide it
 0204            sectionView.Hide();
 0205    }
 206
 207    private IEnumerator ResetSectionOpenLock()
 208    {
 5209        yield return null;
 0210        isOpeningSectionThisFrame = false;
 0211    }
 212
 213    public void SetVisible(bool visible)
 214    {
 2215        if (visible)
 216        {
 1217            DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true);
 1218            Show();
 219
 1220            ISectionToggle sectionToGo = sectionSelector.GetSection(DataStore.i.exploreV2.currentSectionIndex.Get());
 221
 1222            if (sectionToGo != null && sectionToGo.IsActive())
 1223                GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get());
 224            else
 0225                GoToFirstActiveSection();
 226        }
 227        else
 228        {
 1229            Hide();
 1230            AudioScriptableObjects.dialogClose.Play(true);
 231        }
 1232    }
 233
 234    private void GoToFirstActiveSection()
 235    {
 0236        foreach (ISectionToggle section in sectionSelector.GetAllSections())
 0237            if (section != null && section.IsActive())
 238            {
 0239                section.SelectToggle(reselectIfAlreadyOn: true);
 0240                break;
 241            }
 0242    }
 243
 244    public void GoToSection(ExploreSection section)
 245    {
 1246        sectionSelector.GetSection((int)section)?.SelectToggle(reselectIfAlreadyOn: true);
 247
 1248        AudioScriptableObjects.dialogOpen.Play(true);
 1249        AudioScriptableObjects.listItemAppear.ResetPitch();
 1250    }
 251
 252    public void SetSectionActive(ExploreSection section, bool isActive) =>
 10253        sectionSelector.GetSection((int)section)?.SetActive(isActive);
 254
 255    public void SetSectionAsNew(ExploreSection section, bool isNew) =>
 0256        sectionSelector.GetSection((int)section)?.SetAsNew(isNew);
 257
 258    public bool IsSectionActive(ExploreSection section)
 259    {
 0260        var sectionToCheck = sectionSelector.GetSection((int)section);
 0261        return sectionToCheck != null && sectionToCheck.IsActive();
 262    }
 263
 264    private void OnAfterShowAnimationCompleted(ShowHideAnimator _)
 265    {
 0266        if (!DataStore.i.exploreV2.isOpen.Get())
 0267            return;
 268
 0269        DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false);
 0270        OnAfterShowAnimation?.Invoke();
 0271    }
 272
 273    public void ConfigureEncapsulatedSection(ExploreSection sectionId, BaseVariable<Transform> featureConfiguratorFlag) 
 4274        exploreSectionsById[sectionId]?.EncapsulateFeature(featureConfiguratorFlag);
 275
 276    public override void RefreshControl()
 277    {
 0278        placesAndEventsSection.RefreshControl();
 279
 0280        foreach (ExploreSection section in exploreSectionsById.Keys)
 0281            exploreSectionsById[section]?.RefreshControl();
 0282    }
 283
 284    internal void RemoveSectionSelectorMappings()
 285    {
 612286        foreach (int sectionId in Enum.GetValues(typeof(ExploreSection)))
 272287            sectionSelector.GetSection(sectionId)?.onSelect.RemoveAllListeners();
 34288    }
 289
 290    private void IsSomeModalOpen_OnChange(bool current, bool previous)
 291    {
 20292        closeAction.OnTriggered -= OnCloseActionTriggered;
 293
 20294        if (!current)
 10295            closeAction.OnTriggered += OnCloseActionTriggered;
 20296    }
 297
 298    private void CheckIfProfileCardShouldBeClosed()
 299    {
 0300        if (!DataStore.i.exploreV2.profileCardIsOpen.Get())
 0301            return;
 302
 0303        cameraDataStore ??= DataStore.i.camera;
 304
 0305        if (Input.GetMouseButton(0) &&
 306            !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTransform, Input.mousePosition, cameraData
 307            !RectTransformUtility.RectangleContainsScreenPoint(DataStore.i.myAccount.isInitialized.Get() ? HUDController
 308                Input.mousePosition, cameraDataStore.hudsCamera.Get()) &&
 309            !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.MyAccountCardMenu, Input.
 0310            DataStore.i.exploreV2.profileCardIsOpen.Set(false);
 0311    }
 312
 313    internal void ConfigureCloseButton()
 314    {
 33315        closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false));
 31316        closeAction.OnTriggered += OnCloseActionTriggered;
 31317        DataStore.i.exploreV2.isSomeModalOpen.OnChange += IsSomeModalOpen_OnChange;
 31318    }
 319
 320    private void OnCloseActionTriggered(DCLAction_Trigger action) =>
 3321        OnCloseButtonPressed?.Invoke(true);
 322
 323    public void ShowRealmSelectorModal() =>
 0324        realmSelectorModal.Show();
 325
 326    /// <summary>
 327    /// Instantiates (if does not already exists) a realm selector modal from the given prefab.
 328    /// </summary>
 329    /// <returns>An instance of a realm modal modal.</returns>
 330    internal RealmSelectorComponentView ConfigureRealmSelectorModal()
 331    {
 332        RealmSelectorComponentView realmSelectorView;
 333
 30334        var existingModal = GameObject.Find(REALM_SELECTOR_MODAL_ID);
 335
 30336        if (existingModal != null)
 24337            realmSelectorView = existingModal.GetComponent<RealmSelectorComponentView>();
 338        else
 339        {
 6340            realmSelectorView = Instantiate(realmSelectorModalPrefab);
 6341            realmSelectorView.name = REALM_SELECTOR_MODAL_ID;
 342        }
 343
 30344        realmSelectorView.Hide(true);
 345
 30346        return realmSelectorView;
 347    }
 348
 349    public void HideMapOnEnteringWorld()
 350    {
 0351        placesAndEventsSection.Show();
 0352        mapSection.Hide();
 0353    }
 354
 355    public void SetWalletActive(bool isActive, bool isGuest)
 356    {
 0357        currentWalletCard.SetWalletCardActive(isActive);
 0358        currentWalletCard.SetWalletCardAsGuest(isGuest);
 0359    }
 360
 361    private void HideAllSections()
 362    {
 0363        foreach (var section in exploreSectionsById)
 0364            if (section.Value != null && section.Value.isVisible)
 0365                section.Value.Hide();
 0366    }
 367}