2021-05-14 23:01:17 +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.
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-05-16 12:48:00 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-05-14 23:01:17 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.KeyBinding
|
|
|
|
|
{
|
2021-05-16 12:48:00 +08:00
|
|
|
|
public class RestorableKeyBindingRow : Container, IFilterable
|
2021-05-14 23:01:17 +08:00
|
|
|
|
{
|
2021-05-16 12:48:00 +08:00
|
|
|
|
private readonly object key;
|
2021-05-15 09:24:08 +08:00
|
|
|
|
private readonly ICollection<Input.Bindings.DatabasedKeyBinding> bindings;
|
2021-05-14 23:01:17 +08:00
|
|
|
|
public readonly KeyBindingRow KeyBindingRow;
|
|
|
|
|
|
|
|
|
|
private bool matchingFilter;
|
|
|
|
|
|
|
|
|
|
public bool MatchingFilter
|
|
|
|
|
{
|
|
|
|
|
get => matchingFilter;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
matchingFilter = value;
|
|
|
|
|
this.FadeTo(!matchingFilter ? 0 : 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool FilteringActive { get; set; }
|
|
|
|
|
|
2021-05-16 12:48:00 +08:00
|
|
|
|
public IEnumerable<string> FilterTerms => bindings.Select(b => b.KeyCombination.ReadableString()).Prepend(key.ToString());
|
2021-05-14 23:01:17 +08:00
|
|
|
|
|
2021-05-16 12:48:00 +08:00
|
|
|
|
public RestorableKeyBindingRow(
|
|
|
|
|
object key,
|
2021-05-15 09:24:08 +08:00
|
|
|
|
ICollection<Input.Bindings.DatabasedKeyBinding> bindings,
|
2021-05-16 12:48:00 +08:00
|
|
|
|
RulesetInfo ruleset,
|
|
|
|
|
IEnumerable<KeyCombination> defaults)
|
2021-05-14 23:01:17 +08:00
|
|
|
|
{
|
2021-05-16 12:48:00 +08:00
|
|
|
|
this.key = key;
|
2021-05-14 23:01:17 +08:00
|
|
|
|
this.bindings = bindings;
|
|
|
|
|
|
|
|
|
|
RestoreDefaultValueButton<bool> restoreDefaultButton;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
Padding = new MarginPadding { Right = SettingsPanel.CONTENT_MARGINS };
|
|
|
|
|
|
2021-05-16 12:48:00 +08:00
|
|
|
|
KeyBindingRow = new KeyBindingRow(key, bindings.Where(b => ((int)b.Action).Equals((int)key)))
|
|
|
|
|
{
|
|
|
|
|
AllowMainMouseButtons = ruleset != null,
|
|
|
|
|
Defaults = defaults
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-14 23:01:17 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
restoreDefaultButton = new RestoreDefaultValueButton<bool>(),
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding { Left = SettingsPanel.CONTENT_MARGINS },
|
|
|
|
|
Child = KeyBindingRow
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-15 09:24:08 +08:00
|
|
|
|
restoreDefaultButton.Current = KeyBindingRow.Current;
|
2021-05-14 23:01:17 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|