| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace UIComponents.Scripts.Components.RangeSlider |
| | 5 | | { |
| | 6 | | public class RangeSliderComponentView : BaseComponentView<RangeSliderComponentModel> |
| | 7 | | { |
| | 8 | | [Header("Prefab References")] |
| | 9 | | [SerializeField] internal TMP_Text text; |
| | 10 | | [SerializeField] public RangeSlider slider; |
| | 11 | |
|
| 0 | 12 | | public float MinValue => slider.MinValue; |
| 0 | 13 | | public float MaxValue => slider.MaxValue; |
| 0 | 14 | | public float LowValue => slider.LowValue; |
| 0 | 15 | | public float HighValue => slider.HighValue; |
| 155 | 16 | | public RangeSlider.RangeSliderEvent OnValueChanged => slider.OnValueChanged; |
| | 17 | |
|
| | 18 | | public override void RefreshControl() |
| | 19 | | { |
| 0 | 20 | | if (model == null) |
| 0 | 21 | | return; |
| | 22 | |
|
| 0 | 23 | | SetText(model.text); |
| 0 | 24 | | SetLimits(model.minValue, model.maxValue); |
| 0 | 25 | | SetWholeNumbers(model.wholeNumbers); |
| 0 | 26 | | SetValues(model.lowValue, model.highValue); |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | public void SetText(string newText) |
| | 30 | | { |
| 105 | 31 | | model.text = newText; |
| | 32 | |
|
| 105 | 33 | | if (text == null) |
| 0 | 34 | | return; |
| | 35 | |
|
| 105 | 36 | | text.text = newText; |
| 105 | 37 | | } |
| | 38 | |
|
| | 39 | | public void SetLimits(float minValue, float maxValue) |
| | 40 | | { |
| 51 | 41 | | maxValue = maxValue > minValue ? maxValue : minValue; |
| | 42 | |
|
| 51 | 43 | | model.minValue = minValue; |
| 51 | 44 | | model.maxValue = maxValue; |
| | 45 | |
|
| 51 | 46 | | if (slider == null) |
| 0 | 47 | | return; |
| | 48 | |
|
| 51 | 49 | | slider.MinValue = minValue; |
| 51 | 50 | | slider.MaxValue = maxValue; |
| 51 | 51 | | } |
| | 52 | |
|
| | 53 | | public void SetWholeNumbers(bool isWholeNumbers) |
| | 54 | | { |
| 105 | 55 | | model.wholeNumbers = isWholeNumbers; |
| | 56 | |
|
| 105 | 57 | | if (slider == null) |
| 0 | 58 | | return; |
| | 59 | |
|
| 105 | 60 | | slider.WholeNumbers = isWholeNumbers; |
| 105 | 61 | | } |
| | 62 | |
|
| | 63 | | public void SetValues(float lowValue, float highValue) |
| | 64 | | { |
| 105 | 65 | | lowValue = lowValue >= model.minValue ? lowValue : model.minValue; |
| 105 | 66 | | highValue = highValue > lowValue ? highValue : lowValue; |
| 105 | 67 | | highValue = highValue <= model.maxValue ? highValue : model.maxValue; |
| | 68 | |
|
| 105 | 69 | | model.lowValue = lowValue; |
| 105 | 70 | | model.highValue = highValue; |
| | 71 | |
|
| 105 | 72 | | if (slider == null) |
| 0 | 73 | | return; |
| | 74 | |
|
| 105 | 75 | | slider.LowValue = lowValue; |
| 105 | 76 | | slider.HighValue = highValue; |
| 105 | 77 | | } |
| | 78 | | } |
| | 79 | | } |