mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 18:33:20 +08:00
Merge pull request #20568 from Susko3/update-displays-in-setting
Sync displays dropdown in settings with OS displays
This commit is contained in:
commit
5ce890cdb5
@ -1,9 +1,8 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using osu.Framework;
|
||||
@ -29,37 +28,41 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
||||
{
|
||||
protected override LocalisableString Header => GraphicsSettingsStrings.LayoutHeader;
|
||||
|
||||
private FillFlowContainer<SettingsSlider<float>> scalingSettings;
|
||||
private FillFlowContainer<SettingsSlider<float>> scalingSettings = null!;
|
||||
|
||||
private readonly Bindable<Display> currentDisplay = new Bindable<Display>();
|
||||
private readonly IBindableList<WindowMode> windowModes = new BindableList<WindowMode>();
|
||||
|
||||
private Bindable<ScalingMode> scalingMode;
|
||||
private Bindable<Size> sizeFullscreen;
|
||||
private Bindable<ScalingMode> scalingMode = null!;
|
||||
private Bindable<Size> sizeFullscreen = null!;
|
||||
|
||||
private readonly BindableList<Size> resolutions = new BindableList<Size>(new[] { new Size(9999, 9999) });
|
||||
private readonly IBindable<FullscreenCapability> fullscreenCapability = new Bindable<FullscreenCapability>(FullscreenCapability.Capable);
|
||||
|
||||
[Resolved]
|
||||
private OsuGameBase game { get; set; }
|
||||
private OsuGameBase game { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private GameHost host { get; set; }
|
||||
private GameHost host { get; set; } = null!;
|
||||
|
||||
private SettingsDropdown<Size> resolutionDropdown;
|
||||
private SettingsDropdown<Display> displayDropdown;
|
||||
private SettingsDropdown<WindowMode> windowModeDropdown;
|
||||
private IWindow? window;
|
||||
|
||||
private Bindable<float> scalingPositionX;
|
||||
private Bindable<float> scalingPositionY;
|
||||
private Bindable<float> scalingSizeX;
|
||||
private Bindable<float> scalingSizeY;
|
||||
private SettingsDropdown<Size> resolutionDropdown = null!;
|
||||
private SettingsDropdown<Display> displayDropdown = null!;
|
||||
private SettingsDropdown<WindowMode> windowModeDropdown = null!;
|
||||
|
||||
private Bindable<float> scalingPositionX = null!;
|
||||
private Bindable<float> scalingPositionY = null!;
|
||||
private Bindable<float> scalingSizeX = null!;
|
||||
private Bindable<float> scalingSizeY = null!;
|
||||
|
||||
private const int transition_duration = 400;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(FrameworkConfigManager config, OsuConfigManager osuConfig, GameHost host)
|
||||
{
|
||||
window = host.Window;
|
||||
|
||||
scalingMode = osuConfig.GetBindable<ScalingMode>(OsuSetting.Scaling);
|
||||
sizeFullscreen = config.GetBindable<Size>(FrameworkSetting.SizeFullscreen);
|
||||
scalingSizeX = osuConfig.GetBindable<float>(OsuSetting.ScalingSizeX);
|
||||
@ -67,10 +70,11 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
||||
scalingPositionX = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionX);
|
||||
scalingPositionY = osuConfig.GetBindable<float>(OsuSetting.ScalingPositionY);
|
||||
|
||||
if (host.Window != null)
|
||||
if (window != null)
|
||||
{
|
||||
currentDisplay.BindTo(host.Window.CurrentDisplayBindable);
|
||||
windowModes.BindTo(host.Window.SupportedWindowModes);
|
||||
currentDisplay.BindTo(window.CurrentDisplayBindable);
|
||||
windowModes.BindTo(window.SupportedWindowModes);
|
||||
window.DisplaysChanged += onDisplaysChanged;
|
||||
}
|
||||
|
||||
if (host.Renderer is IWindowsRenderer windowsRenderer)
|
||||
@ -87,7 +91,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
||||
displayDropdown = new DisplaySettingsDropdown
|
||||
{
|
||||
LabelText = GraphicsSettingsStrings.Display,
|
||||
Items = host.Window?.Displays,
|
||||
Items = window?.Displays,
|
||||
Current = currentDisplay,
|
||||
},
|
||||
resolutionDropdown = new ResolutionSettingsDropdown
|
||||
@ -202,19 +206,6 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
||||
// initial update bypasses transforms
|
||||
updateScalingModeVisibility();
|
||||
|
||||
void updateDisplayModeDropdowns()
|
||||
{
|
||||
if (resolutions.Count > 1 && windowModeDropdown.Current.Value == WindowMode.Fullscreen)
|
||||
resolutionDropdown.Show();
|
||||
else
|
||||
resolutionDropdown.Hide();
|
||||
|
||||
if (displayDropdown.Items.Count() > 1)
|
||||
displayDropdown.Show();
|
||||
else
|
||||
displayDropdown.Hide();
|
||||
}
|
||||
|
||||
void updateScalingModeVisibility()
|
||||
{
|
||||
if (scalingMode.Value == ScalingMode.Off)
|
||||
@ -225,6 +216,28 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
||||
}
|
||||
}
|
||||
|
||||
private void onDisplaysChanged(IEnumerable<Display> displays)
|
||||
{
|
||||
Scheduler.AddOnce(d =>
|
||||
{
|
||||
displayDropdown.Items = d;
|
||||
updateDisplayModeDropdowns();
|
||||
}, displays);
|
||||
}
|
||||
|
||||
private void updateDisplayModeDropdowns()
|
||||
{
|
||||
if (resolutions.Count > 1 && windowModeDropdown.Current.Value == WindowMode.Fullscreen)
|
||||
resolutionDropdown.Show();
|
||||
else
|
||||
resolutionDropdown.Hide();
|
||||
|
||||
if (displayDropdown.Items.Count() > 1)
|
||||
displayDropdown.Show();
|
||||
else
|
||||
displayDropdown.Hide();
|
||||
}
|
||||
|
||||
private void updateScreenModeWarning()
|
||||
{
|
||||
if (RuntimeInfo.OS == RuntimeInfo.Platform.macOS)
|
||||
@ -280,7 +293,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
||||
};
|
||||
}
|
||||
|
||||
private Drawable preview;
|
||||
private Drawable? preview;
|
||||
|
||||
private void showPreview()
|
||||
{
|
||||
@ -291,6 +304,14 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
|
||||
preview.Expire();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
if (window != null)
|
||||
window.DisplaysChanged -= onDisplaysChanged;
|
||||
|
||||
base.Dispose(isDisposing);
|
||||
}
|
||||
|
||||
private class ScalingPreview : ScalingContainer
|
||||
{
|
||||
public ScalingPreview()
|
||||
|
Loading…
Reference in New Issue
Block a user