| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using MainScripts.DCL.Controllers.SettingsDesktop; |
| | 5 | | using MainScripts.DCL.Controllers.SettingsDesktop.SettingsControllers; |
| | 6 | | using MainScripts.DCL.ScriptableObjectsDesktop; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace MainScripts.DCL.Controllers.HUD.SettingsPanelHUDDesktop.Scripts |
| | 10 | | { |
| | 11 | | [CreateAssetMenu(menuName = "Settings/Controllers/Controls/Resolution Size", |
| | 12 | | fileName = "ResolutionSizeControlController")] |
| | 13 | | public class ResolutionSizeControlController : SpinBoxSettingsControlControllerDesktop |
| | 14 | | { |
| 0 | 15 | | private List<Resolution> possibleResolutions = new List<Resolution>(); |
| | 16 | |
|
| | 17 | | public override void Initialize() |
| | 18 | | { |
| 0 | 19 | | SetupAvailableResolutions(); |
| 0 | 20 | | base.Initialize(); |
| 0 | 21 | | SetupLabels(); |
| 0 | 22 | | } |
| | 23 | |
|
| | 24 | | // Filter the smallest resolutions as no one will ever use them |
| | 25 | | private void SetupAvailableResolutions() |
| | 26 | | { |
| 0 | 27 | | possibleResolutions.AddRange(ScreenResolutionUtils.Resolutions.SkipWhile(r => r.width <= 1024)); |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | private void SetupLabels() |
| | 31 | | { |
| 0 | 32 | | var length = possibleResolutions.Count; |
| 0 | 33 | | var resolutionLabels = new string[length]; |
| 0 | 34 | | for (var i = 0; i < length; i++) |
| | 35 | | { |
| 0 | 36 | | var resolution = possibleResolutions[i]; |
| | 37 | |
|
| | 38 | | // by design we want the list to be inverted so the biggest resolutions stay on top |
| | 39 | | // our resolutionSizeIndex is based on this decision |
| 0 | 40 | | resolutionLabels[length - 1 - i] = GetLabel(resolution); |
| | 41 | | } |
| | 42 | |
|
| 0 | 43 | | RaiseOnOverrideIndicatorLabel(resolutionLabels); |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | private static string GetLabel(Resolution resolution) |
| | 47 | | { |
| 0 | 48 | | return $"{resolution.width}x{resolution.height} {GetAspectRatio(resolution.width, resolution.height)} {resol |
| | 49 | | } |
| | 50 | |
|
| | 51 | | public override object GetStoredValue() |
| | 52 | | { |
| 0 | 53 | | return currentDisplaySettings.resolutionSizeIndex; |
| | 54 | | } |
| | 55 | |
|
| | 56 | | private static string GetAspectRatio(int width, int height) |
| | 57 | | { |
| | 58 | | int rest; |
| 0 | 59 | | int tempWidth = width; |
| 0 | 60 | | int tempHeight = height; |
| 0 | 61 | | while (height != 0) |
| | 62 | | { |
| 0 | 63 | | rest = width % height; |
| 0 | 64 | | width = height; |
| 0 | 65 | | height = rest; |
| | 66 | | } |
| 0 | 67 | | return (tempWidth / width) + ":" + (tempHeight / width); |
| | 68 | | } |
| | 69 | |
|
| | 70 | | public override void UpdateSetting(object newValue) |
| | 71 | | { |
| 0 | 72 | | var value = (int)newValue; |
| 0 | 73 | | currentDisplaySettings.resolutionSizeIndex = value; |
| 0 | 74 | | ScreenResolutionUtils.Apply(currentDisplaySettings); |
| 0 | 75 | | } |
| | 76 | | } |
| | 77 | | } |