| | 1 | | using DCL.SettingsCommon.SettingsControllers.BaseControllers; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace 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 | |
|
| 0 | 13 | | public SpinBoxPresetted spinBoxControl { get => spinBox; } |
| | 14 | |
|
| | 15 | | private SpinBoxSettingsControlController spinBoxController; |
| | 16 | |
|
| | 17 | | public override void Initialize(SettingsControlModel controlConfig, SettingsControlController settingsControlCon |
| | 18 | | { |
| 1 | 19 | | SetLabels(((SpinBoxControlModel)controlConfig).spinBoxLabels); |
| | 20 | |
|
| 1 | 21 | | spinBoxController = (SpinBoxSettingsControlController)settingsControlController; |
| 1 | 22 | | spinBoxController.OnSetLabels += SetLabels; |
| 1 | 23 | | spinBoxController.OnCurrentLabelChange += spinBox.OverrideCurrentLabel; |
| | 24 | |
|
| 1 | 25 | | base.Initialize(controlConfig, spinBoxController); |
| 1 | 26 | | spinBoxController.UpdateSetting(spinBox.value); |
| | 27 | |
|
| 1 | 28 | | spinBox.onValueChanged.AddListener(spinBoxValue => |
| | 29 | | { |
| 0 | 30 | | ApplySetting(spinBoxValue); |
| 0 | 31 | | }); |
| 1 | 32 | | } |
| | 33 | |
|
| | 34 | | protected override void OnDestroy() |
| | 35 | | { |
| 2 | 36 | | base.OnDestroy(); |
| | 37 | |
|
| 2 | 38 | | if (spinBoxController != null) |
| | 39 | | { |
| 1 | 40 | | spinBoxController.OnSetLabels -= SetLabels; |
| 1 | 41 | | spinBoxController.OnCurrentLabelChange -= spinBox.OverrideCurrentLabel; |
| | 42 | | } |
| 2 | 43 | | } |
| | 44 | |
|
| | 45 | | public override void RefreshControl() |
| | 46 | | { |
| 1 | 47 | | base.RefreshControl(); |
| | 48 | |
|
| 1 | 49 | | int newValue = (int)spinBoxController.GetStoredValue(); |
| 1 | 50 | | if (spinBox.value != newValue) |
| 0 | 51 | | spinBox.value = newValue; |
| 1 | 52 | | } |
| | 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 | | { |
| 1 | 60 | | if (labels.Length == 0) |
| 0 | 61 | | return; |
| | 62 | |
|
| 1 | 63 | | spinBox.SetLabels(labels); |
| 1 | 64 | | spinBox.SetValue(0); |
| 1 | 65 | | } |
| | 66 | | } |
| | 67 | | } |