2021-12-05 22:04:44 +08:00
|
|
|
// 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.
|
|
|
|
|
2021-12-05 23:31:45 +08:00
|
|
|
#nullable enable
|
|
|
|
|
2021-12-06 00:35:10 +08:00
|
|
|
using System;
|
2021-12-05 22:04:44 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-12-05 22:48:02 +08:00
|
|
|
using osu.Framework.Graphics.Effects;
|
2021-12-05 22:04:44 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-12-06 00:35:10 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2021-12-05 23:31:45 +08:00
|
|
|
using osu.Framework.Threading;
|
2021-12-06 00:35:10 +08:00
|
|
|
using osu.Framework.Utils;
|
|
|
|
using osu.Game.Graphics.Containers;
|
2021-12-05 22:04:44 +08:00
|
|
|
using osu.Game.Overlays;
|
2021-12-05 22:48:02 +08:00
|
|
|
using osuTK;
|
2021-12-05 22:04:44 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables.Cards
|
|
|
|
{
|
2021-12-07 03:49:29 +08:00
|
|
|
public class BeatmapCardContent : CompositeDrawable
|
2021-12-05 22:04:44 +08:00
|
|
|
{
|
2021-12-07 03:49:29 +08:00
|
|
|
public Drawable MainContent
|
2021-12-05 22:04:44 +08:00
|
|
|
{
|
|
|
|
set => bodyContent.Child = value;
|
|
|
|
}
|
|
|
|
|
2021-12-07 03:49:29 +08:00
|
|
|
public Drawable ExpandedContent
|
2021-12-05 22:04:44 +08:00
|
|
|
{
|
2021-12-06 00:35:10 +08:00
|
|
|
set => dropdownScroll.Child = value;
|
2021-12-05 22:04:44 +08:00
|
|
|
}
|
|
|
|
|
2021-12-15 14:51:47 +08:00
|
|
|
public IBindable<bool> Expanded => expanded;
|
|
|
|
|
|
|
|
private readonly BindableBool expanded = new BindableBool();
|
2021-12-05 22:04:44 +08:00
|
|
|
|
|
|
|
private readonly Box background;
|
2021-12-05 22:48:02 +08:00
|
|
|
private readonly Container content;
|
2021-12-05 22:04:44 +08:00
|
|
|
private readonly Container bodyContent;
|
|
|
|
private readonly Container dropdownContent;
|
2021-12-06 00:35:10 +08:00
|
|
|
private readonly OsuScrollContainer dropdownScroll;
|
2021-12-05 22:48:02 +08:00
|
|
|
private readonly Container borderContainer;
|
2021-12-05 22:04:44 +08:00
|
|
|
|
2021-12-07 03:49:29 +08:00
|
|
|
public BeatmapCardContent(float height)
|
2021-12-05 22:04:44 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Height = height;
|
|
|
|
|
2021-12-06 13:26:11 +08:00
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
2021-12-05 23:31:45 +08:00
|
|
|
InternalChild = content = new HoverHandlingContainer
|
2021-12-05 22:04:44 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
CornerRadius = BeatmapCard.CORNER_RADIUS,
|
|
|
|
Masking = true,
|
2021-12-05 23:31:45 +08:00
|
|
|
Unhovered = _ => checkForHide(),
|
2021-12-05 22:04:44 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
},
|
|
|
|
bodyContent = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = height,
|
|
|
|
CornerRadius = BeatmapCard.CORNER_RADIUS,
|
|
|
|
Masking = true,
|
|
|
|
},
|
2021-12-05 23:31:45 +08:00
|
|
|
dropdownContent = new HoverHandlingContainer
|
2021-12-05 22:04:44 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Margin = new MarginPadding { Top = height },
|
2021-12-05 23:31:45 +08:00
|
|
|
Alpha = 0,
|
|
|
|
Hovered = _ =>
|
|
|
|
{
|
|
|
|
keep();
|
|
|
|
return true;
|
|
|
|
},
|
2021-12-06 00:35:10 +08:00
|
|
|
Unhovered = _ => checkForHide(),
|
2021-12-07 03:49:29 +08:00
|
|
|
Child = dropdownScroll = new ExpandedContentScrollContainer
|
2021-12-06 00:35:10 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
ScrollbarVisible = false
|
|
|
|
}
|
2021-12-05 22:48:02 +08:00
|
|
|
},
|
|
|
|
borderContainer = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
CornerRadius = BeatmapCard.CORNER_RADIUS,
|
|
|
|
Masking = true,
|
|
|
|
BorderThickness = 3,
|
|
|
|
Child = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
AlwaysPresent = true
|
|
|
|
}
|
2021-12-05 22:04:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
{
|
|
|
|
background.Colour = colourProvider.Background2;
|
2021-12-05 22:48:02 +08:00
|
|
|
borderContainer.BorderColour = colourProvider.Highlight1;
|
2021-12-05 22:04:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2021-12-05 22:48:02 +08:00
|
|
|
Expanded.BindValueChanged(_ => updateState(), true);
|
|
|
|
FinishTransforms(true);
|
2021-12-05 22:04:44 +08:00
|
|
|
}
|
|
|
|
|
2021-12-05 23:31:45 +08:00
|
|
|
private ScheduledDelegate? scheduledExpandedChange;
|
|
|
|
|
|
|
|
public void ScheduleShow()
|
|
|
|
{
|
|
|
|
scheduledExpandedChange?.Cancel();
|
2021-12-06 00:16:41 +08:00
|
|
|
if (Expanded.Disabled || Expanded.Value)
|
2021-12-05 23:31:45 +08:00
|
|
|
return;
|
|
|
|
|
2021-12-06 00:16:41 +08:00
|
|
|
scheduledExpandedChange = Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
if (!Expanded.Disabled)
|
2021-12-15 14:51:47 +08:00
|
|
|
expanded.Value = true;
|
2021-12-06 00:16:41 +08:00
|
|
|
}, 100);
|
2021-12-05 23:31:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ScheduleHide()
|
|
|
|
{
|
|
|
|
scheduledExpandedChange?.Cancel();
|
2021-12-06 00:16:41 +08:00
|
|
|
if (Expanded.Disabled || !Expanded.Value)
|
2021-12-05 23:31:45 +08:00
|
|
|
return;
|
|
|
|
|
2021-12-06 00:16:41 +08:00
|
|
|
scheduledExpandedChange = Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
if (!Expanded.Disabled)
|
2021-12-15 14:51:47 +08:00
|
|
|
expanded.Value = false;
|
2021-12-06 00:16:41 +08:00
|
|
|
}, 500);
|
2021-12-05 23:31:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void checkForHide()
|
|
|
|
{
|
2021-12-06 00:16:41 +08:00
|
|
|
if (Expanded.Disabled)
|
|
|
|
return;
|
|
|
|
|
2021-12-05 23:31:45 +08:00
|
|
|
if (content.IsHovered || dropdownContent.IsHovered)
|
|
|
|
return;
|
|
|
|
|
|
|
|
scheduledExpandedChange?.Cancel();
|
2021-12-15 14:51:47 +08:00
|
|
|
expanded.Value = false;
|
2021-12-05 23:31:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void keep()
|
|
|
|
{
|
2021-12-06 00:16:41 +08:00
|
|
|
if (Expanded.Disabled)
|
|
|
|
return;
|
|
|
|
|
2021-12-05 23:31:45 +08:00
|
|
|
scheduledExpandedChange?.Cancel();
|
2021-12-15 14:51:47 +08:00
|
|
|
expanded.Value = true;
|
2021-12-05 23:31:45 +08:00
|
|
|
}
|
|
|
|
|
2021-12-05 22:04:44 +08:00
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
background.FadeTo(Expanded.Value ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
dropdownContent.FadeTo(Expanded.Value ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
2021-12-05 22:48:02 +08:00
|
|
|
borderContainer.FadeTo(Expanded.Value ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
|
|
|
|
content.TweenEdgeEffectTo(new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Offset = new Vector2(0, 2),
|
|
|
|
Radius = 10,
|
|
|
|
Colour = Colour4.Black.Opacity(Expanded.Value ? 0.3f : 0f),
|
|
|
|
Hollow = true,
|
|
|
|
}, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
2021-12-05 22:04:44 +08:00
|
|
|
}
|
2021-12-06 00:35:10 +08:00
|
|
|
|
2021-12-07 03:49:29 +08:00
|
|
|
private class ExpandedContentScrollContainer : OsuScrollContainer
|
2021-12-06 00:35:10 +08:00
|
|
|
{
|
2021-12-07 03:49:29 +08:00
|
|
|
public ExpandedContentScrollContainer()
|
2021-12-06 00:35:10 +08:00
|
|
|
{
|
|
|
|
ScrollbarVisible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
Height = Math.Min(Content.DrawHeight, 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool allowScroll => !Precision.AlmostEquals(DrawSize, Content.DrawSize);
|
|
|
|
|
|
|
|
protected override bool OnDragStart(DragStartEvent e)
|
|
|
|
{
|
|
|
|
if (!allowScroll)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return base.OnDragStart(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDrag(DragEvent e)
|
|
|
|
{
|
|
|
|
if (!allowScroll)
|
|
|
|
return;
|
|
|
|
|
|
|
|
base.OnDrag(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDragEnd(DragEndEvent e)
|
|
|
|
{
|
|
|
|
if (!allowScroll)
|
|
|
|
return;
|
|
|
|
|
|
|
|
base.OnDragEnd(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnScroll(ScrollEvent e)
|
|
|
|
{
|
|
|
|
if (!allowScroll)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return base.OnScroll(e);
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 22:04:44 +08:00
|
|
|
}
|
|
|
|
}
|