2021-12-17 19:58:05 +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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Beatmaps.Drawables.Cards.Buttons;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Online;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables.Cards
|
|
|
|
{
|
|
|
|
public partial class CollapsibleButtonContainer : Container
|
|
|
|
{
|
|
|
|
public Bindable<bool> ShowDetails = new Bindable<bool>();
|
|
|
|
public Bindable<BeatmapSetFavouriteState> FavouriteState = new Bindable<BeatmapSetFavouriteState>();
|
|
|
|
|
|
|
|
private readonly BeatmapDownloadTracker downloadTracker;
|
|
|
|
|
|
|
|
private float buttonsExpandedWidth;
|
|
|
|
|
|
|
|
public float ButtonsExpandedWidth
|
|
|
|
{
|
|
|
|
get => buttonsExpandedWidth;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
buttonsExpandedWidth = value;
|
|
|
|
buttonArea.Width = value;
|
|
|
|
if (IsLoaded)
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private float buttonsCollapsedWidth;
|
|
|
|
|
|
|
|
public float ButtonsCollapsedWidth
|
|
|
|
{
|
|
|
|
get => buttonsCollapsedWidth;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
buttonsCollapsedWidth = value;
|
|
|
|
if (IsLoaded)
|
|
|
|
updateState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Container<Drawable> Content => mainContent;
|
|
|
|
|
|
|
|
private readonly Container background;
|
|
|
|
|
|
|
|
private readonly Container buttonArea;
|
|
|
|
private readonly Container<BeatmapCardIconButton> buttons;
|
|
|
|
|
|
|
|
private readonly Container mainArea;
|
|
|
|
private readonly Container mainContent;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
|
|
|
public CollapsibleButtonContainer(APIBeatmapSet beatmapSet)
|
|
|
|
{
|
|
|
|
downloadTracker = new BeatmapDownloadTracker(beatmapSet);
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
Masking = true;
|
2021-12-21 15:26:19 +08:00
|
|
|
CornerRadius = BeatmapCard.CORNER_RADIUS;
|
2021-12-17 19:58:05 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
downloadTracker,
|
|
|
|
background = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Child = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Colour4.White
|
|
|
|
},
|
|
|
|
},
|
|
|
|
buttonArea = new Container
|
|
|
|
{
|
|
|
|
Name = @"Right (button) area",
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Child = buttons = new Container<BeatmapCardIconButton>
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-11-03 13:03:28 +08:00
|
|
|
// Padding of 4 avoids touching the card borders when in the expanded (ie. showing difficulties) state.
|
|
|
|
// Left override allows the buttons to visually be wider and look better.
|
|
|
|
Padding = new MarginPadding(4) { Left = 2 },
|
2021-12-17 19:58:05 +08:00
|
|
|
Children = new BeatmapCardIconButton[]
|
|
|
|
{
|
|
|
|
new FavouriteButton(beatmapSet)
|
|
|
|
{
|
|
|
|
Current = FavouriteState,
|
|
|
|
Anchor = Anchor.TopCentre,
|
2022-10-13 20:52:20 +08:00
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Height = 0.48f,
|
2021-12-17 19:58:05 +08:00
|
|
|
},
|
|
|
|
new DownloadButton(beatmapSet)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
2022-10-13 20:52:20 +08:00
|
|
|
State = { BindTarget = downloadTracker.State },
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Height = 0.48f,
|
2021-12-17 19:58:05 +08:00
|
|
|
},
|
|
|
|
new GoToBeatmapButton(beatmapSet)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
2022-10-13 20:52:20 +08:00
|
|
|
State = { BindTarget = downloadTracker.State },
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Height = 0.48f,
|
2021-12-17 19:58:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mainArea = new Container
|
|
|
|
{
|
|
|
|
Name = @"Main content",
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2021-12-21 15:26:19 +08:00
|
|
|
CornerRadius = BeatmapCard.CORNER_RADIUS,
|
2021-12-17 19:58:05 +08:00
|
|
|
Masking = true,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new BeatmapCardContentBackground(beatmapSet)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Dimmed = { BindTarget = ShowDetails }
|
|
|
|
},
|
|
|
|
mainContent = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding
|
|
|
|
{
|
|
|
|
Horizontal = 10,
|
|
|
|
Vertical = 4
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
downloadTracker.State.BindValueChanged(_ => updateState());
|
|
|
|
ShowDetails.BindValueChanged(_ => updateState(), true);
|
|
|
|
FinishTransforms(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
float targetWidth = Width - (ShowDetails.Value ? ButtonsExpandedWidth : ButtonsCollapsedWidth);
|
|
|
|
|
2021-12-21 15:26:19 +08:00
|
|
|
mainArea.ResizeWidthTo(targetWidth, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
2021-12-17 19:58:05 +08:00
|
|
|
|
2021-12-21 15:26:19 +08:00
|
|
|
background.FadeColour(downloadTracker.State.Value == DownloadState.LocallyAvailable ? colours.Lime0 : colourProvider.Background3, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
|
|
|
buttons.FadeTo(ShowDetails.Value ? 1 : 0, BeatmapCard.TRANSITION_DURATION, Easing.OutQuint);
|
2021-12-17 19:58:05 +08:00
|
|
|
|
|
|
|
foreach (var button in buttons)
|
|
|
|
{
|
|
|
|
button.IdleColour = downloadTracker.State.Value != DownloadState.LocallyAvailable ? colourProvider.Light1 : colourProvider.Background3;
|
|
|
|
button.HoverColour = downloadTracker.State.Value != DownloadState.LocallyAvailable ? colourProvider.Content1 : colourProvider.Foreground1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|