2019-01-24 16:43:03 +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
|
|
|
|
|
2023-06-27 15:35:59 +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;
|
2023-11-12 14:12:04 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2017-01-27 20:57:22 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-05-23 16:53:42 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2023-06-06 06:04:29 +08:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2023-06-15 03:15:12 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-03-07 15:28:54 +08:00
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
2023-03-07 15:31:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A flowing display of all gameplay keys. Individual keys can be added using <see cref="InputTrigger"/> implementations.
|
|
|
|
|
/// </summary>
|
2024-08-06 14:52:03 +08:00
|
|
|
|
public abstract partial class KeyCounterDisplay : Container, ISerialisableDrawable
|
2016-09-24 09:53:58 +08:00
|
|
|
|
{
|
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>
|
2023-02-22 22:58:27 +08:00
|
|
|
|
public Bindable<bool> AlwaysVisible { get; } = new Bindable<bool>(true);
|
|
|
|
|
|
2023-04-25 20:22:55 +08:00
|
|
|
|
protected abstract FillFlowContainer<KeyCounter> KeyFlow { get; }
|
2023-03-08 08:47:16 +08:00
|
|
|
|
|
2023-02-22 22:58:27 +08:00
|
|
|
|
protected readonly Bindable<bool> ConfigVisibility = new Bindable<bool>();
|
|
|
|
|
|
2023-06-27 15:35:59 +08:00
|
|
|
|
private readonly IBindableList<InputTrigger> triggers = new BindableList<InputTrigger>();
|
|
|
|
|
|
2024-08-06 14:52:03 +08:00
|
|
|
|
protected override Container<Drawable> Content { get; } = new Container
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-15 03:13:35 +08:00
|
|
|
|
[Resolved]
|
2023-06-27 01:27:42 +08:00
|
|
|
|
private InputCountController controller { get; set; } = null!;
|
2023-06-06 06:04:29 +08:00
|
|
|
|
|
2023-11-12 14:12:04 +08:00
|
|
|
|
private const int duration = 100;
|
|
|
|
|
|
2024-08-06 14:52:03 +08:00
|
|
|
|
protected KeyCounterDisplay()
|
2023-11-12 14:12:04 +08:00
|
|
|
|
{
|
2024-08-06 14:52:03 +08:00
|
|
|
|
AddInternal(Content);
|
2023-11-12 14:12:04 +08:00
|
|
|
|
}
|
2023-02-22 22:58:27 +08:00
|
|
|
|
|
2017-05-23 16:53:42 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2023-06-15 03:13:35 +08:00
|
|
|
|
private void load(OsuConfigManager config, DrawableRuleset? drawableRuleset)
|
2017-05-23 16:53:42 +08:00
|
|
|
|
{
|
2023-11-12 14:12:04 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
2023-02-13 09:33:09 +08:00
|
|
|
|
config.BindWith(OsuSetting.KeyOverlay, ConfigVisibility);
|
2023-06-15 03:13:35 +08:00
|
|
|
|
|
|
|
|
|
if (drawableRuleset != null)
|
|
|
|
|
AlwaysVisible.BindTo(drawableRuleset.HasReplayLoaded);
|
2019-12-19 22:52:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2018-06-12 16:59:59 +08:00
|
|
|
|
|
2023-06-27 15:35:59 +08:00
|
|
|
|
triggers.BindTo(controller.Triggers);
|
|
|
|
|
triggers.BindCollectionChanged(triggersChanged, true);
|
2023-06-15 03:13:35 +08:00
|
|
|
|
|
2023-02-13 09:33:09 +08:00
|
|
|
|
AlwaysVisible.BindValueChanged(_ => UpdateVisibility());
|
|
|
|
|
ConfigVisibility.BindValueChanged(_ => UpdateVisibility(), true);
|
2017-05-23 16:53:42 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-08-06 14:52:03 +08:00
|
|
|
|
protected void UpdateVisibility()
|
|
|
|
|
{
|
|
|
|
|
bool visible = AlwaysVisible.Value || ConfigVisibility.Value;
|
|
|
|
|
|
|
|
|
|
// Isolate changing visibility of the key counters from fading this component.
|
|
|
|
|
Content.FadeTo(visible ? 1 : 0, duration);
|
|
|
|
|
|
|
|
|
|
// Ensure a valid size is immediately obtained even if partially off-screen
|
|
|
|
|
// See https://github.com/ppy/osu/issues/14793.
|
|
|
|
|
Content.AlwaysPresent = visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract KeyCounter CreateCounter(InputTrigger trigger);
|
|
|
|
|
|
2023-06-27 15:35:59 +08:00
|
|
|
|
private void triggersChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
2017-03-07 18:30:39 +08:00
|
|
|
|
{
|
2023-06-27 15:35:59 +08:00
|
|
|
|
KeyFlow.Clear();
|
|
|
|
|
foreach (var trigger in controller.Triggers)
|
|
|
|
|
KeyFlow.Add(CreateCounter(trigger));
|
2017-03-07 18:30:39 +08:00
|
|
|
|
}
|
2023-06-15 03:15:12 +08:00
|
|
|
|
|
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
2016-09-24 09:53:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|