2021-01-25 12:22:37 +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
|
|
|
|
|
2021-01-25 12:22:37 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
using osu.Game.Tournament.Models;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Components
|
|
|
|
{
|
2021-01-26 10:15:19 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Mod icon displayed in tournament usages, allowing user overridden graphics.
|
|
|
|
/// </summary>
|
|
|
|
public partial class TournamentModIcon : CompositeDrawable
|
2021-01-25 12:22:37 +00:00
|
|
|
{
|
2021-01-25 14:47:31 +00:00
|
|
|
private readonly string modAcronym;
|
2021-01-25 12:22:37 +00:00
|
|
|
|
|
|
|
[Resolved]
|
2021-12-03 09:14:44 +00:00
|
|
|
private IRulesetStore rulesets { get; set; }
|
2021-01-25 12:22:37 +00:00
|
|
|
|
2021-01-26 10:15:19 +00:00
|
|
|
public TournamentModIcon(string modAcronym)
|
2021-01-25 14:47:31 +00:00
|
|
|
{
|
2021-01-26 10:15:19 +00:00
|
|
|
this.modAcronym = modAcronym;
|
2021-01-25 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 12:22:37 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2021-01-25 13:57:35 +00:00
|
|
|
private void load(TextureStore textures, LadderInfo ladderInfo)
|
2021-01-25 12:22:37 +00:00
|
|
|
{
|
2021-11-28 15:14:12 +00:00
|
|
|
var customTexture = textures.Get($"Mods/{modAcronym}");
|
2021-01-25 12:22:37 +00:00
|
|
|
|
2021-01-26 10:16:38 +00:00
|
|
|
if (customTexture != null)
|
2021-01-25 12:22:37 +00:00
|
|
|
{
|
|
|
|
AddInternal(new Sprite
|
|
|
|
{
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
2021-01-26 10:16:38 +00:00
|
|
|
Texture = customTexture
|
2021-01-25 12:22:37 +00:00
|
|
|
});
|
2021-01-26 10:16:38 +00:00
|
|
|
|
|
|
|
return;
|
2021-01-25 12:22:37 +00:00
|
|
|
}
|
2021-01-25 13:21:53 +00:00
|
|
|
|
2022-01-27 06:19:48 +00:00
|
|
|
var ruleset = rulesets.GetRuleset(ladderInfo.Ruleset.Value?.OnlineID ?? 0);
|
2021-09-10 02:09:13 +00:00
|
|
|
var modIcon = ruleset?.CreateInstance().CreateModFromAcronym(modAcronym);
|
2021-01-25 12:22:37 +00:00
|
|
|
|
2021-01-26 10:16:38 +00:00
|
|
|
if (modIcon == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AddInternal(new ModIcon(modIcon, false)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Scale = new Vector2(0.5f)
|
|
|
|
});
|
2021-01-25 12:22:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|