1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:33:21 +08:00

Merge pull request #21020 from peppy/fix-pause-button-interaction

Fix hold to pause button not working when HUD is hidden
This commit is contained in:
Bartłomiej Dach 2022-10-30 14:23:18 +01:00 committed by GitHub
commit 93c3bc6550
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 9 deletions

View File

@ -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;
@ -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());
@ -149,6 +149,41 @@ namespace osu.Game.Tests.Visual.Gameplay
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());
InputManager.PressButton(MouseButton.Left);
});
AddUntilStep("activated", () => activated);
AddStep("release mouse button", () =>
{
InputManager.ReleaseButton(MouseButton.Left);
});
}
[Test]
public void TestInputDoesntWorkWhenHUDHidden()
{
@ -220,7 +255,7 @@ namespace osu.Game.Tests.Visual.Gameplay
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", () =>
{
@ -239,7 +274,9 @@ namespace osu.Game.Tests.Visual.Gameplay
protected override void Dispose(bool isDisposing)
{
localConfig?.Dispose();
if (localConfig.IsNotNull())
localConfig.Dispose();
base.Dispose(isDisposing);
}
}

View File

@ -39,9 +39,16 @@ namespace osu.Game.Screens.Play
/// </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;