1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 10:57:30 +08:00
osu-lazer/osu.Game/Overlays/BeatmapSet/AuthorInfo.cs

170 lines
5.3 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 17:19:50 +08:00
2020-02-10 05:27:37 +08:00
using System;
2021-06-17 15:05:50 +08:00
using osu.Framework.Allocation;
2018-04-13 17:19:50 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Users.Drawables;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
2019-04-02 13:51:28 +08:00
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Users;
using osu.Game.Graphics.Containers;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.BeatmapSet
{
public class AuthorInfo : Container
{
private const float height = 50;
2021-06-17 15:05:50 +08:00
private UpdateableAvatar avatar;
private FillFlowContainer fields;
2018-04-13 17:19:50 +08:00
private BeatmapSetInfo beatmapSet;
2018-04-13 17:19:50 +08:00
public BeatmapSetInfo BeatmapSet
{
get => beatmapSet;
2018-04-13 17:19:50 +08:00
set
{
if (value == beatmapSet) return;
2019-02-28 12:31:40 +08:00
2018-04-13 17:19:50 +08:00
beatmapSet = value;
2021-06-17 15:05:50 +08:00
Scheduler.AddOnce(updateDisplay);
2018-04-13 17:19:50 +08:00
}
}
2021-06-17 15:05:50 +08:00
[BackgroundDependencyLoader]
private void load()
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.X;
Height = height;
Children = new Drawable[]
{
2018-12-20 19:08:22 +08:00
new Container
2018-04-13 17:19:50 +08:00
{
AutoSizeAxes = Axes.Both,
CornerRadius = 4,
2018-04-13 17:19:50 +08:00
Masking = true,
2021-06-17 15:33:43 +08:00
Child = avatar = new UpdateableAvatar(showGuestOnNull: false)
2018-04-13 17:19:50 +08:00
{
Size = new Vector2(height),
},
EdgeEffect = new EdgeEffectParameters
{
Colour = Color4.Black.Opacity(0.25f),
Type = EdgeEffectType.Shadow,
Radius = 4,
2018-04-13 17:19:50 +08:00
Offset = new Vector2(0f, 1f),
},
},
fields = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Left = height + 5 },
},
};
2021-06-17 15:05:50 +08:00
Scheduler.AddOnce(updateDisplay);
2018-04-13 17:19:50 +08:00
}
2021-06-17 15:05:50 +08:00
private void updateDisplay()
2018-04-13 17:19:50 +08:00
{
2021-06-17 15:05:50 +08:00
avatar.User = BeatmapSet?.Metadata.Author;
fields.Clear();
if (BeatmapSet == null)
return;
var online = BeatmapSet.OnlineInfo;
fields.Children = new Drawable[]
{
new Field("mapped by", BeatmapSet.Metadata.Author, OsuFont.GetFont(weight: FontWeight.Regular, italics: true)),
new Field("submitted", online.Submitted, OsuFont.GetFont(weight: FontWeight.Bold))
{
Margin = new MarginPadding { Top = 5 },
},
};
if (online.Ranked.HasValue)
{
fields.Add(new Field(online.Status.ToString().ToLowerInvariant(), online.Ranked.Value, OsuFont.GetFont(weight: FontWeight.Bold)));
}
else if (online.LastUpdated.HasValue)
{
fields.Add(new Field("last updated", online.LastUpdated.Value, OsuFont.GetFont(weight: FontWeight.Bold)));
}
2018-04-13 17:19:50 +08:00
}
private class Field : FillFlowContainer
{
public Field(string first, string second, FontUsage secondFont)
2018-04-13 17:19:50 +08:00
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Children = new[]
{
new OsuSpriteText
{
Text = $"{first} ",
Font = OsuFont.GetFont(size: 11)
2018-04-13 17:19:50 +08:00
},
new OsuSpriteText
{
Text = second,
Font = secondFont.With(size: 11)
2018-04-13 17:19:50 +08:00
},
};
}
2020-02-10 05:27:37 +08:00
public Field(string first, DateTimeOffset second, FontUsage secondFont)
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Children = new[]
{
new OsuSpriteText
{
Text = $"{first} ",
Font = OsuFont.GetFont(size: 13)
},
new DrawableDate(second)
{
Font = secondFont.With(size: 13)
}
};
}
public Field(string first, User second, FontUsage secondFont)
{
AutoSizeAxes = Axes.Both;
Direction = FillDirection.Horizontal;
Children = new[]
{
new LinkFlowContainer(s =>
{
s.Font = OsuFont.GetFont(size: 11);
}).With(d =>
{
d.AutoSizeAxes = Axes.Both;
d.AddText($"{first} ");
d.AddUserLink(second, s => s.Font = secondFont.With(size: 11));
}),
};
}
2018-04-13 17:19:50 +08:00
}
}
}