2020-02-14 17:13:52 +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 System.Collections.Generic;
|
2021-05-14 21:12:25 +08:00
|
|
|
using System.Diagnostics;
|
2020-02-14 17:13:52 +08: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 16:14:13 +08:00
|
|
|
using osu.Framework.Localisation;
|
2020-02-14 17:13:52 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
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;
|
2021-05-08 16:44:29 +08:00
|
|
|
using osu.Game.Screens.Ranking.Expanded;
|
2020-02-14 17:13:52 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Displays beatmap metadata inside <see cref="PlayerLoader"/>
|
|
|
|
/// </summary>
|
|
|
|
public class BeatmapMetadataDisplay : Container
|
|
|
|
{
|
|
|
|
private readonly WorkingBeatmap beatmap;
|
|
|
|
private readonly Bindable<IReadOnlyList<Mod>> mods;
|
2021-05-08 16:46:28 +08:00
|
|
|
private readonly Drawable logoFacade;
|
2020-02-21 14:33:31 +08:00
|
|
|
private LoadingSpinner loading;
|
2020-02-14 17:13:52 +08:00
|
|
|
|
|
|
|
public IBindable<IReadOnlyList<Mod>> Mods => mods;
|
|
|
|
|
|
|
|
public bool Loading
|
|
|
|
{
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
loading.Show();
|
|
|
|
else
|
|
|
|
loading.Hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 23:43:17 +08:00
|
|
|
public BeatmapMetadataDisplay(WorkingBeatmap beatmap, Bindable<IReadOnlyList<Mod>> mods, Drawable logoFacade)
|
2020-02-14 17:13:52 +08:00
|
|
|
{
|
|
|
|
this.beatmap = beatmap;
|
2021-05-08 16:46:28 +08:00
|
|
|
this.logoFacade = logoFacade;
|
2020-02-14 17:13:52 +08:00
|
|
|
|
|
|
|
this.mods = new Bindable<IReadOnlyList<Mod>>();
|
|
|
|
this.mods.BindTo(mods);
|
|
|
|
}
|
|
|
|
|
2021-05-08 17:59:59 +08:00
|
|
|
private IBindable<StarDifficulty?> starDifficulty;
|
|
|
|
|
2021-05-14 20:55:26 +08:00
|
|
|
private FillFlowContainer versionFlow;
|
|
|
|
private StarRatingDisplay starRatingDisplay;
|
|
|
|
|
2020-02-14 17:13:52 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2021-05-08 16:44:29 +08:00
|
|
|
private void load(BeatmapDifficultyCache difficultyCache)
|
2020-02-14 17:13:52 +08:00
|
|
|
{
|
2021-05-15 15:00:04 +08:00
|
|
|
var metadata = beatmap.BeatmapInfo.Metadata;
|
2021-05-08 16:44:29 +08:00
|
|
|
|
2020-02-14 17:13:52 +08: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 23:43:17 +08:00
|
|
|
logoFacade.With(d =>
|
2020-02-14 17:13:52 +08:00
|
|
|
{
|
|
|
|
d.Anchor = Anchor.TopCentre;
|
|
|
|
d.Origin = Anchor.TopCentre;
|
2021-05-08 23:43:17 +08:00
|
|
|
}),
|
2020-02-14 17:13:52 +08:00
|
|
|
new OsuSpriteText
|
|
|
|
{
|
2021-02-25 13:12:59 +08:00
|
|
|
Text = new RomanisableString(metadata.TitleUnicode, metadata.Title),
|
2020-02-14 17:13:52 +08:00
|
|
|
Font = OsuFont.GetFont(size: 36, italics: true),
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Margin = new MarginPadding { Top = 15 },
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
2021-02-25 13:12:59 +08:00
|
|
|
Text = new RomanisableString(metadata.ArtistUnicode, metadata.Artist),
|
2020-02-14 17:13:52 +08: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-06 05:39:59 +08:00
|
|
|
new Sprite
|
2020-02-14 17:13:52 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Texture = beatmap?.Background,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
},
|
2021-01-04 21:42:39 +08:00
|
|
|
loading = new LoadingLayer(true)
|
2020-02-14 17:13:52 +08:00
|
|
|
}
|
|
|
|
},
|
2021-05-14 20:55:26 +08:00
|
|
|
versionFlow = new FillFlowContainer
|
2020-02-14 17:13:52 +08:00
|
|
|
{
|
2021-05-08 16:44:29 +08:00
|
|
|
AutoSizeAxes = Axes.Both,
|
2020-02-14 17:13:52 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
2021-05-08 16:44:29 +08:00
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(5f),
|
|
|
|
Margin = new MarginPadding { Bottom = 40 },
|
|
|
|
Children = new Drawable[]
|
2020-02-14 17:13:52 +08:00
|
|
|
{
|
2021-05-08 16:44:29 +08:00
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = beatmap?.BeatmapInfo?.Version,
|
|
|
|
Font = OsuFont.GetFont(size: 26, italics: true),
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
},
|
2021-05-14 21:12:25 +08:00
|
|
|
starRatingDisplay = new StarRatingDisplay(default)
|
2021-05-08 16:44:29 +08:00
|
|
|
{
|
2021-05-14 21:12:25 +08:00
|
|
|
Alpha = 0f,
|
2021-05-08 16:44:29 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 17:13:52 +08:00
|
|
|
},
|
2021-02-08 07:14:08 +08:00
|
|
|
new GridContainer
|
2020-02-14 17:13:52 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2021-02-08 07:14:08 +08: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"),
|
|
|
|
new MetadataLineInfo(metadata.AuthorString)
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 17:13:52 +08:00
|
|
|
},
|
|
|
|
new ModDisplay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Margin = new MarginPadding { Top = 20 },
|
|
|
|
Current = mods
|
2020-07-20 18:24:17 +08:00
|
|
|
},
|
2020-02-14 17:13:52 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-08 17:59:59 +08:00
|
|
|
starDifficulty = difficultyCache.GetBindableDifficulty(beatmap.BeatmapInfo);
|
|
|
|
|
2020-02-14 17:13:52 +08:00
|
|
|
Loading = true;
|
|
|
|
}
|
2021-02-08 07:14:08 +08:00
|
|
|
|
2021-05-14 20:55:26 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
if (starDifficulty.Value != null)
|
2021-05-14 21:12:25 +08:00
|
|
|
{
|
|
|
|
starRatingDisplay.Current.Value = starDifficulty.Value.Value;
|
|
|
|
starRatingDisplay.Show();
|
|
|
|
}
|
2021-05-14 20:55:26 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
starRatingDisplay.Hide();
|
|
|
|
|
|
|
|
starDifficulty.ValueChanged += d =>
|
|
|
|
{
|
2021-05-14 21:12:25 +08:00
|
|
|
Debug.Assert(d.NewValue != null);
|
|
|
|
|
|
|
|
starRatingDisplay.Current.Value = d.NewValue.Value;
|
2021-05-14 20:55:26 +08:00
|
|
|
|
|
|
|
versionFlow.AutoSizeDuration = 300;
|
|
|
|
versionFlow.AutoSizeEasing = Easing.OutQuint;
|
|
|
|
|
|
|
|
starRatingDisplay.FadeIn(300, Easing.InQuint);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-08 07:14:08 +08: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 17:13:52 +08:00
|
|
|
}
|
|
|
|
}
|