1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 16:07:25 +08:00
osu-lazer/osu.Game/Overlays/Settings/Sections/InputSection.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
3.3 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
2017-02-07 12:52:19 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
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.Platform;
using osu.Game.Localisation;
using osu.Game.Overlays.Settings.Sections.Input;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.Settings.Sections
2017-02-07 12:52:19 +08:00
{
public class InputSection : SettingsSection
2017-02-07 12:52:19 +08:00
{
private readonly KeyBindingPanel keyConfig;
public override LocalisableString Header => InputSettingsStrings.InputSectionHeader;
[Resolved]
private GameHost host { get; set; }
public override Drawable CreateIcon() => new SpriteIcon
{
Icon = FontAwesome.Solid.Keyboard
};
2018-04-13 17:19:50 +08:00
public InputSection(KeyBindingPanel keyConfig)
{
this.keyConfig = keyConfig;
}
[BackgroundDependencyLoader]
private void load()
2017-02-07 12:52:19 +08:00
{
Children = new Drawable[]
{
new BindingSettings(keyConfig),
2017-02-07 12:52:19 +08:00
};
foreach (var handler in host.AvailableInputHandlers)
{
var handlerSection = createSectionFor(handler);
if (handlerSection != null)
Add(handlerSection);
}
}
private SettingsSubsection createSectionFor(InputHandler handler)
{
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 jh:
section = new JoystickSettings(jh);
break;
case MidiHandler _:
section = new HandlerSection(handler);
break;
default:
return null;
}
return section;
}
private class HandlerSection : SettingsSubsection
{
private readonly InputHandler handler;
public HandlerSection(InputHandler handler)
{
this.handler = handler;
}
[BackgroundDependencyLoader]
private void load()
{
Children = new Drawable[]
{
new SettingsCheckbox
{
LabelText = CommonStrings.Enabled,
Current = handler.Enabled
},
};
}
protected override LocalisableString Header => handler.Description;
2017-02-07 12:52:19 +08:00
}
}
}