< Summary

Class:PlacesAndEventsSectionComponentView
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/PlacesAndEventsSectionComponentView.cs
Covered lines:47
Uncovered lines:13
Coverable lines:60
Total lines:151
Line coverage:78.3% (47 of 60)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlacesAndEventsSectionComponentView()0%110100%
Awake()0%110100%
Start()0%110100%
GoToSubsection(...)0%220100%
SetActive(...)0%6.056088.89%
RefreshControl()0%2100%
Dispose()0%110100%
CreateSubSectionSelectorMappings()0%660100%
RemoveSectionSelectorMappings()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Sections/PlacesAndEventsSection/PlacesAndEventsSectionComponentView.cs

#LineLine coverage
 1using DCL;
 2using UnityEngine;
 3
 4public interface IPlacesAndEventsSectionComponentView
 5{
 6    /// <summary>
 7    /// Highlights sub-section component.
 8    /// </summary>
 9    IHighlightsSubSectionComponentView HighlightsSubSectionView { get; }
 10
 11    /// <summary>
 12    /// Places sub-section component.
 13    /// </summary>
 14    IPlacesSubSectionComponentView PlacesSubSectionView { get; }
 15
 16    /// <summary>
 17    /// Events sub-section component.
 18    /// </summary>
 19    IEventsSubSectionComponentView EventsSubSectionView { get; }
 20
 21    /// <summary>
 22    /// Favorites sub-section component.
 23    /// </summary>
 24    IFavoritesSubSectionComponentView FavoritesSubSectionView { get; }
 25
 26    /// <summary>
 27    /// Open a sub-section.
 28    /// </summary>
 29    /// <param name="subSectionIndex">Sub-section index.</param>
 30    void GoToSubsection(int subSectionIndex);
 31
 32    /// <summary>
 33    /// Activates/deactivates the section.
 34    /// </summary>
 35    /// <param name="isActive"></param>
 36    void SetActive(bool isActive);
 37}
 38
 39public class PlacesAndEventsSectionComponentView : BaseComponentView, IPlacesAndEventsSectionComponentView
 40{
 41    internal const int HIGHLIGHTS_SUB_SECTION_INDEX = 0;
 42    internal const int PLACES_SUB_SECTION_INDEX = 1;
 43    internal const int EVENTS_SUB_SECTION_INDEX = 2;
 44    internal const int FAVORITES_SUB_SECTION_INDEX = 3;
 45
 46    [Header("Top Menu")]
 47    [SerializeField] internal SectionSelectorComponentView subSectionSelector;
 48
 49    [Header("Sub-Sections")]
 50    [SerializeField] internal HighlightsSubSectionComponentView highlightsSubSection;
 51    [SerializeField] internal PlacesSubSectionComponentView placesSubSection;
 52    [SerializeField] internal EventsSubSectionComponentView eventsSubSection;
 53    [SerializeField] internal FavoritesSubSectionComponentView favoritesSubSection;
 54
 55    private Canvas canvas;
 4256    private int currentSelectedIndex = -1;
 57
 58    public override void Awake()
 59    {
 4060        base.Awake();
 4061        canvas = GetComponent<Canvas>();
 4062    }
 63
 64    public override void Start()
 65    {
 3966        CreateSubSectionSelectorMappings();
 3967        SetActive(false);
 3968    }
 69
 070    public IHighlightsSubSectionComponentView HighlightsSubSectionView => highlightsSubSection;
 071    public IPlacesSubSectionComponentView PlacesSubSectionView => placesSubSection;
 072    public IEventsSubSectionComponentView EventsSubSectionView => eventsSubSection;
 073    public IFavoritesSubSectionComponentView FavoritesSubSectionView => favoritesSubSection;
 74
 75    public void GoToSubsection(int subSectionIndex) =>
 376        subSectionSelector.GetSection(subSectionIndex)?.SelectToggle(reselectIfAlreadyOn: true);
 77
 78    public void SetActive(bool isActive)
 79    {
 4180        canvas.enabled = isActive;
 81
 82        //Temporary untill the full feature is released
 4183        if(DataStore.i.HUDs.enableFavoritePlaces.Get())
 084            subSectionSelector.EnableSection(FAVORITES_SUB_SECTION_INDEX);
 85        else
 4186            subSectionSelector.DisableSection(FAVORITES_SUB_SECTION_INDEX);
 87
 4188        highlightsSubSection.SetActive(isActive && currentSelectedIndex == HIGHLIGHTS_SUB_SECTION_INDEX);
 4189        placesSubSection.SetActive(isActive && currentSelectedIndex == PLACES_SUB_SECTION_INDEX);
 4190        eventsSubSection.SetActive(isActive && currentSelectedIndex == EVENTS_SUB_SECTION_INDEX);
 4191        favoritesSubSection.SetActive(isActive && currentSelectedIndex == FAVORITES_SUB_SECTION_INDEX);
 4192    }
 93
 94    public override void RefreshControl()
 95    {
 096        highlightsSubSection.RefreshControl();
 097        placesSubSection.RefreshControl();
 098        eventsSubSection.RefreshControl();
 099        favoritesSubSection.RefreshControl();
 0100    }
 101
 102    public override void Dispose()
 103    {
 51104        base.Dispose();
 105
 51106        RemoveSectionSelectorMappings();
 51107        highlightsSubSection.Dispose();
 51108        placesSubSection.Dispose();
 51109        eventsSubSection.Dispose();
 51110        favoritesSubSection.Dispose();
 51111    }
 112
 113    internal void CreateSubSectionSelectorMappings()
 114    {
 45115        subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 116        {
 53117            highlightsSubSection.SetActive(isActive);
 53118            currentSelectedIndex = HIGHLIGHTS_SUB_SECTION_INDEX;
 53119        });
 45120        subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 121        {
 3122            placesSubSection.SetActive(isActive);
 3123            currentSelectedIndex = PLACES_SUB_SECTION_INDEX;
 3124        });
 45125        subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 126        {
 3127            eventsSubSection.SetActive(isActive);
 3128            currentSelectedIndex = EVENTS_SUB_SECTION_INDEX;
 3129        });
 45130        subSectionSelector.GetSection(FAVORITES_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) =>
 131        {
 0132            favoritesSubSection.SetActive(isActive);
 0133            currentSelectedIndex = FAVORITES_SUB_SECTION_INDEX;
 0134        });
 135
 45136        placesSubSection.SetActive(false);
 45137        eventsSubSection.SetActive(false);
 45138        highlightsSubSection.SetActive(false);
 45139        favoritesSubSection.SetActive(false);
 140
 45141        subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.SelectToggle(reselectIfAlreadyOn: true);
 45142    }
 143
 144    internal void RemoveSectionSelectorMappings()
 145    {
 54146        subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 54147        subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 54148        subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 54149        subSectionSelector.GetSection(FAVORITES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners();
 54150    }
 151}