mirror of
https://github.com/ppy/osu.git
synced 2024-09-22 04:07:25 +08:00
Refactor star rating display layout with flexibility in mind
This commit is contained in:
parent
3a0dd5b019
commit
74d6c26520
@ -8,17 +8,15 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Drawables;
|
using osu.Game.Beatmaps.Drawables;
|
||||||
using osu.Game.Graphics.Containers;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
public class TestSceneStarRatingDisplay : OsuTestScene
|
public class TestSceneStarRatingDisplay : OsuTestScene
|
||||||
{
|
{
|
||||||
[TestCase(52f, 20f)]
|
[TestCase(StarRatingDisplaySize.Regular)]
|
||||||
[TestCase(52f, 16f)]
|
[TestCase(StarRatingDisplaySize.Small)]
|
||||||
[TestCase(50f, 14f)]
|
public void TestDisplay(StarRatingDisplaySize size)
|
||||||
public void TestDisplay(float width, float height)
|
|
||||||
{
|
{
|
||||||
AddStep("load displays", () =>
|
AddStep("load displays", () =>
|
||||||
{
|
{
|
||||||
@ -36,11 +34,10 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Spacing = new Vector2(2f),
|
Spacing = new Vector2(2f),
|
||||||
Direction = FillDirection.Vertical,
|
Direction = FillDirection.Vertical,
|
||||||
ChildrenEnumerable = Enumerable.Range(0, 10).Select(j => new StarRatingDisplay(new StarDifficulty(i * (i >= 11 ? 25f : 1f) + j * 0.1f, 0))
|
ChildrenEnumerable = Enumerable.Range(0, 10).Select(j => new StarRatingDisplay(new StarDifficulty(i * (i >= 11 ? 25f : 1f) + j * 0.1f, 0), size)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Size = new Vector2(width, height),
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
@ -44,40 +44,63 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
/// Creates a new <see cref="StarRatingDisplay"/> using an already computed <see cref="StarDifficulty"/>.
|
/// Creates a new <see cref="StarRatingDisplay"/> using an already computed <see cref="StarDifficulty"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="starDifficulty">The already computed <see cref="StarDifficulty"/> to display.</param>
|
/// <param name="starDifficulty">The already computed <see cref="StarDifficulty"/> to display.</param>
|
||||||
public StarRatingDisplay(StarDifficulty starDifficulty)
|
/// <param name="size">The size of the star rating display.</param>
|
||||||
|
public StarRatingDisplay(StarDifficulty starDifficulty, StarRatingDisplaySize size = StarRatingDisplaySize.Regular)
|
||||||
{
|
{
|
||||||
Current.Value = starDifficulty;
|
Current.Value = starDifficulty;
|
||||||
|
|
||||||
Size = new Vector2(52f, 20f);
|
AutoSizeAxes = Axes.Both;
|
||||||
|
|
||||||
InternalChild = new CircularContainer
|
InternalChild = new CircularContainer
|
||||||
{
|
{
|
||||||
Masking = true,
|
Masking = true,
|
||||||
RelativeSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
background = new Box
|
background = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
starIcon = new SpriteIcon
|
new GridContainer
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Margin = new MarginPadding { Right = 30f },
|
AutoSizeAxes = Axes.Both,
|
||||||
Icon = FontAwesome.Solid.Star,
|
Margin = size == StarRatingDisplaySize.Small
|
||||||
Size = new Vector2(8f),
|
? new MarginPadding { Horizontal = 7f }
|
||||||
|
: new MarginPadding { Horizontal = 8f, Vertical = 2f },
|
||||||
|
ColumnDimensions = new[]
|
||||||
|
{
|
||||||
|
new Dimension(GridSizeMode.AutoSize),
|
||||||
|
new Dimension(GridSizeMode.Absolute, 3f),
|
||||||
|
new Dimension(GridSizeMode.AutoSize, minSize: 25f),
|
||||||
|
},
|
||||||
|
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
|
||||||
|
Content = new[]
|
||||||
|
{
|
||||||
|
new[]
|
||||||
|
{
|
||||||
|
starIcon = new SpriteIcon
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Icon = FontAwesome.Solid.Star,
|
||||||
|
Size = new Vector2(8f),
|
||||||
|
},
|
||||||
|
Empty(),
|
||||||
|
starsText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Margin = new MarginPadding { Bottom = 1.5f },
|
||||||
|
// todo: this should be size: 12f, but to match up with the design, it needs to be 14.4f
|
||||||
|
// see https://github.com/ppy/osu-framework/issues/3271.
|
||||||
|
Font = OsuFont.Torus.With(size: 14.4f, weight: FontWeight.Bold),
|
||||||
|
Shadow = false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
starsText = new OsuSpriteText
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Margin = new MarginPadding { Left = 10f, Bottom = 2f },
|
|
||||||
// todo: this should be size: 12f, but to match up with the design, it needs to be 14.4f
|
|
||||||
// see https://github.com/ppy/osu-framework/issues/3271.
|
|
||||||
Font = OsuFont.Torus.With(size: 14.4f, weight: FontWeight.Bold),
|
|
||||||
Shadow = false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -97,4 +120,10 @@ namespace osu.Game.Beatmaps.Drawables
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum StarRatingDisplaySize
|
||||||
|
{
|
||||||
|
Small,
|
||||||
|
Regular,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user