mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 14:32:55 +08:00
Allow ModIcon
to be constructed using an IMod
This commit is contained in:
parent
c3531e1361
commit
464797fecf
@ -1,7 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
using osu.Game.Rulesets.Osu.Mods;
|
using osu.Game.Rulesets.Osu.Mods;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
@ -17,5 +19,16 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddStep("create mod icon", () => Child = icon = new ModIcon(new OsuModDoubleTime()));
|
AddStep("create mod icon", () => Child = icon = new ModIcon(new OsuModDoubleTime()));
|
||||||
AddStep("change mod", () => icon.Mod = new OsuModEasy());
|
AddStep("change mod", () => icon.Mod = new OsuModEasy());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestInterfaceModType()
|
||||||
|
{
|
||||||
|
ModIcon icon = null;
|
||||||
|
|
||||||
|
var ruleset = new OsuRuleset();
|
||||||
|
|
||||||
|
AddStep("create mod icon", () => Child = icon = new ModIcon(ruleset.AllMods.First(m => m.Acronym == "DT")));
|
||||||
|
AddStep("change mod", () => icon.Mod = ruleset.AllMods.First(m => m.Acronym == "EZ"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,12 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
private const float size = 80;
|
private const float size = 80;
|
||||||
|
|
||||||
public virtual LocalisableString TooltipText => showTooltip ? mod.IconTooltip : null;
|
public virtual LocalisableString TooltipText => showTooltip ? ((mod as Mod)?.IconTooltip ?? mod.Name) : null;
|
||||||
|
|
||||||
private Mod mod;
|
private IMod mod;
|
||||||
private readonly bool showTooltip;
|
private readonly bool showTooltip;
|
||||||
|
|
||||||
public Mod Mod
|
public IMod Mod
|
||||||
{
|
{
|
||||||
get => mod;
|
get => mod;
|
||||||
set
|
set
|
||||||
@ -58,7 +58,7 @@ namespace osu.Game.Rulesets.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="mod">The mod to be displayed</param>
|
/// <param name="mod">The mod to be displayed</param>
|
||||||
/// <param name="showTooltip">Whether a tooltip describing the mod should display on hover.</param>
|
/// <param name="showTooltip">Whether a tooltip describing the mod should display on hover.</param>
|
||||||
public ModIcon(Mod mod, bool showTooltip = true)
|
public ModIcon(IMod mod, bool showTooltip = true)
|
||||||
{
|
{
|
||||||
this.mod = mod ?? throw new ArgumentNullException(nameof(mod));
|
this.mod = mod ?? throw new ArgumentNullException(nameof(mod));
|
||||||
this.showTooltip = showTooltip;
|
this.showTooltip = showTooltip;
|
||||||
@ -105,7 +105,7 @@ namespace osu.Game.Rulesets.UI
|
|||||||
updateMod(mod);
|
updateMod(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMod(Mod value)
|
private void updateMod(IMod value)
|
||||||
{
|
{
|
||||||
modAcronym.Text = value.Acronym;
|
modAcronym.Text = value.Acronym;
|
||||||
modIcon.Icon = value.Icon ?? FontAwesome.Solid.Question;
|
modIcon.Icon = value.Icon ?? FontAwesome.Solid.Question;
|
||||||
|
Loading…
Reference in New Issue
Block a user