| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | namespace UIComponents.Scripts.Components.RangeSlider |
| | 6 | | { |
| | 7 | | public class DropdownWithRangeSliderComponentView : BaseComponentView<RangeSliderComponentModel> |
| | 8 | | { |
| | 9 | | [Header("Prefab References")] |
| | 10 | | [SerializeField] public RangeSliderComponentView slider; |
| | 11 | | [SerializeField] internal Button button; |
| | 12 | | [SerializeField] internal TMP_Text title; |
| | 13 | | [SerializeField] internal GameObject contentPanel; |
| | 14 | | [SerializeField] internal UIHelper_ClickBlocker blocker; |
| | 15 | |
|
| 0 | 16 | | public float MinValue => slider.MinValue; |
| 0 | 17 | | public float MaxValue => slider.MaxValue; |
| 0 | 18 | | public float LowValue => slider.LowValue; |
| 0 | 19 | | public float HighValue => slider.HighValue; |
| 155 | 20 | | public RangeSlider.RangeSliderEvent OnValueChanged => slider.OnValueChanged; |
| | 21 | |
|
| | 22 | | private bool isOpen; |
| | 23 | |
|
| | 24 | | public override void Awake() |
| | 25 | | { |
| 51 | 26 | | base.Awake(); |
| | 27 | |
|
| 51 | 28 | | RefreshControl(); |
| 51 | 29 | | Close(); |
| | 30 | |
|
| 51 | 31 | | blocker.OnClicked += Close; |
| 51 | 32 | | button.onClick.AddListener(() => ToggleOptionsList()); |
| 51 | 33 | | } |
| | 34 | |
|
| | 35 | | public override void Dispose() |
| | 36 | | { |
| 51 | 37 | | base.Dispose(); |
| | 38 | |
|
| 51 | 39 | | blocker.OnClicked -= Close; |
| 51 | 40 | | button.onClick.RemoveAllListeners(); |
| 51 | 41 | | } |
| | 42 | |
|
| | 43 | | public override void RefreshControl() |
| | 44 | | { |
| 51 | 45 | | SetTitle(model.text); |
| 51 | 46 | | SetLimits(model.minValue, model.maxValue); |
| 51 | 47 | | SetWholeNumbers(model.wholeNumbers); |
| 51 | 48 | | SetValues(model.lowValue, model.highValue); |
| 51 | 49 | | } |
| | 50 | |
|
| | 51 | | public void Open() |
| | 52 | | { |
| 0 | 53 | | contentPanel.SetActive(true); |
| 0 | 54 | | isOpen = true; |
| 0 | 55 | | blocker.Activate(); |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | public void Close() |
| | 59 | | { |
| 51 | 60 | | contentPanel.SetActive(false); |
| 51 | 61 | | isOpen = false; |
| 51 | 62 | | blocker.Deactivate(); |
| 51 | 63 | | } |
| | 64 | |
|
| | 65 | | public void SetTitle(string newText) |
| | 66 | | { |
| 105 | 67 | | if (title != null) |
| 105 | 68 | | title.text = newText; |
| | 69 | |
|
| 105 | 70 | | if (slider != null) |
| 105 | 71 | | slider.SetText(newText); |
| 105 | 72 | | } |
| | 73 | |
|
| | 74 | | public void SetLimits(float minValue, float maxValue) |
| | 75 | | { |
| 51 | 76 | | if (slider == null) |
| 0 | 77 | | return; |
| | 78 | |
|
| 51 | 79 | | slider.SetLimits(minValue, maxValue); |
| 51 | 80 | | } |
| | 81 | |
|
| | 82 | | public void SetWholeNumbers(bool isWholeNumbers) |
| | 83 | | { |
| 105 | 84 | | if (slider == null) |
| 0 | 85 | | return; |
| | 86 | |
|
| 105 | 87 | | slider.SetWholeNumbers(isWholeNumbers); |
| 105 | 88 | | } |
| | 89 | |
|
| | 90 | | public void SetValues(float lowValue, float highValue) |
| | 91 | | { |
| 105 | 92 | | if (slider == null) |
| 0 | 93 | | return; |
| | 94 | |
|
| 105 | 95 | | slider.SetValues(lowValue, highValue); |
| 105 | 96 | | } |
| | 97 | |
|
| | 98 | | private void ToggleOptionsList() |
| | 99 | | { |
| 0 | 100 | | if (isOpen) |
| 0 | 101 | | Close(); |
| | 102 | | else |
| 0 | 103 | | Open(); |
| 0 | 104 | | } |
| | 105 | | } |
| | 106 | | } |