mirror of
https://github.com/ppy/osu.git
synced 2026-05-19 05:09:54 +08:00
Store input padding adjustments in CarouselItem to allow more reliable inflation
This commit is contained in:
@@ -177,7 +177,6 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("broken")]
|
||||
public void TestInputHandlingWithinGaps()
|
||||
{
|
||||
AddAssert("no beatmaps visible", () => !GetVisiblePanels<PanelBeatmap>().Any());
|
||||
@@ -204,10 +203,10 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
ClickVisiblePanelWithOffset<PanelBeatmap>(0, new Vector2(0, -(CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
|
||||
WaitForGroupSelection(0, 1);
|
||||
|
||||
ClickVisiblePanelWithOffset<PanelBeatmap>(1, new Vector2(0, (CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
|
||||
ClickVisiblePanelWithOffset<PanelBeatmap>(1, new Vector2(0, CarouselItem.DEFAULT_HEIGHT / 2 + 1));
|
||||
WaitForGroupSelection(0, 2);
|
||||
|
||||
ClickVisiblePanelWithOffset<PanelBeatmapSet>(1, new Vector2(0, (CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
|
||||
ClickVisiblePanelWithOffset<PanelBeatmapSet>(1, new Vector2(0, CarouselItem.DEFAULT_HEIGHT / 2 + 1));
|
||||
WaitForGroupSelection(0, 5);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,6 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("broken")]
|
||||
public void TestInputHandlingWithinGaps()
|
||||
{
|
||||
AddAssert("no beatmaps visible", () => !GetVisiblePanels<PanelBeatmapStandalone>().Any());
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.Carousel;
|
||||
using osu.Game.Screens.Select.Filter;
|
||||
using osu.Game.Screens.SelectV2;
|
||||
using osuTK;
|
||||
@@ -259,7 +258,6 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("broken")]
|
||||
public void TestInputHandlingWithinGaps()
|
||||
{
|
||||
AddBeatmaps(2, 5);
|
||||
@@ -278,14 +276,16 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
WaitForSelection(0, 0);
|
||||
|
||||
// Beatmap panels expand their selection area to cover holes from spacing.
|
||||
ClickVisiblePanelWithOffset<PanelBeatmap>(1, new Vector2(0, -(CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
|
||||
ClickVisiblePanelWithOffset<PanelBeatmap>(0, new Vector2(0, -(PanelBeatmap.HEIGHT / 2 + 1)));
|
||||
WaitForSelection(0, 0);
|
||||
|
||||
// Panels with higher depth will handle clicks in the gutters for simplicity.
|
||||
ClickVisiblePanelWithOffset<PanelBeatmap>(2, new Vector2(0, (CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
|
||||
ClickVisiblePanelWithOffset<PanelBeatmap>(2, new Vector2(0, (PanelBeatmap.HEIGHT / 2 + 1)));
|
||||
WaitForSelection(0, 2);
|
||||
|
||||
ClickVisiblePanelWithOffset<PanelBeatmap>(3, new Vector2(0, (CarouselItem.DEFAULT_HEIGHT / 2 + 1)));
|
||||
ClickVisiblePanelWithOffset<PanelBeatmap>(2, new Vector2(0, -(PanelBeatmap.HEIGHT / 2 + 1)));
|
||||
WaitForSelection(0, 2);
|
||||
|
||||
ClickVisiblePanelWithOffset<PanelBeatmap>(3, new Vector2(0, (PanelBeatmap.HEIGHT / 2 + 1)));
|
||||
WaitForSelection(0, 3);
|
||||
}
|
||||
|
||||
|
||||
@@ -395,6 +395,10 @@ namespace osu.Game.Graphics.Carousel
|
||||
offset += spacing;
|
||||
item.CarouselYPosition = offset;
|
||||
|
||||
item.CarouselInputLenienceAbove = spacing / 2;
|
||||
if (previousVisible != null)
|
||||
previousVisible.CarouselInputLenienceBelow = item.CarouselInputLenienceAbove;
|
||||
|
||||
if (item.IsVisible)
|
||||
{
|
||||
offset += item.DrawHeight;
|
||||
|
||||
@@ -20,10 +20,27 @@ namespace osu.Game.Graphics.Carousel
|
||||
|
||||
/// <summary>
|
||||
/// The current Y position in the carousel.
|
||||
///
|
||||
/// This is managed by <see cref="Carousel{T}"/> and should not be set manually.
|
||||
/// </summary>
|
||||
public double CarouselYPosition { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount of input padding/lenience to be added to the area above this panel.
|
||||
/// Calculated as half of the calculated spacing between this panel and the panel above it.
|
||||
///
|
||||
/// This is managed by <see cref="Carousel{T}"/> and should not be set manually.
|
||||
/// </summary>
|
||||
public float CarouselInputLenienceAbove { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The amount of input padding/lenience to be added to the area below this panel.
|
||||
/// Calculated as half of the calculated spacing between this panel and the panel below it.
|
||||
///
|
||||
/// This is managed by <see cref="Carousel{T}"/> and should not be set manually.
|
||||
/// </summary>
|
||||
public float CarouselInputLenienceBelow { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The height this item will take when displayed. Defaults to <see cref="DEFAULT_HEIGHT"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -68,10 +68,19 @@ namespace osu.Game.Screens.SelectV2
|
||||
}
|
||||
}
|
||||
|
||||
// content is offset by PanelXOffset, make sure we only handle input at the actual visible
|
||||
// offset region.
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
|
||||
TopLevelContent.ReceivePositionalInputAt(screenSpacePos);
|
||||
public sealed override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
||||
{
|
||||
var inputRectangle = TopLevelContent.DrawRectangle;
|
||||
|
||||
// Cover the gaps introduced by the spacing between panels so that user mis-aims don't result in no-ops.
|
||||
inputRectangle = inputRectangle.Inflate(new MarginPadding
|
||||
{
|
||||
Top = item!.CarouselInputLenienceAbove,
|
||||
Bottom = item!.CarouselInputLenienceBelow,
|
||||
});
|
||||
|
||||
return inputRectangle.Contains(TopLevelContent.ToLocalSpace(screenSpacePos));
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private BeatmapCarousel? carousel { get; set; }
|
||||
|
||||
@@ -72,19 +72,6 @@ namespace osu.Game.Screens.SelectV2
|
||||
PanelXOffset = 60;
|
||||
}
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
||||
{
|
||||
var inputRectangle = TopLevelContent.DrawRectangle;
|
||||
|
||||
// Cover the gaps introduced by the spacing between BeatmapPanels so that clicks will not fall through the carousel.
|
||||
//
|
||||
// Caveat is that for simplicity, we are covering the full spacing, so panels with frontmost depth will have a slightly
|
||||
// larger hit target.
|
||||
inputRectangle = inputRectangle.Inflate(new MarginPadding { Vertical = BeatmapCarousel.SPACING });
|
||||
|
||||
return inputRectangle.Contains(TopLevelContent.ToLocalSpace(screenSpacePos));
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colourProvider)
|
||||
{
|
||||
|
||||
@@ -67,19 +67,6 @@ namespace osu.Game.Screens.SelectV2
|
||||
PanelXOffset = 20f;
|
||||
}
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
||||
{
|
||||
var inputRectangle = TopLevelContent.DrawRectangle;
|
||||
|
||||
// Cover the gaps introduced by the spacing between BeatmapPanels so that clicks will not fall through the carousel.
|
||||
//
|
||||
// Caveat is that for simplicity, we are covering the full spacing, so panels with frontmost depth will have a slightly
|
||||
// larger hit target.
|
||||
inputRectangle = inputRectangle.Inflate(new MarginPadding { Vertical = BeatmapCarousel.SPACING });
|
||||
|
||||
return inputRectangle.Contains(TopLevelContent.ToLocalSpace(screenSpacePos));
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
|
||||
@@ -71,22 +71,6 @@ namespace osu.Game.Screens.SelectV2
|
||||
private OsuSpriteText authorText = null!;
|
||||
private FillFlowContainer mainFill = null!;
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)
|
||||
{
|
||||
var inputRectangle = TopLevelContent.DrawRectangle;
|
||||
|
||||
if (Selected.Value)
|
||||
{
|
||||
// Cover the gaps introduced by the spacing between BeatmapPanels so that clicks will not fall through the carousel.
|
||||
//
|
||||
// Caveat is that for simplicity, we are covering the full spacing, so panels with frontmost depth will have a slightly
|
||||
// larger hit target.
|
||||
inputRectangle = inputRectangle.Inflate(new MarginPadding { Vertical = BeatmapCarousel.SPACING * 2 });
|
||||
}
|
||||
|
||||
return inputRectangle.Contains(TopLevelContent.ToLocalSpace(screenSpacePos));
|
||||
}
|
||||
|
||||
public PanelBeatmapStandalone()
|
||||
{
|
||||
PanelXOffset = 20;
|
||||
|
||||
Reference in New Issue
Block a user