< 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:28
Uncovered lines:2
Coverable lines:30
Total lines:71
Line coverage:93.3% (28 of 30)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
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
 15        public override void Initialize(SettingsControlModel controlConfig, SettingsControlController settingsControlCon
 16        {
 17            //we use spinbox control model and control controller for compatibility
 518            SetLabels(((SpinBoxControlModel)controlConfig).spinBoxLabels);
 19
 520            spinBoxController = (SpinBoxSettingsControlController)settingsControlController;
 521            spinBoxController.OnSetLabels += SetLabels;
 522            spinBoxController.OnCurrentLabelChange += SetOption;
 23
 524            base.Initialize(controlConfig, spinBoxController);
 525            spinBoxController.UpdateSetting(dropdown.value);
 26
 527            dropdown.onValueChanged.AddListener(spinBoxValue =>
 28            {
 029                ApplySetting(spinBoxValue);
 030            });
 531        }
 32        private void SetOption(string option)
 33        {
 134            dropdown.captionText.text = option;
 135        }
 36        private void SetLabels(string[] labels)
 37        {
 738            if (labels.Length == 0)
 139                return;
 40
 641            dropdown.ClearOptions();
 3042            List<TMP_Dropdown.OptionData> dropdownOptions = labels.Select(l => new TMP_Dropdown.OptionData(l)).ToList();
 6043            foreach (TMP_Dropdown.OptionData data in dropdownOptions)
 44            {
 2445                dropdown.options.Add(data);
 46            }
 647            dropdown.RefreshShownValue();
 648        }
 49
 50        protected override void OnDestroy()
 51        {
 552            base.OnDestroy();
 53
 554            if (spinBoxController != null)
 55            {
 556                spinBoxController.OnSetLabels -= SetLabels;
 557                spinBoxController.OnCurrentLabelChange -= SetOption;
 58            }
 559        }
 60
 61        public override void RefreshControl()
 62        {
 563            base.RefreshControl();
 64
 565            int newValue = (int)spinBoxController.GetStoredValue();
 566            if (dropdown.value != newValue)
 567                dropdown.value = newValue;
 568        }
 69
 70    }
 71}