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.
|
|
|
|
|
|
2022-01-21 21:01:49 +08:00
|
|
|
|
using System;
|
2019-11-30 08:01:07 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2024-05-10 20:32:21 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
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;
|
2024-05-10 20:32:21 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2021-07-30 20:32:08 +08:00
|
|
|
|
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-11-24 13:32:20 +08:00
|
|
|
|
public partial class UpdateableFlag : ModelBackedDrawable<CountryCode>
|
2019-06-19 08:50:16 +08:00
|
|
|
|
{
|
2024-05-10 20:32:21 +08:00
|
|
|
|
private CountryCode countryCode;
|
|
|
|
|
|
2022-07-18 13:40:34 +08:00
|
|
|
|
public CountryCode CountryCode
|
2019-06-19 08:50:16 +08:00
|
|
|
|
{
|
2024-05-10 20:32:21 +08:00
|
|
|
|
get => countryCode;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
countryCode = value;
|
|
|
|
|
updateModel();
|
|
|
|
|
}
|
2019-06-19 08:50:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-21 21:01:49 +08: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>
|
2023-03-06 07:15:58 +08:00
|
|
|
|
public Action? Action;
|
2022-01-21 21:01:49 +08:00
|
|
|
|
|
2024-05-10 20:32:21 +08:00
|
|
|
|
private readonly Bindable<bool> hideFlags = new BindableBool();
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private RankingsOverlay? rankingsOverlay { get; set; }
|
|
|
|
|
|
2022-07-18 13:54:35 +08:00
|
|
|
|
public UpdateableFlag(CountryCode countryCode = CountryCode.Unknown)
|
2019-06-19 08:50:16 +08:00
|
|
|
|
{
|
2022-07-18 13:40:34 +08:00
|
|
|
|
CountryCode = countryCode;
|
2024-05-10 20:32:21 +08:00
|
|
|
|
hideFlags.BindValueChanged(_ => updateModel());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
|
{
|
|
|
|
|
config.BindWith(OsuSetting.HideCountryFlags, hideFlags);
|
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
|
|
|
|
{
|
2021-07-30 20:32:08 +08:00
|
|
|
|
return new Container
|
2019-06-20 01:17:02 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2021-07-30 20:32:08 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2022-07-18 13:40:34 +08:00
|
|
|
|
new DrawableFlag(countryCode)
|
2021-07-30 20:32:08 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
2022-06-01 20:00:14 +08:00
|
|
|
|
new HoverClickSounds()
|
2021-07-30 20:32:08 +08:00
|
|
|
|
}
|
2019-06-20 01:17:02 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2019-11-30 08:01:07 +08:00
|
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
2022-01-21 21:01:49 +08:00
|
|
|
|
Action?.Invoke();
|
2022-07-18 13:40:34 +08:00
|
|
|
|
rankingsOverlay?.ShowCountry(CountryCode);
|
2019-11-30 08:01:07 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-05-10 20:32:21 +08:00
|
|
|
|
|
|
|
|
|
private void updateModel() => Model = hideFlags.Value ? CountryCode.Unknown : countryCode;
|
2019-06-19 08:50:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|