mirror of
https://github.com/ppy/osu.git
synced 2025-03-25 18:57:18 +08:00
Add drawable implementations of team logo
This commit is contained in:
parent
88188e8fcb
commit
303961d101
@ -199,6 +199,12 @@ namespace osu.Game.Online.Leaderboards
|
||||
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,
|
||||
|
@ -160,7 +160,20 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
{
|
||||
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
|
||||
|
@ -27,7 +27,9 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
private readonly UpdateableAvatar avatar;
|
||||
private readonly LinkFlowContainer usernameText;
|
||||
private readonly DrawableDate achievedOn;
|
||||
|
||||
private readonly UpdateableFlag flag;
|
||||
private readonly UpdateableTeamFlag teamFlag;
|
||||
|
||||
public TopScoreUserSection()
|
||||
{
|
||||
@ -112,12 +114,30 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
},
|
||||
}
|
||||
},
|
||||
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
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -139,6 +159,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
|
||||
{
|
||||
avatar.User = value.User;
|
||||
flag.CountryCode = value.User.CountryCode;
|
||||
teamFlag.Team = value.User.Team;
|
||||
achievedOn.Date = value.Date;
|
||||
|
||||
usernameText.Clear();
|
||||
|
@ -42,6 +42,7 @@ namespace osu.Game.Overlays.Profile.Header
|
||||
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!;
|
||||
@ -166,6 +167,10 @@ namespace osu.Game.Overlays.Profile.Header
|
||||
{
|
||||
Size = new Vector2(28, 20),
|
||||
},
|
||||
teamFlag = new UpdateableTeamFlag
|
||||
{
|
||||
Size = new Vector2(40, 20),
|
||||
},
|
||||
userCountryContainer = new OsuHoverContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
@ -215,6 +220,7 @@ namespace osu.Game.Overlays.Profile.Header
|
||||
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;
|
||||
|
@ -140,6 +140,12 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
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,
|
||||
|
@ -339,6 +339,12 @@ namespace osu.Game.Screens.SelectV2.Leaderboards
|
||||
Origin = Anchor.CentreLeft,
|
||||
Size = new Vector2(24, 16),
|
||||
},
|
||||
new UpdateableTeamFlag(user.Team)
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Size = new Vector2(40, 20),
|
||||
},
|
||||
new DateLabel(score.Date)
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.API;
|
||||
@ -221,7 +222,15 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
: new APIUser
|
||||
{
|
||||
Id = id,
|
||||
Username = $"User {id}"
|
||||
Username = $"User {id}",
|
||||
Team = RNG.NextBool()
|
||||
? new APITeam
|
||||
{
|
||||
Name = "Collective Wangs",
|
||||
ShortName = "WANG",
|
||||
FlagUrl = "https://assets.ppy.sh/teams/logo/1/wanglogo.jpg",
|
||||
}
|
||||
: null,
|
||||
})
|
||||
.Where(u => u != null).ToList(),
|
||||
});
|
||||
|
86
osu.Game/Users/Drawables/UpdateableTeamFlag.cs
Normal file
86
osu.Game/Users/Drawables/UpdateableTeamFlag.cs
Normal file
@ -0,0 +1,86 @@
|
||||
// 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 osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
|
||||
namespace osu.Game.Users.Drawables
|
||||
{
|
||||
/// <summary>
|
||||
/// A team logo which can update to a new team when needed.
|
||||
/// </summary>
|
||||
public partial class UpdateableTeamFlag : ModelBackedDrawable<APITeam?>
|
||||
{
|
||||
public APITeam? Team
|
||||
{
|
||||
get => Model;
|
||||
set => Model = value;
|
||||
}
|
||||
|
||||
protected override double LoadDelay => 200;
|
||||
|
||||
public UpdateableTeamFlag(APITeam? team = null)
|
||||
{
|
||||
Team = team;
|
||||
|
||||
Masking = true;
|
||||
}
|
||||
|
||||
protected override Drawable? CreateDrawable(APITeam? team)
|
||||
{
|
||||
if (team == null)
|
||||
return Empty();
|
||||
|
||||
return new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new TeamFlag(team)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
new HoverClickSounds()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Generally we just want team flags to disappear if the user doesn't have one.
|
||||
// This also handles fill flow cases and avoids spacing being added for non-displaying flags.
|
||||
public override bool IsPresent => base.IsPresent && Team != null;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
CornerRadius = DrawHeight / 8;
|
||||
}
|
||||
|
||||
public partial class TeamFlag : Sprite, IHasTooltip
|
||||
{
|
||||
private readonly APITeam team;
|
||||
|
||||
public LocalisableString TooltipText { get; }
|
||||
|
||||
public TeamFlag(APITeam team)
|
||||
{
|
||||
this.team = team;
|
||||
TooltipText = team.Name;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(LargeTextureStore textures)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(team.Name))
|
||||
Texture = textures.Get(team.FlagUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -82,9 +82,10 @@ namespace osu.Game.Users
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(6),
|
||||
Children = new Drawable[]
|
||||
Children = new[]
|
||||
{
|
||||
CreateFlag(),
|
||||
CreateTeamLogo(),
|
||||
// supporter icon is being added later
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +130,11 @@ namespace osu.Game.Users
|
||||
Action = Action,
|
||||
};
|
||||
|
||||
protected Drawable CreateTeamLogo() => new UpdateableTeamFlag(User.Team)
|
||||
{
|
||||
Size = new Vector2(52, 26),
|
||||
};
|
||||
|
||||
public MenuItem[] ContextMenuItems
|
||||
{
|
||||
get
|
||||
|
@ -147,9 +147,10 @@ namespace osu.Game.Users
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(6),
|
||||
Children = new Drawable[]
|
||||
Children = new[]
|
||||
{
|
||||
CreateFlag(),
|
||||
CreateTeamLogo(),
|
||||
// supporter icon is being added later
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user