UpdateableCountryText rewrite

This commit is contained in:
_ltn
2023-04-28 01:14:42 +03:00
parent f5c652325a
commit b13201fb79

View File

@ -7,6 +7,7 @@ using osu.Framework.Input.Events;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -14,53 +15,31 @@ using osu.Framework.Extensions;
namespace osu.Game.Users.Drawables namespace osu.Game.Users.Drawables
{ {
public partial class UpdateableCountryText : ModelBackedDrawable<CountryCode> public partial class UpdateableCountryText : OsuHoverContainer
{ {
public CountryCode CountryCode
{
get => Model;
set => Model = value;
}
public bool ShowPlaceholderOnUnknown = true; public bool ShowPlaceholderOnUnknown = true;
public Action? Action;
protected override Drawable? CreateDrawable(CountryCode countryCode)
{
if (countryCode == CountryCode.Unknown && !ShowPlaceholderOnUnknown)
return null;
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
{
Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular),
Margin = new MarginPadding { Left = 5 },
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Text = countryCode.GetDescription(),
},
new HoverClickSounds()
}
};
}
[Resolved] [Resolved]
private RankingsOverlay? rankingsOverlay { get; set; } private RankingsOverlay? rankingsOverlay { get; set; }
public UpdateableCountryText()
public UpdateableCountryText(CountryCode countryCode = CountryCode.Unknown)
{ {
CountryCode = countryCode; AutoSizeAxes = Axes.Both;
} }
protected override bool OnClick(ClickEvent e)
// [BackgroundDependencyLoader]
public void load(CountryCode countryCode)
{ {
Action?.Invoke(); Action = () =>
rankingsOverlay?.ShowCountry(CountryCode); {
return true; rankingsOverlay?.ShowCountry(countryCode);
};
Child = new OsuSpriteText
{
Font = OsuFont.GetFont(size: 14f, weight: FontWeight.Regular),
Text = countryCode.GetDescription(),
};
} }
} }