1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 06:27:27 +08:00
osu-lazer/osu.Game/Overlays/Profile/Header/Components/GroupBadge.cs

99 lines
3.6 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2023-01-11 12:11:38 +08:00
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osuTK;
namespace osu.Game.Overlays.Profile.Header.Components
{
public partial class GroupBadge : Container, IHasTooltip
{
2023-01-22 17:09:08 +08:00
public LocalisableString TooltipText { get; private set; }
2023-01-11 12:11:38 +08:00
public int TextSize { get; set; } = 12;
private readonly APIUserGroup group;
public GroupBadge(APIUserGroup group)
{
this.group = group;
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 8;
TooltipText = group.Name;
2023-01-23 04:42:53 +08:00
if (group.IsProbationary)
{
Alpha = 0.6f;
}
2023-01-11 12:11:38 +08:00
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider? colourProvider, RulesetStore rulesets)
{
FillFlowContainer innerContainer;
2023-01-23 04:42:53 +08:00
AddRangeInternal(new Drawable[]
2023-01-11 12:11:38 +08:00
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider?.Background6 ?? Colour4.Black,
2023-01-26 22:09:16 +08:00
// Normal badges background opacity is 75%, probationary is full opacity as the whole badge gets a bit transparent
2023-02-03 22:48:11 +08:00
// Goal is to match osu-web so this is the most accurate it can be, its a bit scuffed but it is what it is
// Source: https://github.com/ppy/osu-web/blob/master/resources/css/bem/user-group-badge.less#L50
Alpha = group.IsProbationary ? 1 : 0.75f,
2023-01-11 12:11:38 +08:00
},
innerContainer = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Padding = new MarginPadding { Vertical = 2, Horizontal = 10 },
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new[]
{
new OsuSpriteText
{
Text = group.ShortName,
Colour = Color4Extensions.FromHex(group.Colour ?? Colour4.White.ToHex()),
2023-01-11 12:11:38 +08:00
Shadow = false,
Font = OsuFont.GetFont(size: TextSize, weight: FontWeight.Bold, italics: true)
}
}
}
2023-01-23 04:42:53 +08:00
});
2023-01-11 12:11:38 +08:00
if (group.Playmodes?.Length > 0)
{
innerContainer.AddRange(group.Playmodes.Select(p =>
2023-01-11 15:50:37 +08:00
(rulesets.GetRuleset(p)?.CreateInstance().CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle }).With(icon =>
2023-01-11 12:11:38 +08:00
{
icon.Size = new Vector2(TextSize - 1);
})).ToList()
);
2023-01-22 12:36:53 +08:00
var badgeModesList = group.Playmodes.Select(p => rulesets.GetRuleset(p)?.Name).ToList();
string modesDisplay = string.Join(", ", badgeModesList);
2023-01-22 17:07:47 +08:00
TooltipText += $" ({modesDisplay})";
2023-01-22 12:36:53 +08:00
}
2023-01-11 12:11:38 +08:00
}
}
}