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