Skip to content

Commit

Permalink
Merge pull request ppy#25411 from peppy/fix-key-counter-sizing-woes
Browse files Browse the repository at this point in the history
Refactor `KeyCounterDisplay` to use autosize
  • Loading branch information
bdach authored Nov 12, 2023
2 parents 469b9e2 + 7d26de7 commit bb2f38d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
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

0 comments on commit bb2f38d

Please sign in to comment.