< 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:114
Uncovered lines:53
Coverable lines:167
Total lines:468
Line coverage:68.2% (114 of 167)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
OnDestroy()0%220100%
Start()0%110100%
IsInitialized_OnChange(...)0%2.032080%
Update()0%2100%
RefreshControl()0%2100%
Dispose()0%220100%
SetVisible(...)0%11.17056.25%
OnAfterShowAnimationCompleted()0%12300%
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%220100%
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    internal HUDCanvasCameraModeController hudCanvasCameraModeController;
 174
 175    public override void Awake()
 176    {
 40177        base.Awake();
 178
 40179        profileCardRectTranform = profileCard.GetComponent<RectTransform>();
 40180        realmSelectorModal = ConfigureRealmSelectorModal();
 40181        hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud
 40182    }
 183
 184    public void OnDestroy()
 185    {
 40186        hudCanvasCameraModeController?.Dispose();
 40187    }
 188
 189    public override void Start()
 190    {
 40191        DataStore.i.exploreV2.currentSectionIndex.Set((int)DEFAULT_SECTION, false);
 192
 40193        DataStore.i.exploreV2.isInitialized.OnChange += IsInitialized_OnChange;
 40194        IsInitialized_OnChange(DataStore.i.exploreV2.isInitialized.Get(), false);
 195
 40196        ConfigureCloseButton();
 40197    }
 198
 199    private void IsInitialized_OnChange(bool current, bool previous)
 200    {
 40201        if (!current)
 0202            return;
 203
 40204        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 40205        StartCoroutine(CreateSectionSelectorMappingsAfterDelay());
 40206    }
 207
 0208    public override void Update() { CheckIfProfileCardShouldBeClosed(); }
 209
 210    public override void RefreshControl()
 211    {
 0212        placesAndEventsSection.RefreshControl();
 0213        backpackSection.RefreshControl();
 0214        mapSection.RefreshControl();
 0215        builderSection.RefreshControl();
 0216        questSection.RefreshControl();
 0217        settingsSection.RefreshControl();
 0218    }
 219
 220    public override void Dispose()
 221    {
 40222        base.Dispose();
 223
 40224        RemoveSectionSelectorMappings();
 40225        closeMenuButton.onClick.RemoveAllListeners();
 40226        closeAction.OnTriggered -= OnCloseActionTriggered;
 40227        DataStore.i.exploreV2.isSomeModalOpen.OnChange -= IsSomeModalOpen_OnChange;
 40228        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 229
 40230        if (realmSelectorModal != null)
 40231            realmSelectorModal.Dispose();
 40232    }
 233
 234    public void SetVisible(bool isActive)
 235    {
 2236        if (isActive)
 237        {
 1238            DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true);
 1239            Show();
 240
 1241            ISectionToggle sectionToGo = sectionSelector.GetSection(DataStore.i.exploreV2.currentSectionIndex.Get());
 1242            if (sectionToGo != null && sectionToGo.IsActive())
 1243                GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get());
 244            else
 245            {
 0246                List<ISectionToggle> allSections = sectionSelector.GetAllSections();
 0247                foreach (ISectionToggle section in allSections)
 248                {
 0249                    if (section != null && section.IsActive())
 250                    {
 0251                        section.SelectToggle(true);
 0252                        break;
 253                    }
 254                }
 255            }
 256        }
 257        else
 258        {
 1259            Hide();
 1260            AudioScriptableObjects.dialogClose.Play(true);
 261        }
 1262    }
 263
 264    public void OnAfterShowAnimationCompleted()
 265    {
 0266        if(!DataStore.i.exploreV2.isOpen.Get())
 0267            return;
 268
 0269        DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false);
 0270        OnAfterShowAnimation?.Invoke();
 0271    }
 272
 273    public void GoToSection(ExploreSection section)
 274    {
 7275        if (DataStore.i.exploreV2.currentSectionIndex.Get() != (int)section)
 6276            DataStore.i.exploreV2.currentSectionIndex.Set((int)section);
 277
 7278        sectionSelector.GetSection((int)section)?.SelectToggle(true);
 279
 7280        AudioScriptableObjects.dialogOpen.Play(true);
 7281        AudioScriptableObjects.listItemAppear.ResetPitch();
 7282    }
 283
 24284    public void SetSectionActive(ExploreSection section, bool isActive) { sectionSelector.GetSection((int)section).SetAc
 285
 0286    public bool IsSectionActive(ExploreSection section) { return sectionSelector.GetSection((int)section).IsActive(); }
 287
 288    public void ConfigureEncapsulatedSection(ExploreSection section, BaseVariable<Transform> featureConfiguratorFlag)
 289    {
 5290        FeatureEncapsulatorComponentView sectionView = null;
 291        switch (section)
 292        {
 293            case ExploreSection.Backpack:
 1294                sectionView = backpackSection;
 1295                break;
 296            case ExploreSection.Map:
 1297                sectionView = mapSection;
 1298                break;
 299            case ExploreSection.Builder:
 1300                sectionView = builderSection;
 1301                break;
 302            case ExploreSection.Quest:
 1303                sectionView = questSection;
 1304                break;
 305            case ExploreSection.Settings:
 1306                sectionView = settingsSection;
 307                break;
 308        }
 309
 5310        sectionView?.EncapsulateFeature(featureConfiguratorFlag);
 5311    }
 312
 313    public IEnumerator CreateSectionSelectorMappingsAfterDelay()
 314    {
 40315        yield return null;
 0316        CreateSectionSelectorMappings();
 0317    }
 318
 319    internal void CreateSectionSelectorMappings()
 320    {
 12321        sectionSelector.GetSection((int)ExploreSection.Explore)
 322                       ?.onSelect.AddListener((isOn) =>
 323                       {
 1324                           if (isOn)
 325                           {
 1326                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Explore, false);
 1327                               OnSectionOpen?.Invoke(ExploreSection.Explore);
 328                           }
 1329                       });
 330
 12331        sectionSelector.GetSection((int)ExploreSection.Backpack)
 332                       ?.onSelect.AddListener((isOn) =>
 333                       {
 1334                           if (isOn)
 335                           {
 1336                               backpackSection.Show();
 1337                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Backpack, false);
 1338                               OnSectionOpen?.Invoke(ExploreSection.Backpack);
 1339                           }
 340                           else
 0341                               backpackSection.Hide();
 0342                       });
 343
 12344        sectionSelector.GetSection((int)ExploreSection.Map)
 345                       ?.onSelect.AddListener((isOn) =>
 346                       {
 1347                           if (isOn)
 348                           {
 1349                               mapSection.Show();
 1350                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Map, false);
 1351                               OnSectionOpen?.Invoke(ExploreSection.Map);
 1352                           }
 353                           else
 0354                               mapSection.Hide();
 0355                       });
 356
 12357        sectionSelector.GetSection((int)ExploreSection.Builder)
 358                       ?.onSelect.AddListener((isOn) =>
 359                       {
 1360                           if (isOn)
 361                           {
 1362                               builderSection.Show();
 1363                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Builder, false);
 1364                               OnSectionOpen?.Invoke(ExploreSection.Builder);
 1365                           }
 366                           else
 0367                               builderSection.Hide();
 0368                       });
 369
 12370        sectionSelector.GetSection((int)ExploreSection.Quest)
 371                       ?.onSelect.AddListener((isOn) =>
 372                       {
 1373                           if (isOn)
 374                           {
 1375                               questSection.Show();
 1376                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Quest, false);
 1377                               OnSectionOpen?.Invoke(ExploreSection.Quest);
 1378                           }
 379                           else
 0380                               questSection.Hide();
 0381                       });
 382
 12383        sectionSelector.GetSection((int)ExploreSection.Settings)
 384                       ?.onSelect.AddListener((isOn) =>
 385                       {
 1386                           if (isOn)
 387                           {
 1388                               settingsSection.Show();
 1389                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Settings, false);
 1390                               OnSectionOpen?.Invoke(ExploreSection.Settings);
 1391                           }
 392                           else
 0393                               settingsSection.Hide();
 0394                       });
 12395    }
 396
 397    internal void RemoveSectionSelectorMappings()
 398    {
 46399        sectionSelector.GetSection((int)ExploreSection.Explore)?.onSelect.RemoveAllListeners();
 46400        sectionSelector.GetSection((int)ExploreSection.Backpack)?.onSelect.RemoveAllListeners();
 46401        sectionSelector.GetSection((int)ExploreSection.Map)?.onSelect.RemoveAllListeners();
 46402        sectionSelector.GetSection((int)ExploreSection.Builder)?.onSelect.RemoveAllListeners();
 46403        sectionSelector.GetSection((int)ExploreSection.Quest)?.onSelect.RemoveAllListeners();
 46404        sectionSelector.GetSection((int)ExploreSection.Settings)?.onSelect.RemoveAllListeners();
 46405    }
 406
 407    internal void ConfigureCloseButton()
 408    {
 44409        closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false));
 42410        closeAction.OnTriggered += OnCloseActionTriggered;
 42411        DataStore.i.exploreV2.isSomeModalOpen.OnChange += IsSomeModalOpen_OnChange;
 42412    }
 413
 414    internal void IsSomeModalOpen_OnChange(bool current, bool previous)
 415    {
 28416        closeAction.OnTriggered -= OnCloseActionTriggered;
 417
 28418        if (!current)
 14419            closeAction.OnTriggered += OnCloseActionTriggered;
 28420    }
 421
 6422    internal void OnCloseActionTriggered(DCLAction_Trigger action) { OnCloseButtonPressed?.Invoke(true); }
 423
 424    internal void CheckIfProfileCardShouldBeClosed()
 425    {
 0426        if (!DataStore.i.exploreV2.profileCardIsOpen.Get())
 0427            return;
 428
 0429        if (Input.GetMouseButton(0) &&
 430            !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTranform, Input.mousePosition, Camera.main
 431            !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.expandedMenu, Input.mouse
 432        {
 0433            DataStore.i.exploreV2.profileCardIsOpen.Set(false);
 434        }
 0435    }
 436
 437    /// <summary>
 438    /// Instantiates (if does not already exists) a realm selector modal from the given prefab.
 439    /// </summary>
 440    /// <returns>An instance of a realm modal modal.</returns>
 441    internal RealmSelectorComponentView ConfigureRealmSelectorModal()
 442    {
 41443        RealmSelectorComponentView realmSelectorModal = null;
 444
 41445        GameObject existingModal = GameObject.Find(REALM_SELECTOR_MODAL_ID);
 41446        if (existingModal != null)
 34447            realmSelectorModal = existingModal.GetComponent<RealmSelectorComponentView>();
 448        else
 449        {
 7450            realmSelectorModal = GameObject.Instantiate(realmSelectorModalPrefab);
 7451            realmSelectorModal.name = REALM_SELECTOR_MODAL_ID;
 452        }
 453
 41454        realmSelectorModal.Hide(true);
 455
 41456        return realmSelectorModal;
 457    }
 458
 0459    public void ShowRealmSelectorModal() { realmSelectorModal.Show(); }
 460
 461    internal static ExploreV2MenuComponentView Create()
 462    {
 0463        ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get
 0464        exploreV2View.name = "_ExploreV2";
 465
 0466        return exploreV2View;
 467    }
 468}