< 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:54
Coverable lines:168
Total lines:471
Line coverage:67.8% (114 of 168)
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%42600%
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    private DataStore_Camera cameraDataStore;
 175
 176    public override void Awake()
 177    {
 40178        base.Awake();
 179
 40180        profileCardRectTranform = profileCard.GetComponent<RectTransform>();
 40181        realmSelectorModal = ConfigureRealmSelectorModal();
 40182        hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud
 40183    }
 184
 185    public void OnDestroy()
 186    {
 40187        hudCanvasCameraModeController?.Dispose();
 40188    }
 189
 190    public override void Start()
 191    {
 40192        DataStore.i.exploreV2.currentSectionIndex.Set((int)DEFAULT_SECTION, false);
 193
 40194        DataStore.i.exploreV2.isInitialized.OnChange += IsInitialized_OnChange;
 40195        IsInitialized_OnChange(DataStore.i.exploreV2.isInitialized.Get(), false);
 196
 40197        ConfigureCloseButton();
 40198    }
 199
 200    private void IsInitialized_OnChange(bool current, bool previous)
 201    {
 40202        if (!current)
 0203            return;
 204
 40205        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 40206        StartCoroutine(CreateSectionSelectorMappingsAfterDelay());
 40207    }
 208
 0209    public override void Update() { CheckIfProfileCardShouldBeClosed(); }
 210
 211    public override void RefreshControl()
 212    {
 0213        placesAndEventsSection.RefreshControl();
 0214        backpackSection.RefreshControl();
 0215        mapSection.RefreshControl();
 0216        builderSection.RefreshControl();
 0217        questSection.RefreshControl();
 0218        settingsSection.RefreshControl();
 0219    }
 220
 221    public override void Dispose()
 222    {
 40223        base.Dispose();
 224
 40225        RemoveSectionSelectorMappings();
 40226        closeMenuButton.onClick.RemoveAllListeners();
 40227        closeAction.OnTriggered -= OnCloseActionTriggered;
 40228        DataStore.i.exploreV2.isSomeModalOpen.OnChange -= IsSomeModalOpen_OnChange;
 40229        DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange;
 230
 40231        if (realmSelectorModal != null)
 40232            realmSelectorModal.Dispose();
 40233    }
 234
 235    public void SetVisible(bool isActive)
 236    {
 2237        if (isActive)
 238        {
 1239            DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true);
 1240            Show();
 241
 1242            ISectionToggle sectionToGo = sectionSelector.GetSection(DataStore.i.exploreV2.currentSectionIndex.Get());
 1243            if (sectionToGo != null && sectionToGo.IsActive())
 1244                GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get());
 245            else
 246            {
 0247                List<ISectionToggle> allSections = sectionSelector.GetAllSections();
 0248                foreach (ISectionToggle section in allSections)
 249                {
 0250                    if (section != null && section.IsActive())
 251                    {
 0252                        section.SelectToggle(true);
 0253                        break;
 254                    }
 255                }
 256            }
 257        }
 258        else
 259        {
 1260            Hide();
 1261            AudioScriptableObjects.dialogClose.Play(true);
 262        }
 1263    }
 264
 265    public void OnAfterShowAnimationCompleted()
 266    {
 0267        if(!DataStore.i.exploreV2.isOpen.Get())
 0268            return;
 269
 0270        DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false);
 0271        OnAfterShowAnimation?.Invoke();
 0272    }
 273
 274    public void GoToSection(ExploreSection section)
 275    {
 7276        if (DataStore.i.exploreV2.currentSectionIndex.Get() != (int)section)
 6277            DataStore.i.exploreV2.currentSectionIndex.Set((int)section);
 278
 7279        sectionSelector.GetSection((int)section)?.SelectToggle(true);
 280
 7281        AudioScriptableObjects.dialogOpen.Play(true);
 7282        AudioScriptableObjects.listItemAppear.ResetPitch();
 7283    }
 284
 24285    public void SetSectionActive(ExploreSection section, bool isActive) { sectionSelector.GetSection((int)section).SetAc
 286
 0287    public bool IsSectionActive(ExploreSection section) { return sectionSelector.GetSection((int)section).IsActive(); }
 288
 289    public void ConfigureEncapsulatedSection(ExploreSection section, BaseVariable<Transform> featureConfiguratorFlag)
 290    {
 5291        FeatureEncapsulatorComponentView sectionView = null;
 292        switch (section)
 293        {
 294            case ExploreSection.Backpack:
 1295                sectionView = backpackSection;
 1296                break;
 297            case ExploreSection.Map:
 1298                sectionView = mapSection;
 1299                break;
 300            case ExploreSection.Builder:
 1301                sectionView = builderSection;
 1302                break;
 303            case ExploreSection.Quest:
 1304                sectionView = questSection;
 1305                break;
 306            case ExploreSection.Settings:
 1307                sectionView = settingsSection;
 308                break;
 309        }
 310
 5311        sectionView?.EncapsulateFeature(featureConfiguratorFlag);
 5312    }
 313
 314    public IEnumerator CreateSectionSelectorMappingsAfterDelay()
 315    {
 40316        yield return null;
 0317        CreateSectionSelectorMappings();
 0318    }
 319
 320    internal void CreateSectionSelectorMappings()
 321    {
 12322        sectionSelector.GetSection((int)ExploreSection.Explore)
 323                       ?.onSelect.AddListener((isOn) =>
 324                       {
 1325                           if (isOn)
 326                           {
 1327                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Explore, false);
 1328                               OnSectionOpen?.Invoke(ExploreSection.Explore);
 329                           }
 1330                       });
 331
 12332        sectionSelector.GetSection((int)ExploreSection.Backpack)
 333                       ?.onSelect.AddListener((isOn) =>
 334                       {
 1335                           if (isOn)
 336                           {
 1337                               backpackSection.Show();
 1338                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Backpack, false);
 1339                               OnSectionOpen?.Invoke(ExploreSection.Backpack);
 1340                           }
 341                           else
 0342                               backpackSection.Hide();
 0343                       });
 344
 12345        sectionSelector.GetSection((int)ExploreSection.Map)
 346                       ?.onSelect.AddListener((isOn) =>
 347                       {
 1348                           if (isOn)
 349                           {
 1350                               mapSection.Show();
 1351                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Map, false);
 1352                               OnSectionOpen?.Invoke(ExploreSection.Map);
 1353                           }
 354                           else
 0355                               mapSection.Hide();
 0356                       });
 357
 12358        sectionSelector.GetSection((int)ExploreSection.Builder)
 359                       ?.onSelect.AddListener((isOn) =>
 360                       {
 1361                           if (isOn)
 362                           {
 1363                               builderSection.Show();
 1364                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Builder, false);
 1365                               OnSectionOpen?.Invoke(ExploreSection.Builder);
 1366                           }
 367                           else
 0368                               builderSection.Hide();
 0369                       });
 370
 12371        sectionSelector.GetSection((int)ExploreSection.Quest)
 372                       ?.onSelect.AddListener((isOn) =>
 373                       {
 1374                           if (isOn)
 375                           {
 1376                               questSection.Show();
 1377                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Quest, false);
 1378                               OnSectionOpen?.Invoke(ExploreSection.Quest);
 1379                           }
 380                           else
 0381                               questSection.Hide();
 0382                       });
 383
 12384        sectionSelector.GetSection((int)ExploreSection.Settings)
 385                       ?.onSelect.AddListener((isOn) =>
 386                       {
 1387                           if (isOn)
 388                           {
 1389                               settingsSection.Show();
 1390                               DataStore.i.exploreV2.currentSectionIndex.Set((int)ExploreSection.Settings, false);
 1391                               OnSectionOpen?.Invoke(ExploreSection.Settings);
 1392                           }
 393                           else
 0394                               settingsSection.Hide();
 0395                       });
 12396    }
 397
 398    internal void RemoveSectionSelectorMappings()
 399    {
 46400        sectionSelector.GetSection((int)ExploreSection.Explore)?.onSelect.RemoveAllListeners();
 46401        sectionSelector.GetSection((int)ExploreSection.Backpack)?.onSelect.RemoveAllListeners();
 46402        sectionSelector.GetSection((int)ExploreSection.Map)?.onSelect.RemoveAllListeners();
 46403        sectionSelector.GetSection((int)ExploreSection.Builder)?.onSelect.RemoveAllListeners();
 46404        sectionSelector.GetSection((int)ExploreSection.Quest)?.onSelect.RemoveAllListeners();
 46405        sectionSelector.GetSection((int)ExploreSection.Settings)?.onSelect.RemoveAllListeners();
 46406    }
 407
 408    internal void ConfigureCloseButton()
 409    {
 44410        closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false));
 42411        closeAction.OnTriggered += OnCloseActionTriggered;
 42412        DataStore.i.exploreV2.isSomeModalOpen.OnChange += IsSomeModalOpen_OnChange;
 42413    }
 414
 415    internal void IsSomeModalOpen_OnChange(bool current, bool previous)
 416    {
 28417        closeAction.OnTriggered -= OnCloseActionTriggered;
 418
 28419        if (!current)
 14420            closeAction.OnTriggered += OnCloseActionTriggered;
 28421    }
 422
 6423    internal void OnCloseActionTriggered(DCLAction_Trigger action) { OnCloseButtonPressed?.Invoke(true); }
 424
 425    internal void CheckIfProfileCardShouldBeClosed()
 426    {
 0427        if (!DataStore.i.exploreV2.profileCardIsOpen.Get())
 0428            return;
 429
 0430        cameraDataStore ??= DataStore.i.camera;
 431
 0432        if (Input.GetMouseButton(0) &&
 433            !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTranform, Input.mousePosition, cameraDataS
 434            !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.expandedMenu, Input.mouse
 435        {
 0436            DataStore.i.exploreV2.profileCardIsOpen.Set(false);
 437        }
 0438    }
 439
 440    /// <summary>
 441    /// Instantiates (if does not already exists) a realm selector modal from the given prefab.
 442    /// </summary>
 443    /// <returns>An instance of a realm modal modal.</returns>
 444    internal RealmSelectorComponentView ConfigureRealmSelectorModal()
 445    {
 41446        RealmSelectorComponentView realmSelectorModal = null;
 447
 41448        GameObject existingModal = GameObject.Find(REALM_SELECTOR_MODAL_ID);
 41449        if (existingModal != null)
 34450            realmSelectorModal = existingModal.GetComponent<RealmSelectorComponentView>();
 451        else
 452        {
 7453            realmSelectorModal = GameObject.Instantiate(realmSelectorModalPrefab);
 7454            realmSelectorModal.name = REALM_SELECTOR_MODAL_ID;
 455        }
 456
 41457        realmSelectorModal.Hide(true);
 458
 41459        return realmSelectorModal;
 460    }
 461
 0462    public void ShowRealmSelectorModal() { realmSelectorModal.Show(); }
 463
 464    internal static ExploreV2MenuComponentView Create()
 465    {
 0466        ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get
 0467        exploreV2View.name = "_ExploreV2";
 468
 0469        return exploreV2View;
 470    }
 471}