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-02-22 22:58:27 +08:00
|
|
|
|
using System.Collections.Generic;
|
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-02-22 22:58:27 +08:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Configuration;
|
2023-06-06 06:04:29 +08:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-03-07 15:28:54 +08:00
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2018-04-13 17:19:50 +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>
|
2023-06-06 06:04:29 +08:00
|
|
|
|
public abstract partial class KeyCounterDisplay : CompositeDrawable, IAttachableSkinComponent
|
2018-04-13 17:19:50 +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-03-08 08:47:16 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The <see cref="KeyCounter"/>s contained in this <see cref="KeyCounterDisplay"/>.
|
|
|
|
|
/// </summary>
|
2023-04-25 20:22:55 +08:00
|
|
|
|
public IEnumerable<KeyCounter> Counters => KeyFlow;
|
|
|
|
|
|
|
|
|
|
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-15 03:13:35 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private KeyCounterController controller { get; set; } = null!;
|
2023-06-06 06:04:29 +08:00
|
|
|
|
|
2023-06-15 03:13:35 +08:00
|
|
|
|
protected abstract void UpdateVisibility();
|
2023-02-22 22:58:27 +08:00
|
|
|
|
|
2023-03-08 08:58:54 +08:00
|
|
|
|
/// <summary>
|
2023-03-15 17:02:41 +08:00
|
|
|
|
/// Add a <see cref="InputTrigger"/> to this display.
|
2023-03-08 08:58:54 +08:00
|
|
|
|
/// </summary>
|
2023-04-25 20:31:39 +08:00
|
|
|
|
public void Add(InputTrigger trigger)
|
|
|
|
|
{
|
|
|
|
|
var keyCounter = CreateCounter(trigger);
|
|
|
|
|
|
|
|
|
|
KeyFlow.Add(keyCounter);
|
|
|
|
|
}
|
2023-02-22 22:58:27 +08:00
|
|
|
|
|
2023-03-08 08:58:54 +08:00
|
|
|
|
/// <summary>
|
2023-03-15 17:02:41 +08:00
|
|
|
|
/// Add a range of <see cref="InputTrigger"/> to this display.
|
2023-03-08 08:58:54 +08:00
|
|
|
|
/// </summary>
|
2023-03-15 17:02:41 +08:00
|
|
|
|
public void AddRange(IEnumerable<InputTrigger> triggers) => triggers.ForEach(Add);
|
2023-02-22 22:58:27 +08:00
|
|
|
|
|
2023-04-25 20:22:55 +08:00
|
|
|
|
protected abstract KeyCounter CreateCounter(InputTrigger trigger);
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2023-06-15 03:13:35 +08:00
|
|
|
|
private void load(OsuConfigManager config, DrawableRuleset? drawableRuleset)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
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-15 03:13:35 +08:00
|
|
|
|
controller.OnNewTrigger += Add;
|
|
|
|
|
AddRange(controller.Triggers);
|
|
|
|
|
|
2023-02-13 09:33:09 +08:00
|
|
|
|
AlwaysVisible.BindValueChanged(_ => UpdateVisibility());
|
|
|
|
|
ConfigVisibility.BindValueChanged(_ => UpdateVisibility(), true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 03:13:35 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2023-06-15 03:13:35 +08:00
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
controller.OnNewTrigger -= Add;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|