osu/osu.Game/Users/Drawables/UpdateableFlag.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
1.9 KiB
C#
Raw Normal View History

2019-06-19 00:50:16 +00:00
// 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;
2019-11-30 00:01:07 +00:00
using osu.Framework.Allocation;
2019-06-19 00:50:16 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-11-30 00:01:07 +00:00
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
2019-11-30 00:01:07 +00:00
using osu.Game.Overlays;
2019-06-19 00:50:16 +00:00
namespace osu.Game.Users.Drawables
{
public class UpdateableFlag : ModelBackedDrawable<Country>
{
public Country Country
{
get => Model;
set => Model = value;
}
/// <summary>
/// Whether to show a place holder on null country.
/// </summary>
public bool ShowPlaceholderOnNull = true;
/// <summary>
/// Perform an action in addition to showing the country ranking.
/// This should be used to perform auxiliary tasks and not as a primary action for clicking a flag (to maintain a consistent UX).
/// </summary>
public Action Action;
public UpdateableFlag(Country country = null)
2019-06-19 00:50:16 +00:00
{
Country = country;
}
protected override Drawable CreateDrawable(Country country)
2019-06-19 00:50:16 +00:00
{
if (country == null && !ShowPlaceholderOnNull)
return null;
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new DrawableFlag(country)
{
RelativeSizeAxes = Axes.Both
},
2022-06-01 12:00:14 +00:00
new HoverClickSounds()
}
};
}
2019-11-30 00:01:07 +00:00
[Resolved(canBeNull: true)]
private RankingsOverlay rankingsOverlay { get; set; }
protected override bool OnClick(ClickEvent e)
{
Action?.Invoke();
2019-12-01 00:56:03 +00:00
rankingsOverlay?.ShowCountry(Country);
2019-11-30 00:01:07 +00:00
return true;
}
2019-06-19 00:50:16 +00:00
}
}