1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 11:07:25 +08:00
osu-lazer/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

298 lines
14 KiB
C#
Raw Normal View History

2021-10-18 00:24:17 +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-10-18 02:50:44 +08:00
using System.Collections.Generic;
2021-10-18 00:24:17 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
2021-10-18 02:50:44 +08:00
using osu.Game.Beatmaps.Drawables.Cards.Statistics;
2021-10-18 00:24:17 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapSet;
using osuTK;
using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Beatmaps.Drawables.Cards
{
2021-12-21 15:26:19 +08:00
public partial class BeatmapCardNormal : BeatmapCard
2021-10-18 00:24:17 +08:00
{
2021-12-17 20:27:11 +08:00
protected override Drawable IdleContent => idleBottomContent;
protected override Drawable DownloadInProgressContent => downloadProgressBar;
2021-10-18 00:24:17 +08:00
private const float height = 100;
[Cached]
private readonly BeatmapCardContent content;
private BeatmapCardThumbnail thumbnail = null!;
private CollapsibleButtonContainer buttonContainer = null!;
2021-10-18 00:59:31 +08:00
private FillFlowContainer<BeatmapCardStatistic> statisticsContainer = null!;
2021-10-18 00:24:17 +08:00
private FillFlowContainer idleBottomContent = null!;
private BeatmapCardDownloadProgressBar downloadProgressBar = null!;
2021-10-18 00:24:17 +08:00
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
2021-10-18 00:24:17 +08:00
2021-12-21 15:25:52 +08:00
public BeatmapCardNormal(APIBeatmapSet beatmapSet, bool allowExpansion = true)
2021-12-17 20:27:11 +08:00
: base(beatmapSet, allowExpansion)
2021-10-18 00:24:17 +08:00
{
content = new BeatmapCardContent(height);
2021-10-18 00:24:17 +08:00
}
2021-12-17 20:27:11 +08:00
[BackgroundDependencyLoader]
private void load()
2021-10-18 00:24:17 +08:00
{
Width = WIDTH;
2021-10-18 00:24:17 +08:00
Height = height;
FillFlowContainer leftIconArea = null!;
FillFlowContainer titleBadgeArea = null!;
GridContainer artistContainer = null!;
2021-12-17 20:27:11 +08:00
Child = content.With(c =>
2021-10-18 00:24:17 +08:00
{
c.MainContent = new Container
2021-10-18 03:34:31 +08:00
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
2021-10-18 03:34:31 +08:00
{
2021-12-17 20:27:11 +08:00
thumbnail = new BeatmapCardThumbnail(BeatmapSet)
{
Name = @"Left (icon) area",
Size = new Vector2(height),
Padding = new MarginPadding { Right = CORNER_RADIUS },
Child = leftIconArea = new FillFlowContainer
{
Margin = new MarginPadding(5),
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(1)
}
2021-10-18 00:24:17 +08:00
},
2021-12-17 20:27:11 +08:00
buttonContainer = new CollapsibleButtonContainer(BeatmapSet)
2021-10-18 00:24:17 +08:00
{
X = height - CORNER_RADIUS,
Width = WIDTH - height + CORNER_RADIUS,
2021-12-17 20:27:11 +08:00
FavouriteState = { BindTarget = FavouriteState },
ButtonsCollapsedWidth = CORNER_RADIUS,
ButtonsExpandedWidth = 30,
Children = new Drawable[]
{
new FillFlowContainer
2021-10-18 00:24:17 +08:00
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Children = new Drawable[]
2021-10-18 00:24:17 +08:00
{
new GridContainer
2021-10-18 00:24:17 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ColumnDimensions = new[]
2021-10-18 00:24:17 +08:00
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
2021-10-18 00:24:17 +08:00
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize)
},
Content = new[]
{
new Drawable[]
{
new OsuSpriteText
{
2021-12-17 20:27:11 +08:00
Text = new RomanisableString(BeatmapSet.TitleUnicode, BeatmapSet.Title),
Font = OsuFont.Default.With(size: 22.5f, weight: FontWeight.SemiBold),
RelativeSizeAxes = Axes.X,
Truncate = true
},
titleBadgeArea = new FillFlowContainer
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
}
}
}
2021-10-18 00:24:17 +08:00
},
artistContainer = new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ColumnDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize)
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize)
},
Content = new[]
{
new[]
{
new OsuSpriteText
{
Text = createArtistText(),
Font = OsuFont.Default.With(size: 17.5f, weight: FontWeight.SemiBold),
RelativeSizeAxes = Axes.X,
Truncate = true
},
Empty()
},
}
},
new LinkFlowContainer(s =>
{
s.Shadow = false;
s.Font = OsuFont.GetFont(size: 14, weight: FontWeight.SemiBold);
}).With(d =>
{
d.AutoSizeAxes = Axes.Both;
d.Margin = new MarginPadding { Top = 2 };
d.AddText("mapped by ", t => t.Colour = colourProvider.Content2);
2021-12-17 20:27:11 +08:00
d.AddUserLink(BeatmapSet.Author);
}),
2021-10-18 00:24:17 +08:00
}
},
new Container
2021-10-18 00:24:17 +08:00
{
Name = @"Bottom content",
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Children = new Drawable[]
{
idleBottomContent = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 3),
AlwaysPresent = true,
Children = new Drawable[]
{
statisticsContainer = new FillFlowContainer<BeatmapCardStatistic>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10, 0),
Alpha = 0,
AlwaysPresent = true,
ChildrenEnumerable = createStatistics()
},
2021-12-17 20:27:11 +08:00
new BeatmapCardExtraInfoRow(BeatmapSet)
}
},
downloadProgressBar = new BeatmapCardDownloadProgressBar
{
RelativeSizeAxes = Axes.X,
Height = 6,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2021-12-17 20:27:11 +08:00
State = { BindTarget = DownloadTracker.State },
Progress = { BindTarget = DownloadTracker.Progress }
}
}
2021-10-18 00:24:17 +08:00
}
}
}
}
};
c.ExpandedContent = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Padding = new MarginPadding { Horizontal = 10, Vertical = 13 },
2021-12-17 20:27:11 +08:00
Child = new BeatmapCardDifficultyList(BeatmapSet)
};
c.Expanded.BindTarget = Expanded;
});
2021-10-18 00:24:17 +08:00
2021-12-17 20:27:11 +08:00
if (BeatmapSet.HasVideo)
leftIconArea.Add(new VideoIconPill { IconSize = new Vector2(20) });
2021-10-18 00:24:17 +08:00
2021-12-17 20:27:11 +08:00
if (BeatmapSet.HasStoryboard)
leftIconArea.Add(new StoryboardIconPill { IconSize = new Vector2(20) });
2021-10-18 00:24:17 +08:00
if (BeatmapSet.FeaturedInSpotlight)
{
2022-05-15 01:52:38 +08:00
titleBadgeArea.Add(new SpotlightBeatmapBadge
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding { Left = 5 }
});
}
2021-12-17 20:27:11 +08:00
if (BeatmapSet.HasExplicitContent)
2021-10-18 00:24:17 +08:00
{
2022-05-15 01:52:38 +08:00
titleBadgeArea.Add(new ExplicitContentBeatmapBadge
2021-10-18 00:24:17 +08:00
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding { Left = 5 }
});
2021-10-18 00:24:17 +08:00
}
2021-12-17 20:27:11 +08:00
if (BeatmapSet.TrackId != null)
2021-10-18 00:24:17 +08:00
{
2022-05-15 01:52:38 +08:00
artistContainer.Content[0][1] = new FeaturedArtistBeatmapBadge
2021-10-18 00:24:17 +08:00
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding { Left = 5 }
};
}
2021-10-18 00:59:31 +08:00
}
2021-11-03 07:10:50 +08:00
private LocalisableString createArtistText()
{
2021-12-17 20:27:11 +08:00
var romanisableArtist = new RomanisableString(BeatmapSet.ArtistUnicode, BeatmapSet.Artist);
2021-11-03 07:10:50 +08:00
return BeatmapsetsStrings.ShowDetailsByArtist(romanisableArtist);
}
2021-10-18 02:50:44 +08:00
private IEnumerable<BeatmapCardStatistic> createStatistics()
{
2021-12-17 20:27:11 +08:00
var hypesStatistic = HypesStatistic.CreateFor(BeatmapSet);
if (hypesStatistic != null)
yield return hypesStatistic;
2021-12-17 20:27:11 +08:00
var nominationsStatistic = NominationsStatistic.CreateFor(BeatmapSet);
if (nominationsStatistic != null)
yield return nominationsStatistic;
2021-12-17 20:27:11 +08:00
yield return new FavouritesStatistic(BeatmapSet) { Current = FavouriteState };
yield return new PlayCountStatistic(BeatmapSet);
2021-10-18 02:50:44 +08:00
2021-12-17 20:27:11 +08:00
var dateStatistic = BeatmapCardDateStatistic.CreateFor(BeatmapSet);
2021-10-18 02:50:44 +08:00
if (dateStatistic != null)
yield return dateStatistic;
}
2021-12-17 20:27:11 +08:00
protected override void UpdateState()
2021-10-18 00:59:31 +08:00
{
2021-12-17 20:27:11 +08:00
base.UpdateState();
bool showDetails = IsHovered || Expanded.Value;
buttonContainer.ShowDetails.Value = showDetails;
thumbnail.Dimmed.Value = showDetails;
statisticsContainer.FadeTo(showDetails ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint);
2021-10-18 00:59:31 +08:00
}
2021-10-18 00:24:17 +08:00
}
}