< Summary

Class:DCL.SettingsPanelHUD.Controls.SliderSettingsControlView
Assembly:SettingsPanelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/ControlsModule/SliderSettingsControlView.cs
Covered lines:24
Uncovered lines:5
Coverable lines:29
Total lines:82
Line coverage:82.7% (24 of 29)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%220100%
OnDestroy()0%220100%
OverrideIndicatorLabel(...)0%110100%
RefreshControl()0%440100%
RemapSliderValueTo01(...)0%110100%
RemapNormalizedValueToSlider(...)0%110100%

File(s)

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

#LineLine coverage
 1using System;
 2using DCL.SettingsCommon.SettingsControllers.BaseControllers;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7namespace DCL.SettingsPanelHUD.Controls
 8{
 9    /// <summary>
 10    /// MonoBehaviour that represents the view of a SLIDER type CONTROL.
 11    /// </summary>
 12    public class SliderSettingsControlView : SettingsControlView
 13    {
 14        [SerializeField] private Slider slider;
 15        [SerializeField] private TextMeshProUGUI indicatorLabel;
 16
 017        public Slider sliderControl => slider;
 18
 19        private SliderControlModel sliderControlConfig;
 20        private SliderSettingsControlController sliderController;
 21
 22        public override void Initialize(SettingsControlModel controlConfig, SettingsControlController settingsControlCon
 23        {
 1724            sliderController = (SliderSettingsControlController)settingsControlController;
 1725            sliderController.OnIndicatorLabelChange += OverrideIndicatorLabel;
 26
 1727            this.sliderControlConfig = (SliderControlModel)controlConfig;
 1728            slider.maxValue = this.sliderControlConfig.sliderMaxValue;
 1729            slider.minValue = this.sliderControlConfig.sliderMinValue;
 1730            slider.wholeNumbers = this.sliderControlConfig.wholeNumbers;
 31
 1732            base.Initialize(controlConfig, sliderController);
 1733            OverrideIndicatorLabel(slider.value.ToString());
 1734            sliderController.UpdateSetting(this.sliderControlConfig.storeValueAsNormalized ? RemapSliderValueTo01(slider
 35
 1736            slider.onValueChanged.AddListener(sliderValue =>
 37            {
 38                // https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
 39                // FX = floating point with X precision digits
 040                string stringFormat = sliderControlConfig.wholeNumbers ? "F0" : "F1";
 41
 042                OverrideIndicatorLabel( sliderValue.ToString(stringFormat) );
 043                ApplySetting(this.sliderControlConfig.storeValueAsNormalized ? RemapSliderValueTo01(sliderValue) : slide
 044            });
 1745        }
 46
 47        protected override void OnDestroy()
 48        {
 1849            base.OnDestroy();
 50
 1851            if (sliderController != null)
 1752                sliderController.OnIndicatorLabelChange -= OverrideIndicatorLabel;
 1853        }
 54
 55        /// <summary>
 56        /// Overrides the text of the label associated to the slider.
 57        /// </summary>
 58        /// <param name="text">New label text.</param>
 4659        public void OverrideIndicatorLabel(string text) { indicatorLabel.text = text; }
 60
 61        public override void RefreshControl()
 62        {
 1763            base.RefreshControl();
 64
 1765            float storedValue = Convert.ToSingle( sliderController.GetStoredValue() );
 66
 1767            float newValue = sliderControlConfig.storeValueAsNormalized ? RemapNormalizedValueToSlider(storedValue) : st
 68
 1769            if (slider.value != newValue)
 1670                slider.value = newValue;
 1771        }
 72
 73        private float RemapSliderValueTo01(float value)
 74        {
 175            return (value - slider.minValue)
 76                / (slider.maxValue - slider.minValue)
 77                * (1 - 0) + 0; //(value - from1) / (to1 - from1) * (to2 - from2) + from2
 78        }
 79
 180        private float RemapNormalizedValueToSlider(float value) { return Mathf.Lerp(slider.minValue, slider.maxValue, va
 81    }
 82}