< 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:92
Uncovered lines:50
Coverable lines:142
Total lines:402
Line coverage:64.7% (92 of 142)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%110100%
IsInitialized_OnChange(...)0%2.032080%
Update()0%2100%
RefreshControl()0%2100%
Dispose()0%110100%
SetVisible(...)0%11.17056.25%
OnAfterShowAnimationCompleted()0%6200%
GoToSection(...)0%330100%
SetSectionActive(...)0%110100%
IsSectionActive(...)0%2100%
ConfigureEncapsulatedSection(...)0%770100%
CreateSectionSelectorMappingsAfterDelay()0%5.673033.33%
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 System.Collections;
 4using System.Collections.Generic;
 5using UnityEngine;
 6
 7public interface IExploreV2MenuComponentView : IDisposable
 8{
 9    /// <summary>
 10    /// It will be triggered when the close button is clicked.
 11    /// </summary>
 12    event Action<bool> OnCloseButtonPressed;
 13
 14    /// <summary>
 15    /// It will be triggered when a section is open.
 16    /// </summary>
 17    event Action<ExploreSection> OnSectionOpen;
 18
 19    /// <summary>
 20    /// It will be triggered after the show animation has finished.
 21    /// </summary>
 22    event Action OnAfterShowAnimation;
 23
 24    /// <summary>
 25    /// Real viewer component.
 26    /// </summary>
 27    IRealmViewerComponentView currentRealmViewer { get; }
 28
 29    /// <summary>
 30    /// Profile card component.
 31    /// </summary>
 32    IProfileCardComponentView currentProfileCard { get; }
 33
 34    /// <summary>
 35    /// Places and Events section component.
 36    /// </summary>
 37    IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection { get; }
 38
 39    /// <summary>
 40    /// Transform used to positionate the top menu tooltips.
 41    /// </summary>
 42    RectTransform currentTopMenuTooltipReference { get; }
 43
 44    /// <summary>
 45    /// Transform used to positionate the places and events section tooltips.
 46    /// </summary>
 47    RectTransform currentPlacesAndEventsTooltipReference { get; }
 48
 49    /// <summary>
 50    /// Transform used to positionate the backpack section tooltips.
 51    /// </summary>
 52    RectTransform currentBackpackTooltipReference { get; }
 53
 54    /// <summary>
 55    /// Transform used to positionate the map section tooltips.
 56    /// </summary>
 57    RectTransform currentMapTooltipReference { get; }
 58
 59    /// <summary>
 60    /// Transform used to positionate the builder section tooltips.
 61    /// </summary>
 62    RectTransform currentBuilderTooltipReference { get; }
 63
 64    /// <summary>
 65    /// Transform used to positionate the quest section tooltips.
 66    /// </summary>
 67    RectTransform currentQuestTooltipReference { get; }
 68
 69    /// <summary>
 70    /// Transform used to positionate the settings section tooltips.
 71    /// </summary>
 72    RectTransform currentSettingsTooltipReference { get; }
 73
 74    /// <summary>
 75    /// Transform used to positionate the profile section tooltips.
 76    /// </summary>
 77    RectTransform currentProfileCardTooltipReference { get; }
 78
 79    /// <summary>
 80    /// Shows/Hides the game object of the explore menu.
 81    /// </summary>
 82    /// <param name="isActive">True to show it.</param>
 83    void SetVisible(bool isActive);
 84
 85    /// <summary>
 86    /// It is called after the show animation has finished.
 87    /// </summary>
 88    void OnAfterShowAnimationCompleted();
 89
 90    /// <summary>
 91    /// Open a section.
 92    /// </summary>
 93    /// <param name="section">Section to go.</param>
 94    void GoToSection(ExploreSection section);
 95
 96    /// <summary>
 97    /// Activates/Deactivates a section in the selector.
 98    /// </summary>
 99    /// <param name="section">Section to activate/deactivate.</param>
 100    /// <param name="isActive">True for activating.</param>
 101    void SetSectionActive(ExploreSection section, bool isActive);
 102
 103    /// <summary>
 104    /// Check if a section is actived or not.
 105    /// </summary>
 106    /// <param name="section">Section to check.</param>
 107    /// <returns></returns>
 108    bool IsSectionActive(ExploreSection section);
 109
 110    /// <summary>
 111    /// Configures a encapsulated section.
 112    /// </summary>
 113    /// <param name="section">Section to configure.</param>
 114    /// <param name="featureConfiguratorFlag">Flag used to configurates the feature.</param>
 115    void ConfigureEncapsulatedSection(ExploreSection section, BaseVariable<Transform> featureConfiguratorFlag);
 116}
 117
 118public class ExploreV2MenuComponentView : BaseComponentView, IExploreV2MenuComponentView
 119{
 120    [Header("Top Menu")]
 121    [SerializeField] internal SectionSelectorComponentView sectionSelector;
 122    [SerializeField] internal ProfileCardComponentView profileCard;
 123    [SerializeField] internal RealmViewerComponentView realmViewer;
 124    [SerializeField] internal ButtonComponentView closeMenuButton;
 125    [SerializeField] internal InputAction_Trigger closeAction;
 126
 127    [Header("Sections")]
 128    [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection;
 129    [SerializeField] internal FeatureEncapsulatorComponentView backpackSection;
 130    [SerializeField] internal FeatureEncapsulatorComponentView mapSection;
 131    [SerializeField] internal FeatureEncapsulatorComponentView builderSection;
 132    [SerializeField] internal FeatureEncapsulatorComponentView questSection;
 133    [SerializeField] internal FeatureEncapsulatorComponentView settingsSection;
 134
 135    [Header("Tutorial References")]
 136    [SerializeField] internal RectTransform profileCardTooltipReference;
 137
 138    internal const ExploreSection DEFAULT_SECTION = ExploreSection.Explore;
 139
 0140    public IRealmViewerComponentView currentRealmViewer => realmViewer;
 0141    public IProfileCardComponentView currentProfileCard => profileCard;
 0142    public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection;
 0143    public RectTransform currentTopMenuTooltipReference => sectionSelector.GetSection((int) ExploreSection.Explore).pivo
 0144    public RectTransform currentPlacesAndEventsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explor
 0145    public RectTransform currentBackpackTooltipReference => sectionSelector.GetSection((int)ExploreSection.Backpack).piv
 0146    public RectTransform currentMapTooltipReference => sectionSelector.GetSection((int)ExploreSection.Map).pivot;
 0147    public RectTransform currentBuilderTooltipReference => sectionSelector.GetSection((int)ExploreSection.Builder).pivot
 0148    public RectTransform currentQuestTooltipReference => sectionSelector.GetSection((int)ExploreSection.Quest).pivot;
 0149    public RectTransform currentSettingsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Settings).piv
 0150    public RectTransform currentProfileCardTooltipReference => profileCardTooltipReference;
 151
 152    public event Action<bool> OnCloseButtonPressed;
 153    public event Action<ExploreSection> OnSectionOpen;
 154    public event Action OnAfterShowAnimation;
 155
 156    internal RectTransform profileCardRectTranform;
 157
 158    public override void Start()
 159    {
 39160        profileCardRectTranform = profileCard.GetComponent<RectTransform>();
 161
 39162        DataStore.i.exploreV2.currentSectionIndex.Set((int)DEFAULT_SECTION, false);
 163
 39164        DataStore.i.exploreV2.isInitialized.OnChange += IsInitialized_OnChange;
 39165        IsInitialized_OnChange(DataStore.i.exploreV2.isInitialized.Get(), false);
 166
 39167        ConfigureCloseButton();
 39168    }
 169
 170    private void IsInitialized_OnChange(bool current, bool previous)
 171    {
 39172        if (!current)
 0173            return;
 174
 39175        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 39176        StartCoroutine(CreateSectionSelectorMappingsAfterDelay());
 39177    }
 178
 179    public override void Update()
 180    {
 0181        CheckIfProfileCardShouldBeClosed();
 0182    }
 183
 184    public override void RefreshControl()
 185    {
 0186        placesAndEventsSection.RefreshControl();
 0187        backpackSection.RefreshControl();
 0188        mapSection.RefreshControl();
 0189        builderSection.RefreshControl();
 0190        questSection.RefreshControl();
 0191        settingsSection.RefreshControl();
 0192    }
 193
 194    public override void Dispose()
 195    {
 78196        base.Dispose();
 197
 78198        RemoveSectionSelectorMappings();
 78199        closeMenuButton.onClick.RemoveAllListeners();
 78200        closeAction.OnTriggered -= OnCloseActionTriggered;
 78201        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 78202    }
 203
 204    public void SetVisible(bool isActive)
 205    {
 2206        if (isActive)
 207        {
 1208            DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true);
 1209            Show();
 210
 1211            ISectionToggle sectionToGo = sectionSelector.GetSection(DataStore.i.exploreV2.currentSectionIndex.Get());
 1212            if (sectionToGo != null && sectionToGo.IsActive())
 1213                GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get());
 214            else
 215            {
 0216                List<ISectionToggle> allSections = sectionSelector.GetAllSections();
 0217                foreach (ISectionToggle section in allSections)
 218                {
 0219                    if (section != null && section.IsActive())
 220                    {
 0221                        section.SelectToggle(true);
 0222                        break;
 223                    }
 224                }
 225            }
 226        }
 227        else
 228        {
 1229            Hide();
 1230            AudioScriptableObjects.dialogClose.Play(true);
 231        }
 1232    }
 233
 234    public void OnAfterShowAnimationCompleted()
 235    {
 0236        DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false);
 0237        OnAfterShowAnimation?.Invoke();
 0238    }
 239
 240    public void GoToSection(ExploreSection section)
 241    {
 7242        if (DataStore.i.exploreV2.currentSectionIndex.Get() != (int)section)
 6243            DataStore.i.exploreV2.currentSectionIndex.Set((int)section);
 244
 7245        sectionSelector.GetSection((int)section)?.SelectToggle(true);
 246
 7247        AudioScriptableObjects.dialogOpen.Play(true);
 7248        AudioScriptableObjects.listItemAppear.ResetPitch();
 7249    }
 250
 24251    public void SetSectionActive(ExploreSection section, bool isActive) { sectionSelector.GetSection((int)section).SetAc
 252
 0253    public bool IsSectionActive(ExploreSection section) { return sectionSelector.GetSection((int)section).IsActive(); }
 254
 255    public void ConfigureEncapsulatedSection(ExploreSection section, BaseVariable<Transform> featureConfiguratorFlag)
 256    {
 5257        FeatureEncapsulatorComponentView sectionView = null;
 258        switch (section)
 259        {
 260            case ExploreSection.Backpack:
 1261                sectionView = backpackSection;
 1262                break;
 263            case ExploreSection.Map:
 1264                sectionView = mapSection;
 1265                break;
 266            case ExploreSection.Builder:
 1267                sectionView = builderSection;
 1268                break;
 269            case ExploreSection.Quest:
 1270                sectionView = questSection;
 1271                break;
 272            case ExploreSection.Settings:
 1273                sectionView = settingsSection;
 274                break;
 275        }
 276
 5277        sectionView?.EncapsulateFeature(featureConfiguratorFlag);
 5278    }
 279
 280    public IEnumerator CreateSectionSelectorMappingsAfterDelay()
 281    {
 39282        yield return null;
 0283        CreateSectionSelectorMappings();
 0284    }
 285
 286    internal void CreateSectionSelectorMappings()
 287    {
 12288        sectionSelector.GetSection((int)ExploreSection.Explore)
 289                       ?.onSelect.AddListener((isOn) =>
 290                       {
 1291                           if (isOn)
 292                           {
 1293                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Explore, false);
 1294                               OnSectionOpen?.Invoke(ExploreSection.Explore);
 295                           }
 1296                       });
 297
 12298        sectionSelector.GetSection((int)ExploreSection.Backpack)
 299                       ?.onSelect.AddListener((isOn) =>
 300                       {
 1301                           if (isOn)
 302                           {
 1303                               backpackSection.Show();
 1304                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Backpack, false);
 1305                               OnSectionOpen?.Invoke(ExploreSection.Backpack);
 1306                           }
 307                           else
 0308                               backpackSection.Hide();
 0309                       });
 310
 12311        sectionSelector.GetSection((int)ExploreSection.Map)
 312                       ?.onSelect.AddListener((isOn) =>
 313                       {
 1314                           if (isOn)
 315                           {
 1316                               mapSection.Show();
 1317                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Map, false);
 1318                               OnSectionOpen?.Invoke(ExploreSection.Map);
 1319                           }
 320                           else
 0321                               mapSection.Hide();
 0322                       });
 323
 12324        sectionSelector.GetSection((int)ExploreSection.Builder)
 325                       ?.onSelect.AddListener((isOn) =>
 326                       {
 1327                           if (isOn)
 328                           {
 1329                               builderSection.Show();
 1330                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Builder, false);
 1331                               OnSectionOpen?.Invoke(ExploreSection.Builder);
 1332                           }
 333                           else
 0334                               builderSection.Hide();
 0335                       });
 336
 12337        sectionSelector.GetSection((int)ExploreSection.Quest)
 338                       ?.onSelect.AddListener((isOn) =>
 339                       {
 1340                           if (isOn)
 341                           {
 1342                               questSection.Show();
 1343                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Quest, false);
 1344                               OnSectionOpen?.Invoke(ExploreSection.Quest);
 1345                           }
 346                           else
 0347                               questSection.Hide();
 0348                       });
 349
 12350        sectionSelector.GetSection((int)ExploreSection.Settings)
 351                       ?.onSelect.AddListener((isOn) =>
 352                       {
 1353                           if (isOn)
 354                           {
 1355                               settingsSection.Show();
 1356                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Settings, false);
 1357                               OnSectionOpen?.Invoke(ExploreSection.Settings);
 1358                           }
 359                           else
 0360                               settingsSection.Hide();
 0361                       });
 12362    }
 363
 364    internal void RemoveSectionSelectorMappings()
 365    {
 84366        sectionSelector.GetSection((int)ExploreSection.Explore)?.onSelect.RemoveAllListeners();
 84367        sectionSelector.GetSection((int)ExploreSection.Backpack)?.onSelect.RemoveAllListeners();
 84368        sectionSelector.GetSection((int)ExploreSection.Map)?.onSelect.RemoveAllListeners();
 84369        sectionSelector.GetSection((int)ExploreSection.Builder)?.onSelect.RemoveAllListeners();
 84370        sectionSelector.GetSection((int)ExploreSection.Quest)?.onSelect.RemoveAllListeners();
 84371        sectionSelector.GetSection((int)ExploreSection.Settings)?.onSelect.RemoveAllListeners();
 84372    }
 373
 374    internal void ConfigureCloseButton()
 375    {
 43376        closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false));
 41377        closeAction.OnTriggered += OnCloseActionTriggered;
 41378    }
 379
 6380    internal void OnCloseActionTriggered(DCLAction_Trigger action) { OnCloseButtonPressed?.Invoke(true); }
 381
 382    internal void CheckIfProfileCardShouldBeClosed()
 383    {
 0384        if (!DataStore.i.exploreV2.profileCardIsOpen.Get())
 0385            return;
 386
 0387        if (Input.GetMouseButton(0) &&
 388            !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTranform, Input.mousePosition, Camera.main
 389            !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.expandedMenu, Input.mouse
 390        {
 0391            DataStore.i.exploreV2.profileCardIsOpen.Set(false);
 392        }
 0393    }
 394
 395    internal static ExploreV2MenuComponentView Create()
 396    {
 0397        ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get
 0398        exploreV2View.name = "_ExploreV2";
 399
 0400        return exploreV2View;
 401    }
 402}