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-03-09 05:10:34 +08:00
|
|
|
using System.Collections.Generic;
|
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-03-15 17:02:12 +08:00
|
|
|
private readonly FillFlowContainer<DefaultKeyCounter> keyFlow;
|
2023-02-22 22:58:27 +08:00
|
|
|
|
2023-03-09 05:10:34 +08:00
|
|
|
public override IEnumerable<KeyCounter> Counters => keyFlow;
|
2023-02-13 09:33:09 +08:00
|
|
|
|
|
|
|
public DefaultKeyCounterDisplay()
|
|
|
|
{
|
2023-03-15 17:02:12 +08:00
|
|
|
InternalChild = keyFlow = new FillFlowContainer<DefaultKeyCounter>
|
|
|
|
{
|
|
|
|
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-02-22 22:58:27 +08:00
|
|
|
Size = keyFlow.Size;
|
|
|
|
}
|
|
|
|
|
2023-03-15 17:02:41 +08:00
|
|
|
public override void Add(InputTrigger trigger) =>
|
2023-03-15 17:02:12 +08:00
|
|
|
keyFlow.Add(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-02-22 22:58:27 +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-03-08 08:47:16 +08:00
|
|
|
foreach (var child in keyFlow)
|
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-03-08 08:47:16 +08:00
|
|
|
foreach (var child in keyFlow)
|
2023-03-09 05:10:34 +08:00
|
|
|
child.KeyUpTextColor = value;
|
2023-02-13 09:33:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|