< 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:21
Uncovered lines:5
Coverable lines:26
Total lines:67
Line coverage:80.7% (21 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%2.032080%
SetLabels(...)0%2.032080%

File(s)

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

#LineLine coverage
 1using DCL.SettingsCommon.SettingsControllers.BaseControllers;
 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        {
 119            SetLabels(((SpinBoxControlModel)controlConfig).spinBoxLabels);
 20
 121            spinBoxController = (SpinBoxSettingsControlController)settingsControlController;
 122            spinBoxController.OnSetLabels += SetLabels;
 123            spinBoxController.OnCurrentLabelChange += spinBox.OverrideCurrentLabel;
 24
 125            base.Initialize(controlConfig, spinBoxController);
 126            spinBoxController.UpdateSetting(spinBox.value);
 27
 128            spinBox.onValueChanged.AddListener(spinBoxValue =>
 29            {
 030                ApplySetting(spinBoxValue);
 031            });
 132        }
 33
 34        protected override void OnDestroy()
 35        {
 236            base.OnDestroy();
 37
 238            if (spinBoxController != null)
 39            {
 140                spinBoxController.OnSetLabels -= SetLabels;
 141                spinBoxController.OnCurrentLabelChange -= spinBox.OverrideCurrentLabel;
 42            }
 243        }
 44
 45        public override void RefreshControl()
 46        {
 147            base.RefreshControl();
 48
 149            int newValue = (int)spinBoxController.GetStoredValue();
 150            if (spinBox.value != newValue)
 051                spinBox.value = newValue;
 152        }
 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        {
 160            if (labels.Length == 0)
 061                return;
 62
 163            spinBox.SetLabels(labels);
 164            spinBox.SetValue(0);
 165        }
 66    }
 67}