mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 20:25:39 +08:00
Fix resolution dropdown not respecting current display changes
This commit is contained in:
parent
9de42f8646
commit
dab5924a63
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -25,9 +24,13 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
|
|
||||||
private FillFlowContainer<SettingsSlider<float>> scalingSettings;
|
private FillFlowContainer<SettingsSlider<float>> scalingSettings;
|
||||||
|
|
||||||
|
private readonly IBindable<Display> currentDisplay = new Bindable<Display>();
|
||||||
|
private readonly IBindableList<WindowMode> windowModes = new BindableList<WindowMode>();
|
||||||
|
|
||||||
private Bindable<ScalingMode> scalingMode;
|
private Bindable<ScalingMode> scalingMode;
|
||||||
private Bindable<Size> sizeFullscreen;
|
private Bindable<Size> sizeFullscreen;
|
||||||
private readonly IBindableList<WindowMode> windowModes = new BindableList<WindowMode>();
|
|
||||||
|
private readonly BindableList<Size> resolutions = new BindableList<Size>(new[] { new Size(9999, 9999) });
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuGameBase game { get; set; }
|
private OsuGameBase game { get; set; }
|
||||||
@ -53,9 +56,10 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
scalingPositionY = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionY);
|
scalingPositionY = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionY);
|
||||||
|
|
||||||
if (host.Window != null)
|
if (host.Window != null)
|
||||||
|
{
|
||||||
|
currentDisplay.BindTo(host.Window.CurrentDisplayBindable);
|
||||||
windowModes.BindTo(host.Window.SupportedWindowModes);
|
windowModes.BindTo(host.Window.SupportedWindowModes);
|
||||||
|
}
|
||||||
Container resolutionSettingsContainer;
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -65,10 +69,12 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
Current = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode),
|
Current = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode),
|
||||||
ItemSource = windowModes,
|
ItemSource = windowModes,
|
||||||
},
|
},
|
||||||
resolutionSettingsContainer = new Container
|
resolutionDropdown = new ResolutionSettingsDropdown
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
LabelText = "Resolution",
|
||||||
AutoSizeAxes = Axes.Y
|
ShowsDefaultIndicator = false,
|
||||||
|
ItemSource = resolutions,
|
||||||
|
Current = sizeFullscreen
|
||||||
},
|
},
|
||||||
new SettingsSlider<float, UIScaleSlider>
|
new SettingsSlider<float, UIScaleSlider>
|
||||||
{
|
{
|
||||||
@ -126,31 +132,34 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
scalingSettings.ForEach(s => bindPreviewEvent(s.Current));
|
windowModes.BindCollectionChanged((sender, args) =>
|
||||||
|
|
||||||
var resolutions = getResolutions();
|
|
||||||
|
|
||||||
if (resolutions.Count > 1)
|
|
||||||
{
|
{
|
||||||
resolutionSettingsContainer.Child = resolutionDropdown = new ResolutionSettingsDropdown
|
if (windowModes.Count > 1)
|
||||||
{
|
windowModeDropdown.Show();
|
||||||
LabelText = "Resolution",
|
else
|
||||||
ShowsDefaultIndicator = false,
|
windowModeDropdown.Hide();
|
||||||
Items = resolutions,
|
}, true);
|
||||||
Current = sizeFullscreen
|
|
||||||
};
|
|
||||||
|
|
||||||
windowModeDropdown.Current.BindValueChanged(mode =>
|
windowModeDropdown.Current.ValueChanged += v => updateResolutionDropdown();
|
||||||
|
|
||||||
|
currentDisplay.BindValueChanged(v => Schedule(() =>
|
||||||
|
{
|
||||||
|
resolutions.RemoveRange(1, resolutions.Count - 1);
|
||||||
|
|
||||||
|
if (v.NewValue != null)
|
||||||
{
|
{
|
||||||
if (mode.NewValue == WindowMode.Fullscreen)
|
resolutions.AddRange(v.NewValue.DisplayModes
|
||||||
{
|
.Where(m => m.Size.Width >= 800 && m.Size.Height >= 600)
|
||||||
resolutionDropdown.Show();
|
.OrderByDescending(m => m.Size.Width)
|
||||||
sizeFullscreen.TriggerChange();
|
.ThenByDescending(m => m.Size.Height)
|
||||||
}
|
.Select(m => m.Size)
|
||||||
else
|
.Distinct());
|
||||||
resolutionDropdown.Hide();
|
}
|
||||||
}, true);
|
|
||||||
}
|
updateResolutionDropdown();
|
||||||
|
}), true);
|
||||||
|
|
||||||
|
scalingSettings.ForEach(s => bindPreviewEvent(s.Current));
|
||||||
|
|
||||||
scalingMode.BindValueChanged(mode =>
|
scalingMode.BindValueChanged(mode =>
|
||||||
{
|
{
|
||||||
@ -163,17 +172,13 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
scalingSettings.ForEach(s => s.TransferValueOnCommit = mode.NewValue == ScalingMode.Everything);
|
scalingSettings.ForEach(s => s.TransferValueOnCommit = mode.NewValue == ScalingMode.Everything);
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
windowModes.CollectionChanged += (sender, args) => windowModesChanged();
|
void updateResolutionDropdown()
|
||||||
|
{
|
||||||
windowModesChanged();
|
if (resolutions.Count > 1 && windowModeDropdown.Current.Value == WindowMode.Fullscreen)
|
||||||
}
|
resolutionDropdown.Show();
|
||||||
|
else
|
||||||
private void windowModesChanged()
|
resolutionDropdown.Hide();
|
||||||
{
|
}
|
||||||
if (windowModes.Count > 1)
|
|
||||||
windowModeDropdown.Show();
|
|
||||||
else
|
|
||||||
windowModeDropdown.Hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -205,24 +210,6 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
|||||||
preview.Expire();
|
preview.Expire();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IReadOnlyList<Size> getResolutions()
|
|
||||||
{
|
|
||||||
var resolutions = new List<Size> { new Size(9999, 9999) };
|
|
||||||
var currentDisplay = game.Window?.CurrentDisplayBindable.Value;
|
|
||||||
|
|
||||||
if (currentDisplay != null)
|
|
||||||
{
|
|
||||||
resolutions.AddRange(currentDisplay.DisplayModes
|
|
||||||
.Where(m => m.Size.Width >= 800 && m.Size.Height >= 600)
|
|
||||||
.OrderByDescending(m => m.Size.Width)
|
|
||||||
.ThenByDescending(m => m.Size.Height)
|
|
||||||
.Select(m => m.Size)
|
|
||||||
.Distinct());
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolutions;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ScalingPreview : ScalingContainer
|
private class ScalingPreview : ScalingContainer
|
||||||
{
|
{
|
||||||
public ScalingPreview()
|
public ScalingPreview()
|
||||||
|
Loading…
Reference in New Issue
Block a user