< 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:84
Uncovered lines:43
Coverable lines:127
Total lines:375
Line coverage:66.1% (84 of 127)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%2.022083.33%
Update()0%2100%
RefreshControl()0%2100%
Dispose()0%110100%
SetVisible(...)0%220100%
OnAfterShowAnimationCompleted()0%6200%
GoToSection(...)0%330100%
SetSectionActive(...)0%110100%
IsSectionActive(...)0%2100%
ConfigureEncapsulatedSection(...)0%770100%
CreateSectionSelectorMappings()0%770100%
RemoveSectionSelectorMappings()0%770100%
ConfigureCloseButton()0%110100%
OnCloseActionTriggered(...)0%220100%
CheckIfProfileCardShouldBeClosed()0%30500%
Create()0%2100%

File(s)

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

#LineLine coverage
 1using DCL;
 2using System;
 3using UnityEngine;
 4
 5public interface IExploreV2MenuComponentView : IDisposable
 6{
 7    /// <summary>
 8    /// It will be triggered when the view is fully initialized.
 9    /// </summary>
 10    event Action OnInitialized;
 11
 12    /// <summary>
 13    /// It will be triggered when the close button is clicked.
 14    /// </summary>
 15    event Action<bool> OnCloseButtonPressed;
 16
 17    /// <summary>
 18    /// It will be triggered when a section is open.
 19    /// </summary>
 20    event Action<ExploreSection> OnSectionOpen;
 21
 22    /// <summary>
 23    /// It will be triggered after the show animation has finished.
 24    /// </summary>
 25    event Action OnAfterShowAnimation;
 26
 27    /// <summary>
 28    /// Real viewer component.
 29    /// </summary>
 30    IRealmViewerComponentView currentRealmViewer { get; }
 31
 32    /// <summary>
 33    /// Profile card component.
 34    /// </summary>
 35    IProfileCardComponentView currentProfileCard { get; }
 36
 37    /// <summary>
 38    /// Places and Events section component.
 39    /// </summary>
 40    IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection { get; }
 41
 42    /// <summary>
 43    /// Transform used to positionate the top menu tooltips.
 44    /// </summary>
 45    RectTransform currentTopMenuTooltipReference { get; }
 46
 47    /// <summary>
 48    /// Transform used to positionate the places and events section tooltips.
 49    /// </summary>
 50    RectTransform currentPlacesAndEventsTooltipReference { get; }
 51
 52    /// <summary>
 53    /// Transform used to positionate the backpack section tooltips.
 54    /// </summary>
 55    RectTransform currentBackpackTooltipReference { get; }
 56
 57    /// <summary>
 58    /// Transform used to positionate the map section tooltips.
 59    /// </summary>
 60    RectTransform currentMapTooltipReference { get; }
 61
 62    /// <summary>
 63    /// Transform used to positionate the builder section tooltips.
 64    /// </summary>
 65    RectTransform currentBuilderTooltipReference { get; }
 66
 67    /// <summary>
 68    /// Transform used to positionate the quest section tooltips.
 69    /// </summary>
 70    RectTransform currentQuestTooltipReference { get; }
 71
 72    /// <summary>
 73    /// Transform used to positionate the settings section tooltips.
 74    /// </summary>
 75    RectTransform currentSettingsTooltipReference { get; }
 76
 77    /// <summary>
 78    /// Transform used to positionate the profile section tooltips.
 79    /// </summary>
 80    RectTransform currentProfileCardTooltipReference { get; }
 81
 82    /// <summary>
 83    /// Shows/Hides the game object of the explore menu.
 84    /// </summary>
 85    /// <param name="isActive">True to show it.</param>
 86    void SetVisible(bool isActive);
 87
 88    /// <summary>
 89    /// It is called after the show animation has finished.
 90    /// </summary>
 91    void OnAfterShowAnimationCompleted();
 92
 93    /// <summary>
 94    /// Open a section.
 95    /// </summary>
 96    /// <param name="section">Section to go.</param>
 97    void GoToSection(ExploreSection section);
 98
 99    /// <summary>
 100    /// Activates/Deactivates a section in the selector.
 101    /// </summary>
 102    /// <param name="section">Section to activate/deactivate.</param>
 103    /// <param name="isActive">True for activating.</param>
 104    void SetSectionActive(ExploreSection section, bool isActive);
 105
 106    /// <summary>
 107    /// Check if a section is actived or not.
 108    /// </summary>
 109    /// <param name="section">Section to check.</param>
 110    /// <returns></returns>
 111    bool IsSectionActive(ExploreSection section);
 112
 113    /// <summary>
 114    /// Configures a encapsulated section.
 115    /// </summary>
 116    /// <param name="section">Section to configure.</param>
 117    /// <param name="featureConfiguratorFlag">Flag used to configurates the feature.</param>
 118    void ConfigureEncapsulatedSection(ExploreSection section, BaseVariable<Transform> featureConfiguratorFlag);
 119}
 120
 121public class ExploreV2MenuComponentView : BaseComponentView, IExploreV2MenuComponentView
 122{
 123    [Header("Top Menu")]
 124    [SerializeField] internal SectionSelectorComponentView sectionSelector;
 125    [SerializeField] internal ProfileCardComponentView profileCard;
 126    [SerializeField] internal RealmViewerComponentView realmViewer;
 127    [SerializeField] internal ButtonComponentView closeMenuButton;
 128    [SerializeField] internal InputAction_Trigger closeAction;
 129
 130    [Header("Sections")]
 131    [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection;
 132    [SerializeField] internal FeatureEncapsulatorComponentView backpackSection;
 133    [SerializeField] internal FeatureEncapsulatorComponentView mapSection;
 134    [SerializeField] internal FeatureEncapsulatorComponentView builderSection;
 135    [SerializeField] internal FeatureEncapsulatorComponentView questSection;
 136    [SerializeField] internal FeatureEncapsulatorComponentView settingsSection;
 137
 138    [Header("Tutorial References")]
 139    [SerializeField] internal RectTransform profileCardTooltipReference;
 140
 141    internal const ExploreSection DEFAULT_SECTION = ExploreSection.Explore;
 142
 0143    public IRealmViewerComponentView currentRealmViewer => realmViewer;
 0144    public IProfileCardComponentView currentProfileCard => profileCard;
 0145    public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection;
 0146    public RectTransform currentTopMenuTooltipReference => sectionSelector.GetSection((int) ExploreSection.Explore).pivo
 0147    public RectTransform currentPlacesAndEventsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explor
 0148    public RectTransform currentBackpackTooltipReference => sectionSelector.GetSection((int)ExploreSection.Backpack).piv
 0149    public RectTransform currentMapTooltipReference => sectionSelector.GetSection((int)ExploreSection.Map).pivot;
 0150    public RectTransform currentBuilderTooltipReference => sectionSelector.GetSection((int)ExploreSection.Builder).pivot
 0151    public RectTransform currentQuestTooltipReference => sectionSelector.GetSection((int)ExploreSection.Quest).pivot;
 0152    public RectTransform currentSettingsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Settings).piv
 0153    public RectTransform currentProfileCardTooltipReference => profileCardTooltipReference;
 154
 155    public event Action OnInitialized;
 156    public event Action<bool> OnCloseButtonPressed;
 157    public event Action<ExploreSection> OnSectionOpen;
 158    public event Action OnAfterShowAnimation;
 159
 160    internal RectTransform profileCardRectTranform;
 161
 162    public override void Start()
 163    {
 39164        profileCardRectTranform = profileCard.GetComponent<RectTransform>();
 165
 39166        DataStore.i.exploreV2.currentSectionIndex.Set((int)DEFAULT_SECTION, false);
 167
 39168        CreateSectionSelectorMappings();
 39169        ConfigureCloseButton();
 170
 39171        OnInitialized?.Invoke();
 0172    }
 173
 174    public override void Update()
 175    {
 0176        CheckIfProfileCardShouldBeClosed();
 0177    }
 178
 179    public override void RefreshControl()
 180    {
 0181        placesAndEventsSection.RefreshControl();
 0182        backpackSection.RefreshControl();
 0183        mapSection.RefreshControl();
 0184        builderSection.RefreshControl();
 0185        questSection.RefreshControl();
 0186        settingsSection.RefreshControl();
 0187    }
 188
 189    public override void Dispose()
 190    {
 78191        base.Dispose();
 192
 78193        RemoveSectionSelectorMappings();
 78194        closeMenuButton.onClick.RemoveAllListeners();
 78195        closeAction.OnTriggered -= OnCloseActionTriggered;
 78196    }
 197
 198    public void SetVisible(bool isActive)
 199    {
 2200        if (isActive)
 201        {
 1202            DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true);
 1203            Show();
 1204            GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get());
 1205        }
 206        else
 207        {
 1208            Hide();
 1209            AudioScriptableObjects.dialogClose.Play(true);
 210        }
 1211    }
 212
 213    public void OnAfterShowAnimationCompleted()
 214    {
 0215        DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false);
 0216        OnAfterShowAnimation?.Invoke();
 0217    }
 218
 219    public void GoToSection(ExploreSection section)
 220    {
 7221        if (DataStore.i.exploreV2.currentSectionIndex.Get() != (int)section)
 6222            DataStore.i.exploreV2.currentSectionIndex.Set((int)section);
 223
 7224        sectionSelector.GetSection((int)section)?.SelectToggle(true);
 225
 7226        AudioScriptableObjects.dialogOpen.Play(true);
 7227        AudioScriptableObjects.listItemAppear.ResetPitch();
 7228    }
 229
 24230    public void SetSectionActive(ExploreSection section, bool isActive) { sectionSelector.GetSection((int)section).SetAc
 231
 0232    public bool IsSectionActive(ExploreSection section) { return sectionSelector.GetSection((int)section).IsActive(); }
 233
 234    public void ConfigureEncapsulatedSection(ExploreSection section, BaseVariable<Transform> featureConfiguratorFlag)
 235    {
 5236        FeatureEncapsulatorComponentView sectionView = null;
 237        switch (section)
 238        {
 239            case ExploreSection.Backpack:
 1240                sectionView = backpackSection;
 1241                break;
 242            case ExploreSection.Map:
 1243                sectionView = mapSection;
 1244                break;
 245            case ExploreSection.Builder:
 1246                sectionView = builderSection;
 1247                break;
 248            case ExploreSection.Quest:
 1249                sectionView = questSection;
 1250                break;
 251            case ExploreSection.Settings:
 1252                sectionView = settingsSection;
 253                break;
 254        }
 255
 5256        sectionView?.EncapsulateFeature(featureConfiguratorFlag);
 5257    }
 258
 259    internal void CreateSectionSelectorMappings()
 260    {
 51261        sectionSelector.GetSection((int)ExploreSection.Explore)
 262                       ?.onSelect.AddListener((isOn) =>
 263                       {
 8264                           if (isOn)
 265                           {
 3266                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Explore, false);
 3267                               OnSectionOpen?.Invoke(ExploreSection.Explore);
 268                           }
 6269                       });
 270
 51271        sectionSelector.GetSection((int)ExploreSection.Backpack)
 272                       ?.onSelect.AddListener((isOn) =>
 273                       {
 2274                           if (isOn)
 275                           {
 2276                               backpackSection.Show();
 2277                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Backpack, false);
 2278                               OnSectionOpen?.Invoke(ExploreSection.Backpack);
 1279                           }
 280                           else
 0281                               backpackSection.Hide();
 0282                       });
 283
 51284        sectionSelector.GetSection((int)ExploreSection.Map)
 285                       ?.onSelect.AddListener((isOn) =>
 286                       {
 2287                           if (isOn)
 288                           {
 2289                               mapSection.Show();
 2290                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Map, false);
 2291                               OnSectionOpen?.Invoke(ExploreSection.Map);
 1292                           }
 293                           else
 0294                               mapSection.Hide();
 0295                       });
 296
 51297        sectionSelector.GetSection((int)ExploreSection.Builder)
 298                       ?.onSelect.AddListener((isOn) =>
 299                       {
 2300                           if (isOn)
 301                           {
 2302                               builderSection.Show();
 2303                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Builder, false);
 2304                               OnSectionOpen?.Invoke(ExploreSection.Builder);
 1305                           }
 306                           else
 0307                               builderSection.Hide();
 0308                       });
 309
 51310        sectionSelector.GetSection((int)ExploreSection.Quest)
 311                       ?.onSelect.AddListener((isOn) =>
 312                       {
 2313                           if (isOn)
 314                           {
 2315                               questSection.Show();
 2316                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Quest, false);
 2317                               OnSectionOpen?.Invoke(ExploreSection.Quest);
 1318                           }
 319                           else
 0320                               questSection.Hide();
 0321                       });
 322
 51323        sectionSelector.GetSection((int)ExploreSection.Settings)
 324                       ?.onSelect.AddListener((isOn) =>
 325                       {
 2326                           if (isOn)
 327                           {
 2328                               settingsSection.Show();
 2329                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Settings, false);
 2330                               OnSectionOpen?.Invoke(ExploreSection.Settings);
 1331                           }
 332                           else
 0333                               settingsSection.Hide();
 0334                       });
 51335    }
 336
 337    internal void RemoveSectionSelectorMappings()
 338    {
 84339        sectionSelector.GetSection((int)ExploreSection.Explore)?.onSelect.RemoveAllListeners();
 84340        sectionSelector.GetSection((int)ExploreSection.Backpack)?.onSelect.RemoveAllListeners();
 84341        sectionSelector.GetSection((int)ExploreSection.Map)?.onSelect.RemoveAllListeners();
 84342        sectionSelector.GetSection((int)ExploreSection.Builder)?.onSelect.RemoveAllListeners();
 84343        sectionSelector.GetSection((int)ExploreSection.Quest)?.onSelect.RemoveAllListeners();
 84344        sectionSelector.GetSection((int)ExploreSection.Settings)?.onSelect.RemoveAllListeners();
 84345    }
 346
 347    internal void ConfigureCloseButton()
 348    {
 43349        closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false));
 41350        closeAction.OnTriggered += OnCloseActionTriggered;
 41351    }
 352
 6353    internal void OnCloseActionTriggered(DCLAction_Trigger action) { OnCloseButtonPressed?.Invoke(true); }
 354
 355    internal void CheckIfProfileCardShouldBeClosed()
 356    {
 0357        if (!DataStore.i.exploreV2.profileCardIsOpen.Get())
 0358            return;
 359
 0360        if (Input.GetMouseButton(0) &&
 361            !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTranform, Input.mousePosition, Camera.main
 362            !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.expandedMenu, Input.mouse
 363        {
 0364            DataStore.i.exploreV2.profileCardIsOpen.Set(false);
 365        }
 0366    }
 367
 368    internal static ExploreV2MenuComponentView Create()
 369    {
 0370        ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get
 0371        exploreV2View.name = "_ExploreV2";
 372
 0373        return exploreV2View;
 374    }
 375}