< 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:22
Uncovered lines:4
Coverable lines:26
Total lines:67
Line coverage:84.6% (22 of 26)
Covered branches:0
Total branches:0
Covered methods:4
Total methods:5
Method coverage:80% (4 of 5)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%110100%
OnDestroy()0%220100%
RefreshControl()0%220100%
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 model, SettingsControlController controller)
 18        {
 219            SetLabels(((SpinBoxControlModel)model).spinBoxLabels);
 20
 221            spinBoxController = (SpinBoxSettingsControlController)controller;
 222            spinBoxController.OnSetLabels += SetLabels;
 223            spinBoxController.OnCurrentLabelChange += spinBox.OverrideCurrentLabel;
 24
 225            base.Initialize(model, spinBoxController);
 226            spinBoxController.UpdateSetting(spinBox.value);
 27
 228            spinBox.onValueChanged.AddListener(spinBoxValue =>
 29            {
 030                ApplySetting(spinBoxValue);
 031            });
 232        }
 33
 34        protected override void OnDestroy()
 35        {
 436            base.OnDestroy();
 37
 438            if (spinBoxController != null)
 39            {
 240                spinBoxController.OnSetLabels -= SetLabels;
 241                spinBoxController.OnCurrentLabelChange -= spinBox.OverrideCurrentLabel;
 42            }
 443        }
 44
 45        public override void RefreshControl()
 46        {
 247            base.RefreshControl();
 48
 249            int newValue = (int)spinBoxController.GetStoredValue();
 250            if (spinBox.value != newValue)
 151                spinBox.value = newValue;
 252        }
 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        {
 260            if (labels.Length == 0)
 061                return;
 62
 263            spinBox.SetLabels(labels);
 264            spinBox.SetValue(0);
 265        }
 66    }
 67}