< 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
 418            SetLabels(((SpinBoxControlModel)controlConfig).spinBoxLabels);
 19
 420            spinBoxController = (SpinBoxSettingsControlController)settingsControlController;
 421            spinBoxController.OnSetLabels += SetLabels;
 422            spinBoxController.OnCurrentLabelChange += SetOption;
 23
 424            base.Initialize(controlConfig, spinBoxController);
 425            spinBoxController.UpdateSetting(dropdown.value);
 26
 427            dropdown.onValueChanged.AddListener(spinBoxValue =>
 28            {
 029                ApplySetting(spinBoxValue);
 030            });
 431        }
 32        private void SetOption(string option)
 33        {
 134            dropdown.captionText.text = option;
 135        }
 36        private void SetLabels(string[] labels)
 37        {
 638            if (labels.Length == 0)
 139                return;
 40
 541            dropdown.ClearOptions();
 2642            List<TMP_Dropdown.OptionData> dropdownOptions = labels.Select(l => new TMP_Dropdown.OptionData(l)).ToList();
 5243            foreach (TMP_Dropdown.OptionData data in dropdownOptions)
 44            {
 2145                dropdown.options.Add(data);
 46            }
 547            dropdown.RefreshShownValue();
 548        }
 49
 50        protected override void OnDestroy()
 51        {
 452            base.OnDestroy();
 53
 454            if (spinBoxController != null)
 55            {
 456                spinBoxController.OnSetLabels -= SetLabels;
 457                spinBoxController.OnCurrentLabelChange -= SetOption;
 58            }
 459        }
 60
 61        public override void RefreshControl()
 62        {
 463            base.RefreshControl();
 64
 465            int newValue = (int)spinBoxController.GetStoredValue();
 466            if (dropdown.value != newValue)
 267                dropdown.value = newValue;
 468        }
 69
 70    }
 71}