2023-02-13 09:33:09 +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.
|
|
|
|
|
2023-04-25 20:22:55 +08:00
|
|
|
using System.Linq;
|
2023-02-13 09:33:09 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2023-03-07 15:28:54 +08:00
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2023-02-13 09:33:09 +08:00
|
|
|
{
|
|
|
|
public partial class DefaultKeyCounterDisplay : KeyCounterDisplay
|
|
|
|
{
|
|
|
|
private const int duration = 100;
|
|
|
|
private const double key_fade_time = 80;
|
|
|
|
|
2023-04-25 20:22:55 +08:00
|
|
|
protected override FillFlowContainer<KeyCounter> KeyFlow { get; }
|
2023-02-13 09:33:09 +08:00
|
|
|
|
|
|
|
public DefaultKeyCounterDisplay()
|
|
|
|
{
|
2023-04-25 20:22:55 +08:00
|
|
|
InternalChild = KeyFlow = new FillFlowContainer<KeyCounter>
|
2023-03-15 17:02:12 +08:00
|
|
|
{
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
};
|
2023-02-13 09:33:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
// 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.
|
2023-04-25 20:22:55 +08:00
|
|
|
Size = KeyFlow.Size;
|
2023-02-22 22:58:27 +08:00
|
|
|
}
|
|
|
|
|
2023-04-25 20:22:55 +08:00
|
|
|
protected override KeyCounter CreateCounter(InputTrigger trigger) => new DefaultKeyCounter(trigger)
|
|
|
|
{
|
|
|
|
FadeTime = key_fade_time,
|
|
|
|
KeyDownTextColor = KeyDownTextColor,
|
|
|
|
KeyUpTextColor = KeyUpTextColor,
|
|
|
|
};
|
2023-02-13 09:33:09 +08:00
|
|
|
|
|
|
|
protected override void UpdateVisibility() =>
|
|
|
|
// Isolate changing visibility of the key counters from fading this component.
|
2023-04-25 20:22:55 +08:00
|
|
|
KeyFlow.FadeTo(AlwaysVisible.Value || ConfigVisibility.Value ? 1 : 0, duration);
|
2023-02-13 09:33:09 +08:00
|
|
|
|
|
|
|
private Color4 keyDownTextColor = Color4.DarkGray;
|
|
|
|
|
|
|
|
public Color4 KeyDownTextColor
|
|
|
|
{
|
|
|
|
get => keyDownTextColor;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value != keyDownTextColor)
|
|
|
|
{
|
|
|
|
keyDownTextColor = value;
|
2023-04-25 20:22:55 +08:00
|
|
|
foreach (var child in KeyFlow.Cast<DefaultKeyCounter>())
|
2023-03-09 05:10:34 +08:00
|
|
|
child.KeyDownTextColor = value;
|
2023-02-13 09:33:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Color4 keyUpTextColor = Color4.White;
|
|
|
|
|
|
|
|
public Color4 KeyUpTextColor
|
|
|
|
{
|
|
|
|
get => keyUpTextColor;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value != keyUpTextColor)
|
|
|
|
{
|
|
|
|
keyUpTextColor = value;
|
2023-04-25 20:22:55 +08:00
|
|
|
foreach (var child in KeyFlow.Cast<DefaultKeyCounter>())
|
2023-03-09 05:10:34 +08:00
|
|
|
child.KeyUpTextColor = value;
|
2023-02-13 09:33:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|