1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 14:12:55 +08:00

Merge pull request #22924 from peppy/add-renderer-selection

Add ability to select renderer
This commit is contained in:
Bartłomiej Dach 2023-03-26 15:33:05 +02:00 committed by GitHub
commit 6751f78304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 4 deletions

View File

@ -19,6 +19,11 @@ namespace osu.Game.Localisation
/// </summary>
public static LocalisableString RendererHeader => new TranslatableString(getKey(@"renderer_header"), @"Renderer");
/// <summary>
/// "Renderer"
/// </summary>
public static LocalisableString Renderer => new TranslatableString(getKey(@"renderer"), @"Renderer");
/// <summary>
/// "Frame limiter"
/// </summary>
@ -144,6 +149,12 @@ namespace osu.Game.Localisation
/// </summary>
public static LocalisableString Png => new TranslatableString(getKey(@"png_lossless"), @"PNG (lossless)");
/// <summary>
/// "In order to change the renderer, the game will close. Please open it again."
/// </summary>
public static LocalisableString ChangeRendererConfirmation =>
new TranslatableString(getKey(@"change_renderer_configuration"), @"In order to change the renderer, the game will close. Please open it again.");
private static string getKey(string key) => $"{prefix}:{key}";
}
}

View File

@ -1,15 +1,18 @@
// 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.Linq;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Extensions;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Framework.Platform;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Overlays.Dialog;
namespace osu.Game.Overlays.Settings.Sections.Graphics
{
@ -17,12 +20,25 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
{
protected override LocalisableString Header => GraphicsSettingsStrings.RendererHeader;
private bool automaticRendererInUse;
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager config, OsuConfigManager osuConfig)
private void load(FrameworkConfigManager config, OsuConfigManager osuConfig, IDialogOverlay? dialogOverlay, OsuGame? game, GameHost host)
{
// NOTE: Compatability mode omitted
var renderer = config.GetBindable<RendererType>(FrameworkSetting.Renderer);
automaticRendererInUse = renderer.Value == RendererType.Automatic;
SettingsEnumDropdown<RendererType> rendererDropdown;
Children = new Drawable[]
{
rendererDropdown = new RendererSettingsDropdown
{
LabelText = GraphicsSettingsStrings.Renderer,
Current = renderer,
Items = host.GetPreferredRenderersForCurrentPlatform().OrderBy(t => t),
Keywords = new[] { @"compatibility", @"directx" },
},
// TODO: this needs to be a custom dropdown at some point
new SettingsEnumDropdown<FrameSync>
{
@ -41,6 +57,55 @@ namespace osu.Game.Overlays.Settings.Sections.Graphics
Current = osuConfig.GetBindable<bool>(OsuSetting.ShowFpsDisplay)
},
};
renderer.BindValueChanged(r =>
{
if (r.NewValue == host.ResolvedRenderer)
return;
// Need to check startup renderer for the "automatic" case, as ResolvedRenderer above will track the final resolved renderer instead.
if (r.NewValue == RendererType.Automatic && automaticRendererInUse)
return;
dialogOverlay?.Push(new ConfirmDialog(GraphicsSettingsStrings.ChangeRendererConfirmation, () => game?.AttemptExit(), () =>
{
renderer.Value = automaticRendererInUse ? RendererType.Automatic : host.ResolvedRenderer;
}));
});
// TODO: remove this once we support SDL+android.
if (RuntimeInfo.OS == RuntimeInfo.Platform.Android)
{
rendererDropdown.Items = new[] { RendererType.Automatic, RendererType.OpenGLLegacy };
rendererDropdown.SetNoticeText("New renderer support for android is coming soon!", true);
}
}
private partial class RendererSettingsDropdown : SettingsEnumDropdown<RendererType>
{
protected override OsuDropdown<RendererType> CreateDropdown() => new RendererDropdown();
protected partial class RendererDropdown : DropdownControl
{
private RendererType hostResolvedRenderer;
private bool automaticRendererInUse;
[BackgroundDependencyLoader]
private void load(FrameworkConfigManager config, GameHost host)
{
var renderer = config.GetBindable<RendererType>(FrameworkSetting.Renderer);
automaticRendererInUse = renderer.Value == RendererType.Automatic;
hostResolvedRenderer = host.ResolvedRenderer;
}
protected override LocalisableString GenerateItemText(RendererType item)
{
if (item == RendererType.Automatic && automaticRendererInUse)
return LocalisableString.Interpolate($"{base.GenerateItemText(item)} ({hostResolvedRenderer.GetDescription()})");
return base.GenerateItemText(item);
}
}
}
}
}