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
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
using osu.Framework.Graphics;
|
2021-01-11 18:47:51 +08:00
|
|
|
using osu.Game.Database;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-01-13 15:53:04 +08:00
|
|
|
using osu.Game.Input.Bindings;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Overlays.Settings;
|
|
|
|
using osu.Game.Rulesets;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.KeyBinding
|
|
|
|
{
|
|
|
|
public abstract class KeyBindingsSubsection : SettingsSubsection
|
|
|
|
{
|
|
|
|
protected IEnumerable<Framework.Input.Bindings.KeyBinding> Defaults;
|
|
|
|
|
|
|
|
protected RulesetInfo Ruleset;
|
|
|
|
|
|
|
|
private readonly int? variant;
|
|
|
|
|
|
|
|
protected KeyBindingsSubsection(int? variant)
|
|
|
|
{
|
|
|
|
this.variant = variant;
|
|
|
|
|
|
|
|
FlowContent.Spacing = new Vector2(0, 1);
|
2019-05-14 09:45:05 +08:00
|
|
|
FlowContent.Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS, Right = SettingsPanel.CONTENT_MARGINS };
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2021-01-13 15:53:04 +08:00
|
|
|
private void load(RealmContextFactory realmFactory)
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2021-01-13 15:53:04 +08:00
|
|
|
var rulesetId = Ruleset?.ID;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-01-14 15:33:55 +08:00
|
|
|
List<RealmKeyBinding> bindings;
|
|
|
|
|
2021-01-22 16:28:47 +08:00
|
|
|
using (var usage = realmFactory.GetForRead())
|
|
|
|
bindings = usage.Realm.All<RealmKeyBinding>().Where(b => b.RulesetID == rulesetId && b.Variant == variant).Detach();
|
2021-01-14 15:33:55 +08:00
|
|
|
|
|
|
|
foreach (var defaultGroup in Defaults.GroupBy(d => d.Action))
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2021-01-14 15:33:55 +08:00
|
|
|
int intKey = (int)defaultGroup.Key;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-01-14 15:33:55 +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
|
|
|
{
|
2021-01-14 15:33:55 +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-05-11 10:00:57 +08:00
|
|
|
public class ResetButton : DangerousTriangleButton
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
[BackgroundDependencyLoader]
|
2021-05-11 10:00:57 +08:00
|
|
|
private void load()
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
2019-06-21 12:50:05 +08:00
|
|
|
Text = "Reset all bindings in section";
|
2018-04-13 17:19:50 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
2021-05-18 12:47:39 +08:00
|
|
|
Width = 0.5f;
|
|
|
|
Anchor = Anchor.TopCentre;
|
|
|
|
Origin = Anchor.TopCentre;
|
|
|
|
Margin = new MarginPadding { Top = 15 };
|
|
|
|
Height = 30;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
Content.CornerRadius = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|