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.
|
|
|
|
|
|
|
|
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-08 09:52:12 +08:00
|
|
|
private readonly FillFlowContainer<KeyCounter> keyFlow = new FillFlowContainer<KeyCounter>();
|
2023-02-22 22:58:27 +08:00
|
|
|
|
2023-03-08 09:52:12 +08:00
|
|
|
public override Container<KeyCounter> Counters => keyFlow;
|
2023-02-13 09:33:09 +08:00
|
|
|
|
|
|
|
public DefaultKeyCounterDisplay()
|
|
|
|
{
|
2023-02-22 22:58:27 +08:00
|
|
|
keyFlow.Direction = FillDirection.Horizontal;
|
|
|
|
keyFlow.AutoSizeAxes = Axes.Both;
|
|
|
|
keyFlow.Alpha = 0;
|
2023-02-16 06:06:10 +08:00
|
|
|
|
2023-02-22 22:58:27 +08:00
|
|
|
InternalChild = keyFlow;
|
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-02-22 23:03:44 +08:00
|
|
|
public override void AddTrigger(InputTrigger trigger)
|
2023-02-22 22:58:27 +08:00
|
|
|
{
|
|
|
|
DefaultKeyCounter key = new DefaultKeyCounter(trigger);
|
2023-03-08 08:47:16 +08:00
|
|
|
keyFlow.Add(key);
|
2023-02-22 22:58:27 +08:00
|
|
|
key.FadeTime = key_fade_time;
|
|
|
|
key.KeyDownTextColor = KeyDownTextColor;
|
|
|
|
key.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-08 09:52:12 +08:00
|
|
|
((DefaultKeyCounter)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-08 09:52:12 +08:00
|
|
|
((DefaultKeyCounter)child).KeyUpTextColor = value;
|
2023-02-13 09:33:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|