mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 09:22:54 +08:00
Use bindable size
This commit is contained in:
parent
4233211fb3
commit
de7e4328c5
@ -1,8 +1,8 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
@ -19,11 +19,13 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
private FillFlowContainer letterboxSettings;
|
private FillFlowContainer letterboxSettings;
|
||||||
|
|
||||||
private Bindable<bool> letterboxing;
|
private Bindable<bool> letterboxing;
|
||||||
|
private Bindable<Size> sizeFullscreen;
|
||||||
|
|
||||||
private OsuGame game;
|
private OsuGame game;
|
||||||
private SettingsDropdown<int> resolutionDropdown;
|
private SettingsDropdown<int> resolutionDropdown;
|
||||||
private SettingsEnumDropdown<WindowMode> windowModeDropdown;
|
private SettingsEnumDropdown<WindowMode> windowModeDropdown;
|
||||||
|
|
||||||
|
|
||||||
private const int transition_duration = 400;
|
private const int transition_duration = 400;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -32,6 +34,17 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
letterboxing = config.GetBindable<bool>(FrameworkSetting.Letterboxing);
|
letterboxing = config.GetBindable<bool>(FrameworkSetting.Letterboxing);
|
||||||
|
sizeFullscreen = config.GetBindable<Size>(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[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -43,8 +56,8 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
resolutionDropdown = new SettingsDropdown<int>
|
resolutionDropdown = new SettingsDropdown<int>
|
||||||
{
|
{
|
||||||
LabelText = "Resolution",
|
LabelText = "Resolution",
|
||||||
Items = getResolutions(),
|
Items = resolutions,
|
||||||
Bindable = config.GetBindable<int>(FrameworkSetting.FullscreenResolution)
|
Bindable = resolutionDropdownBindable
|
||||||
},
|
},
|
||||||
new SettingsCheckbox
|
new SettingsCheckbox
|
||||||
{
|
{
|
||||||
@ -98,11 +111,14 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
letterboxing.TriggerChange();
|
letterboxing.TriggerChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<KeyValuePair<string, int>> getResolutions()
|
private List<KeyValuePair<string, int>> getResolutions()
|
||||||
{
|
{
|
||||||
var availableDisplayResolutions = (game.Window as DesktopGameWindow)?.AvailableDisplayResolutions;
|
var availableDisplayResolutions = (game.Window as DesktopGameWindow)?.AvailableDisplayResolutions;
|
||||||
|
if (availableDisplayResolutions == null)
|
||||||
|
return new List<KeyValuePair<string, int>>();
|
||||||
|
var availableDisplayResolutionsStr = availableDisplayResolutions.Select(r => $"{r.Width}x{r.Height}").Distinct().ToList();
|
||||||
|
|
||||||
return (availableDisplayResolutions ?? throw new InvalidOperationException()).Select((t, i) => new KeyValuePair<string, int>($"{t.Width}x{t.Height}@{t.RefreshRate}Hz", i));
|
return availableDisplayResolutionsStr.Select((t, i) => new KeyValuePair<string, int>(t, i)).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user