mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 09:03:50 +09:00
Merge pull request #11589 from MiraiSubject/osu-mod-icon-fallbacks
Allow tournament client to use default mod icons if custom icons are not present
This commit is contained in:
@ -0,0 +1,60 @@
|
|||||||
|
// 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 osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Tournament.Components;
|
||||||
|
|
||||||
|
namespace osu.Game.Tournament.Tests.Components
|
||||||
|
{
|
||||||
|
public class TestSceneTournamentModDisplay : TournamentTestScene
|
||||||
|
{
|
||||||
|
[Resolved]
|
||||||
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
|
private FillFlowContainer<TournamentBeatmapPanel> fillFlow;
|
||||||
|
|
||||||
|
private BeatmapInfo beatmap;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
var req = new GetBeatmapRequest(new BeatmapInfo { OnlineBeatmapID = 490154 });
|
||||||
|
req.Success += success;
|
||||||
|
api.Queue(req);
|
||||||
|
|
||||||
|
Add(fillFlow = new FillFlowContainer<TournamentBeatmapPanel>
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Direction = FillDirection.Full,
|
||||||
|
Spacing = new osuTK.Vector2(10)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void success(APIBeatmap apiBeatmap)
|
||||||
|
{
|
||||||
|
beatmap = apiBeatmap.ToBeatmap(rulesets);
|
||||||
|
var mods = rulesets.GetRuleset(Ladder.Ruleset.Value.ID ?? 0).CreateInstance().GetAllMods();
|
||||||
|
|
||||||
|
foreach (var mod in mods)
|
||||||
|
{
|
||||||
|
fillFlow.Add(new TournamentBeatmapPanel(beatmap, mod.Acronym)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,7 +9,6 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -23,7 +22,7 @@ namespace osu.Game.Tournament.Components
|
|||||||
public class TournamentBeatmapPanel : CompositeDrawable
|
public class TournamentBeatmapPanel : CompositeDrawable
|
||||||
{
|
{
|
||||||
public readonly BeatmapInfo Beatmap;
|
public readonly BeatmapInfo Beatmap;
|
||||||
private readonly string mods;
|
private readonly string mod;
|
||||||
|
|
||||||
private const float horizontal_padding = 10;
|
private const float horizontal_padding = 10;
|
||||||
private const float vertical_padding = 10;
|
private const float vertical_padding = 10;
|
||||||
@ -33,12 +32,12 @@ namespace osu.Game.Tournament.Components
|
|||||||
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
|
private readonly Bindable<TournamentMatch> currentMatch = new Bindable<TournamentMatch>();
|
||||||
private Box flash;
|
private Box flash;
|
||||||
|
|
||||||
public TournamentBeatmapPanel(BeatmapInfo beatmap, string mods = null)
|
public TournamentBeatmapPanel(BeatmapInfo beatmap, string mod = null)
|
||||||
{
|
{
|
||||||
if (beatmap == null) throw new ArgumentNullException(nameof(beatmap));
|
if (beatmap == null) throw new ArgumentNullException(nameof(beatmap));
|
||||||
|
|
||||||
Beatmap = beatmap;
|
Beatmap = beatmap;
|
||||||
this.mods = mods;
|
this.mod = mod;
|
||||||
Width = 400;
|
Width = 400;
|
||||||
Height = HEIGHT;
|
Height = HEIGHT;
|
||||||
}
|
}
|
||||||
@ -122,23 +121,15 @@ namespace osu.Game.Tournament.Components
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(mods))
|
if (!string.IsNullOrEmpty(mod))
|
||||||
{
|
{
|
||||||
AddInternal(new Container
|
AddInternal(new TournamentModIcon(mod)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y,
|
|
||||||
Width = 60,
|
|
||||||
Anchor = Anchor.CentreRight,
|
Anchor = Anchor.CentreRight,
|
||||||
Origin = Anchor.CentreRight,
|
Origin = Anchor.CentreRight,
|
||||||
Margin = new MarginPadding(10),
|
Margin = new MarginPadding(10),
|
||||||
Child = new Sprite
|
Width = 60,
|
||||||
{
|
RelativeSizeAxes = Axes.Y,
|
||||||
FillMode = FillMode.Fit,
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Anchor = Anchor.CentreRight,
|
|
||||||
Origin = Anchor.CentreRight,
|
|
||||||
Texture = textures.Get($"mods/{mods}"),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
65
osu.Game.Tournament/Components/TournamentModIcon.cs
Normal file
65
osu.Game.Tournament/Components/TournamentModIcon.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// 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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Mod icon displayed in tournament usages, allowing user overridden graphics.
|
||||||
|
/// </summary>
|
||||||
|
public class TournamentModIcon : CompositeDrawable
|
||||||
|
{
|
||||||
|
private readonly string modAcronym;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
|
public TournamentModIcon(string modAcronym)
|
||||||
|
{
|
||||||
|
this.modAcronym = modAcronym;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(TextureStore textures, LadderInfo ladderInfo)
|
||||||
|
{
|
||||||
|
var customTexture = textures.Get($"mods/{modAcronym}");
|
||||||
|
|
||||||
|
if (customTexture != null)
|
||||||
|
{
|
||||||
|
AddInternal(new Sprite
|
||||||
|
{
|
||||||
|
FillMode = FillMode.Fit,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.CentreRight,
|
||||||
|
Origin = Anchor.CentreRight,
|
||||||
|
Texture = customTexture
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ruleset = rulesets.GetRuleset(ladderInfo.Ruleset.Value?.ID ?? 0);
|
||||||
|
var modIcon = ruleset?.CreateInstance().GetAllMods().FirstOrDefault(mod => mod.Acronym == modAcronym);
|
||||||
|
|
||||||
|
if (modIcon == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AddInternal(new ModIcon(modIcon, false)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Scale = new Vector2(0.5f)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -236,13 +236,13 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
iconsContainer.AddRange(new[]
|
iconsContainer.AddRange(new[]
|
||||||
{
|
{
|
||||||
backgroundIcon = new PassThroughTooltipModIcon(Mods[1])
|
backgroundIcon = new ModIcon(Mods[1], false)
|
||||||
{
|
{
|
||||||
Origin = Anchor.BottomRight,
|
Origin = Anchor.BottomRight,
|
||||||
Anchor = Anchor.BottomRight,
|
Anchor = Anchor.BottomRight,
|
||||||
Position = new Vector2(1.5f),
|
Position = new Vector2(1.5f),
|
||||||
},
|
},
|
||||||
foregroundIcon = new PassThroughTooltipModIcon(Mods[0])
|
foregroundIcon = new ModIcon(Mods[0], false)
|
||||||
{
|
{
|
||||||
Origin = Anchor.BottomRight,
|
Origin = Anchor.BottomRight,
|
||||||
Anchor = Anchor.BottomRight,
|
Anchor = Anchor.BottomRight,
|
||||||
@ -252,7 +252,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
iconsContainer.Add(foregroundIcon = new PassThroughTooltipModIcon(Mod)
|
iconsContainer.Add(foregroundIcon = new ModIcon(Mod, false)
|
||||||
{
|
{
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -297,15 +297,5 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
Mod = mod;
|
Mod = mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PassThroughTooltipModIcon : ModIcon
|
|
||||||
{
|
|
||||||
public override string TooltipText => null;
|
|
||||||
|
|
||||||
public PassThroughTooltipModIcon(Mod mod)
|
|
||||||
: base(mod)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,9 @@ using osu.Framework.Bindables;
|
|||||||
|
|
||||||
namespace osu.Game.Rulesets.UI
|
namespace osu.Game.Rulesets.UI
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Display the specified mod at a fixed size.
|
||||||
|
/// </summary>
|
||||||
public class ModIcon : Container, IHasTooltip
|
public class ModIcon : Container, IHasTooltip
|
||||||
{
|
{
|
||||||
public readonly BindableBool Selected = new BindableBool();
|
public readonly BindableBool Selected = new BindableBool();
|
||||||
@ -28,9 +31,10 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
private readonly ModType type;
|
private readonly ModType type;
|
||||||
|
|
||||||
public virtual string TooltipText => mod.IconTooltip;
|
public virtual string TooltipText => showTooltip ? mod.IconTooltip : null;
|
||||||
|
|
||||||
private Mod mod;
|
private Mod mod;
|
||||||
|
private readonly bool showTooltip;
|
||||||
|
|
||||||
public Mod Mod
|
public Mod Mod
|
||||||
{
|
{
|
||||||
@ -42,9 +46,15 @@ namespace osu.Game.Rulesets.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ModIcon(Mod mod)
|
/// <summary>
|
||||||
|
/// Construct a new instance.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mod">The mod to be displayed</param>
|
||||||
|
/// <param name="showTooltip">Whether a tooltip describing the mod should display on hover.</param>
|
||||||
|
public ModIcon(Mod mod, bool showTooltip = true)
|
||||||
{
|
{
|
||||||
this.mod = mod ?? throw new ArgumentNullException(nameof(mod));
|
this.mod = mod ?? throw new ArgumentNullException(nameof(mod));
|
||||||
|
this.showTooltip = showTooltip;
|
||||||
|
|
||||||
type = mod.Type;
|
type = mod.Type;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user