1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-04 06:12:57 +08:00

Move input handler settings creation to OsuGameBase

This commit is contained in:
Susko3 2022-01-14 23:16:07 +01:00
parent e7d9a2fa00
commit f3eaa95041
3 changed files with 49 additions and 38 deletions

View File

@ -20,8 +20,15 @@ using osu.Framework.Screens;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using osu.Game.Updater; using osu.Game.Updater;
using osu.Desktop.Windows; using osu.Desktop.Windows;
using osu.Framework.Input.Handlers;
using osu.Framework.Input.Handlers.Joystick;
using osu.Framework.Input.Handlers.Mouse;
using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.IO; using osu.Game.IO;
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections;
using osu.Game.Overlays.Settings.Sections.Input;
namespace osu.Desktop namespace osu.Desktop
{ {
@ -156,6 +163,24 @@ namespace osu.Desktop
desktopWindow.DragDrop += f => fileDrop(new[] { f }); desktopWindow.DragDrop += f => fileDrop(new[] { f });
} }
public override SettingsSubsection CreateSettingsSubsectionFor(InputHandler handler)
{
switch (handler)
{
case ITabletHandler th:
return new TabletSettings(th);
case MouseHandler mh:
return new MouseSettings(mh);
case JoystickHandler _:
return new InputSection.HandlerSection(handler);
default:
return base.CreateSettingsSubsectionFor(handler);
}
}
private readonly List<string> importableFiles = new List<string>(); private readonly List<string> importableFiles = new List<string>();
private ScheduledDelegate importSchedule; private ScheduledDelegate importSchedule;

View File

@ -17,6 +17,8 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Performance; using osu.Framework.Graphics.Performance;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Input.Handlers;
using osu.Framework.Input.Handlers.Midi;
using osu.Framework.IO.Stores; using osu.Framework.IO.Stores;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Platform; using osu.Framework.Platform;
@ -35,6 +37,8 @@ using osu.Game.Online.Chat;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Spectator; using osu.Game.Online.Spectator;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Settings;
using osu.Game.Overlays.Settings.Sections;
using osu.Game.Resources; using osu.Game.Resources;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
@ -448,6 +452,23 @@ namespace osu.Game
protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorage(host, defaultStorage); protected override Storage CreateStorage(GameHost host, Storage defaultStorage) => new OsuStorage(host, defaultStorage);
/// <summary>
/// Creates an input settings subsection for an <see cref="InputHandler"/>.
/// </summary>
/// <remarks>Should be overriden per-platform to provide settings for platform-specific handlers.</remarks>
public virtual SettingsSubsection CreateSettingsSubsectionFor(InputHandler handler)
{
switch (handler)
{
case MidiHandler _:
return new InputSection.HandlerSection(handler);
// return null for handlers that shouldn't have settings.
default:
return null;
}
}
private void onRulesetChanged(ValueChangedEvent<RulesetInfo> r) private void onRulesetChanged(ValueChangedEvent<RulesetInfo> r)
{ {
if (r.NewValue?.Available != true) if (r.NewValue?.Available != true)

View File

@ -5,10 +5,6 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Handlers; using osu.Framework.Input.Handlers;
using osu.Framework.Input.Handlers.Joystick;
using osu.Framework.Input.Handlers.Midi;
using osu.Framework.Input.Handlers.Mouse;
using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Localisation; using osu.Game.Localisation;
@ -22,9 +18,6 @@ namespace osu.Game.Overlays.Settings.Sections
public override LocalisableString Header => InputSettingsStrings.InputSectionHeader; public override LocalisableString Header => InputSettingsStrings.InputSectionHeader;
[Resolved]
private GameHost host { get; set; }
public override Drawable CreateIcon() => new SpriteIcon public override Drawable CreateIcon() => new SpriteIcon
{ {
Icon = FontAwesome.Solid.Keyboard Icon = FontAwesome.Solid.Keyboard
@ -36,7 +29,7 @@ namespace osu.Game.Overlays.Settings.Sections
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(GameHost host, OsuGameBase game)
{ {
Children = new Drawable[] Children = new Drawable[]
{ {
@ -45,42 +38,14 @@ namespace osu.Game.Overlays.Settings.Sections
foreach (var handler in host.AvailableInputHandlers) foreach (var handler in host.AvailableInputHandlers)
{ {
var handlerSection = createSectionFor(handler); var handlerSection = game.CreateSettingsSubsectionFor(handler);
if (handlerSection != null) if (handlerSection != null)
Add(handlerSection); Add(handlerSection);
} }
} }
private SettingsSubsection createSectionFor(InputHandler handler) public class HandlerSection : SettingsSubsection
{
SettingsSubsection section;
switch (handler)
{
// ReSharper disable once SuspiciousTypeConversion.Global (net standard fuckery)
case ITabletHandler th:
section = new TabletSettings(th);
break;
case MouseHandler mh:
section = new MouseSettings(mh);
break;
// whitelist the handlers which should be displayed to avoid any weird cases of users touching settings they shouldn't.
case JoystickHandler _:
case MidiHandler _:
section = new HandlerSection(handler);
break;
default:
return null;
}
return section;
}
private class HandlerSection : SettingsSubsection
{ {
private readonly InputHandler handler; private readonly InputHandler handler;