diff --git a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs index b3a2243ca3..2d970e41de 100644 --- a/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Graphics/LayoutSettings.cs @@ -1,8 +1,8 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Configuration; @@ -19,11 +19,13 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics private FillFlowContainer letterboxSettings; private Bindable letterboxing; + private Bindable sizeFullscreen; private OsuGame game; private SettingsDropdown resolutionDropdown; private SettingsEnumDropdown windowModeDropdown; + private const int transition_duration = 400; [BackgroundDependencyLoader] @@ -32,6 +34,17 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics this.game = game; letterboxing = config.GetBindable(FrameworkSetting.Letterboxing); + sizeFullscreen = config.GetBindable(FrameworkSetting.SizeFullscreen); + + var resolutions = getResolutions(); + var resolutionDropdownBindable = new BindableInt(resolutions.FirstOrDefault(r => r.Key.StartsWith($"{sizeFullscreen.Value.Width}x{sizeFullscreen.Value.Height}")).Value); + + resolutionDropdownBindable.ValueChanged += _ => + { + var newResolution = resolutions.First(r => r.Value == _); + var newResolutionparts = newResolution.Key.Split('x'); + sizeFullscreen.Value = new Size(int.Parse(newResolutionparts.First()), int.Parse(newResolutionparts.Last())); + }; Children = new Drawable[] { @@ -43,8 +56,8 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics resolutionDropdown = new SettingsDropdown { LabelText = "Resolution", - Items = getResolutions(), - Bindable = config.GetBindable(FrameworkSetting.FullscreenResolution) + Items = resolutions, + Bindable = resolutionDropdownBindable }, new SettingsCheckbox { @@ -98,11 +111,14 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics letterboxing.TriggerChange(); } - private IEnumerable> getResolutions() + private List> getResolutions() { var availableDisplayResolutions = (game.Window as DesktopGameWindow)?.AvailableDisplayResolutions; + if (availableDisplayResolutions == null) + return new List>(); + var availableDisplayResolutionsStr = availableDisplayResolutions.Select(r => $"{r.Width}x{r.Height}").Distinct().ToList(); - return (availableDisplayResolutions ?? throw new InvalidOperationException()).Select((t, i) => new KeyValuePair($"{t.Width}x{t.Height}@{t.RefreshRate}Hz", i)); + return availableDisplayResolutionsStr.Select((t, i) => new KeyValuePair(t, i)).ToList(); } } }