2020-02-14 09:13:52 +00: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 System.Collections.Generic;
|
2021-05-14 13:12:25 +00:00
|
|
|
using System.Diagnostics;
|
2020-02-14 09:13:52 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-02-22 08:14:13 +00:00
|
|
|
using osu.Framework.Localisation;
|
2020-02-14 09:13:52 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2021-07-17 03:54:11 +00:00
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2020-02-14 09:13:52 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Screens.Play.HUD;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Displays beatmap metadata inside <see cref="PlayerLoader"/>
|
|
|
|
/// </summary>
|
|
|
|
public class BeatmapMetadataDisplay : Container
|
|
|
|
{
|
2021-11-15 09:46:11 +00:00
|
|
|
private readonly IWorkingBeatmap beatmap;
|
2020-02-14 09:13:52 +00:00
|
|
|
private readonly Bindable<IReadOnlyList<Mod>> mods;
|
2021-05-08 08:46:28 +00:00
|
|
|
private readonly Drawable logoFacade;
|
2020-02-21 06:33:31 +00:00
|
|
|
private LoadingSpinner loading;
|
2020-02-14 09:13:52 +00:00
|
|
|
|
|
|
|
public IBindable<IReadOnlyList<Mod>> Mods => mods;
|
|
|
|
|
|
|
|
public bool Loading
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
loading.Show();
|
|
|
|
else
|
|
|
|
loading.Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-15 09:46:11 +00:00
|
|
|
public BeatmapMetadataDisplay(IWorkingBeatmap beatmap, Bindable<IReadOnlyList<Mod>> mods, Drawable logoFacade)
|
2020-02-14 09:13:52 +00:00
|
|
|
{
|
|
|
|
this.beatmap = beatmap;
|
2021-05-08 08:46:28 +00:00
|
|
|
this.logoFacade = logoFacade;
|
2020-02-14 09:13:52 +00:00
|
|
|
|
|
|
|
this.mods = new Bindable<IReadOnlyList<Mod>>();
|
|
|
|
this.mods.BindTo(mods);
|
|
|
|
}
|
|
|
|
|
2021-05-08 09:59:59 +00:00
|
|
|
private IBindable<StarDifficulty?> starDifficulty;
|
|
|
|
|
2021-05-14 12:55:26 +00:00
|
|
|
private FillFlowContainer versionFlow;
|
|
|
|
private StarRatingDisplay starRatingDisplay;
|
|
|
|
|
2020-02-14 09:13:52 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2021-05-08 08:44:29 +00:00
|
|
|
private void load(BeatmapDifficultyCache difficultyCache)
|
2020-02-14 09:13:52 +00:00
|
|
|
{
|
2021-05-15 07:00:04 +00:00
|
|
|
var metadata = beatmap.BeatmapInfo.Metadata;
|
2021-05-08 08:44:29 +00:00
|
|
|
|
2020-02-14 09:13:52 +00:00
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new[]
|
|
|
|
{
|
2021-05-08 15:43:17 +00:00
|
|
|
logoFacade.With(d =>
|
2020-02-14 09:13:52 +00:00
|
|
|
{
|
|
|
|
d.Anchor = Anchor.TopCentre;
|
|
|
|
d.Origin = Anchor.TopCentre;
|
2021-05-08 15:43:17 +00:00
|
|
|
}),
|
2020-02-14 09:13:52 +00:00
|
|
|
new OsuSpriteText
|
|
|
|
{
|
2021-02-25 05:12:59 +00:00
|
|
|
Text = new RomanisableString(metadata.TitleUnicode, metadata.Title),
|
2020-02-14 09:13:52 +00:00
|
|
|
Font = OsuFont.GetFont(size: 36, italics: true),
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Margin = new MarginPadding { Top = 15 },
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
2021-02-25 05:12:59 +00:00
|
|
|
Text = new RomanisableString(metadata.ArtistUnicode, metadata.Artist),
|
2020-02-14 09:13:52 +00:00
|
|
|
Font = OsuFont.GetFont(size: 26, italics: true),
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Size = new Vector2(300, 60),
|
|
|
|
Margin = new MarginPadding(10),
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
CornerRadius = 10,
|
|
|
|
Masking = true,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2021-01-05 21:39:59 +00:00
|
|
|
new Sprite
|
2020-02-14 09:13:52 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Texture = beatmap?.Background,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
},
|
2021-01-04 13:42:39 +00:00
|
|
|
loading = new LoadingLayer(true)
|
2020-02-14 09:13:52 +00:00
|
|
|
}
|
|
|
|
},
|
2021-05-14 12:55:26 +00:00
|
|
|
versionFlow = new FillFlowContainer
|
2020-02-14 09:13:52 +00:00
|
|
|
{
|
2021-05-08 08:44:29 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
2020-02-14 09:13:52 +00:00
|
|
|
Anchor = Anchor.TopCentre,
|
2021-05-08 08:44:29 +00:00
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(5f),
|
|
|
|
Margin = new MarginPadding { Bottom = 40 },
|
|
|
|
Children = new Drawable[]
|
2020-02-14 09:13:52 +00:00
|
|
|
{
|
2021-05-08 08:44:29 +00:00
|
|
|
new OsuSpriteText
|
|
|
|
{
|
2021-11-11 08:19:53 +00:00
|
|
|
Text = beatmap?.BeatmapInfo?.DifficultyName,
|
2021-05-08 08:44:29 +00:00
|
|
|
Font = OsuFont.GetFont(size: 26, italics: true),
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
},
|
2021-05-14 13:12:25 +00:00
|
|
|
starRatingDisplay = new StarRatingDisplay(default)
|
2021-05-08 08:44:29 +00:00
|
|
|
{
|
2021-05-14 13:12:25 +00:00
|
|
|
Alpha = 0f,
|
2021-05-08 08:44:29 +00:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 09:13:52 +00:00
|
|
|
},
|
2021-02-07 23:14:08 +00:00
|
|
|
new GridContainer
|
2020-02-14 09:13:52 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2021-02-07 23:14:08 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
},
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new MetadataLineLabel("Source"),
|
|
|
|
new MetadataLineInfo(metadata.Source)
|
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new MetadataLineLabel("Mapper"),
|
2021-11-04 09:46:26 +00:00
|
|
|
new MetadataLineInfo(metadata.Author.Username)
|
2021-02-07 23:14:08 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-14 09:13:52 +00:00
|
|
|
},
|
|
|
|
new ModDisplay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Margin = new MarginPadding { Top = 20 },
|
|
|
|
Current = mods
|
2020-07-20 10:24:17 +00:00
|
|
|
},
|
2020-02-14 09:13:52 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-08 09:59:59 +00:00
|
|
|
starDifficulty = difficultyCache.GetBindableDifficulty(beatmap.BeatmapInfo);
|
|
|
|
|
2020-02-14 09:13:52 +00:00
|
|
|
Loading = true;
|
|
|
|
}
|
2021-02-07 23:14:08 +00:00
|
|
|
|
2021-05-14 12:55:26 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
if (starDifficulty.Value != null)
|
2021-05-14 13:12:25 +00:00
|
|
|
{
|
|
|
|
starRatingDisplay.Current.Value = starDifficulty.Value.Value;
|
|
|
|
starRatingDisplay.Show();
|
|
|
|
}
|
2021-05-14 12:55:26 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
starRatingDisplay.Hide();
|
|
|
|
|
|
|
|
starDifficulty.ValueChanged += d =>
|
|
|
|
{
|
2021-05-14 13:12:25 +00:00
|
|
|
Debug.Assert(d.NewValue != null);
|
|
|
|
|
|
|
|
starRatingDisplay.Current.Value = d.NewValue.Value;
|
2021-05-14 12:55:26 +00:00
|
|
|
|
|
|
|
versionFlow.AutoSizeDuration = 300;
|
|
|
|
versionFlow.AutoSizeEasing = Easing.OutQuint;
|
|
|
|
|
|
|
|
starRatingDisplay.FadeIn(300, Easing.InQuint);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 23:14:08 +00:00
|
|
|
private class MetadataLineLabel : OsuSpriteText
|
|
|
|
{
|
|
|
|
public MetadataLineLabel(string text)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopRight;
|
|
|
|
Origin = Anchor.TopRight;
|
|
|
|
Margin = new MarginPadding { Right = 5 };
|
|
|
|
Colour = OsuColour.Gray(0.8f);
|
|
|
|
Text = text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class MetadataLineInfo : OsuSpriteText
|
|
|
|
{
|
|
|
|
public MetadataLineInfo(string text)
|
|
|
|
{
|
|
|
|
Margin = new MarginPadding { Left = 5 };
|
|
|
|
Text = string.IsNullOrEmpty(text) ? @"-" : text;
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 09:13:52 +00:00
|
|
|
}
|
|
|
|
}
|