< 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:70
Uncovered lines:43
Coverable lines:113
Total lines:400
Line coverage:61.9% (70 of 113)
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%11.17056.25%
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
 56    /// <summary>
 57    /// Transform used to positionate the quest section tooltips.
 58    /// </summary>
 59    RectTransform currentQuestTooltipReference { get; }
 60
 61    /// <summary>
 62    /// Transform used to positionate the settings section tooltips.
 63    /// </summary>
 64    RectTransform currentSettingsTooltipReference { get; }
 65
 66    /// <summary>
 67    /// Transform used to positionate the profile section tooltips.
 68    /// </summary>
 69    RectTransform currentProfileCardTooltipReference { get; }
 70    /// <summary>
 71    /// It will be triggered when the close button is clicked.
 72    /// </summary>
 73    event Action<bool> OnCloseButtonPressed;
 74
 75    /// <summary>
 76    /// It will be triggered when a section is open.
 77    /// </summary>
 78    event Action<ExploreSection> OnSectionOpen;
 79
 80    /// <summary>
 81    /// It will be triggered after the show animation has finished.
 82    /// </summary>
 83    event Action OnAfterShowAnimation;
 84
 85    /// <summary>
 86    /// Shows/Hides the game object of the explore menu.
 87    /// </summary>
 88    /// <param name="isActive">True to show it.</param>
 89    void SetVisible(bool isActive);
 90
 91    /// <summary>
 92    /// Open a section.
 93    /// </summary>
 94    /// <param name="section">Section to go.</param>
 95    void GoToSection(ExploreSection section);
 96
 97    /// <summary>
 98    /// Activates/Deactivates a section in the selector.
 99    /// </summary>
 100    /// <param name="section">Section to activate/deactivate.</param>
 101    /// <param name="isActive">True for activating.</param>
 102    void SetSectionActive(ExploreSection section, bool isActive);
 103
 104    /// <summary>
 105    /// Check if a section is actived or not.
 106    /// </summary>
 107    /// <param name="section">Section to check.</param>
 108    /// <returns></returns>
 109    bool IsSectionActive(ExploreSection section);
 110
 111    /// <summary>
 112    /// Configures a encapsulated section.
 113    /// </summary>
 114    /// <param name="sectionId">Section to configure.</param>
 115    /// <param name="featureConfiguratorFlag">Flag used to configurates the feature.</param>
 116    void ConfigureEncapsulatedSection(ExploreSection sectionId, BaseVariable<Transform> featureConfiguratorFlag);
 117
 118    /// <summary>
 119    /// Shows the Realm Selector modal.
 120    /// </summary>
 121    void ShowRealmSelectorModal();
 122}
 123
 124public class ExploreV2MenuComponentView : BaseComponentView, IExploreV2MenuComponentView
 125{
 126    internal const string REALM_SELECTOR_MODAL_ID = "RealmSelector_Modal";
 127
 128    [Header("Assets References")]
 129    [SerializeField] internal RealmSelectorComponentView realmSelectorModalPrefab;
 130
 131    [Header("Top Menu")]
 132    [SerializeField] internal SectionSelectorComponentView sectionSelector;
 133    [SerializeField] internal ProfileCardComponentView profileCard;
 134    [SerializeField] internal RealmViewerComponentView realmViewer;
 135    [SerializeField] internal ButtonComponentView closeMenuButton;
 136    [SerializeField] internal InputAction_Trigger closeAction;
 137
 138    [Header("Sections")]
 139    [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection;
 140    [SerializeField] internal FeatureEncapsulatorComponentView backpackSection;
 141    [SerializeField] internal FeatureEncapsulatorComponentView mapSection;
 142    [SerializeField] internal FeatureEncapsulatorComponentView questSection;
 143    [SerializeField] internal FeatureEncapsulatorComponentView settingsSection;
 144
 145    [Header("Tutorial References")]
 146    [SerializeField] internal RectTransform profileCardTooltipReference;
 147
 148    private DataStore_Camera cameraDataStore;
 149
 150    private Dictionary<ExploreSection, FeatureEncapsulatorComponentView> exploreSectionsById;
 151    private HUDCanvasCameraModeController hudCanvasCameraModeController;
 152
 153    private RectTransform profileCardRectTranform;
 154    private RealmSelectorComponentView realmSelectorModal;
 155
 156    public override void Awake()
 157    {
 29158        base.Awake();
 29159        showHideAnimator.OnWillFinishStart += OnAfterShowAnimationCompleted;
 160
 29161        profileCardRectTranform = profileCard.GetComponent<RectTransform>();
 29162        realmSelectorModal = ConfigureRealmSelectorModal();
 29163        hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud
 164
 29165        exploreSectionsById = new Dictionary<ExploreSection, FeatureEncapsulatorComponentView>()
 166        {
 167            { ExploreSection.Explore, null },
 168            { ExploreSection.Backpack, backpackSection },
 169            { ExploreSection.Map, mapSection },
 170            { ExploreSection.Quest, questSection },
 171            { ExploreSection.Settings, settingsSection },
 172        };
 29173    }
 174
 175    public override void Start()
 176    {
 29177        DataStore.i.exploreV2.isInitialized.OnChange += IsInitialized_OnChange;
 29178        IsInitialized_OnChange(DataStore.i.exploreV2.isInitialized.Get(), false);
 179
 29180        ConfigureCloseButton();
 29181    }
 182
 183    public override void Update() =>
 0184        CheckIfProfileCardShouldBeClosed();
 185
 186    public void OnDestroy() =>
 29187        hudCanvasCameraModeController?.Dispose();
 188
 0189    public IRealmViewerComponentView currentRealmViewer => realmViewer;
 0190    public IRealmSelectorComponentView currentRealmSelectorModal => realmSelectorModal;
 0191    public IProfileCardComponentView currentProfileCard => profileCard;
 0192    public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection;
 0193    public RectTransform currentTopMenuTooltipReference => sectionSelector.GetSection((int) ExploreSection.Explore).pivo
 0194    public RectTransform currentPlacesAndEventsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explor
 0195    public RectTransform currentBackpackTooltipReference => sectionSelector.GetSection((int)ExploreSection.Backpack).piv
 0196    public RectTransform currentMapTooltipReference => sectionSelector.GetSection((int)ExploreSection.Map).pivot;
 0197    public RectTransform currentQuestTooltipReference => sectionSelector.GetSection((int)ExploreSection.Quest).pivot;
 0198    public RectTransform currentSettingsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Settings).piv
 0199    public RectTransform currentProfileCardTooltipReference => profileCardTooltipReference;
 200
 201    public event Action<bool> OnCloseButtonPressed;
 202    public event Action<ExploreSection> OnSectionOpen;
 203    public event Action OnAfterShowAnimation;
 204
 205    public override void Dispose()
 206    {
 29207        base.Dispose();
 208
 29209        RemoveSectionSelectorMappings();
 29210        closeMenuButton.onClick.RemoveAllListeners();
 29211        closeAction.OnTriggered -= OnCloseActionTriggered;
 29212        DataStore.i.exploreV2.isSomeModalOpen.OnChange -= IsSomeModalOpen_OnChange;
 29213        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 214
 29215        if (realmSelectorModal != null)
 29216            realmSelectorModal.Dispose();
 29217    }
 218
 219    public void SetVisible(bool isActive)
 220    {
 2221        if (isActive)
 222        {
 1223            DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true);
 1224            Show();
 225
 1226            ISectionToggle sectionToGo = sectionSelector.GetSection(DataStore.i.exploreV2.currentSectionIndex.Get());
 227
 1228            if (sectionToGo != null && sectionToGo.IsActive())
 229            {
 1230                GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get());
 231            }
 232            else
 233            {
 0234                List<ISectionToggle> allSections = sectionSelector.GetAllSections();
 0235                foreach (ISectionToggle section in allSections)
 236                {
 0237                    if (section != null && section.IsActive())
 238                    {
 0239                        section.SelectToggle(reselectIfAlreadyOn: true);
 0240                        break;
 241                    }
 242                }
 243            }
 244        }
 245        else
 246        {
 1247            Hide();
 1248            AudioScriptableObjects.dialogClose.Play(true);
 249        }
 1250    }
 251
 252    public void GoToSection(ExploreSection section)
 253    {
 1254        sectionSelector.GetSection((int)section)?.SelectToggle(reselectIfAlreadyOn: true);
 255
 1256        AudioScriptableObjects.dialogOpen.Play(true);
 1257        AudioScriptableObjects.listItemAppear.ResetPitch();
 1258    }
 259
 260    public void OnAfterShowAnimationCompleted(ShowHideAnimator _)
 261    {
 0262        if (!DataStore.i.exploreV2.isOpen.Get())
 0263            return;
 264
 0265        DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false);
 0266        OnAfterShowAnimation?.Invoke();
 0267    }
 268
 269    public void SetSectionActive(ExploreSection section, bool isActive) =>
 10270        sectionSelector.GetSection((int)section).SetActive(isActive);
 271
 272    public bool IsSectionActive(ExploreSection section) =>
 0273        sectionSelector.GetSection((int)section).IsActive();
 274
 275    public void ConfigureEncapsulatedSection(ExploreSection sectionId, BaseVariable<Transform> featureConfiguratorFlag) 
 4276        exploreSectionsById[sectionId]?.EncapsulateFeature(featureConfiguratorFlag);
 277
 278    public void ShowRealmSelectorModal() =>
 0279        realmSelectorModal.Show();
 280
 281    public override void RefreshControl()
 282    {
 0283        placesAndEventsSection.RefreshControl();
 284
 0285        foreach (var section in exploreSectionsById.Keys)
 0286            exploreSectionsById[section]?.RefreshControl();
 0287    }
 288
 289    internal void RemoveSectionSelectorMappings()
 290    {
 408291        foreach (int sectionId in Enum.GetValues(typeof(ExploreSection)))
 170292            sectionSelector.GetSection(sectionId)?.onSelect.RemoveAllListeners();
 34293    }
 294
 295    internal void ConfigureCloseButton()
 296    {
 33297        closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false));
 31298        closeAction.OnTriggered += OnCloseActionTriggered;
 31299        DataStore.i.exploreV2.isSomeModalOpen.OnChange += IsSomeModalOpen_OnChange;
 31300    }
 301
 302    /// <summary>
 303    /// Instantiates (if does not already exists) a realm selector modal from the given prefab.
 304    /// </summary>
 305    /// <returns>An instance of a realm modal modal.</returns>
 306    internal RealmSelectorComponentView ConfigureRealmSelectorModal()
 307    {
 30308        RealmSelectorComponentView realmSelectorModal = null;
 309
 30310        GameObject existingModal = GameObject.Find(REALM_SELECTOR_MODAL_ID);
 311
 30312        if (existingModal != null)
 313        {
 24314            realmSelectorModal = existingModal.GetComponent<RealmSelectorComponentView>();
 315        }
 316        else
 317        {
 6318            realmSelectorModal = GameObject.Instantiate(realmSelectorModalPrefab);
 6319            realmSelectorModal.name = REALM_SELECTOR_MODAL_ID;
 320        }
 321
 30322        realmSelectorModal.Hide(true);
 323
 30324        return realmSelectorModal;
 325    }
 326
 327    internal static ExploreV2MenuComponentView Create()
 328    {
 0329        ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get
 0330        exploreV2View.name = "_ExploreV2";
 331
 0332        return exploreV2View;
 333    }
 334
 335    private void IsInitialized_OnChange(bool current, bool previous)
 336    {
 29337        if (!current)
 0338            return;
 339
 29340        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 29341        StartCoroutine(CreateSectionSelectorMappingsAfterDelay());
 29342    }
 343
 344    private IEnumerator CreateSectionSelectorMappingsAfterDelay()
 345    {
 29346        yield return null;
 0347        CreateSectionSelectorMappings();
 0348    }
 349
 350    internal void CreateSectionSelectorMappings()
 351    {
 120352        foreach (ExploreSection sectionId in Enum.GetValues(typeof(ExploreSection)))
 50353            sectionSelector.GetSection((int)sectionId)
 354                           ?.onSelect.AddListener(OnSectionSelected(sectionId));
 10355    }
 356
 357    private UnityAction<bool> OnSectionSelected(ExploreSection sectionId) =>
 50358        isOn =>
 359        {
 5360            FeatureEncapsulatorComponentView sectionView = exploreSectionsById[sectionId];
 361
 5362            if (isOn)
 363            {
 364                // If not an explorer Section, because we do not Show/Hide it
 5365                if (sectionView != null)
 4366                    sectionView.Show();
 367
 5368                OnSectionOpen?.Invoke(sectionId);
 369            }
 0370            else if (sectionView != null) // If not an explorer Section, because we do not Show/Hide it
 371            {
 0372                sectionView.Hide();
 373            }
 0374        };
 375
 376    private void IsSomeModalOpen_OnChange(bool current, bool previous)
 377    {
 28378        closeAction.OnTriggered -= OnCloseActionTriggered;
 379
 28380        if (!current)
 14381            closeAction.OnTriggered += OnCloseActionTriggered;
 28382    }
 383
 3384    private void OnCloseActionTriggered(DCLAction_Trigger action) => OnCloseButtonPressed?.Invoke(true);
 385
 386    private void CheckIfProfileCardShouldBeClosed()
 387    {
 0388        if (!DataStore.i.exploreV2.profileCardIsOpen.Get())
 0389            return;
 390
 0391        cameraDataStore ??= DataStore.i.camera;
 392
 0393        if (Input.GetMouseButton(0) &&
 394            !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTranform, Input.mousePosition, cameraDataS
 395            !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.expandedMenu, Input.mouse
 396        {
 0397            DataStore.i.exploreV2.profileCardIsOpen.Set(false);
 398        }
 0399    }
 400}