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