< Summary

Class:DCL.SettingsPanelHUD.Controls.SpinBoxSettingsControlView
Assembly:SettingsPanelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/ControlsModule/SpinBoxSettingsControlView.cs
Covered lines:23
Uncovered lines:3
Coverable lines:26
Total lines:67
Line coverage:88.4% (23 of 26)
Covered branches:0
Total branches:0

Metrics

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

File(s)

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

#LineLine coverage
 1using DCL.SettingsControls;
 2using UnityEngine;
 3
 4namespace DCL.SettingsPanelHUD.Controls
 5{
 6    /// <summary>
 7    /// MonoBehaviour that represents the view of a SPIN-BOX type CONTROL.
 8    /// </summary>
 9    public class SpinBoxSettingsControlView : SettingsControlView
 10    {
 11        [SerializeField] private SpinBoxPresetted spinBox;
 12
 013        public SpinBoxPresetted spinBoxControl { get => spinBox; }
 14
 15        private SpinBoxSettingsControlController spinBoxController;
 16
 17        public override void Initialize(SettingsControlModel controlConfig, SettingsControlController settingsControlCon
 18        {
 519            SetLabels(((SpinBoxControlModel)controlConfig).spinBoxLabels);
 20
 521            spinBoxController = (SpinBoxSettingsControlController)settingsControlController;
 522            spinBoxController.OnSetLabels += SetLabels;
 523            spinBoxController.OnCurrentLabelChange += spinBox.OverrideCurrentLabel;
 24
 525            base.Initialize(controlConfig, spinBoxController);
 526            spinBoxController.UpdateSetting(spinBox.value);
 27
 528            spinBox.onValueChanged.AddListener(spinBoxValue =>
 29            {
 030                ApplySetting(spinBoxValue);
 031            });
 532        }
 33
 34        protected override void OnDestroy()
 35        {
 636            base.OnDestroy();
 37
 638            if (spinBoxController != null)
 39            {
 540                spinBoxController.OnSetLabels -= SetLabels;
 541                spinBoxController.OnCurrentLabelChange -= spinBox.OverrideCurrentLabel;
 42            }
 643        }
 44
 45        public override void RefreshControl()
 46        {
 547            base.RefreshControl();
 48
 549            int newValue = (int)spinBoxController.GetStoredValue();
 550            if (spinBox.value != newValue)
 151                spinBox.value = newValue;
 552        }
 53
 54        /// <summary>
 55        /// Overrides the current list of available options for the spin-box.
 56        /// </summary>
 57        /// <param name="labels">New list of available options.</param>
 58        public void SetLabels(string[] labels)
 59        {
 660            if (labels.Length == 0)
 161                return;
 62
 563            spinBox.SetLabels(labels);
 564            spinBox.SetValue(0);
 565        }
 66    }
 67}