diff --git a/osu.Game/Online/Leaderboards/LeaderboardScore.cs b/osu.Game/Online/Leaderboards/LeaderboardScore.cs index 323c17b101..1da697e72e 100644 --- a/osu.Game/Online/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Online/Leaderboards/LeaderboardScore.cs @@ -18,6 +18,7 @@ using osu.Game.Graphics.Sprites; using osu.Game.Rulesets.UI; using osu.Game.Scoring; using osu.Game.Users; +using osu.Game.Users.Drawables; using osuTK; using osuTK.Graphics; @@ -157,7 +158,7 @@ namespace osu.Game.Online.Leaderboards Masking = true, Children = new Drawable[] { - new DrawableFlag(user.Country) + new UpdateableFlag(user.Country) { Width = 30, RelativeSizeAxes = Axes.Y, diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs index 5db409a2c6..124b160496 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTable.cs @@ -13,7 +13,7 @@ using osu.Game.Graphics.Sprites; using osu.Game.Online.Leaderboards; using osu.Game.Rulesets.UI; using osu.Game.Scoring; -using osu.Game.Users; +using osu.Game.Users.Drawables; using osuTK; using osuTK.Graphics; @@ -135,7 +135,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores Spacing = new Vector2(5, 0), Children = new Drawable[] { - new DrawableFlag(score.User.Country) { Size = new Vector2(20, 13) }, + new UpdateableFlag(score.User.Country) { Size = new Vector2(20, 13) }, username } }, diff --git a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs index 651b8ce9a7..98ecf1b73f 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/TopScoreUserSection.cs @@ -14,6 +14,7 @@ using osu.Game.Graphics.Sprites; using osu.Game.Online.Leaderboards; using osu.Game.Scoring; using osu.Game.Users; +using osu.Game.Users.Drawables; using osuTK; using osuTK.Graphics; @@ -26,7 +27,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores private readonly UpdateableAvatar avatar; private readonly LinkFlowContainer usernameText; private readonly SpriteText date; - private readonly DrawableFlag flag; + private readonly UpdateableFlag flag; public TopScoreUserSection() { @@ -89,7 +90,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores Origin = Anchor.CentreLeft, Font = OsuFont.GetFont(size: 15, weight: FontWeight.Bold) }, - flag = new DrawableFlag + flag = new UpdateableFlag { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, diff --git a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs index 6fe55e2368..9b124df724 100644 --- a/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs +++ b/osu.Game/Overlays/Profile/Header/TopHeaderContainer.cs @@ -12,6 +12,7 @@ using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; using osu.Game.Overlays.Profile.Header.Components; using osu.Game.Users; +using osu.Game.Users.Drawables; using osuTK; namespace osu.Game.Overlays.Profile.Header @@ -27,7 +28,7 @@ namespace osu.Game.Overlays.Profile.Header private OsuSpriteText usernameText; private ExternalLinkButton openUserExternally; private OsuSpriteText titleText; - private DrawableFlag userFlag; + private UpdateableFlag userFlag; private OsuSpriteText userCountryText; private FillFlowContainer userStats; @@ -51,7 +52,7 @@ namespace osu.Game.Overlays.Profile.Header AutoSizeAxes = Axes.X, Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Children = new[] + Children = new Drawable[] { avatar = new UpdateableAvatar { @@ -115,7 +116,7 @@ namespace osu.Game.Overlays.Profile.Header Margin = new MarginPadding { Top = 5 }, Children = new Drawable[] { - userFlag = new DrawableFlag + userFlag = new UpdateableFlag { Size = new Vector2(30, 20) }, diff --git a/osu.Game/Screens/Multi/Lounge/Components/ParticipantInfo.cs b/osu.Game/Screens/Multi/Lounge/Components/ParticipantInfo.cs index 6570051040..a55db096af 100644 --- a/osu.Game/Screens/Multi/Lounge/Components/ParticipantInfo.cs +++ b/osu.Game/Screens/Multi/Lounge/Components/ParticipantInfo.cs @@ -8,7 +8,7 @@ using osu.Framework.Graphics.Containers; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; -using osu.Game.Users; +using osu.Game.Users.Drawables; using osuTK; namespace osu.Game.Screens.Multi.Lounge.Components @@ -79,7 +79,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components hostText.AddText("hosted by "); hostText.AddUserLink(host.NewValue, s => s.Font = s.Font.With(Typeface.Exo, weight: FontWeight.Bold, italics: true)); - flagContainer.Child = new DrawableFlag(host.NewValue.Country) { RelativeSizeAxes = Axes.Both }; + flagContainer.Child = new UpdateableFlag(host.NewValue.Country) { RelativeSizeAxes = Axes.Both }; } }, true); diff --git a/osu.Game/Users/Country.cs b/osu.Game/Users/Country.cs index a84641d1fd..1dcce6e870 100644 --- a/osu.Game/Users/Country.cs +++ b/osu.Game/Users/Country.cs @@ -1,14 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using Newtonsoft.Json; -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; namespace osu.Game.Users { @@ -26,40 +19,4 @@ namespace osu.Game.Users [JsonProperty(@"code")] public string FlagName; } - - public class DrawableFlag : ModelBackedDrawable, IHasTooltip - { - private TextureStore textures; - - private readonly Country country; - - public Country Country - { - get => Model; - set => Model = value; - } - - public string TooltipText => Country?.FullName; - - public DrawableFlag(Country country = null) - { - this.country = country; - } - - [BackgroundDependencyLoader] - private void load(TextureStore ts) - { - textures = ts ?? throw new ArgumentNullException(nameof(ts)); - Country = country; - } - - protected override Drawable CreateDrawable(Country country) - { - return new Sprite - { - RelativeSizeAxes = Axes.Both, - Texture = textures.Get($@"Flags/{country?.FlagName ?? @"__"}"), - }; - } - } } diff --git a/osu.Game/Users/Drawables/DrawableFlag.cs b/osu.Game/Users/Drawables/DrawableFlag.cs new file mode 100644 index 0000000000..5a2d1185fe --- /dev/null +++ b/osu.Game/Users/Drawables/DrawableFlag.cs @@ -0,0 +1,47 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +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; + +namespace osu.Game.Users.Drawables +{ + public class UpdateableFlag : ModelBackedDrawable + { + public Country Country + { + get => Model; + set => Model = value; + } + + public UpdateableFlag(Country country = null) => Country = country; + + protected override Drawable CreateDrawable(Country country) => new DrawableFlag(country) + { + RelativeSizeAxes = Axes.Both, + }; + } + + public class DrawableFlag : Sprite, IHasTooltip + { + private readonly Country country; + + public string TooltipText => country?.FullName; + + public DrawableFlag(Country country) => this.country = country; + + [BackgroundDependencyLoader] + private void load(TextureStore ts) + { + if (ts == null) + throw new ArgumentNullException(nameof(ts)); + + Texture = ts.Get($@"Flags/{country?.FlagName ?? @"__"}"); + } + } +} diff --git a/osu.Game/Users/UserPanel.cs b/osu.Game/Users/UserPanel.cs index 4b2029e6fd..c63c12773e 100644 --- a/osu.Game/Users/UserPanel.cs +++ b/osu.Game/Users/UserPanel.cs @@ -20,6 +20,7 @@ using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics.Containers; using osu.Game.Overlays.Profile.Header.Components; +using osu.Game.Users.Drawables; namespace osu.Game.Users { @@ -137,7 +138,7 @@ namespace osu.Game.Users Spacing = new Vector2(5f, 0f), Children = new Drawable[] { - new DrawableFlag(user.Country) + new UpdateableFlag(user.Country) { Width = 30f, RelativeSizeAxes = Axes.Y,