Add ability to select which display the game runs on

This commit is contained in:
Dean Herbert 2022-03-02 18:29:07 +09:00
parent 09a74cdfc6
commit c06703d662
2 changed files with 34 additions and 4 deletions

View File

@ -54,6 +54,11 @@ namespace osu.Game.Localisation
/// </summary> /// </summary>
public static LocalisableString Resolution => new TranslatableString(getKey(@"resolution"), @"Resolution"); public static LocalisableString Resolution => new TranslatableString(getKey(@"resolution"), @"Resolution");
/// <summary>
/// "Display"
/// </summary>
public static LocalisableString Display => new TranslatableString(getKey(@"display"), @"Display");
/// <summary> /// <summary>
/// "UI scaling" /// "UI scaling"
/// </summary> /// </summary>

View File

@ -27,7 +27,7 @@ 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 Bindable<Display> currentDisplay = new Bindable<Display>();
private readonly IBindableList<WindowMode> windowModes = new BindableList<WindowMode>(); private readonly IBindableList<WindowMode> windowModes = new BindableList<WindowMode>();
private Bindable<ScalingMode> scalingMode; private Bindable<ScalingMode> scalingMode;
@ -39,6 +39,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
private OsuGameBase game { get; set; } private OsuGameBase game { get; set; }
private SettingsDropdown<Size> resolutionDropdown; private SettingsDropdown<Size> resolutionDropdown;
private SettingsDropdown<Display> displayDropdown;
private SettingsDropdown<WindowMode> windowModeDropdown; private SettingsDropdown<WindowMode> windowModeDropdown;
private Bindable<float> scalingPositionX; private Bindable<float> scalingPositionX;
@ -72,6 +73,12 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
ItemSource = windowModes, ItemSource = windowModes,
Current = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode), Current = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode),
}, },
displayDropdown = new DisplaySettingsDropdown
{
LabelText = GraphicsSettingsStrings.Display,
Items = host.Window?.Displays,
Current = currentDisplay,
},
resolutionDropdown = new ResolutionSettingsDropdown resolutionDropdown = new ResolutionSettingsDropdown
{ {
LabelText = GraphicsSettingsStrings.Resolution, LabelText = GraphicsSettingsStrings.Resolution,
@ -142,7 +149,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
windowModeDropdown.Current.BindValueChanged(mode => windowModeDropdown.Current.BindValueChanged(mode =>
{ {
updateResolutionDropdown(); updateFullscreenDropdowns();
windowModeDropdown.WarningText = mode.NewValue != WindowMode.Fullscreen ? GraphicsSettingsStrings.NotFullscreenNote : default; windowModeDropdown.WarningText = mode.NewValue != WindowMode.Fullscreen ? GraphicsSettingsStrings.NotFullscreenNote : default;
}, true); }, true);
@ -168,7 +175,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
.Distinct()); .Distinct());
} }
updateResolutionDropdown(); updateFullscreenDropdowns();
}), true); }), true);
scalingMode.BindValueChanged(mode => scalingMode.BindValueChanged(mode =>
@ -183,12 +190,17 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
// initial update bypasses transforms // initial update bypasses transforms
updateScalingModeVisibility(); updateScalingModeVisibility();
void updateResolutionDropdown() void updateFullscreenDropdowns()
{ {
if (resolutions.Count > 1 && windowModeDropdown.Current.Value == WindowMode.Fullscreen) if (resolutions.Count > 1 && windowModeDropdown.Current.Value == WindowMode.Fullscreen)
resolutionDropdown.Show(); resolutionDropdown.Show();
else else
resolutionDropdown.Hide(); resolutionDropdown.Hide();
if (displayDropdown.Items.Count() > 1)
displayDropdown.Show();
else
displayDropdown.Hide();
} }
void updateScalingModeVisibility() void updateScalingModeVisibility()
@ -243,6 +255,19 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
public override LocalisableString TooltipText => base.TooltipText + "x"; public override LocalisableString TooltipText => base.TooltipText + "x";
} }
private class DisplaySettingsDropdown : SettingsDropdown<Display>
{
protected override OsuDropdown<Display> CreateDropdown() => new DisplaySettingsDropdownControl();
private class DisplaySettingsDropdownControl : DropdownControl
{
protected override LocalisableString GenerateItemText(Display item)
{
return $"{item.Index}: {item.Name} ({item.Bounds.Width}x{item.Bounds.Height})";
}
}
}
private class ResolutionSettingsDropdown : SettingsDropdown<Size> private class ResolutionSettingsDropdown : SettingsDropdown<Size>
{ {
protected override OsuDropdown<Size> CreateDropdown() => new ResolutionDropdownControl(); protected override OsuDropdown<Size> CreateDropdown() => new ResolutionDropdownControl();