mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 00:23:59 +09:00
Merge pull request #17905 from peppy/sheared-overlay-container-click-away
Add better click-to-dismiss logic for sheared overlays
This commit is contained in:
@ -0,0 +1,102 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.Mods;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class TestSceneShearedOverlayContainer : OsuManualInputManagerTestScene
|
||||||
|
{
|
||||||
|
private TestShearedOverlayContainer overlay;
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetUpSteps()
|
||||||
|
{
|
||||||
|
AddStep("create overlay", () =>
|
||||||
|
{
|
||||||
|
Child = overlay = new TestShearedOverlayContainer
|
||||||
|
{
|
||||||
|
State = { Value = Visibility.Visible }
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestClickAwayToExit()
|
||||||
|
{
|
||||||
|
AddStep("click inside header", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(overlay.ChildrenOfType<ShearedOverlayHeader>().First().ScreenSpaceDrawQuad.Centre);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("overlay not dismissed", () => overlay.State.Value == Visibility.Visible);
|
||||||
|
|
||||||
|
AddStep("click inside content", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(overlay.ScreenSpaceDrawQuad.Centre);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("overlay not dismissed", () => overlay.State.Value == Visibility.Visible);
|
||||||
|
|
||||||
|
AddStep("click outside header", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(new Vector2(overlay.ScreenSpaceDrawQuad.TopLeft.X, overlay.ScreenSpaceDrawQuad.Centre.Y));
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("overlay dismissed", () => overlay.State.Value == Visibility.Hidden);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TestShearedOverlayContainer : ShearedOverlayContainer
|
||||||
|
{
|
||||||
|
protected override OverlayColourScheme ColourScheme => OverlayColourScheme.Green;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
Header.Title = "Sheared overlay header";
|
||||||
|
Header.Description = string.Join(" ", Enumerable.Repeat("This is a description.", 20));
|
||||||
|
|
||||||
|
MainAreaContent.Child = new InputBlockingContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Size = new Vector2(0.9f),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
Colour = Color4.Blue,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
},
|
||||||
|
new OsuSpriteText
|
||||||
|
{
|
||||||
|
Font = OsuFont.Default.With(size: 24),
|
||||||
|
Text = "Content",
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
osu.Game/Graphics/InputBlockingContainer.cs
Normal file
21
osu.Game/Graphics/InputBlockingContainer.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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 enable
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
|
||||||
|
namespace osu.Game.Graphics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A simple container which blocks input events from travelling through it.
|
||||||
|
/// </summary>
|
||||||
|
public class InputBlockingContainer : Container
|
||||||
|
{
|
||||||
|
protected override bool OnHover(HoverEvent e) => true;
|
||||||
|
|
||||||
|
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
||||||
|
|
||||||
|
protected override bool OnClick(ClickEvent e) => true;
|
||||||
|
}
|
||||||
|
}
|
@ -66,7 +66,7 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
},
|
},
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
underlayContainer = new Container
|
underlayContainer = new InputBlockingContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Height = HEIGHT,
|
Height = HEIGHT,
|
||||||
|
@ -52,7 +52,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
Height = HEIGHT;
|
Height = HEIGHT;
|
||||||
AutoSizeAxes = Axes.X;
|
AutoSizeAxes = Axes.X;
|
||||||
|
|
||||||
InternalChild = new Container
|
InternalChild = new InputBlockingContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
AutoSizeAxes = Axes.X,
|
AutoSizeAxes = Axes.X,
|
||||||
|
@ -5,6 +5,8 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
|
||||||
@ -88,7 +90,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
Bottom = footer_height + PADDING,
|
Bottom = footer_height + PADDING,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Footer = new Container
|
Footer = new InputBlockingContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Depth = float.MinValue,
|
Depth = float.MinValue,
|
||||||
@ -113,6 +115,17 @@ namespace osu.Game.Overlays.Mods
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool OnClick(ClickEvent e)
|
||||||
|
{
|
||||||
|
if (State.Value == Visibility.Visible)
|
||||||
|
{
|
||||||
|
Hide();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.OnClick(e);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void PopIn()
|
protected override void PopIn()
|
||||||
{
|
{
|
||||||
const double fade_in_duration = 400;
|
const double fade_in_duration = 400;
|
||||||
|
Reference in New Issue
Block a user