1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 15:57:51 +08:00
osu-lazer/osu.Game/Overlays/Settings/Sections/Input/KeyBindingsSubsection.cs

80 lines
2.6 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 System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Game.Database;
using osu.Game.Input.Bindings;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets;
using osu.Game.Localisation;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.Settings.Sections.Input
2018-04-13 17:19:50 +08:00
{
public abstract class KeyBindingsSubsection : SettingsSubsection
{
protected IEnumerable<Framework.Input.Bindings.KeyBinding> Defaults;
public RulesetInfo Ruleset { get; protected set; }
2018-04-13 17:19:50 +08:00
private readonly int? variant;
protected KeyBindingsSubsection(int? variant)
{
this.variant = variant;
FlowContent.Spacing = new Vector2(0, 3);
2018-04-13 17:19:50 +08:00
}
[BackgroundDependencyLoader]
private void load(RealmAccess realm)
2018-04-13 17:19:50 +08:00
{
string rulesetName = Ruleset?.ShortName;
2018-04-13 17:19:50 +08:00
var bindings = realm.Run(r => r.All<RealmKeyBinding>()
.Where(b => b.RulesetName == rulesetName && b.Variant == variant)
.Detach());
foreach (var defaultGroup in Defaults.GroupBy(d => d.Action))
2018-04-13 17:19:50 +08:00
{
int intKey = (int)defaultGroup.Key;
2018-04-13 17:19:50 +08:00
// one row per valid action.
Add(new KeyBindingRow(defaultGroup.Key, bindings.Where(b => b.ActionInt.Equals(intKey)).ToList())
2018-04-13 17:19:50 +08:00
{
AllowMainMouseButtons = Ruleset != null,
Defaults = defaultGroup.Select(d => d.KeyCombination)
});
2018-04-13 17:19:50 +08:00
}
Add(new ResetButton
{
Action = () => Children.OfType<KeyBindingRow>().ForEach(k => k.RestoreDefaults())
});
}
}
2021-10-11 02:32:56 +08:00
public class ResetButton : DangerousSettingsButton
2018-04-13 17:19:50 +08:00
{
[BackgroundDependencyLoader]
private void load()
2018-04-13 17:19:50 +08:00
{
Text = InputSettingsStrings.ResetSectionButton;
2018-04-13 17:19:50 +08:00
RelativeSizeAxes = Axes.X;
Width = 0.8f;
Anchor = Anchor.TopCentre;
Origin = Anchor.TopCentre;
Margin = new MarginPadding { Top = 15 };
Height = 30;
2018-04-13 17:19:50 +08:00
Content.CornerRadius = 5;
}
// Empty FilterTerms so that the ResetButton is visible only when the whole subsection is visible.
public override IEnumerable<string> FilterTerms => Enumerable.Empty<string>();
2018-04-13 17:19:50 +08:00
}
}