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>
public static LocalisableString Resolution => new TranslatableString(getKey(@"resolution"), @"Resolution");
/// <summary>
/// "Display"
/// </summary>
public static LocalisableString Display => new TranslatableString(getKey(@"display"), @"Display");
/// <summary>
/// "UI scaling"
/// </summary>

View File

@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
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 Bindable<ScalingMode> scalingMode;
@ -39,6 +39,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
private OsuGameBase game { get; set; }
private SettingsDropdown<Size> resolutionDropdown;
private SettingsDropdown<Display> displayDropdown;
private SettingsDropdown<WindowMode> windowModeDropdown;
private Bindable<float> scalingPositionX;
@ -72,6 +73,12 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
ItemSource = windowModes,
Current = config.GetBindable<WindowMode>(FrameworkSetting.WindowMode),
},
displayDropdown = new DisplaySettingsDropdown
{
LabelText = GraphicsSettingsStrings.Display,
Items = host.Window?.Displays,
Current = currentDisplay,
},
resolutionDropdown = new ResolutionSettingsDropdown
{
LabelText = GraphicsSettingsStrings.Resolution,
@ -142,7 +149,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
windowModeDropdown.Current.BindValueChanged(mode =>
{
updateResolutionDropdown();
updateFullscreenDropdowns();
windowModeDropdown.WarningText = mode.NewValue != WindowMode.Fullscreen ? GraphicsSettingsStrings.NotFullscreenNote : default;
}, true);
@ -168,7 +175,7 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
.Distinct());
}
updateResolutionDropdown();
updateFullscreenDropdowns();
}), true);
scalingMode.BindValueChanged(mode =>
@ -183,12 +190,17 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
// initial update bypasses transforms
updateScalingModeVisibility();
void updateResolutionDropdown()
void updateFullscreenDropdowns()
{
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()
@ -243,6 +255,19 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
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>
{
protected override OsuDropdown<Size> CreateDropdown() => new ResolutionDropdownControl();