2019-01-24 16:43:03 +08:00
|
|
|
|
// 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
|
|
|
|
|
2021-03-12 17:38:16 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-03-12 17:38:16 +08:00
|
|
|
|
using osu.Framework.Input.Handlers;
|
2021-03-12 17:40:38 +08:00
|
|
|
|
using osu.Framework.Input.Handlers.Joystick;
|
|
|
|
|
using osu.Framework.Input.Handlers.Midi;
|
2021-03-12 17:38:16 +08:00
|
|
|
|
using osu.Framework.Input.Handlers.Mouse;
|
2021-03-15 17:37:46 +08:00
|
|
|
|
using osu.Framework.Input.Handlers.Tablet;
|
2021-03-12 17:38:16 +08:00
|
|
|
|
using osu.Framework.Platform;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Overlays.Settings.Sections.Input;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Settings.Sections
|
|
|
|
|
{
|
|
|
|
|
public class InputSection : SettingsSection
|
|
|
|
|
{
|
2021-03-12 17:38:16 +08:00
|
|
|
|
private readonly KeyBindingPanel keyConfig;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public override string Header => "Input";
|
2020-04-26 02:35:46 +08:00
|
|
|
|
|
2021-03-12 17:38:16 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private GameHost host { get; set; }
|
|
|
|
|
|
2020-04-26 02:35:46 +08:00
|
|
|
|
public override Drawable CreateIcon() => new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.Solid.Keyboard
|
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-05-14 09:45:05 +08:00
|
|
|
|
public InputSection(KeyBindingPanel keyConfig)
|
2021-03-12 17:38:16 +08:00
|
|
|
|
{
|
|
|
|
|
this.keyConfig = keyConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-03-12 17:38:16 +08:00
|
|
|
|
new BindingSettings(keyConfig),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
};
|
2021-03-12 17:38:16 +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)
|
|
|
|
|
{
|
2021-03-15 17:37:46 +08:00
|
|
|
|
// ReSharper disable once SuspiciousTypeConversion.Global (net standard fuckery)
|
|
|
|
|
case ITabletHandler th:
|
|
|
|
|
section = new TabletSettings(th);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-03-12 17:38:16 +08:00
|
|
|
|
case MouseHandler mh:
|
|
|
|
|
section = new MouseSettings(mh);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-03-12 17:40:38 +08:00
|
|
|
|
// whitelist the handlers which should be displayed to avoid any weird cases of users touching settings they shouldn't.
|
|
|
|
|
case JoystickHandler _:
|
|
|
|
|
case MidiHandler _:
|
2021-03-12 17:38:16 +08:00
|
|
|
|
section = new HandlerSection(handler);
|
|
|
|
|
break;
|
2021-03-12 17:40:38 +08:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
2021-03-12 17:38:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return section;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class HandlerSection : SettingsSubsection
|
|
|
|
|
{
|
|
|
|
|
private readonly InputHandler handler;
|
|
|
|
|
|
|
|
|
|
public HandlerSection(InputHandler handler)
|
|
|
|
|
{
|
|
|
|
|
this.handler = handler;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 20:17:04 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new SettingsCheckbox
|
|
|
|
|
{
|
|
|
|
|
LabelText = "Enabled",
|
|
|
|
|
Current = handler.Enabled
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 17:38:16 +08:00
|
|
|
|
protected override string Header => handler.Description;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|