1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:07:44 +08:00
osu-lazer/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
2.0 KiB
C#
Raw Normal View History

2019-06-19 08:50:16 +08: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 08:01:07 +08:00
using osu.Framework.Allocation;
2019-06-19 08:50:16 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-11-30 08:01:07 +08:00
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
2019-11-30 08:01:07 +08:00
using osu.Game.Overlays;
2019-06-19 08:50:16 +08:00
namespace osu.Game.Users.Drawables
{
2022-07-18 13:40:34 +08:00
public partial class UpdateableFlag : ModelBackedDrawable<CountryCode>
2019-06-19 08:50:16 +08:00
{
2022-07-18 13:40:34 +08:00
public CountryCode CountryCode
2019-06-19 08:50:16 +08:00
{
get => Model;
set => Model = value;
}
/// <summary>
/// Whether to show a place holder on unknown country.
/// </summary>
public bool ShowPlaceholderOnUnknown = 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>
2023-03-06 07:15:58 +08:00
public Action? Action;
public UpdateableFlag(CountryCode countryCode = CountryCode.Unknown)
2019-06-19 08:50:16 +08:00
{
2022-07-18 13:40:34 +08:00
CountryCode = countryCode;
2019-06-19 08:50:16 +08:00
}
2023-03-06 07:15:58 +08:00
protected override Drawable? CreateDrawable(CountryCode countryCode)
2019-06-19 08:50:16 +08:00
{
if (countryCode == CountryCode.Unknown && !ShowPlaceholderOnUnknown)
return null;
return new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
2022-07-18 13:40:34 +08:00
new DrawableFlag(countryCode)
{
RelativeSizeAxes = Axes.Both
},
2022-06-01 20:00:14 +08:00
new HoverClickSounds()
}
};
}
2019-11-30 08:01:07 +08:00
2023-03-06 07:15:58 +08:00
[Resolved]
private RankingsOverlay? rankingsOverlay { get; set; }
2019-11-30 08:01:07 +08:00
protected override bool OnClick(ClickEvent e)
{
Action?.Invoke();
2022-07-18 13:40:34 +08:00
rankingsOverlay?.ShowCountry(CountryCode);
2019-11-30 08:01:07 +08:00
return true;
}
2019-06-19 08:50:16 +08:00
}
}