osu/osu.Game/Overlays/BeatmapSet/Info.cs

215 lines
8.0 KiB
C#
Raw Normal View History

// 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.
2018-04-13 09:19:50 +00:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2018-04-13 09:19:50 +00:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-04-02 05:51:28 +00:00
using osu.Framework.Graphics.Effects;
2018-04-13 09:19:50 +00:00
using osu.Framework.Graphics.Shapes;
2020-01-30 04:30:25 +00:00
using osu.Framework.Graphics.Sprites;
2018-04-13 09:19:50 +00:00
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
2020-01-30 04:30:25 +00:00
using osu.Game.Online.Chat;
using osu.Game.Screens.Select;
2018-11-20 07:51:59 +00:00
using osuTK;
using osuTK.Graphics;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Overlays.BeatmapSet
{
public class Info : Container
{
private const float transition_duration = 250;
private const float metadata_width = 225;
private const float spacing = 20;
private readonly Box successRateBackground;
private readonly SuccessRate successRate;
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>();
2018-04-13 09:19:50 +00:00
public BeatmapInfo Beatmap
{
get => successRate.Beatmap;
set => successRate.Beatmap = value;
2018-04-13 09:19:50 +00:00
}
public Info()
{
MetadataSection source, tags, genre, language;
2018-04-13 09:19:50 +00:00
RelativeSizeAxes = Axes.X;
Height = 220;
Masking = true;
EdgeEffect = new EdgeEffectParameters
{
Colour = Color4.Black.Opacity(0.25f),
Type = EdgeEffectType.Shadow,
Radius = 3,
Offset = new Vector2(0f, 1f),
};
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 15, Horizontal = BeatmapSetOverlay.X_PADDING },
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = metadata_width + BeatmapSetOverlay.RIGHT_WIDTH + spacing * 2 },
Child = new Container
{
RelativeSizeAxes = Axes.Both,
2020-01-30 04:30:25 +00:00
Child = new MetadataSection(MetadataType.Description),
2018-04-13 09:19:50 +00:00
},
},
new Container
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Y,
Width = metadata_width,
Padding = new MarginPadding { Horizontal = 10 },
Margin = new MarginPadding { Right = BeatmapSetOverlay.RIGHT_WIDTH + spacing },
Child = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full,
2018-04-13 09:19:50 +00:00
Children = new[]
{
2020-01-30 04:30:25 +00:00
source = new MetadataSection(MetadataType.Source),
genre = new MetadataSection(MetadataType.Genre) { Width = 0.5f },
language = new MetadataSection(MetadataType.Language) { Width = 0.5f },
tags = new MetadataSection(MetadataType.Tags),
2018-04-13 09:19:50 +00:00
},
},
},
new Container
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Y,
Width = BeatmapSetOverlay.RIGHT_WIDTH,
Children = new Drawable[]
{
successRateBackground = new Box
{
RelativeSizeAxes = Axes.Both,
},
successRate = new SuccessRate
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 20, Horizontal = 15 },
},
},
},
},
},
};
BeatmapSet.ValueChanged += b =>
{
source.Text = b.NewValue?.Metadata.Source ?? string.Empty;
tags.Text = b.NewValue?.Metadata.Tags ?? string.Empty;
genre.Text = b.NewValue?.OnlineInfo?.Genre?.Name ?? string.Empty;
language.Text = b.NewValue?.OnlineInfo?.Language?.Name ?? string.Empty;
};
2018-04-13 09:19:50 +00:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
successRateBackground.Colour = colours.GrayE;
}
private class MetadataSection : FillFlowContainer
{
2020-01-30 04:30:25 +00:00
private readonly MetadataType type;
2018-04-13 09:19:50 +00:00
private readonly OsuSpriteText header;
2020-01-30 04:30:25 +00:00
private readonly LinkFlowContainer textFlow;
2018-04-13 09:19:50 +00:00
public string Text
{
set
{
if (string.IsNullOrEmpty(value))
{
Hide();
2018-04-13 09:19:50 +00:00
return;
}
this.FadeIn(transition_duration);
2020-01-30 04:30:25 +00:00
2018-04-13 09:19:50 +00:00
textFlow.Clear();
2020-01-30 04:30:25 +00:00
static void format(SpriteText t) => t.Font = t.Font.With(size: 14);
2020-01-31 00:17:39 +00:00
switch (type)
2020-01-30 04:30:25 +00:00
{
case MetadataType.Tags:
2020-01-30 22:41:50 +00:00
string[] tags = value.Split(" ");
for (int i = 0; i <= tags.Length - 1; i++)
{
textFlow.AddLink(tags[i], LinkAction.SearchBeatmapSet, tags[i], null, format);
if (i != tags.Length - 1)
textFlow.AddText(" ", format);
}
2020-01-30 04:30:25 +00:00
break;
case MetadataType.Source:
2020-01-30 22:41:50 +00:00
textFlow.AddLink(value, LinkAction.SearchBeatmapSet, value, null, format);
2020-01-30 04:30:25 +00:00
break;
default:
textFlow.AddText(value, format);
break;
}
2018-04-13 09:19:50 +00:00
}
}
2020-01-30 04:30:25 +00:00
public MetadataSection(MetadataType type)
2018-04-13 09:19:50 +00:00
{
2020-01-30 04:30:25 +00:00
this.type = type;
2018-04-13 09:19:50 +00:00
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Spacing = new Vector2(5f);
InternalChildren = new Drawable[]
{
header = new OsuSpriteText
{
2020-01-30 04:30:25 +00:00
Text = this.type.ToString(),
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
2018-04-13 09:19:50 +00:00
Shadow = false,
Margin = new MarginPadding { Top = 20 },
},
2020-01-30 04:30:25 +00:00
textFlow = new LinkFlowContainer
2018-04-13 09:19:50 +00:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
2018-06-03 14:51:57 +00:00
header.Colour = textFlow.Colour = colours.Gray5;
2018-04-13 09:19:50 +00:00
}
}
}
}