mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Improve extensibility of mod display expansion
This commit is contained in:
parent
cb46d34dd7
commit
d4f14e552a
40
osu.Game.Tests/Visual/UserInterface/TestSceneModDisplay.cs
Normal file
40
osu.Game.Tests/Visual/UserInterface/TestSceneModDisplay.cs
Normal file
@ -0,0 +1,40 @@
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneModDisplay : OsuTestScene
|
||||
{
|
||||
[TestCase(ExpansionMode.ExpandOnHover)]
|
||||
[TestCase(ExpansionMode.AlwaysExpanded)]
|
||||
[TestCase(ExpansionMode.AlwaysContracted)]
|
||||
public void TestMode(ExpansionMode mode)
|
||||
{
|
||||
AddStep("create mod display", () =>
|
||||
{
|
||||
Child = new ModDisplay
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
ExpansionMode = mode,
|
||||
Current =
|
||||
{
|
||||
Value = new Mod[]
|
||||
{
|
||||
new OsuModHardRock(),
|
||||
new OsuModDoubleTime(),
|
||||
new OsuModDifficultyAdjust(),
|
||||
new OsuModEasy(),
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
public bool DisplayUnrankedText = true;
|
||||
|
||||
public bool AllowExpand = true;
|
||||
public ExpansionMode ExpansionMode = ExpansionMode.ExpandOnHover;
|
||||
|
||||
private readonly Bindable<IReadOnlyList<Mod>> current = new Bindable<IReadOnlyList<Mod>>();
|
||||
|
||||
@ -110,11 +110,15 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
private void expand()
|
||||
{
|
||||
if (AllowExpand)
|
||||
if (ExpansionMode != ExpansionMode.AlwaysContracted)
|
||||
IconsContainer.TransformSpacingTo(new Vector2(5, 0), 500, Easing.OutQuint);
|
||||
}
|
||||
|
||||
private void contract() => IconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint);
|
||||
private void contract()
|
||||
{
|
||||
if (ExpansionMode != ExpansionMode.AlwaysExpanded)
|
||||
IconsContainer.TransformSpacingTo(new Vector2(-25, 0), 500, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
@ -128,4 +132,22 @@ namespace osu.Game.Screens.Play.HUD
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ExpansionMode
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ModDisplay"/> will expand only when hovered.
|
||||
/// </summary>
|
||||
ExpandOnHover,
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ModDisplay"/> will always be expanded.
|
||||
/// </summary>
|
||||
AlwaysExpanded,
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ModDisplay"/> will always be contracted.
|
||||
/// </summary>
|
||||
AlwaysContracted
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ namespace osu.Game.Screens.Select
|
||||
|
||||
public FooterModDisplay()
|
||||
{
|
||||
AllowExpand = false;
|
||||
ExpansionMode = ExpansionMode.AlwaysContracted;
|
||||
IconsContainer.Margin = new MarginPadding();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user