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

Fix hold to pause button not working when HUD is hidden #21020

Merged
merged 3 commits into from
Oct 30, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// 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.

#nullable disable

using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Timing;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
Expand All @@ -26,9 +26,9 @@ namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneHUDOverlay : OsuManualInputManagerTestScene
{
private OsuConfigManager localConfig;
private OsuConfigManager localConfig = null!;

private HUDOverlay hudOverlay;
private HUDOverlay hudOverlay = null!;

[Cached]
private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset());
Expand Down Expand Up @@ -149,6 +149,41 @@ public void TestChangeHUDVisibilityOnHiddenKeyCounter()
AddAssert("key counters still hidden", () => !keyCounterFlow.IsPresent);
}

[Test]
public void TestHoldForMenuDoesWorkWhenHidden()
{
bool activated = false;

HoldForMenuButton getHoldForMenu() => hudOverlay.ChildrenOfType<HoldForMenuButton>().Single();

createNew();

AddStep("bind action", () =>
{
activated = false;

var holdForMenu = getHoldForMenu();

holdForMenu.Action += () => activated = true;
});

AddStep("set showhud false", () => hudOverlay.ShowHud.Value = false);
AddUntilStep("hidetarget is hidden", () => !hideTarget.IsPresent);

AddStep("attempt activate", () =>
{
InputManager.MoveMouseTo(getHoldForMenu().OfType<HoldToConfirmContainer>().Single());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Threw me off for a hot minute that this was enumerating the children of the HoldForMenuButton but sure.

InputManager.PressButton(MouseButton.Left);
});

AddUntilStep("activated", () => activated);

AddStep("release mouse button", () =>
{
InputManager.ReleaseButton(MouseButton.Left);
});
}

[Test]
public void TestInputDoesntWorkWhenHUDHidden()
{
Expand Down Expand Up @@ -220,7 +255,7 @@ public void TestHiddenHUDDoesntBlockSkinnableComponentsLoad()
AddUntilStep("skinnable components loaded", () => hudOverlay.ChildrenOfType<SkinnableTargetContainer>().Single().ComponentsLoaded);
}

private void createNew(Action<HUDOverlay> action = null)
private void createNew(Action<HUDOverlay>? action = null)
{
AddStep("create overlay", () =>
{
Expand All @@ -239,7 +274,9 @@ private void createNew(Action<HUDOverlay> action = null)

protected override void Dispose(bool isDisposing)
{
localConfig?.Dispose();
if (localConfig.IsNotNull())
localConfig.Dispose();

base.Dispose(isDisposing);
}
}
Expand Down
13 changes: 10 additions & 3 deletions osu.Game/Screens/Play/HUDOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ public class HUDOverlay : Container, IKeyBindingHandler<GlobalAction>
/// </summary>
public float BottomScoringElementsHeight { get; private set; }

// HUD uses AlwaysVisible on child components so they can be in an updated state for next display.
// Without blocking input, this would also allow them to be interacted with in such a state.
public override bool PropagatePositionalInputSubTree => ShowHud.Value;
protected override bool ShouldBeConsideredForInput(Drawable child)
{
// HUD uses AlwaysVisible on child components so they can be in an updated state for next display.
// Without blocking input, this would also allow them to be interacted with in such a state.
if (ShowHud.Value)
return base.ShouldBeConsideredForInput(child);

// hold to quit button should always be interactive.
return child == bottomRightElements;
}

public readonly KeyCounterDisplay KeyCounter;
public readonly ModDisplay ModDisplay;
Expand Down