1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-28 03:15:08 +08:00

Added a BaseDrawableFlag without a tooltip, and used it.

The BaseDrawableFlag is used in a BaseUpdateableFlag so the tooltip is not shown, the ClickableUpdateableFlag still shows the tooltip.
This commit is contained in:
yesseruser 2023-11-21 19:51:35 +01:00
parent cd7e0bf620
commit b2f74325ef
4 changed files with 36 additions and 11 deletions

View File

@ -0,0 +1,29 @@
// 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.Sprites;
using osu.Framework.Graphics.Textures;
namespace osu.Game.Users.Drawables
{
public partial class BaseDrawableFlag : Sprite
{
protected readonly CountryCode CountryCode;
public BaseDrawableFlag(CountryCode countryCode)
{
CountryCode = countryCode;
}
[BackgroundDependencyLoader]
private void load(TextureStore ts)
{
ArgumentNullException.ThrowIfNull(ts);
string textureName = CountryCode == CountryCode.Unknown ? "__" : CountryCode.ToString();
Texture = ts.Get($@"Flags/{textureName}") ?? ts.Get(@"Flags/__");
}
}
}

View File

@ -34,7 +34,8 @@ namespace osu.Game.Users.Drawables
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
{ {
new DrawableFlag(countryCode) // This is a BaseDrawableFlag which does not show a tooltip.
new BaseDrawableFlag(countryCode)
{ {
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
}, },

View File

@ -34,6 +34,7 @@ namespace osu.Game.Users.Drawables
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
{ {
// This is a DrawableFlag which implements IHasTooltip, so a tooltip is shown.
new DrawableFlag(countryCode) new DrawableFlag(countryCode)
{ {
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both

View File

@ -5,29 +5,23 @@ using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Localisation; using osu.Framework.Localisation;
namespace osu.Game.Users.Drawables namespace osu.Game.Users.Drawables
{ {
public partial class DrawableFlag : Sprite, IHasTooltip public partial class DrawableFlag : BaseDrawableFlag, IHasTooltip
{ {
private readonly CountryCode countryCode; public LocalisableString TooltipText => CountryCode == CountryCode.Unknown ? string.Empty : CountryCode.GetDescription();
public LocalisableString TooltipText => countryCode == CountryCode.Unknown ? string.Empty : countryCode.GetDescription(); public DrawableFlag(CountryCode countryCode) : base(countryCode) { }
public DrawableFlag(CountryCode countryCode)
{
this.countryCode = countryCode;
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(TextureStore ts) private void load(TextureStore ts)
{ {
ArgumentNullException.ThrowIfNull(ts); ArgumentNullException.ThrowIfNull(ts);
string textureName = countryCode == CountryCode.Unknown ? "__" : countryCode.ToString(); string textureName = CountryCode == CountryCode.Unknown ? "__" : CountryCode.ToString();
Texture = ts.Get($@"Flags/{textureName}") ?? ts.Get(@"Flags/__"); Texture = ts.Get($@"Flags/{textureName}") ?? ts.Get(@"Flags/__");
} }
} }