< Summary

Class:DCL.SettingsPanelHUD.Controls.DropdownControlView
Assembly:SettingsPanelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/ControlsModule/DropdownControlView.cs
Covered lines:33
Uncovered lines:2
Coverable lines:35
Total lines:83
Line coverage:94.2% (33 of 35)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
Initialize(...)0%110100%
SetOption(...)0%110100%
SetLabels(...)0%440100%
OnDestroy()0%220100%
RefreshControl()0%220100%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using DCL.SettingsCommon.SettingsControllers.BaseControllers;
 4using TMPro;
 5using UnityEngine;
 6
 7namespace DCL.SettingsPanelHUD.Controls
 8{
 9    public class DropdownControlView : SettingsControlView
 10    {
 11        [SerializeField] private TMP_Dropdown dropdown;
 12
 13        private SpinBoxSettingsControlController spinBoxController;
 14        private PointerClickEventInterceptor pointerClick;
 15
 16        private void Awake()
 17        {
 618            pointerClick = dropdown.GetComponent<PointerClickEventInterceptor>();
 619        }
 20
 21        public override void Initialize(SettingsControlModel controlConfig, SettingsControlController settingsControlCon
 22        {
 23            // we use spinbox control model and control controller for compatibility
 624            SetLabels(((SpinBoxControlModel)controlConfig).spinBoxLabels);
 25
 626            spinBoxController = (SpinBoxSettingsControlController)settingsControlController;
 627            spinBoxController.OnSetLabels += SetLabels;
 628            spinBoxController.OnCurrentLabelChange += SetOption;
 29
 630            base.Initialize(controlConfig, spinBoxController);
 631            spinBoxController.UpdateSetting(dropdown.value);
 32
 633            dropdown.onValueChanged.AddListener(spinBoxValue =>
 34            {
 035                ApplySetting(spinBoxValue);
 036            });
 37
 638            pointerClick.PointerClicked += spinBoxController.OnPointerClicked;
 639        }
 40
 41        private void SetOption(string option)
 42        {
 143            dropdown.captionText.text = option;
 144        }
 45        private void SetLabels(string[] labels)
 46        {
 847            if (labels.Length == 0)
 148                return;
 49
 750            dropdown.ClearOptions();
 3151            List<TMP_Dropdown.OptionData> dropdownOptions = labels.Select(l => new TMP_Dropdown.OptionData(l)).ToList();
 6252            foreach (TMP_Dropdown.OptionData data in dropdownOptions)
 53            {
 2454                dropdown.options.Add(data);
 55            }
 56
 757            dropdown.Hide();
 758            dropdown.RefreshShownValue();
 759        }
 60
 61        protected override void OnDestroy()
 62        {
 663            base.OnDestroy();
 664            pointerClick.PointerClicked -= spinBoxController.OnPointerClicked;
 65
 666            if (spinBoxController != null)
 67            {
 668                spinBoxController.OnSetLabels -= SetLabels;
 669                spinBoxController.OnCurrentLabelChange -= SetOption;
 70            }
 671        }
 72
 73        public override void RefreshControl()
 74        {
 675            base.RefreshControl();
 76
 677            int newValue = (int)spinBoxController.GetStoredValue();
 678            if (dropdown.value != newValue)
 579                dropdown.value = newValue;
 680        }
 81
 82    }
 83}