1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 18:27:31 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/KeyCounterDisplay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
2.4 KiB
C#
Raw Normal View History

// 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.Specialized;
2018-07-22 22:16:17 +08:00
using osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2017-01-27 20:57:22 +08:00
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
using osu.Game.Rulesets.UI;
using osu.Game.Skinning;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Play.HUD
{
/// <summary>
/// A flowing display of all gameplay keys. Individual keys can be added using <see cref="InputTrigger"/> implementations.
/// </summary>
public abstract partial class KeyCounterDisplay : CompositeDrawable, ISerialisableDrawable
{
2020-02-04 01:00:43 +08:00
/// <summary>
/// Whether the key counter should be visible regardless of the configuration value.
/// This is true by default, but can be changed.
/// </summary>
public Bindable<bool> AlwaysVisible { get; } = new Bindable<bool>(true);
protected abstract FillFlowContainer<KeyCounter> KeyFlow { get; }
protected readonly Bindable<bool> ConfigVisibility = new Bindable<bool>();
private readonly IBindableList<InputTrigger> triggers = new BindableList<InputTrigger>();
[Resolved]
private InputCountController controller { get; set; } = null!;
protected abstract void UpdateVisibility();
protected abstract KeyCounter CreateCounter(InputTrigger trigger);
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, DrawableRuleset? drawableRuleset)
{
config.BindWith(OsuSetting.KeyOverlay, ConfigVisibility);
if (drawableRuleset != null)
AlwaysVisible.BindTo(drawableRuleset.HasReplayLoaded);
}
protected override void LoadComplete()
{
base.LoadComplete();
triggers.BindTo(controller.Triggers);
triggers.BindCollectionChanged(triggersChanged, true);
AlwaysVisible.BindValueChanged(_ => UpdateVisibility());
ConfigVisibility.BindValueChanged(_ => UpdateVisibility(), true);
}
2018-04-13 17:19:50 +08:00
private void triggersChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
KeyFlow.Clear();
foreach (var trigger in controller.Triggers)
KeyFlow.Add(CreateCounter(trigger));
}
public bool UsesFixedAnchor { get; set; }
}
}