Restructure key counters to use a common flow

This commit is contained in:
Dean Herbert 2023-04-25 21:22:55 +09:00
parent 0c3a015953
commit 0a861ffcee
3 changed files with 24 additions and 27 deletions

View File

@ -1,7 +1,6 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Screens.Play.HUD;
@ -13,13 +12,11 @@ namespace osu.Game.Screens.Play
{
private const int duration = 100;
private readonly FillFlowContainer<ArgonKeyCounter> keyFlow;
public override IEnumerable<KeyCounter> Counters => keyFlow;
protected override FillFlowContainer<KeyCounter> KeyFlow { get; }
public ArgonKeyCounterDisplay()
{
InternalChild = keyFlow = new FillFlowContainer<ArgonKeyCounter>
InternalChild = KeyFlow = new FillFlowContainer<KeyCounter>
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
@ -32,13 +29,12 @@ namespace osu.Game.Screens.Play
{
base.Update();
Size = keyFlow.Size;
Size = KeyFlow.Size;
}
public override void Add(InputTrigger trigger) =>
keyFlow.Add(new ArgonKeyCounter(trigger));
protected override KeyCounter CreateCounter(InputTrigger trigger) => new ArgonKeyCounter(trigger);
protected override void UpdateVisibility()
=> keyFlow.FadeTo(AlwaysVisible.Value || ConfigVisibility.Value ? 1 : 0, duration);
=> KeyFlow.FadeTo(AlwaysVisible.Value || ConfigVisibility.Value ? 1 : 0, duration);
}
}

View File

@ -1,7 +1,7 @@
// 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 osuTK.Graphics;
@ -13,13 +13,11 @@ namespace osu.Game.Screens.Play.HUD
private const int duration = 100;
private const double key_fade_time = 80;
private readonly FillFlowContainer<DefaultKeyCounter> keyFlow;
public override IEnumerable<KeyCounter> Counters => keyFlow;
protected override FillFlowContainer<KeyCounter> KeyFlow { get; }
public DefaultKeyCounterDisplay()
{
InternalChild = keyFlow = new FillFlowContainer<DefaultKeyCounter>
InternalChild = KeyFlow = new FillFlowContainer<KeyCounter>
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
@ -33,20 +31,19 @@ namespace osu.Game.Screens.Play.HUD
// Don't use autosize as it will shrink to zero when KeyFlow is hidden.
// In turn this can cause the display to be masked off screen and never become visible again.
Size = keyFlow.Size;
Size = KeyFlow.Size;
}
public override void Add(InputTrigger trigger) =>
keyFlow.Add(new DefaultKeyCounter(trigger)
{
FadeTime = key_fade_time,
KeyDownTextColor = KeyDownTextColor,
KeyUpTextColor = KeyUpTextColor,
});
protected override KeyCounter CreateCounter(InputTrigger trigger) => new DefaultKeyCounter(trigger)
{
FadeTime = key_fade_time,
KeyDownTextColor = KeyDownTextColor,
KeyUpTextColor = KeyUpTextColor,
};
protected override void UpdateVisibility() =>
// Isolate changing visibility of the key counters from fading this component.
keyFlow.FadeTo(AlwaysVisible.Value || ConfigVisibility.Value ? 1 : 0, duration);
KeyFlow.FadeTo(AlwaysVisible.Value || ConfigVisibility.Value ? 1 : 0, duration);
private Color4 keyDownTextColor = Color4.DarkGray;
@ -58,7 +55,7 @@ namespace osu.Game.Screens.Play.HUD
if (value != keyDownTextColor)
{
keyDownTextColor = value;
foreach (var child in keyFlow)
foreach (var child in KeyFlow.Cast<DefaultKeyCounter>())
child.KeyDownTextColor = value;
}
}
@ -74,7 +71,7 @@ namespace osu.Game.Screens.Play.HUD
if (value != keyUpTextColor)
{
keyUpTextColor = value;
foreach (var child in keyFlow)
foreach (var child in KeyFlow.Cast<DefaultKeyCounter>())
child.KeyUpTextColor = value;
}
}

View File

@ -29,7 +29,9 @@ namespace osu.Game.Screens.Play.HUD
/// <summary>
/// The <see cref="KeyCounter"/>s contained in this <see cref="KeyCounterDisplay"/>.
/// </summary>
public abstract IEnumerable<KeyCounter> Counters { get; }
public IEnumerable<KeyCounter> Counters => KeyFlow;
protected abstract FillFlowContainer<KeyCounter> KeyFlow { get; }
/// <summary>
/// Whether the actions reported by all <see cref="InputTrigger"/>s within this <see cref="KeyCounterDisplay"/> should be counted.
@ -53,13 +55,15 @@ namespace osu.Game.Screens.Play.HUD
/// <summary>
/// Add a <see cref="InputTrigger"/> to this display.
/// </summary>
public abstract void Add(InputTrigger trigger);
public void Add(InputTrigger trigger) => KeyFlow.Add(CreateCounter(trigger));
/// <summary>
/// Add a range of <see cref="InputTrigger"/> to this display.
/// </summary>
public void AddRange(IEnumerable<InputTrigger> triggers) => triggers.ForEach(Add);
protected abstract KeyCounter CreateCounter(InputTrigger trigger);
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{