< Summary

Class:DCL.SettingsPanelHUD.SettingsPanelHUDController
Assembly:SettingsPanelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/SettingsPanelHUDController.cs
Covered lines:48
Uncovered lines:18
Coverable lines:66
Total lines:213
Line coverage:72.7% (48 of 66)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SettingsPanelHUDController()0%110100%
Initialize()0%110100%
CreateView()0%110100%
Dispose()0%220100%
SetVisibility(...)0%110100%
OnSettingsPanelVisibleChanged(...)0%110100%
SetVisibility_Internal(...)0%8.147071.43%
AddSection(...)0%330100%
OpenSection(...)0%6200%
OpenSection(...)0%220100%
MarkMenuButtonAsSelected(...)0%220100%
SaveSettings()0%110100%
ResetAllSettings()0%2100%
SetTutorialButtonEnabled(...)0%2100%
AddHelpAndSupportWindow(...)0%3.333066.67%
ConfigureSettingsInFullscreenMenuChanged(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/SettingsPanelHUDController.cs

#LineLine coverage
 1using DCL.SettingsPanelHUD.Sections;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL.SettingsCommon;
 5using UnityEngine;
 6using DCL.HelpAndSupportHUD;
 7
 8namespace DCL.SettingsPanelHUD
 9{
 10    /// <summary>
 11    /// Interface to implement a controller for the main settings panel.
 12    /// </summary>
 13    public interface ISettingsPanelHUDController
 14    {
 15        event System.Action OnRestartTutorial;
 16
 17        /// <summary>
 18        /// List of all SECTIONS added to the main settings panel.
 19        /// </summary>
 20        List<ISettingsSectionView> sections { get; }
 21
 22        /// <summary>
 23        /// All the needed logic to initializes the controller and its associated view, and make them works.
 24        /// </summary>
 25        void Initialize();
 26
 27        /// <summary>
 28        /// Adds a SECTION into the main settings panel.
 29        /// </summary>
 30        /// <param name="newMenuButton">MonoBehaviour that will represent the menu button associated to the new SECTION.
 31        /// <param name="newSection">New SECTION that will be added.</param>
 32        /// <param name="newSectionController">Controller belonging to the new SECTION.</param>
 33        /// <param name="sectionConfig">Model that will contain the configuration of the new SECTION.</param>
 34        void AddSection(SettingsButtonEntry newMenuButton, ISettingsSectionView newSection, ISettingsSectionController n
 35
 36        /// <summary>
 37        /// Opens a specific SECTION of the main settings panel.
 38        /// </summary>
 39        /// <param name="sectionToOpen">SECTION to be opened.</param>
 40        void OpenSection(ISettingsSectionView sectionToOpen);
 41
 42        /// <summary>
 43        /// Opens a specific SECTION of the main settings panel.
 44        /// </summary>
 45        /// <param name="sectionIndex">SECTION index to be opened. The index must be less than the section list length.<
 46        void OpenSection(int sectionIndex);
 47
 48        /// <summary>
 49        /// Mark a specific menu button as selected.
 50        /// </summary>
 51        /// <param name="buttonIndex">Menu button index to be selected.</param>
 52        void MarkMenuButtonAsSelected(int buttonIndex);
 53
 54        /// <summary>
 55        /// Save all the current settings values.
 56        /// </summary>
 57        void SaveSettings();
 58
 59        /// <summary>
 60        /// Reset all the current settings to their default values.
 61        /// </summary>
 62        void ResetAllSettings();
 63
 64        /// <summary>
 65        /// Set the tutorial button as enabled/disabled.
 66        /// </summary>
 67        /// <param name="isEnabled">True for set it as enabled.</param>
 68        void SetTutorialButtonEnabled(bool isEnabled);
 69    }
 70
 71    /// <summary>
 72    /// This controller is in charge of manage all the logic related to the main settings panel.
 73    /// </summary>
 74    public class SettingsPanelHUDController : IHUD, ISettingsPanelHUDController
 75    {
 076        public SettingsPanelHUDView view { get; private set; }
 77
 78        public event System.Action OnOpen;
 79        public event System.Action OnClose;
 80
 181        public List<ISettingsSectionView> sections { get; } = new List<ISettingsSectionView>();
 82
 183        private List<SettingsButtonEntry> menuButtons = new List<SettingsButtonEntry>();
 84        private HelpAndSupportHUDController helpAndSupportHud;
 85
 486        BaseVariable<bool> settingsPanelVisible => DataStore.i.settings.settingsPanelVisible;
 387        BaseVariable<Transform> configureSettingsInFullscreenMenu => DataStore.i.exploreV2.configureSettingsInFullscreen
 88
 89        public event System.Action OnRestartTutorial;
 90
 91        public void Initialize()
 92        {
 193            view = CreateView();
 194            view.Initialize(this, this);
 95
 196            view.OnRestartTutorial += () =>
 97            {
 098                OnRestartTutorial?.Invoke();
 099                DataStore.i.exploreV2.isOpen.Set(false);
 0100            };
 101
 1102            view.OnHelpAndSupportClicked += () => helpAndSupportHud.SetVisibility(true);
 103
 1104            settingsPanelVisible.OnChange += OnSettingsPanelVisibleChanged;
 1105            OnSettingsPanelVisibleChanged(settingsPanelVisible.Get(), false);
 106
 1107            configureSettingsInFullscreenMenu.OnChange += ConfigureSettingsInFullscreenMenuChanged;
 1108            ConfigureSettingsInFullscreenMenuChanged(configureSettingsInFullscreenMenu.Get(), null);
 109
 1110            DataStore.i.settings.isInitialized.Set(true);
 1111        }
 1112        protected virtual SettingsPanelHUDView CreateView() { return SettingsPanelHUDView.Create(); }
 113
 114        public void Dispose()
 115        {
 1116            settingsPanelVisible.OnChange -= OnSettingsPanelVisibleChanged;
 1117            configureSettingsInFullscreenMenu.OnChange -= ConfigureSettingsInFullscreenMenuChanged;
 118
 1119            if (view != null)
 1120                UnityEngine.Object.Destroy(view.gameObject);
 1121        }
 122
 2123        public void SetVisibility(bool visible) { settingsPanelVisible.Set(visible); }
 124
 4125        private void OnSettingsPanelVisibleChanged(bool current, bool previous) { SetVisibility_Internal(current); }
 126
 127        public void SetVisibility_Internal(bool visible)
 128        {
 2129            if (!visible && view.isOpen)
 130            {
 0131                OnClose?.Invoke();
 0132            }
 2133            else if (visible && !view.isOpen)
 134            {
 1135                OnOpen?.Invoke();
 136            }
 137
 2138            view.SetVisibility(visible);
 2139        }
 140
 141        public void AddSection(
 142            SettingsButtonEntry newMenuButton,
 143            ISettingsSectionView newSection,
 144            ISettingsSectionController newSectionController,
 145            SettingsSectionModel sectionConfig)
 146        {
 3147            newMenuButton?.Initialize(sectionConfig.icon, sectionConfig.text);
 148
 3149            newSection.Initialize(newSectionController, sectionConfig.widgets.ToList());
 3150            newSection.SetActive(false);
 3151            sections.Add(newSection);
 152
 3153            newMenuButton?.ConfigureAction(() =>
 154            {
 0155                foreach (var button in menuButtons)
 156                {
 0157                    button.MarkAsSelected(false);
 158                }
 0159                newMenuButton.MarkAsSelected(true);
 160
 0161                OpenSection(newSection);
 0162            });
 163
 3164            menuButtons.Add(newMenuButton);
 3165        }
 166
 167        public void OpenSection(ISettingsSectionView sectionToOpen)
 168        {
 0169            foreach (var section in sections)
 170            {
 0171                section.SetActive(section == sectionToOpen);
 172            }
 0173        }
 174
 175        public void OpenSection(int sectionIndex)
 176        {
 16177            for (int i = 0; i < sections.Count; i++)
 178            {
 6179                var section = sections[i];
 6180                section.SetActive(i == sectionIndex);
 181            }
 2182        }
 183
 184        public void MarkMenuButtonAsSelected(int buttonIndex)
 185        {
 16186            for (int i = 0; i < menuButtons.Count; i++)
 187            {
 6188                var button = menuButtons[i];
 6189                button.MarkAsSelected(i == buttonIndex);
 190            }
 2191        }
 192
 2193        public virtual void SaveSettings() { Settings.i.SaveSettings(); }
 194
 0195        public void ResetAllSettings() { Settings.i.ResetAllSettings(); }
 196
 0197        public void SetTutorialButtonEnabled(bool isEnabled) { view.SetTutorialButtonEnabled(isEnabled); }
 198
 199        public void AddHelpAndSupportWindow(HelpAndSupportHUDController controller)
 200        {
 1201            if (controller == null || controller.view == null)
 202            {
 0203                Debug.LogWarning("AddHelpAndSupportWindow >>> Help and Support window doesn't exist yet!");
 0204                return;
 205            }
 206
 1207            helpAndSupportHud = controller;
 1208            view.OnAddHelpAndSupportWindow();
 1209        }
 210
 2211        private void ConfigureSettingsInFullscreenMenuChanged(Transform currentParentTransform, Transform previousParent
 212    }
 213}