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

Add basic legend and line colouring

This commit is contained in:
Dean Herbert 2022-10-17 23:41:07 +09:00
parent 94c57a459d
commit 1ea2a1ff04

View File

@ -1,15 +1,18 @@
// 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;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
@ -27,6 +30,20 @@ namespace osu.Game.Tests.Gameplay
private GraphContainer graphs = null!; private GraphContainer graphs = null!;
private SettingsSlider<int> sliderMaxCombo = null!; private SettingsSlider<int> sliderMaxCombo = null!;
private FillFlowContainer legend = null!;
private static readonly Color4[] line_colours =
{
Color4Extensions.FromHex("588c7e"),
Color4Extensions.FromHex("b2a367"),
Color4Extensions.FromHex("c98f65"),
Color4Extensions.FromHex("bc5151"),
Color4Extensions.FromHex("5c8bd6"),
Color4Extensions.FromHex("7f6ab7"),
Color4Extensions.FromHex("a368ad"),
Color4Extensions.FromHex("aa6880"),
};
[Test] [Test]
public void TestBasic() public void TestBasic()
{ {
@ -48,6 +65,15 @@ namespace osu.Game.Tests.Gameplay
}, },
}, },
new Drawable[] new Drawable[]
{
legend = new FillFlowContainer
{
Direction = FillDirection.Vertical,
RelativeSizeAxes = Axes.X,
Height = 200,
},
},
new Drawable[]
{ {
new FillFlowContainer new FillFlowContainer
{ {
@ -58,6 +84,7 @@ namespace osu.Game.Tests.Gameplay
sliderMaxCombo = new SettingsSlider<int> sliderMaxCombo = new SettingsSlider<int>
{ {
Width = 0.5f, Width = 0.5f,
TransferValueOnCommit = true,
Current = new BindableInt(1024) Current = new BindableInt(1024)
{ {
MinValue = 96, MinValue = 96,
@ -72,7 +99,7 @@ namespace osu.Game.Tests.Gameplay
} }
}; };
sliderMaxCombo.Current.BindValueChanged(_ => rerun(true)); sliderMaxCombo.Current.BindValueChanged(_ => rerun());
graphs.MissLocations.BindCollectionChanged((_, __) => rerun()); graphs.MissLocations.BindCollectionChanged((_, __) => rerun());
graphs.MaxCombo.BindTo(sliderMaxCombo.Current); graphs.MaxCombo.BindTo(sliderMaxCombo.Current);
@ -81,22 +108,19 @@ namespace osu.Game.Tests.Gameplay
}); });
} }
private ScheduledDelegate? debouncedRun; private void rerun()
private void rerun(bool debounce = false)
{ {
graphs.Clear(); graphs.Clear();
legend.Clear();
debouncedRun?.Cancel();
debouncedRun = Scheduler.AddDelayed(() =>
{
runForProcessor("lazer-classic", new ScoreProcessor(new OsuRuleset()) { Mode = { Value = ScoringMode.Classic } }); runForProcessor("lazer-classic", new ScoreProcessor(new OsuRuleset()) { Mode = { Value = ScoringMode.Classic } });
runForProcessor("lazer-standardised", new ScoreProcessor(new OsuRuleset()) { Mode = { Value = ScoringMode.Standardised } }); runForProcessor("lazer-standardised", new ScoreProcessor(new OsuRuleset()) { Mode = { Value = ScoringMode.Standardised } });
}, debounce ? 200 : 0);
} }
private void runForProcessor(string name, ScoreProcessor processor) private void runForProcessor(string name, ScoreProcessor processor)
{ {
Color4 colour = line_colours[Math.Abs(name.GetHashCode()) % line_colours.Length];
int maxCombo = sliderMaxCombo.Current.Value; int maxCombo = sliderMaxCombo.Current.Value;
var beatmap = new OsuBeatmap(); var beatmap = new OsuBeatmap();
@ -133,9 +157,15 @@ namespace osu.Game.Tests.Gameplay
graphs.Add(new LineGraph graphs.Add(new LineGraph
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
LineColour = Color4.Red, LineColour = colour,
Values = results Values = results
}); });
legend.Add(new OsuSpriteText
{
Colour = colour,
Text = $"{FontAwesome.Solid.Circle.Icon} {name}"
});
} }
} }