From f7fe0830181e28248f29131afd2b1feaa1b6da0a Mon Sep 17 00:00:00 2001 From: Aergwyn Date: Sat, 30 Dec 2017 14:57:57 +0100 Subject: [PATCH] add tooltip to country flags --- .../BeatmapSet/Scores/DrawableScore.cs | 2 +- .../BeatmapSet/Scores/DrawableTopScore.cs | 2 +- osu.Game/Overlays/Profile/ProfileHeader.cs | 4 +- .../Screens/Multiplayer/ParticipantInfo.cs | 2 +- .../Select/Leaderboards/LeaderboardScore.cs | 2 +- osu.Game/Users/Country.cs | 43 +++++++++++-------- osu.Game/Users/UserPanel.cs | 2 +- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs b/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs index 5a3aba7b43..8b407ac208 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/DrawableScore.cs @@ -48,7 +48,7 @@ public DrawableScore(int index, OnlineScore score) Font = @"Exo2.0-RegularItalic", Margin = new MarginPadding { Left = side_margin } }, - new DrawableFlag(score.User.Country?.FlagName) + new DrawableFlag(score.User.Country) { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, diff --git a/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs b/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs index 833ed94c0f..66bf89bbac 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs @@ -52,7 +52,7 @@ public OnlineScore Score score = value; avatar.User = username.User = score.User; - flag.FlagName = score.User.Country?.FlagName; + flag.Country = score.User.Country; date.Text = $@"achieved {score.Date:MMM d, yyyy}"; rank.UpdateRank(score.Rank); diff --git a/osu.Game/Overlays/Profile/ProfileHeader.cs b/osu.Game/Overlays/Profile/ProfileHeader.cs index 18e77cf186..960bb60287 100644 --- a/osu.Game/Overlays/Profile/ProfileHeader.cs +++ b/osu.Game/Overlays/Profile/ProfileHeader.cs @@ -109,7 +109,7 @@ public ProfileHeader(User user) Origin = Anchor.BottomLeft, Y = -48, }, - countryFlag = new DrawableFlag(user.Country?.FlagName) + countryFlag = new DrawableFlag(user.Country) { Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, @@ -333,7 +333,7 @@ private void loadUser() { infoTextLeft.AddText("from "); infoTextLeft.AddText(user.Country.FullName, boldItalic); - countryFlag.FlagName = user.Country.FlagName; + countryFlag.Country = user.Country; } infoTextLeft.NewParagraph(); diff --git a/osu.Game/Screens/Multiplayer/ParticipantInfo.cs b/osu.Game/Screens/Multiplayer/ParticipantInfo.cs index fa48287ce1..2197b7477c 100644 --- a/osu.Game/Screens/Multiplayer/ParticipantInfo.cs +++ b/osu.Game/Screens/Multiplayer/ParticipantInfo.cs @@ -27,7 +27,7 @@ public User Host set { host.Text = value.Username; - flagContainer.Children = new[] { new DrawableFlag(value.Country?.FlagName) { RelativeSizeAxes = Axes.Both } }; + flagContainer.Children = new[] { new DrawableFlag(value.Country) { RelativeSizeAxes = Axes.Both } }; } } diff --git a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs index 03466439ad..e0c9a3e04e 100644 --- a/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs +++ b/osu.Game/Screens/Select/Leaderboards/LeaderboardScore.cs @@ -145,7 +145,7 @@ private void load() Masking = true, Children = new Drawable[] { - new DrawableFlag(Score.User?.Country?.FlagName) + new DrawableFlag(Score.User?.Country) { Width = 30, RelativeSizeAxes = Axes.Y, diff --git a/osu.Game/Users/Country.cs b/osu.Game/Users/Country.cs index 0c0d12c1cc..46ddaee637 100644 --- a/osu.Game/Users/Country.cs +++ b/osu.Game/Users/Country.cs @@ -6,6 +6,7 @@ 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; @@ -26,36 +27,30 @@ public class Country public string FlagName; } - public class DrawableFlag : Container + public class DrawableFlag : Container, IHasTooltip { private readonly Sprite sprite; private TextureStore textures; - private string flagName; - public string FlagName + private Country country; + public Country Country { - get { return flagName; } + get { return country; } set { - if (value == flagName) return; - flagName = value; - sprite.Texture = textures.Get($@"Flags/{flagName}"); + if (value == country) + return; + + country = value; + sprite.Texture = getFlagTexture(); } } - [BackgroundDependencyLoader] - private void load(TextureStore ts) - { - if (ts == null) - throw new ArgumentNullException(nameof(ts)); + public string TooltipText => country?.FullName; - textures = ts; - sprite.Texture = textures.Get($@"Flags/{flagName}"); - } - - public DrawableFlag(string name = null) + public DrawableFlag(Country country = null) { - flagName = name ?? @"__"; + this.country = country; Children = new Drawable[] { @@ -65,5 +60,17 @@ public DrawableFlag(string name = null) }, }; } + + [BackgroundDependencyLoader] + private void load(TextureStore ts) + { + if (ts == null) + throw new ArgumentNullException(nameof(ts)); + + textures = ts; + sprite.Texture = getFlagTexture(); + } + + private Texture getFlagTexture() => textures.Get($@"Flags/{country?.FlagName ?? @"__"}"); } } diff --git a/osu.Game/Users/UserPanel.cs b/osu.Game/Users/UserPanel.cs index a2cc8e8d49..e0a4e3184d 100644 --- a/osu.Game/Users/UserPanel.cs +++ b/osu.Game/Users/UserPanel.cs @@ -114,7 +114,7 @@ public UserPanel(User user) Spacing = new Vector2(5f, 0f), Children = new Drawable[] { - new DrawableFlag(user.Country?.FlagName) + new DrawableFlag(user.Country) { Width = 30f, RelativeSizeAxes = Axes.Y,