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. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Play.HUD;
@ -13,13 +12,11 @@ namespace osu.Game.Screens.Play
{ {
private const int duration = 100; private const int duration = 100;
private readonly FillFlowContainer<ArgonKeyCounter> keyFlow; protected override FillFlowContainer<KeyCounter> KeyFlow { get; }
public override IEnumerable<KeyCounter> Counters => keyFlow;
public ArgonKeyCounterDisplay() public ArgonKeyCounterDisplay()
{ {
InternalChild = keyFlow = new FillFlowContainer<ArgonKeyCounter> InternalChild = KeyFlow = new FillFlowContainer<KeyCounter>
{ {
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
@ -32,13 +29,12 @@ namespace osu.Game.Screens.Play
{ {
base.Update(); base.Update();
Size = keyFlow.Size; Size = KeyFlow.Size;
} }
public override void Add(InputTrigger trigger) => protected override KeyCounter CreateCounter(InputTrigger trigger) => new ArgonKeyCounter(trigger);
keyFlow.Add(new ArgonKeyCounter(trigger));
protected override void UpdateVisibility() 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. // 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. // 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;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osuTK.Graphics; using osuTK.Graphics;
@ -13,13 +13,11 @@ namespace osu.Game.Screens.Play.HUD
private const int duration = 100; private const int duration = 100;
private const double key_fade_time = 80; private const double key_fade_time = 80;
private readonly FillFlowContainer<DefaultKeyCounter> keyFlow; protected override FillFlowContainer<KeyCounter> KeyFlow { get; }
public override IEnumerable<KeyCounter> Counters => keyFlow;
public DefaultKeyCounterDisplay() public DefaultKeyCounterDisplay()
{ {
InternalChild = keyFlow = new FillFlowContainer<DefaultKeyCounter> InternalChild = KeyFlow = new FillFlowContainer<KeyCounter>
{ {
Direction = FillDirection.Horizontal, Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both, 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. // 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. // 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) => protected override KeyCounter CreateCounter(InputTrigger trigger) => new DefaultKeyCounter(trigger)
keyFlow.Add(new DefaultKeyCounter(trigger)
{ {
FadeTime = key_fade_time, FadeTime = key_fade_time,
KeyDownTextColor = KeyDownTextColor, KeyDownTextColor = KeyDownTextColor,
KeyUpTextColor = KeyUpTextColor, KeyUpTextColor = KeyUpTextColor,
}); };
protected override void UpdateVisibility() => protected override void UpdateVisibility() =>
// Isolate changing visibility of the key counters from fading this component. // 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; private Color4 keyDownTextColor = Color4.DarkGray;
@ -58,7 +55,7 @@ namespace osu.Game.Screens.Play.HUD
if (value != keyDownTextColor) if (value != keyDownTextColor)
{ {
keyDownTextColor = value; keyDownTextColor = value;
foreach (var child in keyFlow) foreach (var child in KeyFlow.Cast<DefaultKeyCounter>())
child.KeyDownTextColor = value; child.KeyDownTextColor = value;
} }
} }
@ -74,7 +71,7 @@ namespace osu.Game.Screens.Play.HUD
if (value != keyUpTextColor) if (value != keyUpTextColor)
{ {
keyUpTextColor = value; keyUpTextColor = value;
foreach (var child in keyFlow) foreach (var child in KeyFlow.Cast<DefaultKeyCounter>())
child.KeyUpTextColor = value; child.KeyUpTextColor = value;
} }
} }

View File

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