1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 10:17:32 +08:00
osu-lazer/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs

65 lines
2.3 KiB
C#
Raw Normal View History

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