< 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:72
Uncovered lines:44
Coverable lines:116
Total lines:409
Line coverage:62% (72 of 116)
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    /// It is called after the show animation has finished.
 94    /// </summary>
 95    [UsedImplicitly]
 96    void OnAfterShowAnimationCompleted();
 97
 98    /// <summary>
 99    /// Open a section.
 100    /// </summary>
 101    /// <param name="section">Section to go.</param>
 102    void GoToSection(ExploreSection section);
 103
 104    /// <summary>
 105    /// Activates/Deactivates a section in the selector.
 106    /// </summary>
 107    /// <param name="section">Section to activate/deactivate.</param>
 108    /// <param name="isActive">True for activating.</param>
 109    void SetSectionActive(ExploreSection section, bool isActive);
 110
 111    /// <summary>
 112    /// Check if a section is actived or not.
 113    /// </summary>
 114    /// <param name="section">Section to check.</param>
 115    /// <returns></returns>
 116    bool IsSectionActive(ExploreSection section);
 117
 118    /// <summary>
 119    /// Configures a encapsulated section.
 120    /// </summary>
 121    /// <param name="sectionId">Section to configure.</param>
 122    /// <param name="featureConfiguratorFlag">Flag used to configurates the feature.</param>
 123    void ConfigureEncapsulatedSection(ExploreSection sectionId, BaseVariable<Transform> featureConfiguratorFlag);
 124
 125    /// <summary>
 126    /// Shows the Realm Selector modal.
 127    /// </summary>
 128    void ShowRealmSelectorModal();
 129}
 130
 131public class ExploreV2MenuComponentView : BaseComponentView, IExploreV2MenuComponentView
 132{
 133    internal const string REALM_SELECTOR_MODAL_ID = "RealmSelector_Modal";
 134
 135    [Header("Assets References")]
 136    [SerializeField] internal RealmSelectorComponentView realmSelectorModalPrefab;
 137
 138    [Header("Top Menu")]
 139    [SerializeField] internal SectionSelectorComponentView sectionSelector;
 140    [SerializeField] internal ProfileCardComponentView profileCard;
 141    [SerializeField] internal RealmViewerComponentView realmViewer;
 142    [SerializeField] internal ButtonComponentView closeMenuButton;
 143    [SerializeField] internal InputAction_Trigger closeAction;
 144
 145    [Header("Sections")]
 146    [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection;
 147    [SerializeField] internal FeatureEncapsulatorComponentView backpackSection;
 148    [SerializeField] internal FeatureEncapsulatorComponentView mapSection;
 149    [SerializeField] internal FeatureEncapsulatorComponentView builderSection;
 150    [SerializeField] internal FeatureEncapsulatorComponentView questSection;
 151    [SerializeField] internal FeatureEncapsulatorComponentView settingsSection;
 152
 153    [Header("Tutorial References")]
 154    [SerializeField] internal RectTransform profileCardTooltipReference;
 155
 156    private DataStore_Camera cameraDataStore;
 157
 158    private  Dictionary<ExploreSection, FeatureEncapsulatorComponentView> exploreSectionsById;
 159    private HUDCanvasCameraModeController hudCanvasCameraModeController;
 160
 161    private RectTransform profileCardRectTranform;
 162    private RealmSelectorComponentView realmSelectorModal;
 163
 164    public override void Awake()
 165    {
 34166        base.Awake();
 167
 34168        profileCardRectTranform = profileCard.GetComponent<RectTransform>();
 34169        realmSelectorModal = ConfigureRealmSelectorModal();
 34170        hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud
 171
 34172        exploreSectionsById = new Dictionary<ExploreSection, FeatureEncapsulatorComponentView>()
 173        {
 174            { ExploreSection.Explore, null },
 175            { ExploreSection.Backpack, backpackSection },
 176            { ExploreSection.Map, mapSection },
 177            { ExploreSection.Builder, builderSection },
 178            { ExploreSection.Quest, questSection },
 179            { ExploreSection.Settings, settingsSection },
 180        };
 34181    }
 182
 183    public override void Start()
 184    {
 34185        DataStore.i.exploreV2.isInitialized.OnChange += IsInitialized_OnChange;
 34186        IsInitialized_OnChange(DataStore.i.exploreV2.isInitialized.Get(), false);
 187
 34188        ConfigureCloseButton();
 34189    }
 190
 191    public override void Update() =>
 0192        CheckIfProfileCardShouldBeClosed();
 193
 194    public void OnDestroy() =>
 34195        hudCanvasCameraModeController?.Dispose();
 196
 0197    public IRealmViewerComponentView currentRealmViewer => realmViewer;
 0198    public IRealmSelectorComponentView currentRealmSelectorModal => realmSelectorModal;
 0199    public IProfileCardComponentView currentProfileCard => profileCard;
 0200    public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection;
 0201    public RectTransform currentTopMenuTooltipReference => sectionSelector.GetSection((int) ExploreSection.Explore).pivo
 0202    public RectTransform currentPlacesAndEventsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explor
 0203    public RectTransform currentBackpackTooltipReference => sectionSelector.GetSection((int)ExploreSection.Backpack).piv
 0204    public RectTransform currentMapTooltipReference => sectionSelector.GetSection((int)ExploreSection.Map).pivot;
 0205    public RectTransform currentBuilderTooltipReference => sectionSelector.GetSection((int)ExploreSection.Builder).pivot
 0206    public RectTransform currentQuestTooltipReference => sectionSelector.GetSection((int)ExploreSection.Quest).pivot;
 0207    public RectTransform currentSettingsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Settings).piv
 0208    public RectTransform currentProfileCardTooltipReference => profileCardTooltipReference;
 209
 210    public event Action<bool> OnCloseButtonPressed;
 211    public event Action<ExploreSection> OnSectionOpen;
 212    public event Action OnAfterShowAnimation;
 213
 214    public override void Dispose()
 215    {
 34216        base.Dispose();
 217
 34218        RemoveSectionSelectorMappings();
 34219        closeMenuButton.onClick.RemoveAllListeners();
 34220        closeAction.OnTriggered -= OnCloseActionTriggered;
 34221        DataStore.i.exploreV2.isSomeModalOpen.OnChange -= IsSomeModalOpen_OnChange;
 34222        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 223
 34224        if (realmSelectorModal != null)
 34225            realmSelectorModal.Dispose();
 34226    }
 227
 228    public void SetVisible(bool isActive)
 229    {
 2230        if (isActive)
 231        {
 1232            DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true);
 1233            Show();
 234
 1235            ISectionToggle sectionToGo = sectionSelector.GetSection(DataStore.i.exploreV2.currentSectionIndex.Get());
 236
 1237            if (sectionToGo != null && sectionToGo.IsActive())
 238            {
 1239                GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get());
 1240            }
 241            else
 242            {
 0243                List<ISectionToggle> allSections = sectionSelector.GetAllSections();
 0244                foreach (ISectionToggle section in allSections)
 245                {
 0246                    if (section != null && section.IsActive())
 247                    {
 0248                        section.SelectToggle(reselectIfAlreadyOn: true);
 0249                        break;
 250                    }
 251                }
 252            }
 253        }
 254        else
 255        {
 1256            Hide();
 1257            AudioScriptableObjects.dialogClose.Play(true);
 258        }
 1259    }
 260
 261    public void GoToSection(ExploreSection section)
 262    {
 1263        sectionSelector.GetSection((int)section)?.SelectToggle(reselectIfAlreadyOn: true);
 264
 1265        AudioScriptableObjects.dialogOpen.Play(true);
 1266        AudioScriptableObjects.listItemAppear.ResetPitch();
 1267    }
 268
 269    public void OnAfterShowAnimationCompleted()
 270    {
 0271        if (!DataStore.i.exploreV2.isOpen.Get())
 0272            return;
 273
 0274        DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false);
 0275        OnAfterShowAnimation?.Invoke();
 0276    }
 277
 278    public void SetSectionActive(ExploreSection section, bool isActive) =>
 12279        sectionSelector.GetSection((int)section).SetActive(isActive);
 280
 281    public bool IsSectionActive(ExploreSection section) =>
 0282        sectionSelector.GetSection((int)section).IsActive();
 283
 284    public void ConfigureEncapsulatedSection(ExploreSection sectionId, BaseVariable<Transform> featureConfiguratorFlag) 
 5285        exploreSectionsById[sectionId]?.EncapsulateFeature(featureConfiguratorFlag);
 286
 287    public void ShowRealmSelectorModal() =>
 0288        realmSelectorModal.Show();
 289
 290    public override void RefreshControl()
 291    {
 0292        placesAndEventsSection.RefreshControl();
 293
 0294        foreach (var section in exploreSectionsById.Keys)
 0295            exploreSectionsById[section]?.RefreshControl();
 0296    }
 297
 298    internal void RemoveSectionSelectorMappings()
 299    {
 560300        foreach (int sectionId in Enum.GetValues(typeof(ExploreSection)))
 240301            sectionSelector.GetSection(sectionId)?.onSelect.RemoveAllListeners();
 40302    }
 303
 304    internal void ConfigureCloseButton()
 305    {
 38306        closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false));
 36307        closeAction.OnTriggered += OnCloseActionTriggered;
 36308        DataStore.i.exploreV2.isSomeModalOpen.OnChange += IsSomeModalOpen_OnChange;
 36309    }
 310
 311    /// <summary>
 312    /// Instantiates (if does not already exists) a realm selector modal from the given prefab.
 313    /// </summary>
 314    /// <returns>An instance of a realm modal modal.</returns>
 315    internal RealmSelectorComponentView ConfigureRealmSelectorModal()
 316    {
 35317        RealmSelectorComponentView realmSelectorModal = null;
 318
 35319        GameObject existingModal = GameObject.Find(REALM_SELECTOR_MODAL_ID);
 320
 35321        if (existingModal != null)
 322        {
 29323            realmSelectorModal = existingModal.GetComponent<RealmSelectorComponentView>();
 29324        }
 325        else
 326        {
 6327            realmSelectorModal = GameObject.Instantiate(realmSelectorModalPrefab);
 6328            realmSelectorModal.name = REALM_SELECTOR_MODAL_ID;
 329        }
 330
 35331        realmSelectorModal.Hide(true);
 332
 35333        return realmSelectorModal;
 334    }
 335
 336    internal static ExploreV2MenuComponentView Create()
 337    {
 0338        ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get
 0339        exploreV2View.name = "_ExploreV2";
 340
 0341        return exploreV2View;
 342    }
 343
 344    private void IsInitialized_OnChange(bool current, bool previous)
 345    {
 34346        if (!current)
 0347            return;
 348
 34349        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 34350        StartCoroutine(CreateSectionSelectorMappingsAfterDelay());
 34351    }
 352
 353    private IEnumerator CreateSectionSelectorMappingsAfterDelay()
 354    {
 34355        yield return null;
 0356        CreateSectionSelectorMappings();
 0357    }
 358
 359    internal void CreateSectionSelectorMappings()
 360    {
 168361        foreach (ExploreSection sectionId in Enum.GetValues(typeof(ExploreSection)))
 72362            sectionSelector.GetSection((int)sectionId)
 363                           ?.onSelect.AddListener(OnSectionSelected(sectionId));
 12364    }
 365
 366    private UnityAction<bool> OnSectionSelected(ExploreSection sectionId) =>
 72367        isOn =>
 368        {
 6369            FeatureEncapsulatorComponentView sectionView = exploreSectionsById[sectionId];
 370
 6371            if (isOn)
 372            {
 373                // If not an explorer Section, because we do not Show/Hide it
 6374                if (sectionView != null)
 5375                    sectionView.Show();
 376
 6377                OnSectionOpen?.Invoke(sectionId);
 6378            }
 0379            else if (sectionView != null) // If not an explorer Section, because we do not Show/Hide it
 380            {
 0381                sectionView.Hide();
 382            }
 0383        };
 384
 385    private void IsSomeModalOpen_OnChange(bool current, bool previous)
 386    {
 28387        closeAction.OnTriggered -= OnCloseActionTriggered;
 388
 28389        if (!current)
 14390            closeAction.OnTriggered += OnCloseActionTriggered;
 28391    }
 392
 3393    private void OnCloseActionTriggered(DCLAction_Trigger action) => OnCloseButtonPressed?.Invoke(true);
 394
 395    private void CheckIfProfileCardShouldBeClosed()
 396    {
 0397        if (!DataStore.i.exploreV2.profileCardIsOpen.Get())
 0398            return;
 399
 0400        cameraDataStore ??= DataStore.i.camera;
 401
 0402        if (Input.GetMouseButton(0) &&
 403            !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTranform, Input.mousePosition, cameraDataS
 404            !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.expandedMenu, Input.mouse
 405        {
 0406            DataStore.i.exploreV2.profileCardIsOpen.Set(false);
 407        }
 0408    }
 409}