1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-19 07:42:58 +08:00

Add dropdown for selecting fullscreen resolution

This commit is contained in:
Roman Kapustin 2018-06-02 21:02:45 +03:00
parent 53b11155d1
commit e98f9f1323

View File

@ -1,10 +1,14 @@
// 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.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Platform;
namespace osu.Game.Overlays.Settings.Sections.Graphics namespace osu.Game.Overlays.Settings.Sections.Graphics
{ {
@ -16,20 +20,32 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
private Bindable<bool> letterboxing; private Bindable<bool> letterboxing;
private OsuGame game;
private SettingsDropdown<int> resolutionDropdown;
private SettingsEnumDropdown<WindowMode> windowModeDropdown;
private const int transition_duration = 400; private const int transition_duration = 400;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(FrameworkConfigManager config) private void load(FrameworkConfigManager config, OsuGame game)
{ {
this.game = game;
letterboxing = config.GetBindable<bool>(FrameworkSetting.Letterboxing); letterboxing = config.GetBindable<bool>(FrameworkSetting.Letterboxing);
Children = new Drawable[] Children = new Drawable[]
{ {
new SettingsEnumDropdown<WindowMode> windowModeDropdown = new SettingsEnumDropdown<WindowMode>
{ {
LabelText = "Screen mode", LabelText = "Screen mode",
Bindable = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode), Bindable = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode),
}, },
resolutionDropdown = new SettingsDropdown<int>
{
LabelText = "Resolution",
Items = getResolutions(),
Bindable = config.GetBindable<int>(FrameworkSetting.FullscreenResolution)
},
new SettingsCheckbox new SettingsCheckbox
{ {
LabelText = "Letterboxing", LabelText = "Letterboxing",
@ -62,6 +78,15 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
}, },
}; };
windowModeDropdown.Bindable.ValueChanged += (s) =>
{
if (windowModeDropdown.Bindable.Value == WindowMode.Fullscreen)
resolutionDropdown.Show();
else
resolutionDropdown.Hide();
};
windowModeDropdown.Bindable.TriggerChange();
letterboxing.ValueChanged += isVisible => letterboxing.ValueChanged += isVisible =>
{ {
letterboxSettings.ClearTransforms(); letterboxSettings.ClearTransforms();
@ -72,5 +97,12 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
}; };
letterboxing.TriggerChange(); letterboxing.TriggerChange();
} }
private IEnumerable<KeyValuePair<string, int>> getResolutions()
{
var availableDisplayResolutions = (game.Window as DesktopGameWindow)?.AvailableDisplayResolutions;
return (availableDisplayResolutions ?? throw new InvalidOperationException()).Select((t, i) => new KeyValuePair<string, int>($"{t.Width}x{t.Height}@{t.RefreshRate}Hz", i));
}
} }
} }