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.
|
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2022-01-21 13:01:49 +00:00
|
|
|
|
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;
|
2021-07-30 12:32:08 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2022-07-18 05:40:34 +00:00
|
|
|
|
public partial class UpdateableFlag : ModelBackedDrawable<CountryCode>
|
2019-06-19 00:50:16 +00:00
|
|
|
|
{
|
2022-07-18 05:40:34 +00:00
|
|
|
|
public CountryCode CountryCode
|
2019-06-19 00:50:16 +00:00
|
|
|
|
{
|
|
|
|
|
get => Model;
|
|
|
|
|
set => Model = value;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-19 17:17:02 +00:00
|
|
|
|
/// <summary>
|
2022-07-16 03:07:53 +00:00
|
|
|
|
/// Whether to show a place holder on unknown country.
|
2019-06-19 17:17:02 +00:00
|
|
|
|
/// </summary>
|
2022-07-16 03:07:53 +00:00
|
|
|
|
public bool ShowPlaceholderOnUnknown = true;
|
2019-06-19 17:17:02 +00:00
|
|
|
|
|
2022-01-21 13:01:49 +00:00
|
|
|
|
/// <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;
|
|
|
|
|
|
2022-07-18 05:54:35 +00:00
|
|
|
|
public UpdateableFlag(CountryCode countryCode = CountryCode.Unknown)
|
2019-06-19 00:50:16 +00:00
|
|
|
|
{
|
2022-07-18 05:40:34 +00:00
|
|
|
|
CountryCode = countryCode;
|
2019-06-19 00:50:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-18 05:40:34 +00:00
|
|
|
|
protected override Drawable CreateDrawable(CountryCode countryCode)
|
2019-06-19 00:50:16 +00:00
|
|
|
|
{
|
2022-07-18 05:54:35 +00:00
|
|
|
|
if (countryCode == CountryCode.Unknown && !ShowPlaceholderOnUnknown)
|
2019-06-19 17:17:02 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
2021-07-30 12:32:08 +00:00
|
|
|
|
return new Container
|
2019-06-19 17:17:02 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-07-30 12:32:08 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2022-07-18 05:40:34 +00:00
|
|
|
|
new DrawableFlag(countryCode)
|
2021-07-30 12:32:08 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
2022-06-01 12:00:14 +00:00
|
|
|
|
new HoverClickSounds()
|
2021-07-30 12:32:08 +00:00
|
|
|
|
}
|
2019-06-19 17:17:02 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
2019-11-30 00:01:07 +00:00
|
|
|
|
|
|
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
|
private RankingsOverlay rankingsOverlay { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
2022-01-21 13:01:49 +00:00
|
|
|
|
Action?.Invoke();
|
2022-07-18 05:40:34 +00:00
|
|
|
|
rankingsOverlay?.ShowCountry(CountryCode);
|
2019-11-30 00:01:07 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-06-19 00:50:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|