2021-01-25 20:22:37 +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.Linq;
|
|
|
|
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 18:15:19 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Mod icon displayed in tournament usages, allowing user overridden graphics.
|
|
|
|
/// </summary>
|
|
|
|
public class TournamentModIcon : CompositeDrawable
|
2021-01-25 20:22:37 +08:00
|
|
|
{
|
2021-01-25 22:47:31 +08:00
|
|
|
private readonly string modAcronym;
|
2021-01-25 20:22:37 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private RulesetStore rulesets { get; set; }
|
|
|
|
|
2021-01-26 18:15:19 +08:00
|
|
|
public TournamentModIcon(string modAcronym)
|
2021-01-25 22:47:31 +08:00
|
|
|
{
|
2021-01-26 18:15:19 +08:00
|
|
|
this.modAcronym = modAcronym;
|
2021-01-25 22:47:31 +08:00
|
|
|
}
|
|
|
|
|
2021-01-25 20:22:37 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2021-01-25 21:57:35 +08:00
|
|
|
private void load(TextureStore textures, LadderInfo ladderInfo)
|
2021-01-25 20:22:37 +08:00
|
|
|
{
|
2021-01-26 18:16:38 +08:00
|
|
|
var customTexture = textures.Get($"mods/{modAcronym}");
|
2021-01-25 20:22:37 +08:00
|
|
|
|
2021-01-26 18:16:38 +08:00
|
|
|
if (customTexture != null)
|
2021-01-25 20:22:37 +08:00
|
|
|
{
|
|
|
|
AddInternal(new Sprite
|
|
|
|
{
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
2021-01-26 18:16:38 +08:00
|
|
|
Texture = customTexture
|
2021-01-25 20:22:37 +08:00
|
|
|
});
|
2021-01-26 18:16:38 +08:00
|
|
|
|
|
|
|
return;
|
2021-01-25 20:22:37 +08:00
|
|
|
}
|
2021-01-25 21:21:53 +08:00
|
|
|
|
2021-01-26 18:16:38 +08:00
|
|
|
var ruleset = rulesets.GetRuleset(ladderInfo.Ruleset.Value?.ID ?? 0);
|
|
|
|
var modIcon = ruleset?.CreateInstance().GetAllMods().FirstOrDefault(mod => mod.Acronym == modAcronym);
|
2021-01-25 20:22:37 +08:00
|
|
|
|
2021-01-26 18:16:38 +08:00
|
|
|
if (modIcon == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AddInternal(new ModIcon(modIcon, false)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Scale = new Vector2(0.5f)
|
|
|
|
});
|
2021-01-25 20:22:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|