1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:07:25 +08:00

Seperate drawable and updateable flag from Country + Use UpdateableFlag

This commit is contained in:
KingLuigi4932 2019-06-17 20:57:57 +03:00
parent 794ba17a2f
commit d665f1fe4b
8 changed files with 62 additions and 54 deletions

View File

@ -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,

View File

@ -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
}
},

View File

@ -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,

View File

@ -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)
},

View File

@ -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);

View File

@ -1,14 +1,7 @@
// 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 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<Country>, 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 ?? @"__"}"),
};
}
}
}

View File

@ -0,0 +1,47 @@
// 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 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<Country>
{
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 ?? @"__"}");
}
}
}

View File

@ -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,