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