1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-30 06:52:53 +08:00

Use IWindow.DisplaysChanged to update displays

This commit is contained in:
Susko3 2022-10-03 23:52:04 +02:00
parent 31fefc1ee2
commit efc9bed4f0

View File

@ -2,6 +2,7 @@
// 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; using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using osu.Framework; using osu.Framework;
@ -44,6 +45,8 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
[Resolved] [Resolved]
private GameHost host { get; set; } = null!; private GameHost host { get; set; } = null!;
private IWindow? window;
private SettingsDropdown<Size> resolutionDropdown = null!; private SettingsDropdown<Size> resolutionDropdown = null!;
private SettingsDropdown<Display> displayDropdown = null!; private SettingsDropdown<Display> displayDropdown = null!;
private SettingsDropdown<WindowMode> windowModeDropdown = null!; private SettingsDropdown<WindowMode> windowModeDropdown = null!;
@ -58,6 +61,8 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(FrameworkConfigManager config, OsuConfigManager osuConfig, GameHost host) private void load(FrameworkConfigManager config, OsuConfigManager osuConfig, GameHost host)
{ {
window = host.Window;
scalingMode = osuConfig.GetBindable<ScalingMode>(OsuSetting.Scaling); scalingMode = osuConfig.GetBindable<ScalingMode>(OsuSetting.Scaling);
sizeFullscreen = config.GetBindable<Size>(FrameworkSetting.SizeFullscreen); sizeFullscreen = config.GetBindable<Size>(FrameworkSetting.SizeFullscreen);
scalingSizeX = osuConfig.GetBindable<float>(OsuSetting.ScalingSizeX); scalingSizeX = osuConfig.GetBindable<float>(OsuSetting.ScalingSizeX);
@ -65,10 +70,11 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
scalingPositionX = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionX); scalingPositionX = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionX);
scalingPositionY = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionY); scalingPositionY = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionY);
if (host.Window != null) if (window != null)
{ {
currentDisplay.BindTo(host.Window.CurrentDisplayBindable); currentDisplay.BindTo(window.CurrentDisplayBindable);
windowModes.BindTo(host.Window.SupportedWindowModes); windowModes.BindTo(window.SupportedWindowModes);
window.DisplaysChanged += onDisplaysChanged;
} }
if (host.Window is WindowsWindow windowsWindow) if (host.Window is WindowsWindow windowsWindow)
@ -85,7 +91,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
displayDropdown = new DisplaySettingsDropdown displayDropdown = new DisplaySettingsDropdown
{ {
LabelText = GraphicsSettingsStrings.Display, LabelText = GraphicsSettingsStrings.Display,
Items = host.Window?.Displays, Items = window?.Displays,
Current = currentDisplay, Current = currentDisplay,
}, },
resolutionDropdown = new ResolutionSettingsDropdown resolutionDropdown = new ResolutionSettingsDropdown
@ -210,6 +216,15 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
} }
} }
private void onDisplaysChanged(IEnumerable<Display> displays)
{
Scheduler.AddOnce(d =>
{
displayDropdown.Items = d;
updateDisplayModeDropdowns();
}, displays);
}
private void updateDisplayModeDropdowns() private void updateDisplayModeDropdowns()
{ {
if (resolutions.Count > 1 && windowModeDropdown.Current.Value == WindowMode.Fullscreen) if (resolutions.Count > 1 && windowModeDropdown.Current.Value == WindowMode.Fullscreen)
@ -289,6 +304,14 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
preview.Expire(); preview.Expire();
} }
protected override void Dispose(bool isDisposing)
{
if (window != null)
window.DisplaysChanged -= onDisplaysChanged;
base.Dispose(isDisposing);
}
private class ScalingPreview : ScalingContainer private class ScalingPreview : ScalingContainer
{ {
public ScalingPreview() public ScalingPreview()