< 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:73
Uncovered lines:44
Coverable lines:117
Total lines:404
Line coverage:62.3% (73 of 117)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
Start()0%110100%
Update()0%2100%
OnDestroy()0%220100%
Dispose()0%220100%
SetVisible(...)0%10.427058.82%
GoToSection(...)0%220100%
OnAfterShowAnimationCompleted(...)0%12300%
SetSectionActive(...)0%110100%
IsSectionActive(...)0%2100%
ConfigureEncapsulatedSection(...)0%220100%
ShowRealmSelectorModal()0%2100%
RefreshControl()0%12300%
RemoveSectionSelectorMappings()0%440100%
ConfigureCloseButton()0%110100%
ConfigureRealmSelectorModal()0%220100%
Create()0%2100%
IsInitialized_OnChange(...)0%2.032080%
CreateSectionSelectorMappingsAfterDelay()0%5.673033.33%
CreateSectionSelectorMappings()0%440100%
OnSectionSelected(...)0%110100%
IsSomeModalOpen_OnChange(...)0%220100%
OnCloseActionTriggered(...)0%220100%
CheckIfProfileCardShouldBeClosed()0%42600%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using DCL;
 5using JetBrains.Annotations;
 6using UnityEngine;
 7using UnityEngine.Events;
 8
 9public interface IExploreV2MenuComponentView : IDisposable
 10{
 11
 12    /// <summary>
 13    /// Real viewer component.
 14    /// </summary>
 15    IRealmViewerComponentView currentRealmViewer { get; }
 16
 17    /// <summary>
 18    /// Realm Selector component.
 19    /// </summary>
 20    IRealmSelectorComponentView currentRealmSelectorModal { get; }
 21
 22    /// <summary>
 23    /// Profile card component.
 24    /// </summary>
 25    IProfileCardComponentView currentProfileCard { get; }
 26
 27    /// <summary>
 28    /// Places and Events section component.
 29    /// </summary>
 30    IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection { get; }
 31
 32    /// <summary>
 33    /// Transform used to positionate the top menu tooltips.
 34    /// </summary>
 35    RectTransform currentTopMenuTooltipReference { get; }
 36
 37    /// <summary>
 38    /// Transform used to positionate the places and events section tooltips.
 39    /// </summary>
 40    RectTransform currentPlacesAndEventsTooltipReference { get; }
 41
 42    /// <summary>
 43    /// Transform used to positionate the backpack section tooltips.
 44    /// </summary>
 45    RectTransform currentBackpackTooltipReference { get; }
 46
 47    /// <summary>
 48    /// Transform used to positionate the map section tooltips.
 49    /// </summary>
 50    RectTransform currentMapTooltipReference { get; }
 51
 52    /// <summary>
 53    /// Transform used to positionate the builder section tooltips.
 54    /// </summary>
 55    RectTransform currentBuilderTooltipReference { get; }
 56
 57    /// <summary>
 58    /// Transform used to positionate the quest section tooltips.
 59    /// </summary>
 60    RectTransform currentQuestTooltipReference { get; }
 61
 62    /// <summary>
 63    /// Transform used to positionate the settings section tooltips.
 64    /// </summary>
 65    RectTransform currentSettingsTooltipReference { get; }
 66
 67    /// <summary>
 68    /// Transform used to positionate the profile section tooltips.
 69    /// </summary>
 70    RectTransform currentProfileCardTooltipReference { get; }
 71    /// <summary>
 72    /// It will be triggered when the close button is clicked.
 73    /// </summary>
 74    event Action<bool> OnCloseButtonPressed;
 75
 76    /// <summary>
 77    /// It will be triggered when a section is open.
 78    /// </summary>
 79    event Action<ExploreSection> OnSectionOpen;
 80
 81    /// <summary>
 82    /// It will be triggered after the show animation has finished.
 83    /// </summary>
 84    event Action OnAfterShowAnimation;
 85
 86    /// <summary>
 87    /// Shows/Hides the game object of the explore menu.
 88    /// </summary>
 89    /// <param name="isActive">True to show it.</param>
 90    void SetVisible(bool isActive);
 91
 92    /// <summary>
 93    /// Open a section.
 94    /// </summary>
 95    /// <param name="section">Section to go.</param>
 96    void GoToSection(ExploreSection section);
 97
 98    /// <summary>
 99    /// Activates/Deactivates a section in the selector.
 100    /// </summary>
 101    /// <param name="section">Section to activate/deactivate.</param>
 102    /// <param name="isActive">True for activating.</param>
 103    void SetSectionActive(ExploreSection section, bool isActive);
 104
 105    /// <summary>
 106    /// Check if a section is actived or not.
 107    /// </summary>
 108    /// <param name="section">Section to check.</param>
 109    /// <returns></returns>
 110    bool IsSectionActive(ExploreSection section);
 111
 112    /// <summary>
 113    /// Configures a encapsulated section.
 114    /// </summary>
 115    /// <param name="sectionId">Section to configure.</param>
 116    /// <param name="featureConfiguratorFlag">Flag used to configurates the feature.</param>
 117    void ConfigureEncapsulatedSection(ExploreSection sectionId, BaseVariable<Transform> featureConfiguratorFlag);
 118
 119    /// <summary>
 120    /// Shows the Realm Selector modal.
 121    /// </summary>
 122    void ShowRealmSelectorModal();
 123}
 124
 125public class ExploreV2MenuComponentView : BaseComponentView, IExploreV2MenuComponentView
 126{
 127    internal const string REALM_SELECTOR_MODAL_ID = "RealmSelector_Modal";
 128
 129    [Header("Assets References")]
 130    [SerializeField] internal RealmSelectorComponentView realmSelectorModalPrefab;
 131
 132    [Header("Top Menu")]
 133    [SerializeField] internal SectionSelectorComponentView sectionSelector;
 134    [SerializeField] internal ProfileCardComponentView profileCard;
 135    [SerializeField] internal RealmViewerComponentView realmViewer;
 136    [SerializeField] internal ButtonComponentView closeMenuButton;
 137    [SerializeField] internal InputAction_Trigger closeAction;
 138
 139    [Header("Sections")]
 140    [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection;
 141    [SerializeField] internal FeatureEncapsulatorComponentView backpackSection;
 142    [SerializeField] internal FeatureEncapsulatorComponentView mapSection;
 143    [SerializeField] internal FeatureEncapsulatorComponentView builderSection;
 144    [SerializeField] internal FeatureEncapsulatorComponentView questSection;
 145    [SerializeField] internal FeatureEncapsulatorComponentView settingsSection;
 146
 147    [Header("Tutorial References")]
 148    [SerializeField] internal RectTransform profileCardTooltipReference;
 149
 150    private DataStore_Camera cameraDataStore;
 151
 152    private Dictionary<ExploreSection, FeatureEncapsulatorComponentView> exploreSectionsById;
 153    private HUDCanvasCameraModeController hudCanvasCameraModeController;
 154
 155    private RectTransform profileCardRectTranform;
 156    private RealmSelectorComponentView realmSelectorModal;
 157
 158    public override void Awake()
 159    {
 34160        base.Awake();
 34161        showHideAnimator.OnWillFinishStart += OnAfterShowAnimationCompleted;
 162
 34163        profileCardRectTranform = profileCard.GetComponent<RectTransform>();
 34164        realmSelectorModal = ConfigureRealmSelectorModal();
 34165        hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud
 166
 34167        exploreSectionsById = new Dictionary<ExploreSection, FeatureEncapsulatorComponentView>()
 168        {
 169            { ExploreSection.Explore, null },
 170            { ExploreSection.Backpack, backpackSection },
 171            { ExploreSection.Map, mapSection },
 172            { ExploreSection.Builder, builderSection },
 173            { ExploreSection.Quest, questSection },
 174            { ExploreSection.Settings, settingsSection },
 175        };
 34176    }
 177
 178    public override void Start()
 179    {
 34180        DataStore.i.exploreV2.isInitialized.OnChange += IsInitialized_OnChange;
 34181        IsInitialized_OnChange(DataStore.i.exploreV2.isInitialized.Get(), false);
 182
 34183        ConfigureCloseButton();
 34184    }
 185
 186    public override void Update() =>
 0187        CheckIfProfileCardShouldBeClosed();
 188
 189    public void OnDestroy() =>
 34190        hudCanvasCameraModeController?.Dispose();
 191
 0192    public IRealmViewerComponentView currentRealmViewer => realmViewer;
 0193    public IRealmSelectorComponentView currentRealmSelectorModal => realmSelectorModal;
 0194    public IProfileCardComponentView currentProfileCard => profileCard;
 0195    public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection;
 0196    public RectTransform currentTopMenuTooltipReference => sectionSelector.GetSection((int) ExploreSection.Explore).pivo
 0197    public RectTransform currentPlacesAndEventsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explor
 0198    public RectTransform currentBackpackTooltipReference => sectionSelector.GetSection((int)ExploreSection.Backpack).piv
 0199    public RectTransform currentMapTooltipReference => sectionSelector.GetSection((int)ExploreSection.Map).pivot;
 0200    public RectTransform currentBuilderTooltipReference => sectionSelector.GetSection((int)ExploreSection.Builder).pivot
 0201    public RectTransform currentQuestTooltipReference => sectionSelector.GetSection((int)ExploreSection.Quest).pivot;
 0202    public RectTransform currentSettingsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Settings).piv
 0203    public RectTransform currentProfileCardTooltipReference => profileCardTooltipReference;
 204
 205    public event Action<bool> OnCloseButtonPressed;
 206    public event Action<ExploreSection> OnSectionOpen;
 207    public event Action OnAfterShowAnimation;
 208
 209    public override void Dispose()
 210    {
 34211        base.Dispose();
 212
 34213        RemoveSectionSelectorMappings();
 34214        closeMenuButton.onClick.RemoveAllListeners();
 34215        closeAction.OnTriggered -= OnCloseActionTriggered;
 34216        DataStore.i.exploreV2.isSomeModalOpen.OnChange -= IsSomeModalOpen_OnChange;
 34217        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 218
 34219        if (realmSelectorModal != null)
 34220            realmSelectorModal.Dispose();
 34221    }
 222
 223    public void SetVisible(bool isActive)
 224    {
 2225        if (isActive)
 226        {
 1227            DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true);
 1228            Show();
 229
 1230            ISectionToggle sectionToGo = sectionSelector.GetSection(DataStore.i.exploreV2.currentSectionIndex.Get());
 231
 1232            if (sectionToGo != null && sectionToGo.IsActive())
 233            {
 1234                GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get());
 1235            }
 236            else
 237            {
 0238                List<ISectionToggle> allSections = sectionSelector.GetAllSections();
 0239                foreach (ISectionToggle section in allSections)
 240                {
 0241                    if (section != null && section.IsActive())
 242                    {
 0243                        section.SelectToggle(reselectIfAlreadyOn: true);
 0244                        break;
 245                    }
 246                }
 247            }
 248        }
 249        else
 250        {
 1251            Hide();
 1252            AudioScriptableObjects.dialogClose.Play(true);
 253        }
 1254    }
 255
 256    public void GoToSection(ExploreSection section)
 257    {
 1258        sectionSelector.GetSection((int)section)?.SelectToggle(reselectIfAlreadyOn: true);
 259
 1260        AudioScriptableObjects.dialogOpen.Play(true);
 1261        AudioScriptableObjects.listItemAppear.ResetPitch();
 1262    }
 263
 264    public 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 SetSectionActive(ExploreSection section, bool isActive) =>
 12274        sectionSelector.GetSection((int)section).SetActive(isActive);
 275
 276    public bool IsSectionActive(ExploreSection section) =>
 0277        sectionSelector.GetSection((int)section).IsActive();
 278
 279    public void ConfigureEncapsulatedSection(ExploreSection sectionId, BaseVariable<Transform> featureConfiguratorFlag) 
 5280        exploreSectionsById[sectionId]?.EncapsulateFeature(featureConfiguratorFlag);
 281
 282    public void ShowRealmSelectorModal() =>
 0283        realmSelectorModal.Show();
 284
 285    public override void RefreshControl()
 286    {
 0287        placesAndEventsSection.RefreshControl();
 288
 0289        foreach (var section in exploreSectionsById.Keys)
 0290            exploreSectionsById[section]?.RefreshControl();
 0291    }
 292
 293    internal void RemoveSectionSelectorMappings()
 294    {
 560295        foreach (int sectionId in Enum.GetValues(typeof(ExploreSection)))
 240296            sectionSelector.GetSection(sectionId)?.onSelect.RemoveAllListeners();
 40297    }
 298
 299    internal void ConfigureCloseButton()
 300    {
 38301        closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false));
 36302        closeAction.OnTriggered += OnCloseActionTriggered;
 36303        DataStore.i.exploreV2.isSomeModalOpen.OnChange += IsSomeModalOpen_OnChange;
 36304    }
 305
 306    /// <summary>
 307    /// Instantiates (if does not already exists) a realm selector modal from the given prefab.
 308    /// </summary>
 309    /// <returns>An instance of a realm modal modal.</returns>
 310    internal RealmSelectorComponentView ConfigureRealmSelectorModal()
 311    {
 35312        RealmSelectorComponentView realmSelectorModal = null;
 313
 35314        GameObject existingModal = GameObject.Find(REALM_SELECTOR_MODAL_ID);
 315
 35316        if (existingModal != null)
 317        {
 29318            realmSelectorModal = existingModal.GetComponent<RealmSelectorComponentView>();
 29319        }
 320        else
 321        {
 6322            realmSelectorModal = GameObject.Instantiate(realmSelectorModalPrefab);
 6323            realmSelectorModal.name = REALM_SELECTOR_MODAL_ID;
 324        }
 325
 35326        realmSelectorModal.Hide(true);
 327
 35328        return realmSelectorModal;
 329    }
 330
 331    internal static ExploreV2MenuComponentView Create()
 332    {
 0333        ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get
 0334        exploreV2View.name = "_ExploreV2";
 335
 0336        return exploreV2View;
 337    }
 338
 339    private void IsInitialized_OnChange(bool current, bool previous)
 340    {
 34341        if (!current)
 0342            return;
 343
 34344        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 34345        StartCoroutine(CreateSectionSelectorMappingsAfterDelay());
 34346    }
 347
 348    private IEnumerator CreateSectionSelectorMappingsAfterDelay()
 349    {
 34350        yield return null;
 0351        CreateSectionSelectorMappings();
 0352    }
 353
 354    internal void CreateSectionSelectorMappings()
 355    {
 168356        foreach (ExploreSection sectionId in Enum.GetValues(typeof(ExploreSection)))
 72357            sectionSelector.GetSection((int)sectionId)
 358                           ?.onSelect.AddListener(OnSectionSelected(sectionId));
 12359    }
 360
 361    private UnityAction<bool> OnSectionSelected(ExploreSection sectionId) =>
 72362        isOn =>
 363        {
 6364            FeatureEncapsulatorComponentView sectionView = exploreSectionsById[sectionId];
 365
 6366            if (isOn)
 367            {
 368                // If not an explorer Section, because we do not Show/Hide it
 6369                if (sectionView != null)
 5370                    sectionView.Show();
 371
 6372                OnSectionOpen?.Invoke(sectionId);
 6373            }
 0374            else if (sectionView != null) // If not an explorer Section, because we do not Show/Hide it
 375            {
 0376                sectionView.Hide();
 377            }
 0378        };
 379
 380    private void IsSomeModalOpen_OnChange(bool current, bool previous)
 381    {
 28382        closeAction.OnTriggered -= OnCloseActionTriggered;
 383
 28384        if (!current)
 14385            closeAction.OnTriggered += OnCloseActionTriggered;
 28386    }
 387
 3388    private void OnCloseActionTriggered(DCLAction_Trigger action) => OnCloseButtonPressed?.Invoke(true);
 389
 390    private void CheckIfProfileCardShouldBeClosed()
 391    {
 0392        if (!DataStore.i.exploreV2.profileCardIsOpen.Get())
 0393            return;
 394
 0395        cameraDataStore ??= DataStore.i.camera;
 396
 0397        if (Input.GetMouseButton(0) &&
 398            !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTranform, Input.mousePosition, cameraDataS
 399            !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.expandedMenu, Input.mouse
 400        {
 0401            DataStore.i.exploreV2.profileCardIsOpen.Set(false);
 402        }
 0403    }
 404}