1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

Add support for changing dimensions of difficulty spectrum display

This commit is contained in:
Bartłomiej Dach 2021-10-17 16:05:55 +02:00
parent 1a77e98537
commit 3de994449d
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 86 additions and 5 deletions

View File

@ -13,6 +13,8 @@ namespace osu.Game.Tests.Visual.Beatmaps
{
public class TestSceneDifficultySpectrumDisplay : OsuTestScene
{
private DifficultySpectrumDisplay display;
private static APIBeatmapSet createBeatmapSetWith(params (int rulesetId, double stars)[] difficulties) => new APIBeatmapSet
{
Beatmaps = difficulties.Select(difficulty => new APIBeatmap
@ -74,7 +76,31 @@ namespace osu.Game.Tests.Visual.Beatmaps
createDisplay(beatmapSet);
}
private void createDisplay(IBeatmapSetInfo beatmapSetInfo) => AddStep("create spectrum display", () => Child = new DifficultySpectrumDisplay(beatmapSetInfo)
[Test]
public void TestAdjustableDotSize()
{
var beatmapSet = createBeatmapSetWith(
(rulesetId: 0, stars: 2.0),
(rulesetId: 3, stars: 2.3),
(rulesetId: 0, stars: 3.2),
(rulesetId: 1, stars: 4.3),
(rulesetId: 0, stars: 5.6));
createDisplay(beatmapSet);
AddStep("change dot dimensions", () =>
{
display.DotSize = new Vector2(8, 12);
display.DotSpacing = 2;
});
AddStep("change dot dimensions back", () =>
{
display.DotSize = new Vector2(4, 8);
display.DotSpacing = 1;
});
}
private void createDisplay(IBeatmapSetInfo beatmapSetInfo) => AddStep("create spectrum display", () => Child = display = new DifficultySpectrumDisplay(beatmapSetInfo)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -18,12 +18,40 @@ namespace osu.Game.Beatmaps.Drawables
{
public class DifficultySpectrumDisplay : CompositeDrawable
{
private Vector2 dotSize = new Vector2(4, 8);
public Vector2 DotSize
{
get => dotSize;
set
{
dotSize = value;
if (IsLoaded)
updateDotDimensions();
}
}
private float dotSpacing = 1;
public float DotSpacing
{
get => dotSpacing;
set
{
dotSpacing = value;
if (IsLoaded)
updateDotDimensions();
}
}
private readonly FillFlowContainer<RulesetDifficultyGroup> flow;
public DifficultySpectrumDisplay(IBeatmapSetInfo beatmapSet)
{
AutoSizeAxes = Axes.Both;
FillFlowContainer<RulesetDifficultyGroup> flow;
InternalChild = flow = new FillFlowContainer<RulesetDifficultyGroup>
{
AutoSizeAxes = Axes.Both,
@ -40,6 +68,21 @@ namespace osu.Game.Beatmaps.Drawables
}
}
protected override void LoadComplete()
{
base.LoadComplete();
updateDotDimensions();
}
private void updateDotDimensions()
{
foreach (var group in flow)
{
group.DotSize = DotSize;
group.DotSpacing = DotSpacing;
}
}
private class RulesetDifficultyGroup : FillFlowContainer
{
private readonly int rulesetId;
@ -53,6 +96,20 @@ namespace osu.Game.Beatmaps.Drawables
this.collapsed = collapsed;
}
public Vector2 DotSize
{
set
{
foreach (var dot in Children.OfType<DifficultyDot>())
dot.Size = value;
}
}
public float DotSpacing
{
set => Spacing = new Vector2(value, 0);
}
[BackgroundDependencyLoader]
private void load(RulesetStore rulesets)
{
@ -98,8 +155,6 @@ namespace osu.Game.Beatmaps.Drawables
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Width = 4;
Height = 8;
Anchor = Origin = Anchor.Centre;
Masking = true;