Skip to content

Commit

Permalink
Fix legacy key counter's background being visible when intended to be…
Browse files Browse the repository at this point in the history
… hidden
  • Loading branch information
peppy committed Aug 6, 2024
1 parent 90395ae commit 8619bbb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
11 changes: 5 additions & 6 deletions osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using osu.Framework.Audio.Track;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
Expand Down Expand Up @@ -45,7 +44,7 @@ public partial class TestSceneHUDOverlay : OsuManualInputManagerTestScene

// best way to check without exposing.
private Drawable hideTarget => hudOverlay.ChildrenOfType<SkinComponentsContainer>().First();
private Drawable keyCounterFlow => hudOverlay.ChildrenOfType<KeyCounterDisplay>().First().ChildrenOfType<FillFlowContainer<KeyCounter>>().Single();
private Drawable keyCounterContent => hudOverlay.ChildrenOfType<KeyCounterDisplay>().First().ChildrenOfType<Drawable>().Skip(1).First();

public TestSceneHUDOverlay()
{
Expand Down Expand Up @@ -79,7 +78,7 @@ public void TestShownByDefault()
AddAssert("showhud is set", () => hudOverlay.ShowHud.Value);

AddAssert("hidetarget is visible", () => hideTarget.Alpha, () => Is.GreaterThan(0));
AddAssert("key counter flow is visible", () => keyCounterFlow.IsPresent);
AddAssert("key counter flow is visible", () => keyCounterContent.IsPresent);
AddAssert("pause button is visible", () => hudOverlay.HoldToQuit.IsPresent);
}

Expand All @@ -104,7 +103,7 @@ public void TestHideExternally()
AddAssert("pause button is still visible", () => hudOverlay.HoldToQuit.IsPresent);

// Key counter flow container should not be affected by this, only the key counter display will be hidden as checked above.
AddAssert("key counter flow not affected", () => keyCounterFlow.IsPresent);
AddAssert("key counter flow not affected", () => keyCounterContent.IsPresent);
}

[Test]
Expand Down Expand Up @@ -150,11 +149,11 @@ public void TestChangeHUDVisibilityOnHiddenKeyCounter()

AddStep("set showhud false", () => hudOverlay.ShowHud.Value = false);
AddUntilStep("hidetarget is hidden", () => hideTarget.Alpha, () => Is.LessThanOrEqualTo(0));
AddUntilStep("key counters hidden", () => !keyCounterFlow.IsPresent);
AddUntilStep("key counters hidden", () => !keyCounterContent.IsPresent);

AddStep("set showhud true", () => hudOverlay.ShowHud.Value = true);
AddUntilStep("hidetarget is visible", () => hideTarget.Alpha, () => Is.GreaterThan(0));
AddUntilStep("key counters still hidden", () => !keyCounterFlow.IsPresent);
AddUntilStep("key counters still hidden", () => !keyCounterContent.IsPresent);
}

[Test]
Expand Down
3 changes: 1 addition & 2 deletions osu.Game/Screens/Play/ArgonKeyCounterDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ public partial class ArgonKeyCounterDisplay : KeyCounterDisplay

public ArgonKeyCounterDisplay()
{
InternalChild = KeyFlow = new FillFlowContainer<KeyCounter>
Child = KeyFlow = new FillFlowContainer<KeyCounter>
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Alpha = 0,
Spacing = new Vector2(2),
};
}
Expand Down
3 changes: 1 addition & 2 deletions osu.Game/Screens/Play/HUD/DefaultKeyCounterDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ public partial class DefaultKeyCounterDisplay : KeyCounterDisplay

public DefaultKeyCounterDisplay()
{
InternalChild = KeyFlow = new FillFlowContainer<KeyCounter>
Child = KeyFlow = new FillFlowContainer<KeyCounter>
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Alpha = 0,
};
}

Expand Down
35 changes: 23 additions & 12 deletions osu.Game/Screens/Play/HUD/KeyCounterDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace osu.Game.Screens.Play.HUD
/// <summary>
/// A flowing display of all gameplay keys. Individual keys can be added using <see cref="InputTrigger"/> implementations.
/// </summary>
public abstract partial class KeyCounterDisplay : CompositeDrawable, ISerialisableDrawable
public abstract partial class KeyCounterDisplay : Container, ISerialisableDrawable
{
/// <summary>
/// Whether the key counter should be visible regardless of the configuration value.
Expand All @@ -29,25 +29,22 @@ public abstract partial class KeyCounterDisplay : CompositeDrawable, ISerialisab

private readonly IBindableList<InputTrigger> triggers = new BindableList<InputTrigger>();

protected override Container<Drawable> Content { get; } = new Container
{
Alpha = 0,
AutoSizeAxes = Axes.Both,
};

[Resolved]
private InputCountController controller { get; set; } = null!;

private const int duration = 100;

protected void UpdateVisibility()
protected KeyCounterDisplay()
{
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;
AddInternal(Content);
}

protected abstract KeyCounter CreateCounter(InputTrigger trigger);

[BackgroundDependencyLoader]
private void load(OsuConfigManager config, DrawableRuleset? drawableRuleset)
{
Expand All @@ -70,6 +67,20 @@ protected override void LoadComplete()
ConfigVisibility.BindValueChanged(_ => UpdateVisibility(), true);
}

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

// Isolate changing visibility of the key counters from fading this component.
Content.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.
Content.AlwaysPresent = visible;
}

protected abstract KeyCounter CreateCounter(InputTrigger trigger);

private void triggersChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
KeyFlow.Clear();
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Skinning/LegacyKeyCounterDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public LegacyKeyCounterDisplay()
{
AutoSizeAxes = Axes.Both;

AddRangeInternal(new Drawable[]
AddRange(new Drawable[]
{
backgroundSprite = new Sprite
{
Expand Down

0 comments on commit 8619bbb

Please sign in to comment.