1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 12:22:55 +08:00
osu-lazer/osu.Game/Overlays/KeyBinding/RestorableKeyBindingRow.cs

66 lines
2.3 KiB
C#
Raw Normal View History

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