< 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:107
Uncovered lines:55
Coverable lines:162
Total lines:458
Line coverage:66% (107 of 162)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
Start()0%110100%
IsInitialized_OnChange(...)0%2.032080%
Update()0%2100%
RefreshControl()0%2100%
Dispose()0%220100%
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%
IsSomeModalOpen_OnChange(...)0%6200%
OnCloseActionTriggered(...)0%220100%
CheckIfProfileCardShouldBeClosed()0%30500%
ConfigureRealmSelectorModal()0%220100%
ShowRealmSelectorModal()0%2100%
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    /// Realm Selector component.
 31    /// </summary>
 32    IRealmSelectorComponentView currentRealmSelectorModal { get; }
 33
 34    /// <summary>
 35    /// Profile card component.
 36    /// </summary>
 37    IProfileCardComponentView currentProfileCard { get; }
 38
 39    /// <summary>
 40    /// Places and Events section component.
 41    /// </summary>
 42    IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection { get; }
 43
 44    /// <summary>
 45    /// Transform used to positionate the top menu tooltips.
 46    /// </summary>
 47    RectTransform currentTopMenuTooltipReference { get; }
 48
 49    /// <summary>
 50    /// Transform used to positionate the places and events section tooltips.
 51    /// </summary>
 52    RectTransform currentPlacesAndEventsTooltipReference { get; }
 53
 54    /// <summary>
 55    /// Transform used to positionate the backpack section tooltips.
 56    /// </summary>
 57    RectTransform currentBackpackTooltipReference { get; }
 58
 59    /// <summary>
 60    /// Transform used to positionate the map section tooltips.
 61    /// </summary>
 62    RectTransform currentMapTooltipReference { get; }
 63
 64    /// <summary>
 65    /// Transform used to positionate the builder section tooltips.
 66    /// </summary>
 67    RectTransform currentBuilderTooltipReference { get; }
 68
 69    /// <summary>
 70    /// Transform used to positionate the quest section tooltips.
 71    /// </summary>
 72    RectTransform currentQuestTooltipReference { get; }
 73
 74    /// <summary>
 75    /// Transform used to positionate the settings section tooltips.
 76    /// </summary>
 77    RectTransform currentSettingsTooltipReference { get; }
 78
 79    /// <summary>
 80    /// Transform used to positionate the profile section tooltips.
 81    /// </summary>
 82    RectTransform currentProfileCardTooltipReference { get; }
 83
 84    /// <summary>
 85    /// Shows/Hides the game object of the explore menu.
 86    /// </summary>
 87    /// <param name="isActive">True to show it.</param>
 88    void SetVisible(bool isActive);
 89
 90    /// <summary>
 91    /// It is called after the show animation has finished.
 92    /// </summary>
 93    void OnAfterShowAnimationCompleted();
 94
 95    /// <summary>
 96    /// Open a section.
 97    /// </summary>
 98    /// <param name="section">Section to go.</param>
 99    void GoToSection(ExploreSection section);
 100
 101    /// <summary>
 102    /// Activates/Deactivates a section in the selector.
 103    /// </summary>
 104    /// <param name="section">Section to activate/deactivate.</param>
 105    /// <param name="isActive">True for activating.</param>
 106    void SetSectionActive(ExploreSection section, bool isActive);
 107
 108    /// <summary>
 109    /// Check if a section is actived or not.
 110    /// </summary>
 111    /// <param name="section">Section to check.</param>
 112    /// <returns></returns>
 113    bool IsSectionActive(ExploreSection section);
 114
 115    /// <summary>
 116    /// Configures a encapsulated section.
 117    /// </summary>
 118    /// <param name="section">Section to configure.</param>
 119    /// <param name="featureConfiguratorFlag">Flag used to configurates the feature.</param>
 120    void ConfigureEncapsulatedSection(ExploreSection section, BaseVariable<Transform> featureConfiguratorFlag);
 121
 122    /// <summary>
 123    /// Shows the Realm Selector modal.
 124    /// </summary>
 125    void ShowRealmSelectorModal();
 126}
 127
 128public class ExploreV2MenuComponentView : BaseComponentView, IExploreV2MenuComponentView
 129{
 130    [Header("Assets References")]
 131    [SerializeField] internal RealmSelectorComponentView realmSelectorModalPrefab;
 132
 133    [Header("Top Menu")]
 134    [SerializeField] internal SectionSelectorComponentView sectionSelector;
 135    [SerializeField] internal ProfileCardComponentView profileCard;
 136    [SerializeField] internal RealmViewerComponentView realmViewer;
 137    [SerializeField] internal ButtonComponentView closeMenuButton;
 138    [SerializeField] internal InputAction_Trigger closeAction;
 139
 140    [Header("Sections")]
 141    [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection;
 142    [SerializeField] internal FeatureEncapsulatorComponentView backpackSection;
 143    [SerializeField] internal FeatureEncapsulatorComponentView mapSection;
 144    [SerializeField] internal FeatureEncapsulatorComponentView builderSection;
 145    [SerializeField] internal FeatureEncapsulatorComponentView questSection;
 146    [SerializeField] internal FeatureEncapsulatorComponentView settingsSection;
 147
 148    [Header("Tutorial References")]
 149    [SerializeField] internal RectTransform profileCardTooltipReference;
 150
 151    internal const ExploreSection DEFAULT_SECTION = ExploreSection.Explore;
 152    internal const string REALM_SELECTOR_MODAL_ID = "RealmSelector_Modal";
 153
 0154    public IRealmViewerComponentView currentRealmViewer => realmViewer;
 0155    public IRealmSelectorComponentView currentRealmSelectorModal => realmSelectorModal;
 0156    public IProfileCardComponentView currentProfileCard => profileCard;
 0157    public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection;
 0158    public RectTransform currentTopMenuTooltipReference => sectionSelector.GetSection((int) ExploreSection.Explore).pivo
 0159    public RectTransform currentPlacesAndEventsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explor
 0160    public RectTransform currentBackpackTooltipReference => sectionSelector.GetSection((int)ExploreSection.Backpack).piv
 0161    public RectTransform currentMapTooltipReference => sectionSelector.GetSection((int)ExploreSection.Map).pivot;
 0162    public RectTransform currentBuilderTooltipReference => sectionSelector.GetSection((int)ExploreSection.Builder).pivot
 0163    public RectTransform currentQuestTooltipReference => sectionSelector.GetSection((int)ExploreSection.Quest).pivot;
 0164    public RectTransform currentSettingsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Settings).piv
 0165    public RectTransform currentProfileCardTooltipReference => profileCardTooltipReference;
 166
 167    public event Action<bool> OnCloseButtonPressed;
 168    public event Action<ExploreSection> OnSectionOpen;
 169    public event Action OnAfterShowAnimation;
 170
 171    internal RectTransform profileCardRectTranform;
 172    internal RealmSelectorComponentView realmSelectorModal;
 173
 174    public override void Awake()
 175    {
 40176        base.Awake();
 177
 40178        profileCardRectTranform = profileCard.GetComponent<RectTransform>();
 40179        realmSelectorModal = ConfigureRealmSelectorModal();
 40180    }
 181
 182    public override void Start()
 183    {
 40184        DataStore.i.exploreV2.currentSectionIndex.Set((int)DEFAULT_SECTION, false);
 185
 40186        DataStore.i.exploreV2.isInitialized.OnChange += IsInitialized_OnChange;
 40187        IsInitialized_OnChange(DataStore.i.exploreV2.isInitialized.Get(), false);
 188
 40189        ConfigureCloseButton();
 40190    }
 191
 192    private void IsInitialized_OnChange(bool current, bool previous)
 193    {
 40194        if (!current)
 0195            return;
 196
 40197        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 40198        StartCoroutine(CreateSectionSelectorMappingsAfterDelay());
 40199    }
 200
 0201    public override void Update() { CheckIfProfileCardShouldBeClosed(); }
 202
 203    public override void RefreshControl()
 204    {
 0205        placesAndEventsSection.RefreshControl();
 0206        backpackSection.RefreshControl();
 0207        mapSection.RefreshControl();
 0208        builderSection.RefreshControl();
 0209        questSection.RefreshControl();
 0210        settingsSection.RefreshControl();
 0211    }
 212
 213    public override void Dispose()
 214    {
 80215        base.Dispose();
 216
 80217        RemoveSectionSelectorMappings();
 80218        closeMenuButton.onClick.RemoveAllListeners();
 80219        closeAction.OnTriggered -= OnCloseActionTriggered;
 80220        DataStore.i.exploreV2.isSomeModalOpen.OnChange -= IsSomeModalOpen_OnChange;
 80221        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 222
 80223        if (realmSelectorModal != null)
 47224            realmSelectorModal.Dispose();
 80225    }
 226
 227    public void SetVisible(bool isActive)
 228    {
 2229        if (isActive)
 230        {
 1231            DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true);
 1232            Show();
 233
 1234            ISectionToggle sectionToGo = sectionSelector.GetSection(DataStore.i.exploreV2.currentSectionIndex.Get());
 1235            if (sectionToGo != null && sectionToGo.IsActive())
 1236                GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get());
 237            else
 238            {
 0239                List<ISectionToggle> allSections = sectionSelector.GetAllSections();
 0240                foreach (ISectionToggle section in allSections)
 241                {
 0242                    if (section != null && section.IsActive())
 243                    {
 0244                        section.SelectToggle(true);
 0245                        break;
 246                    }
 247                }
 248            }
 249        }
 250        else
 251        {
 1252            Hide();
 1253            AudioScriptableObjects.dialogClose.Play(true);
 254        }
 1255    }
 256
 257    public void OnAfterShowAnimationCompleted()
 258    {
 0259        DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false);
 0260        OnAfterShowAnimation?.Invoke();
 0261    }
 262
 263    public void GoToSection(ExploreSection section)
 264    {
 7265        if (DataStore.i.exploreV2.currentSectionIndex.Get() != (int)section)
 6266            DataStore.i.exploreV2.currentSectionIndex.Set((int)section);
 267
 7268        sectionSelector.GetSection((int)section)?.SelectToggle(true);
 269
 7270        AudioScriptableObjects.dialogOpen.Play(true);
 7271        AudioScriptableObjects.listItemAppear.ResetPitch();
 7272    }
 273
 24274    public void SetSectionActive(ExploreSection section, bool isActive) { sectionSelector.GetSection((int)section).SetAc
 275
 0276    public bool IsSectionActive(ExploreSection section) { return sectionSelector.GetSection((int)section).IsActive(); }
 277
 278    public void ConfigureEncapsulatedSection(ExploreSection section, BaseVariable<Transform> featureConfiguratorFlag)
 279    {
 5280        FeatureEncapsulatorComponentView sectionView = null;
 281        switch (section)
 282        {
 283            case ExploreSection.Backpack:
 1284                sectionView = backpackSection;
 1285                break;
 286            case ExploreSection.Map:
 1287                sectionView = mapSection;
 1288                break;
 289            case ExploreSection.Builder:
 1290                sectionView = builderSection;
 1291                break;
 292            case ExploreSection.Quest:
 1293                sectionView = questSection;
 1294                break;
 295            case ExploreSection.Settings:
 1296                sectionView = settingsSection;
 297                break;
 298        }
 299
 5300        sectionView?.EncapsulateFeature(featureConfiguratorFlag);
 5301    }
 302
 303    public IEnumerator CreateSectionSelectorMappingsAfterDelay()
 304    {
 40305        yield return null;
 0306        CreateSectionSelectorMappings();
 0307    }
 308
 309    internal void CreateSectionSelectorMappings()
 310    {
 12311        sectionSelector.GetSection((int)ExploreSection.Explore)
 312                       ?.onSelect.AddListener((isOn) =>
 313                       {
 1314                           if (isOn)
 315                           {
 1316                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Explore, false);
 1317                               OnSectionOpen?.Invoke(ExploreSection.Explore);
 318                           }
 1319                       });
 320
 12321        sectionSelector.GetSection((int)ExploreSection.Backpack)
 322                       ?.onSelect.AddListener((isOn) =>
 323                       {
 1324                           if (isOn)
 325                           {
 1326                               backpackSection.Show();
 1327                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Backpack, false);
 1328                               OnSectionOpen?.Invoke(ExploreSection.Backpack);
 1329                           }
 330                           else
 0331                               backpackSection.Hide();
 0332                       });
 333
 12334        sectionSelector.GetSection((int)ExploreSection.Map)
 335                       ?.onSelect.AddListener((isOn) =>
 336                       {
 1337                           if (isOn)
 338                           {
 1339                               mapSection.Show();
 1340                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Map, false);
 1341                               OnSectionOpen?.Invoke(ExploreSection.Map);
 1342                           }
 343                           else
 0344                               mapSection.Hide();
 0345                       });
 346
 12347        sectionSelector.GetSection((int)ExploreSection.Builder)
 348                       ?.onSelect.AddListener((isOn) =>
 349                       {
 1350                           if (isOn)
 351                           {
 1352                               builderSection.Show();
 1353                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Builder, false);
 1354                               OnSectionOpen?.Invoke(ExploreSection.Builder);
 1355                           }
 356                           else
 0357                               builderSection.Hide();
 0358                       });
 359
 12360        sectionSelector.GetSection((int)ExploreSection.Quest)
 361                       ?.onSelect.AddListener((isOn) =>
 362                       {
 1363                           if (isOn)
 364                           {
 1365                               questSection.Show();
 1366                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Quest, false);
 1367                               OnSectionOpen?.Invoke(ExploreSection.Quest);
 1368                           }
 369                           else
 0370                               questSection.Hide();
 0371                       });
 372
 12373        sectionSelector.GetSection((int)ExploreSection.Settings)
 374                       ?.onSelect.AddListener((isOn) =>
 375                       {
 1376                           if (isOn)
 377                           {
 1378                               settingsSection.Show();
 1379                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Settings, false);
 1380                               OnSectionOpen?.Invoke(ExploreSection.Settings);
 1381                           }
 382                           else
 0383                               settingsSection.Hide();
 0384                       });
 12385    }
 386
 387    internal void RemoveSectionSelectorMappings()
 388    {
 86389        sectionSelector.GetSection((int)ExploreSection.Explore)?.onSelect.RemoveAllListeners();
 86390        sectionSelector.GetSection((int)ExploreSection.Backpack)?.onSelect.RemoveAllListeners();
 86391        sectionSelector.GetSection((int)ExploreSection.Map)?.onSelect.RemoveAllListeners();
 86392        sectionSelector.GetSection((int)ExploreSection.Builder)?.onSelect.RemoveAllListeners();
 86393        sectionSelector.GetSection((int)ExploreSection.Quest)?.onSelect.RemoveAllListeners();
 86394        sectionSelector.GetSection((int)ExploreSection.Settings)?.onSelect.RemoveAllListeners();
 86395    }
 396
 397    internal void ConfigureCloseButton()
 398    {
 44399        closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false));
 42400        closeAction.OnTriggered += OnCloseActionTriggered;
 42401        DataStore.i.exploreV2.isSomeModalOpen.OnChange += IsSomeModalOpen_OnChange;
 42402    }
 403
 404    internal void IsSomeModalOpen_OnChange(bool current, bool previous)
 405    {
 0406        closeAction.OnTriggered -= OnCloseActionTriggered;
 407
 0408        if (!current)
 0409            closeAction.OnTriggered += OnCloseActionTriggered;
 0410    }
 411
 6412    internal void OnCloseActionTriggered(DCLAction_Trigger action) { OnCloseButtonPressed?.Invoke(true); }
 413
 414    internal void CheckIfProfileCardShouldBeClosed()
 415    {
 0416        if (!DataStore.i.exploreV2.profileCardIsOpen.Get())
 0417            return;
 418
 0419        if (Input.GetMouseButton(0) &&
 420            !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTranform, Input.mousePosition, Camera.main
 421            !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.expandedMenu, Input.mouse
 422        {
 0423            DataStore.i.exploreV2.profileCardIsOpen.Set(false);
 424        }
 0425    }
 426
 427    /// <summary>
 428    /// Instantiates (if does not already exists) a realm selector modal from the given prefab.
 429    /// </summary>
 430    /// <returns>An instance of a realm modal modal.</returns>
 431    internal RealmSelectorComponentView ConfigureRealmSelectorModal()
 432    {
 41433        RealmSelectorComponentView realmSelectorModal = null;
 434
 41435        GameObject existingModal = GameObject.Find(REALM_SELECTOR_MODAL_ID);
 41436        if (existingModal != null)
 34437            realmSelectorModal = existingModal.GetComponent<RealmSelectorComponentView>();
 438        else
 439        {
 7440            realmSelectorModal = GameObject.Instantiate(realmSelectorModalPrefab);
 7441            realmSelectorModal.name = REALM_SELECTOR_MODAL_ID;
 442        }
 443
 41444        realmSelectorModal.Hide(true);
 445
 41446        return realmSelectorModal;
 447    }
 448
 0449    public void ShowRealmSelectorModal() { realmSelectorModal.Show(); }
 450
 451    internal static ExploreV2MenuComponentView Create()
 452    {
 0453        ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get
 0454        exploreV2View.name = "_ExploreV2";
 455
 0456        return exploreV2View;
 457    }
 458}