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

Implement input handling behaviour of beatmap card dropdown

This commit is contained in:
Bartłomiej Dach 2021-12-05 16:31:45 +01:00
parent 250e5b47b7
commit e451e43b90
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
4 changed files with 88 additions and 7 deletions

View File

@ -44,6 +44,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards
private readonly BeatmapDownloadTracker downloadTracker; private readonly BeatmapDownloadTracker downloadTracker;
private BeatmapCardDropdown dropdown = null!;
private BeatmapCardThumbnail thumbnail = null!; private BeatmapCardThumbnail thumbnail = null!;
private Container rightAreaBackground = null!; private Container rightAreaBackground = null!;
@ -80,7 +82,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards
GridContainer titleContainer; GridContainer titleContainer;
GridContainer artistContainer; GridContainer artistContainer;
InternalChild = new BeatmapCardDropdown(height) InternalChild = dropdown = new BeatmapCardDropdown(height)
{ {
Body = new Container Body = new Container
{ {
@ -277,6 +279,14 @@ namespace osu.Game.Beatmaps.Drawables.Cards
ChildrenEnumerable = createStatistics() ChildrenEnumerable = createStatistics()
}, },
new BeatmapCardExtraInfoRow(beatmapSet) new BeatmapCardExtraInfoRow(beatmapSet)
{
Hovered = _ =>
{
dropdown.ScheduleShow();
return false;
},
Unhovered = _ => dropdown.ScheduleHide()
}
} }
}, },
downloadProgressBar = new BeatmapCardDownloadProgressBar downloadProgressBar = new BeatmapCardDownloadProgressBar

View File

@ -1,12 +1,15 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable enable
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Threading;
using osu.Game.Overlays; using osu.Game.Overlays;
using osuTK; using osuTK;
@ -37,13 +40,13 @@ namespace osu.Game.Beatmaps.Drawables.Cards
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
Height = height; Height = height;
InternalChild = content = new Container InternalChild = content = new HoverHandlingContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
CornerRadius = BeatmapCard.CORNER_RADIUS, CornerRadius = BeatmapCard.CORNER_RADIUS,
Masking = true, Masking = true,
Unhovered = _ => checkForHide(),
Children = new Drawable[] Children = new Drawable[]
{ {
background = new Box background = new Box
@ -57,12 +60,18 @@ namespace osu.Game.Beatmaps.Drawables.Cards
CornerRadius = BeatmapCard.CORNER_RADIUS, CornerRadius = BeatmapCard.CORNER_RADIUS,
Masking = true, Masking = true,
}, },
dropdownContent = new Container dropdownContent = new HoverHandlingContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Top = height }, Margin = new MarginPadding { Top = height },
Alpha = 0 Alpha = 0,
Hovered = _ =>
{
keep();
return true;
},
Unhovered = _ => checkForHide()
}, },
borderContainer = new Container borderContainer = new Container
{ {
@ -95,6 +104,41 @@ namespace osu.Game.Beatmaps.Drawables.Cards
FinishTransforms(true); FinishTransforms(true);
} }
private ScheduledDelegate? scheduledExpandedChange;
public void ScheduleShow()
{
scheduledExpandedChange?.Cancel();
if (Expanded.Value)
return;
scheduledExpandedChange = Scheduler.AddDelayed(() => Expanded.Value = true, 100);
}
public void ScheduleHide()
{
scheduledExpandedChange?.Cancel();
if (!Expanded.Value)
return;
scheduledExpandedChange = Scheduler.AddDelayed(() => Expanded.Value = false, 500);
}
private void checkForHide()
{
if (content.IsHovered || dropdownContent.IsHovered)
return;
scheduledExpandedChange?.Cancel();
Expanded.Value = false;
}
private void keep()
{
scheduledExpandedChange?.Cancel();
Expanded.Value = true;
}
private void updateState() private void updateState()
{ {
background.FadeTo(Expanded.Value ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint); background.FadeTo(Expanded.Value ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);

View File

@ -8,14 +8,14 @@ using osuTK;
namespace osu.Game.Beatmaps.Drawables.Cards namespace osu.Game.Beatmaps.Drawables.Cards
{ {
public class BeatmapCardExtraInfoRow : CompositeDrawable public class BeatmapCardExtraInfoRow : HoverHandlingContainer
{ {
public BeatmapCardExtraInfoRow(APIBeatmapSet beatmapSet) public BeatmapCardExtraInfoRow(APIBeatmapSet beatmapSet)
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
InternalChild = new FillFlowContainer Child = new FillFlowContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,

View File

@ -0,0 +1,27 @@
// 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 System;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
namespace osu.Game.Beatmaps.Drawables.Cards
{
public class HoverHandlingContainer : Container
{
public Func<HoverEvent, bool>? Hovered { get; set; }
public Action<HoverLostEvent>? Unhovered { get; set; }
protected override bool OnHover(HoverEvent e) => Hovered?.Invoke(e) ?? base.OnHover(e);
protected override void OnHoverLost(HoverLostEvent e)
{
if (Unhovered != null)
Unhovered?.Invoke(e);
else
base.OnHoverLost(e);
}
}
}