Skip to content

Commit

Permalink
Merge pull request #31880 from peppy/team-logo-support
Browse files Browse the repository at this point in the history
Add basic display support for team logos
  • Loading branch information
peppy authored Feb 14, 2025
2 parents ff81096 + ef2f482 commit 4c851a3
Show file tree
Hide file tree
Showing 20 changed files with 297 additions and 39 deletions.
Binary file not shown.
2 changes: 2 additions & 0 deletions osu.Game.Tests/Skins/SkinDeserialisationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public class SkinDeserialisationTest
"Archives/modified-default-20241207.osk",
// Covers skinnable spectator list
"Archives/modified-argon-20250116.osk",
// Covers player team flag
"Archives/modified-argon-20250214.osk",
};

/// <summary>
Expand Down
23 changes: 23 additions & 0 deletions osu.Game/Online/API/Requests/Responses/APITeam.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using Newtonsoft.Json;

namespace osu.Game.Online.API.Requests.Responses
{
[JsonObject(MemberSerialization.OptIn)]
public class APITeam
{
[JsonProperty(@"id")]
public int Id { get; set; } = 1;

[JsonProperty(@"name")]
public string Name { get; set; } = string.Empty;

[JsonProperty(@"short_name")]
public string ShortName { get; set; } = string.Empty;

[JsonProperty(@"flag_url")]
public string FlagUrl = string.Empty;
}
}
4 changes: 4 additions & 0 deletions osu.Game/Online/API/Requests/Responses/APIUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public CountryCode CountryCode
set => countryCodeString = value.ToString();
}

[JsonProperty(@"team")]
[CanBeNull]
public APITeam Team { get; set; }

[JsonProperty(@"profile_colour")]
public string Colour;

Expand Down
53 changes: 36 additions & 17 deletions osu.Game/Online/Leaderboards/LeaderboardScore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ private void load(IAPIProvider api, OsuColour colour)
Height = 28,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10f, 0f),
Margin = new MarginPadding { Bottom = -2 },
Children = new Drawable[]
{
flagBadgeAndDateContainer = new FillFlowContainer
Expand All @@ -189,7 +190,7 @@ private void load(IAPIProvider api, OsuColour colour)
RelativeSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5f, 0f),
Width = 87f,
Width = 114f,
Masking = true,
Children = new Drawable[]
{
Expand All @@ -199,22 +200,19 @@ private void load(IAPIProvider api, OsuColour colour)
Origin = Anchor.CentreLeft,
Size = new Vector2(28, 20),
},
new UpdateableTeamFlag(user.Team)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(40, 20),
},
new DateLabel(Score.Date)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
},
},
new FillFlowContainer
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Left = edge_margin },
Children = statisticsLabels
},
},
},
},
Expand All @@ -234,6 +232,7 @@ private void load(IAPIProvider api, OsuColour colour)
GlowColour = Color4Extensions.FromHex(@"83ccfa"),
Current = scoreManager.GetBindableTotalScoreString(Score),
Font = OsuFont.Numeric.With(size: 23),
Margin = new MarginPadding { Top = 1 },
},
RankContainer = new Container
{
Expand All @@ -250,13 +249,32 @@ private void load(IAPIProvider api, OsuColour colour)
},
},
},
modsContainer = new FillFlowContainer<ModIcon>
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
ChildrenEnumerable = Score.Mods.AsOrdered().Select(mod => new ModIcon(mod) { Scale = new Vector2(0.375f) })
Children = new Drawable[]
{
new FillFlowContainer
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Margin = new MarginPadding { Left = edge_margin },
Children = statisticsLabels
},
modsContainer = new FillFlowContainer<ModIcon>
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
ChildrenEnumerable = Score.Mods.AsOrdered().Select(mod => new ModIcon(mod) { Scale = new Vector2(0.34f) })
},
}
},
},
},
Expand Down Expand Up @@ -324,7 +342,7 @@ protected override void OnHoverLost(HoverLostEvent e)

private partial class ScoreComponentLabel : Container, IHasTooltip
{
private const float icon_size = 20;
private const float icon_size = 16;
private readonly FillFlowContainer content;

public override bool Contains(Vector2 screenSpacePos) => content.Contains(screenSpacePos);
Expand All @@ -340,7 +358,7 @@ public ScoreComponentLabel(LeaderboardScoreStatistic statistic)
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Padding = new MarginPadding { Right = 10 },
Padding = new MarginPadding { Right = 5 },
Children = new Drawable[]
{
new Container
Expand Down Expand Up @@ -375,7 +393,8 @@ public ScoreComponentLabel(LeaderboardScoreStatistic statistic)
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = statistic.Value,
Font = OsuFont.GetFont(size: 17, weight: FontWeight.Bold, fixedWidth: true)
Spacing = new Vector2(-1, 0),
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold, fixedWidth: true)
},
},
};
Expand Down Expand Up @@ -406,7 +425,7 @@ private partial class DateLabel : DrawableDate
public DateLabel(DateTimeOffset date)
: base(date)
{
Font = OsuFont.GetFont(size: 17, weight: FontWeight.Bold, italics: true);
Font = OsuFont.GetFont(size: 13, weight: FontWeight.Bold, italics: true);
}

protected override string Format() => Date.ToShortRelativeTime(TimeSpan.FromSeconds(30));
Expand Down
15 changes: 14 additions & 1 deletion osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,20 @@ private Drawable[] createContent(int index, ScoreInfo score)
{
Size = new Vector2(19, 14),
},
username,
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(4),
Children = new Drawable[]
{
new UpdateableTeamFlag(score.User.Team)
{
Size = new Vector2(28, 14),
},
username,
}
},
#pragma warning disable 618
new StatisticText(score.MaxCombo, score.BeatmapInfo!.MaxCombo, @"0\x"),
#pragma warning restore 618
Expand Down
27 changes: 24 additions & 3 deletions osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public partial class TopScoreUserSection : CompositeDrawable
private readonly UpdateableAvatar avatar;
private readonly LinkFlowContainer usernameText;
private readonly DrawableDate achievedOn;

private readonly UpdateableFlag flag;
private readonly UpdateableTeamFlag teamFlag;

public TopScoreUserSection()
{
Expand Down Expand Up @@ -112,12 +114,30 @@ public TopScoreUserSection()
},
}
},
flag = new UpdateableFlag
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(19, 14),
Margin = new MarginPadding { Top = 3 }, // makes spacing look more even
Direction = FillDirection.Horizontal,
Spacing = new Vector2(4),
Children = new Drawable[]
{
flag = new UpdateableFlag
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(19, 14),
Margin = new MarginPadding { Top = 3 }, // makes spacing look more even
},
teamFlag = new UpdateableTeamFlag
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(28, 14),
Margin = new MarginPadding { Top = 3 }, // makes spacing look more even
},
}
},
}
}
Expand All @@ -139,6 +159,7 @@ public ScoreInfo Score
{
avatar.User = value.User;
flag.CountryCode = value.User.CountryCode;
teamFlag.Team = value.User.Team;
achievedOn.Date = value.Date;

usernameText.Clear();
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Overlays/KudosuTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override Drawable[] CreateAdditionalContent(APIUser item)

protected override CountryCode GetCountryCode(APIUser item) => item.CountryCode;

protected override Drawable CreateFlagContent(APIUser item)
protected override Drawable[] CreateFlagContent(APIUser item)
{
var username = new LinkFlowContainer(t => t.Font = OsuFont.GetFont(size: TEXT_SIZE, italics: true))
{
Expand All @@ -89,7 +89,7 @@ protected override Drawable CreateFlagContent(APIUser item)
TextAnchor = Anchor.CentreLeft
};
username.AddUserLink(item);
return username;
return [username];
}
}
}
6 changes: 6 additions & 0 deletions osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public partial class TopHeaderContainer : CompositeDrawable
private ExternalLinkButton openUserExternally = null!;
private OsuSpriteText titleText = null!;
private UpdateableFlag userFlag = null!;
private UpdateableTeamFlag teamFlag = null!;
private OsuHoverContainer userCountryContainer = null!;
private OsuSpriteText userCountryText = null!;
private GroupBadgeFlow groupBadgeFlow = null!;
Expand Down Expand Up @@ -166,6 +167,10 @@ private void load(OverlayColourProvider colourProvider, OsuConfigManager configM
{
Size = new Vector2(28, 20),
},
teamFlag = new UpdateableTeamFlag
{
Size = new Vector2(40, 20),
},
userCountryContainer = new OsuHoverContainer
{
AutoSizeAxes = Axes.Both,
Expand Down Expand Up @@ -215,6 +220,7 @@ private void updateUser(UserProfileData? data)
usernameText.Text = user?.Username ?? string.Empty;
openUserExternally.Link = $@"{api.Endpoints.WebsiteUrl}/users/{user?.Id ?? 0}";
userFlag.CountryCode = user?.CountryCode ?? default;
teamFlag.Team = user?.Team;
userCountryText.Text = (user?.CountryCode ?? default).GetDescription();
userCountryContainer.Action = () => rankingsOverlay?.ShowCountry(user?.CountryCode ?? default);
supporterTag.SupportLevel = user?.SupportLevel ?? 0;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Overlays/Rankings/Tables/CountriesTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override RankingsTableColumn[] CreateAdditionalHeaders() => new[]

protected override CountryCode GetCountryCode(CountryStatistics item) => item.Code;

protected override Drawable CreateFlagContent(CountryStatistics item) => new CountryName(item.Code);
protected override Drawable[] CreateFlagContent(CountryStatistics item) => [new CountryName(item.Code)];

protected override Drawable[] CreateAdditionalContent(CountryStatistics item) => new Drawable[]
{
Expand Down
17 changes: 7 additions & 10 deletions osu.Game/Overlays/Rankings/Tables/RankingsTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected sealed override Drawable CreateHeader(int index, TableColumn column)

protected abstract CountryCode GetCountryCode(TModel item);

protected abstract Drawable CreateFlagContent(TModel item);
protected abstract Drawable[] CreateFlagContent(TModel item);

private OsuSpriteText createIndexDrawable(int index) => new RowText
{
Expand All @@ -92,16 +92,13 @@ protected sealed override Drawable CreateHeader(int index, TableColumn column)
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10, 0),
Spacing = new Vector2(5, 0),
Margin = new MarginPadding { Bottom = row_spacing },
Children = new[]
{
new UpdateableFlag(GetCountryCode(item))
{
Size = new Vector2(28, 20),
},
CreateFlagContent(item)
}
Children =
[
new UpdateableFlag(GetCountryCode(item)) { Size = new Vector2(28, 20) },
..CreateFlagContent(item)
]
};

protected class RankingsTableColumn : TableColumn
Expand Down
6 changes: 4 additions & 2 deletions osu.Game/Overlays/Rankings/Tables/UserBasedTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using osu.Game.Scoring;
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Users.Drawables;
using osuTK;

namespace osu.Game.Overlays.Rankings.Tables
{
Expand Down Expand Up @@ -61,7 +63,7 @@ protected override RankingsTableColumn[] CreateAdditionalHeaders() => new[]

protected sealed override CountryCode GetCountryCode(UserStatistics item) => item.User.CountryCode;

protected sealed override Drawable CreateFlagContent(UserStatistics item)
protected sealed override Drawable[] CreateFlagContent(UserStatistics item)
{
var username = new LinkFlowContainer(t => t.Font = OsuFont.GetFont(size: TEXT_SIZE, italics: true))
{
Expand All @@ -70,7 +72,7 @@ protected sealed override Drawable CreateFlagContent(UserStatistics item)
TextAnchor = Anchor.CentreLeft
};
username.AddUserLink(item.User);
return username;
return [new UpdateableTeamFlag(item.User.Team) { Size = new Vector2(40, 20) }, username];
}

protected sealed override Drawable[] CreateAdditionalContent(UserStatistics item) => new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ private void load()
Size = new Vector2(28, 20),
CountryCode = user?.CountryCode ?? default
},
new UpdateableTeamFlag(user?.Team)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(40, 20),
},
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Expand Down
Loading

0 comments on commit 4c851a3

Please sign in to comment.