mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Add basic structure and test coverage for extended info on mod icon
This commit is contained in:
parent
0722bc88b7
commit
16e752e07d
@ -1,10 +1,14 @@
|
|||||||
// 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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Framework.Utils;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Osu;
|
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;
|
||||||
@ -25,6 +29,54 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
ChildrenEnumerable = Ruleset.Value.CreateInstance().CreateAllMods().Select(m => new ModIcon(m)),
|
ChildrenEnumerable = Ruleset.Value.CreateInstance().CreateAllMods().Select(m => new ModIcon(m)),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddStep("toggle selected", () =>
|
||||||
|
{
|
||||||
|
foreach (var icon in this.ChildrenOfType<ModIcon>())
|
||||||
|
icon.Selected.Toggle();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestShowRateAdjusts()
|
||||||
|
{
|
||||||
|
AddStep("create mod icons", () =>
|
||||||
|
{
|
||||||
|
Child = new FillFlowContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Direction = FillDirection.Full,
|
||||||
|
ChildrenEnumerable = Ruleset.Value.CreateInstance().CreateAllMods()
|
||||||
|
.OfType<ModRateAdjust>()
|
||||||
|
.SelectMany((m) =>
|
||||||
|
{
|
||||||
|
List<ModIcon> icons = new List<ModIcon> { new ModIcon(m) };
|
||||||
|
|
||||||
|
for (double i = m.SpeedChange.MinValue; i < m.SpeedChange.MaxValue; i += m.SpeedChange.Precision * 10)
|
||||||
|
{
|
||||||
|
m = (ModRateAdjust)m.DeepClone();
|
||||||
|
m.SpeedChange.Value = i;
|
||||||
|
icons.Add(new ModIcon(m));
|
||||||
|
}
|
||||||
|
|
||||||
|
return icons;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("adjust rates", () =>
|
||||||
|
{
|
||||||
|
foreach (var icon in this.ChildrenOfType<ModIcon>())
|
||||||
|
{
|
||||||
|
if (icon.Mod is ModRateAdjust rateAdjust)
|
||||||
|
{
|
||||||
|
if (RNG.NextDouble() > 0.9)
|
||||||
|
rateAdjust.SpeedChange.Value = rateAdjust.SpeedChange.Default;
|
||||||
|
else
|
||||||
|
rateAdjust.SpeedChange.Value = RNG.NextDouble(rateAdjust.SpeedChange.MinValue, rateAdjust.SpeedChange.MaxValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -19,6 +19,12 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
string Name { get; }
|
string Name { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Short import information to display on the mod icon. For example, a rate adjust mod's rate
|
||||||
|
/// or similarly important setting.
|
||||||
|
/// </summary>
|
||||||
|
string ExtendedIconInformation { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The user readable description of this mod.
|
/// The user readable description of this mod.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -27,6 +27,9 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
|
|
||||||
public abstract string Acronym { get; }
|
public abstract string Acronym { get; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public virtual string ExtendedIconInformation => string.Empty;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public virtual IconUsage? Icon => null;
|
public virtual IconUsage? Icon => null;
|
||||||
|
|
||||||
|
@ -28,5 +28,7 @@ namespace osu.Game.Rulesets.Mods
|
|||||||
public override Type[] IncompatibleMods => new[] { typeof(ModTimeRamp), typeof(ModAdaptiveSpeed), typeof(ModRateAdjust) };
|
public override Type[] IncompatibleMods => new[] { typeof(ModTimeRamp), typeof(ModAdaptiveSpeed), typeof(ModRateAdjust) };
|
||||||
|
|
||||||
public override string SettingDescription => SpeedChange.IsDefault ? string.Empty : $"{SpeedChange.Value:N2}x";
|
public override string SettingDescription => SpeedChange.IsDefault ? string.Empty : $"{SpeedChange.Value:N2}x";
|
||||||
|
|
||||||
|
public override string ExtendedIconInformation => SettingDescription;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ using osu.Game.Rulesets.Mods;
|
|||||||
using osuTK;
|
using osuTK;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.UI
|
namespace osu.Game.Rulesets.UI
|
||||||
@ -27,9 +28,9 @@ namespace osu.Game.Rulesets.UI
|
|||||||
{
|
{
|
||||||
public readonly BindableBool Selected = new BindableBool();
|
public readonly BindableBool Selected = new BindableBool();
|
||||||
|
|
||||||
private readonly SpriteIcon modIcon;
|
private SpriteIcon modIcon;
|
||||||
private readonly SpriteText modAcronym;
|
private SpriteText modAcronym;
|
||||||
private readonly SpriteIcon background;
|
private SpriteIcon background;
|
||||||
|
|
||||||
private const float size = 80;
|
private const float size = 80;
|
||||||
|
|
||||||
@ -55,6 +56,10 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
private Color4 backgroundColour;
|
private Color4 backgroundColour;
|
||||||
|
|
||||||
|
private Sprite extendedBackground;
|
||||||
|
|
||||||
|
private OsuSpriteText extendedText;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Construct a new instance.
|
/// Construct a new instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -64,8 +69,12 @@ namespace osu.Game.Rulesets.UI
|
|||||||
{
|
{
|
||||||
this.mod = mod ?? throw new ArgumentNullException(nameof(mod));
|
this.mod = mod ?? throw new ArgumentNullException(nameof(mod));
|
||||||
this.showTooltip = showTooltip;
|
this.showTooltip = showTooltip;
|
||||||
|
}
|
||||||
|
|
||||||
Size = new Vector2(size);
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(TextureStore textures)
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -77,6 +86,23 @@ namespace osu.Game.Rulesets.UI
|
|||||||
Icon = OsuIcon.ModBg,
|
Icon = OsuIcon.ModBg,
|
||||||
Shadow = true,
|
Shadow = true,
|
||||||
},
|
},
|
||||||
|
extendedBackground = new Sprite
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Texture = textures.Get("Icons/BeatmapDetails/mod-icon-extender"),
|
||||||
|
X = size - 3,
|
||||||
|
Size = new Vector2(120, 55),
|
||||||
|
},
|
||||||
|
extendedText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Font = OsuFont.Default.With(size: 30f, weight: FontWeight.Bold),
|
||||||
|
UseFullGlyphHeight = false,
|
||||||
|
X = size,
|
||||||
|
Text = mod.ExtendedIconInformation,
|
||||||
|
},
|
||||||
modAcronym = new OsuSpriteText
|
modAcronym = new OsuSpriteText
|
||||||
{
|
{
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
@ -129,7 +155,8 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
private void updateColour()
|
private void updateColour()
|
||||||
{
|
{
|
||||||
background.Colour = Selected.Value ? backgroundColour.Lighten(0.2f) : backgroundColour;
|
extendedText.Colour = background.Colour = Selected.Value ? backgroundColour.Lighten(0.2f) : backgroundColour;
|
||||||
|
extendedBackground.Colour = Selected.Value ? backgroundColour.Darken(2.4f) : backgroundColour.Darken(2.8f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user