| | 1 | | using DCL.SettingsCommon.SettingsControllers.BaseControllers; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL.SettingsControls |
| | 5 | | { |
| | 6 | | [CreateAssetMenu(menuName = "Settings/Controllers/Controls/Skybox Time", fileName = "SkyboxTime")] |
| | 7 | | public class SkyboxTimeControlController : SliderSettingsControlController |
| | 8 | | { |
| 2 | 9 | | private readonly DataStore_SkyboxConfig skyboxConfig = DataStore.i.skyboxConfig; |
| | 10 | |
|
| | 11 | | public override void Initialize() |
| | 12 | | { |
| 1 | 13 | | base.Initialize(); |
| 1 | 14 | | UpdateSetting(currentGeneralSettings.skyboxTime); |
| | 15 | |
|
| 1 | 16 | | skyboxConfig.mode.OnChange += OnSkyboxModeChanged; |
| 1 | 17 | | } |
| | 18 | |
|
| | 19 | | private void OnSkyboxModeChanged(SkyboxMode current, SkyboxMode previous) |
| | 20 | | { |
| 0 | 21 | | if (current == previous) return; |
| | 22 | |
|
| 0 | 23 | | RaiseSliderValueChanged((float)GetStoredValue()); |
| 0 | 24 | | UpdateSetting(GetStoredValue()); |
| 0 | 25 | | } |
| | 26 | |
|
| | 27 | | public override object GetStoredValue() => |
| 1 | 28 | | skyboxConfig.mode.Equals(SkyboxMode.Dynamic) |
| | 29 | | ? (object)currentGeneralSettings.skyboxTime |
| | 30 | | : skyboxConfig.fixedTime.Get(); |
| | 31 | |
|
| | 32 | | public override void UpdateSetting(object newValue) |
| | 33 | | { |
| 2 | 34 | | var valueAsFloat = (float)newValue; |
| | 35 | |
|
| 2 | 36 | | valueAsFloat = Mathf.Clamp(valueAsFloat, 0, 23.998f); |
| | 37 | |
|
| 2 | 38 | | currentGeneralSettings.skyboxTime = valueAsFloat; |
| | 39 | |
|
| 2 | 40 | | var hourSection = (int)valueAsFloat; |
| 2 | 41 | | var minuteSection = (int)((valueAsFloat - hourSection) * 60); |
| | 42 | |
|
| 2 | 43 | | RaiseOnIndicatorLabelChange($"{hourSection:00}:{minuteSection:00}"); |
| | 44 | |
|
| 2 | 45 | | skyboxConfig.fixedTime.Set(valueAsFloat); |
| 2 | 46 | | } |
| | 47 | | } |
| | 48 | | } |