2023-01-11 13:03:49 +00:00
|
|
|
// 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 System;
|
2023-01-11 13:37:57 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
2023-01-11 13:03:49 +00:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Graphics;
|
2023-01-18 21:37:26 +00:00
|
|
|
using osu.Framework.Graphics.Colour;
|
2023-05-25 08:15:31 +00:00
|
|
|
using osu.Game.Beatmaps;
|
2023-01-11 13:03:49 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2023-01-11 13:37:57 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2023-01-11 13:03:49 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
|
|
|
public partial class TestSceneSegmentedGraph : OsuTestScene
|
|
|
|
{
|
|
|
|
private readonly SegmentedGraph<int> graph;
|
|
|
|
|
|
|
|
public TestSceneSegmentedGraph()
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2023-01-12 09:13:16 +00:00
|
|
|
graph = new SegmentedGraph<int>(6)
|
2023-01-11 13:03:49 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(1, 0.5f),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-01-12 09:13:16 +00:00
|
|
|
graph.TierColours = new[]
|
2023-01-11 13:03:49 +00:00
|
|
|
{
|
2023-01-12 09:13:16 +00:00
|
|
|
Colour4.Red,
|
|
|
|
Colour4.OrangeRed,
|
|
|
|
Colour4.Orange,
|
|
|
|
Colour4.Yellow,
|
|
|
|
Colour4.YellowGreen,
|
|
|
|
Colour4.Green
|
|
|
|
};
|
2023-01-11 13:03:49 +00:00
|
|
|
|
|
|
|
AddStep("values from 1-10", () => graph.Values = Enumerable.Range(1, 10).ToArray());
|
|
|
|
AddStep("values from 1-100", () => graph.Values = Enumerable.Range(1, 100).ToArray());
|
|
|
|
AddStep("values from 1-500", () => graph.Values = Enumerable.Range(1, 500).ToArray());
|
|
|
|
AddStep("sin() function of size 100", () => sinFunction());
|
|
|
|
AddStep("sin() function of size 500", () => sinFunction(500));
|
|
|
|
AddStep("bumps of size 100", () => bumps());
|
|
|
|
AddStep("bumps of size 500", () => bumps(500));
|
|
|
|
AddStep("100 random values", () => randomValues());
|
|
|
|
AddStep("500 random values", () => randomValues(500));
|
2023-01-11 13:37:57 +00:00
|
|
|
AddStep("beatmap density with granularity of 200", () => beatmapDensity());
|
|
|
|
AddStep("beatmap density with granularity of 300", () => beatmapDensity(300));
|
2023-01-11 13:03:49 +00:00
|
|
|
AddStep("reversed values from 1-10", () => graph.Values = Enumerable.Range(1, 10).Reverse().ToArray());
|
2023-01-18 21:37:26 +00:00
|
|
|
AddStep("change tier colours", () =>
|
2023-01-12 09:57:12 +00:00
|
|
|
{
|
|
|
|
graph.TierColours = new[]
|
|
|
|
{
|
|
|
|
Colour4.White,
|
|
|
|
Colour4.LightBlue,
|
|
|
|
Colour4.Aqua,
|
|
|
|
Colour4.Blue
|
|
|
|
};
|
|
|
|
});
|
2023-01-18 21:37:26 +00:00
|
|
|
AddStep("reset tier colours", () =>
|
2023-01-12 09:57:12 +00:00
|
|
|
{
|
|
|
|
graph.TierColours = new[]
|
|
|
|
{
|
|
|
|
Colour4.Red,
|
|
|
|
Colour4.OrangeRed,
|
|
|
|
Colour4.Orange,
|
|
|
|
Colour4.Yellow,
|
|
|
|
Colour4.YellowGreen,
|
|
|
|
Colour4.Green
|
|
|
|
};
|
|
|
|
});
|
2023-01-18 21:37:26 +00:00
|
|
|
|
|
|
|
AddStep("set graph colour to blue", () => graph.Colour = Colour4.Blue);
|
|
|
|
AddStep("set graph colour to transparent", () => graph.Colour = Colour4.Transparent);
|
|
|
|
AddStep("set graph colour to vertical gradient", () => graph.Colour = ColourInfo.GradientVertical(Colour4.White, Colour4.Black));
|
|
|
|
AddStep("set graph colour to horizontal gradient", () => graph.Colour = ColourInfo.GradientHorizontal(Colour4.White, Colour4.Black));
|
|
|
|
AddStep("reset graph colour", () => graph.Colour = Colour4.White);
|
2023-01-11 13:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void sinFunction(int size = 100)
|
|
|
|
{
|
|
|
|
const int max_value = 255;
|
2023-01-12 01:36:35 +00:00
|
|
|
graph.Values = new int[size];
|
2023-01-11 13:03:49 +00:00
|
|
|
|
|
|
|
float step = 2 * MathF.PI / size;
|
|
|
|
float x = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2023-01-12 01:36:35 +00:00
|
|
|
graph.Values[i] = (int)(max_value * MathF.Sin(x));
|
2023-01-11 13:03:49 +00:00
|
|
|
x += step;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void bumps(int size = 100)
|
|
|
|
{
|
|
|
|
const int max_value = 255;
|
2023-01-12 01:36:35 +00:00
|
|
|
graph.Values = new int[size];
|
2023-01-11 13:03:49 +00:00
|
|
|
|
|
|
|
float step = 2 * MathF.PI / size;
|
|
|
|
float x = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2023-01-12 01:36:35 +00:00
|
|
|
graph.Values[i] = (int)(max_value * Math.Abs(MathF.Sin(x)));
|
2023-01-11 13:03:49 +00:00
|
|
|
x += step;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void randomValues(int size = 100)
|
|
|
|
{
|
|
|
|
Random rng = new Random();
|
|
|
|
|
2023-01-12 01:36:35 +00:00
|
|
|
graph.Values = new int[size];
|
2023-01-11 13:03:49 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2023-01-12 01:36:35 +00:00
|
|
|
graph.Values[i] = rng.Next(255);
|
2023-01-11 13:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-11 13:37:57 +00:00
|
|
|
|
|
|
|
private void beatmapDensity(int granularity = 200)
|
|
|
|
{
|
|
|
|
var ruleset = new OsuRuleset();
|
|
|
|
var beatmap = CreateBeatmap(ruleset.RulesetInfo);
|
|
|
|
IEnumerable<HitObject> objects = beatmap.HitObjects;
|
|
|
|
|
|
|
|
// Taken from SongProgressGraph
|
2023-01-12 01:36:35 +00:00
|
|
|
graph.Values = new int[granularity];
|
2023-01-11 13:37:57 +00:00
|
|
|
|
|
|
|
if (!objects.Any())
|
|
|
|
return;
|
|
|
|
|
2023-05-25 08:15:31 +00:00
|
|
|
(double firstHit, double lastHit) = BeatmapExtensions.CalculatePlayableBounds(objects);
|
2023-01-11 13:37:57 +00:00
|
|
|
|
|
|
|
if (lastHit == 0)
|
|
|
|
lastHit = objects.Last().StartTime;
|
|
|
|
|
|
|
|
double interval = (lastHit - firstHit + 1) / granularity;
|
|
|
|
|
|
|
|
foreach (var h in objects)
|
|
|
|
{
|
|
|
|
double endTime = h.GetEndTime();
|
|
|
|
|
|
|
|
Debug.Assert(endTime >= h.StartTime);
|
|
|
|
|
|
|
|
int startRange = (int)((h.StartTime - firstHit) / interval);
|
|
|
|
int endRange = (int)((endTime - firstHit) / interval);
|
|
|
|
for (int i = startRange; i <= endRange; i++)
|
2023-01-12 01:36:35 +00:00
|
|
|
graph.Values[i]++;
|
2023-01-11 13:37:57 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-11 13:03:49 +00:00
|
|
|
}
|
|
|
|
}
|