Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor KeyCounterDisplay to use autosize #25411

Merged
merged 2 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 0 additions & 12 deletions osu.Game/Screens/Play/ArgonKeyCounterDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace osu.Game.Screens.Play
{
public partial class ArgonKeyCounterDisplay : KeyCounterDisplay
{
private const int duration = 100;

protected override FillFlowContainer<KeyCounter> KeyFlow { get; }

public ArgonKeyCounterDisplay()
Expand All @@ -25,16 +23,6 @@ public ArgonKeyCounterDisplay()
};
}

protected override void Update()
{
base.Update();

Size = KeyFlow.Size;
}

protected override KeyCounter CreateCounter(InputTrigger trigger) => new ArgonKeyCounter(trigger);

protected override void UpdateVisibility()
=> KeyFlow.FadeTo(AlwaysVisible.Value || ConfigVisibility.Value ? 1 : 0, duration);
}
}
14 changes: 0 additions & 14 deletions osu.Game/Screens/Play/HUD/DefaultKeyCounterDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace osu.Game.Screens.Play.HUD
{
public partial class DefaultKeyCounterDisplay : KeyCounterDisplay
{
private const int duration = 100;
private const double key_fade_time = 80;

protected override FillFlowContainer<KeyCounter> KeyFlow { get; }
Expand All @@ -25,26 +24,13 @@ public DefaultKeyCounterDisplay()
};
}

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.
Size = KeyFlow.Size;
}

protected override KeyCounter CreateCounter(InputTrigger trigger) => new DefaultKeyCounter(trigger)
{
FadeTime = key_fade_time,
KeyDownTextColor = KeyDownTextColor,
KeyUpTextColor = KeyUpTextColor,
};

protected override void UpdateVisibility() =>
// Isolate changing visibility of the key counters from fading this component.
KeyFlow.FadeTo(AlwaysVisible.Value || ConfigVisibility.Value ? 1 : 0, duration);

private Color4 keyDownTextColor = Color4.DarkGray;

public Color4 KeyDownTextColor
Expand Down
17 changes: 16 additions & 1 deletion osu.Game/Screens/Play/HUD/KeyCounterDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Specialized;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
using osu.Game.Rulesets.UI;
Expand Down Expand Up @@ -31,13 +32,27 @@ public abstract partial class KeyCounterDisplay : CompositeDrawable, ISerialisab
[Resolved]
private InputCountController controller { get; set; } = null!;

protected abstract void UpdateVisibility();
private const int duration = 100;

protected void UpdateVisibility()
{
bool visible = AlwaysVisible.Value || ConfigVisibility.Value;

// Isolate changing visibility of the key counters from fading this component.
KeyFlow.FadeTo(visible ? 1 : 0, duration);

// Ensure a valid size is immediately obtained even if partially off-screen
// See https://github.com/ppy/osu/issues/14793.
KeyFlow.AlwaysPresent = visible;
}

protected abstract KeyCounter CreateCounter(InputTrigger trigger);

[BackgroundDependencyLoader]
private void load(OsuConfigManager config, DrawableRuleset? drawableRuleset)
{
AutoSizeAxes = Axes.Both;

config.BindWith(OsuSetting.KeyOverlay, ConfigVisibility);

if (drawableRuleset != null)
Expand Down