2022-10-16 17:39:25 +08: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.
|
|
|
|
|
2022-10-17 22:41:07 +08:00
|
|
|
using System;
|
2022-10-16 17:39:25 +08:00
|
|
|
using System.Collections.Generic;
|
2022-10-18 18:01:43 +08:00
|
|
|
using System.Linq;
|
2022-10-16 17:39:25 +08:00
|
|
|
using NUnit.Framework;
|
2023-09-12 17:36:41 +08:00
|
|
|
using osu.Framework.Allocation;
|
2022-10-16 17:39:25 +08:00
|
|
|
using osu.Framework.Bindables;
|
2023-09-12 18:07:12 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2022-10-16 17:39:25 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-10-18 18:01:43 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2022-10-17 22:27:26 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-10-17 22:41:07 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2022-10-17 22:27:26 +08:00
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Graphics;
|
2022-10-18 17:13:13 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2022-10-17 22:41:07 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-10-16 17:39:25 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Overlays.Settings;
|
2023-07-11 08:46:32 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Scoring;
|
2022-10-16 17:39:25 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Osu.Judgements;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2023-05-19 13:09:19 +08:00
|
|
|
using osu.Game.Scoring.Legacy;
|
2022-10-18 18:01:43 +08:00
|
|
|
using osuTK;
|
2022-10-16 17:39:25 +08:00
|
|
|
using osuTK.Graphics;
|
2022-10-18 17:27:05 +08:00
|
|
|
using osuTK.Input;
|
2022-10-16 17:39:25 +08:00
|
|
|
|
2022-10-18 15:55:04 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
|
|
|
public partial class TestSceneScoring : OsuTestScene
|
|
|
|
{
|
2022-10-17 22:27:26 +08:00
|
|
|
private GraphContainer graphs = null!;
|
2022-10-16 17:39:25 +08:00
|
|
|
private SettingsSlider<int> sliderMaxCombo = null!;
|
2023-09-12 19:27:40 +08:00
|
|
|
private SettingsCheckbox scaleToMax = null!;
|
2022-10-16 17:39:25 +08:00
|
|
|
|
2023-09-12 19:27:40 +08:00
|
|
|
private FillFlowContainer<LegendEntry> legend = null!;
|
2022-10-17 22:41:07 +08:00
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
private readonly BindableBool standardisedVisible = new BindableBool(true);
|
|
|
|
private readonly BindableBool classicVisible = new BindableBool(true);
|
|
|
|
private readonly BindableBool scoreV1Visible = new BindableBool(true);
|
|
|
|
private readonly BindableBool scoreV2Visible = new BindableBool(true);
|
|
|
|
|
2023-09-12 17:36:41 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
|
|
|
|
2022-10-16 17:39:25 +08:00
|
|
|
[Test]
|
|
|
|
public void TestBasic()
|
|
|
|
{
|
|
|
|
AddStep("setup tests", () =>
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2023-09-12 17:36:41 +08:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = Colour4.Black
|
|
|
|
},
|
2022-10-16 17:39:25 +08:00
|
|
|
new GridContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-10-18 15:50:30 +08:00
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
},
|
2022-10-16 17:39:25 +08:00
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
2022-10-17 22:27:26 +08:00
|
|
|
graphs = new GraphContainer
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
2022-10-18 15:50:30 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-10-16 17:39:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
new Drawable[]
|
2022-10-17 22:41:07 +08:00
|
|
|
{
|
2023-09-12 19:27:40 +08:00
|
|
|
legend = new FillFlowContainer<LegendEntry>
|
2022-10-17 22:41:07 +08:00
|
|
|
{
|
2022-10-18 15:50:30 +08:00
|
|
|
Padding = new MarginPadding(20),
|
2023-09-12 18:07:12 +08:00
|
|
|
Direction = FillDirection.Vertical,
|
2022-10-17 22:41:07 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2022-10-18 15:50:30 +08:00
|
|
|
AutoSizeAxes = Axes.Y,
|
2022-10-17 22:41:07 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
new Drawable[]
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
2022-10-18 15:50:30 +08:00
|
|
|
Padding = new MarginPadding(20),
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2023-09-12 19:27:40 +08:00
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(10),
|
2022-10-16 17:39:25 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
sliderMaxCombo = new SettingsSlider<int>
|
|
|
|
{
|
2022-10-17 22:41:07 +08:00
|
|
|
TransferValueOnCommit = true,
|
2022-10-16 17:39:25 +08:00
|
|
|
Current = new BindableInt(1024)
|
|
|
|
{
|
|
|
|
MinValue = 96,
|
|
|
|
MaxValue = 8192,
|
|
|
|
},
|
2023-09-12 19:27:40 +08:00
|
|
|
LabelText = "Max combo",
|
|
|
|
},
|
|
|
|
scaleToMax = new SettingsCheckbox
|
|
|
|
{
|
|
|
|
LabelText = "Rescale plots to 100%",
|
|
|
|
Current = { Value = true, Default = true }
|
2022-10-18 17:13:13 +08:00
|
|
|
},
|
|
|
|
new OsuTextFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2023-09-12 19:27:40 +08:00
|
|
|
Text = $"Left click to add miss\nRight click to add OK/{base_ok}",
|
|
|
|
Margin = new MarginPadding { Top = 20 }
|
2022-10-16 17:39:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-17 22:41:07 +08:00
|
|
|
sliderMaxCombo.Current.BindValueChanged(_ => rerun());
|
2023-09-12 19:27:40 +08:00
|
|
|
scaleToMax.Current.BindValueChanged(_ => rerun());
|
|
|
|
|
|
|
|
standardisedVisible.BindValueChanged(_ => rescalePlots());
|
|
|
|
classicVisible.BindValueChanged(_ => rescalePlots());
|
|
|
|
scoreV1Visible.BindValueChanged(_ => rescalePlots());
|
|
|
|
scoreV2Visible.BindValueChanged(_ => rescalePlots());
|
2022-10-18 17:27:05 +08:00
|
|
|
|
2022-10-17 22:27:26 +08:00
|
|
|
graphs.MissLocations.BindCollectionChanged((_, __) => rerun());
|
2022-10-18 17:27:05 +08:00
|
|
|
graphs.NonPerfectLocations.BindCollectionChanged((_, __) => rerun());
|
2022-10-17 22:27:26 +08:00
|
|
|
|
|
|
|
graphs.MaxCombo.BindTo(sliderMaxCombo.Current);
|
2022-10-16 17:39:25 +08:00
|
|
|
|
|
|
|
rerun();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:27:05 +08:00
|
|
|
private const int base_great = 300;
|
|
|
|
private const int base_ok = 100;
|
|
|
|
|
2022-10-17 22:41:07 +08:00
|
|
|
private void rerun()
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
|
|
|
graphs.Clear();
|
2022-10-17 22:41:07 +08:00
|
|
|
legend.Clear();
|
2022-10-16 17:39:25 +08:00
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
runForProcessor("lazer-standardised", colours.Green1, new OsuScoreProcessor(), ScoringMode.Standardised, standardisedVisible);
|
|
|
|
runForProcessor("lazer-classic", colours.Blue1, new OsuScoreProcessor(), ScoringMode.Classic, classicVisible);
|
2022-10-18 16:23:23 +08:00
|
|
|
|
2022-10-18 17:27:05 +08:00
|
|
|
runScoreV1();
|
|
|
|
runScoreV2();
|
2023-09-12 19:27:40 +08:00
|
|
|
|
|
|
|
rescalePlots();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void rescalePlots()
|
|
|
|
{
|
|
|
|
if (!scaleToMax.Current.Value && legend.Any(entry => entry.Visible.Value))
|
|
|
|
{
|
|
|
|
long maxScore = legend.Where(entry => entry.Visible.Value).Max(entry => entry.FinalScore);
|
|
|
|
|
|
|
|
foreach (var graph in graphs)
|
|
|
|
graph.Height = graph.Values.Max() / maxScore;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
foreach (var graph in graphs)
|
|
|
|
graph.Height = 1;
|
|
|
|
}
|
2022-10-18 17:27:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void runScoreV1()
|
|
|
|
{
|
2022-10-18 16:23:23 +08:00
|
|
|
int totalScore = 0;
|
|
|
|
int currentCombo = 0;
|
|
|
|
|
2022-10-18 17:27:05 +08:00
|
|
|
void applyHitV1(int baseScore)
|
2022-10-18 16:23:23 +08:00
|
|
|
{
|
2022-10-18 17:27:05 +08:00
|
|
|
if (baseScore == 0)
|
|
|
|
{
|
|
|
|
currentCombo = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Fix Score V1 simulation in scoring test scene incorrectly applying multiplier
`TestSceneScoring` included a local simulation of stable's Score V1
algorithm. One of the parts of said algorithm is a mysterious
"score multiplier", influenced by - among others - the beatmap's drain
rate, overall difficulty, circle size, object count, drain length,
and active mods. (An implementation of this already exists in lazer
source, in `OsuLegacyScoreSimulator`, but more on this later.)
However, `TestSceneScoring` had this multiplier in _two_ places, with
_two_ distinct values, one of which being 1 (i.e. basically off).
Unfortunately, the place that had 1 as the multiplier was the wrong one.
Stable calculates the score increase for every hit in two stages;
first, it takes the raw numerical value of the judgement, but then
applies a combo-based bonus on top of it:
scoreIncrease += (int)(Math.Max(0, ComboCounter.HitCombo - 1) * (scoreIncrease / 25 * ScoreMultiplier));
On the face of it, it may appear that the `ScoreMultiplier` factor
can be factored out and applied at the end only when returning total
score. However, once the above formula is rewritten as:
scoreIncrease = scoreIncrease + (int)(Math.Max(0, ComboCounter.HitCombo - 1) * (scoreIncrease / 25 * ScoreMultiplier));
= scoreIncrease * (1 + (Math.Max(0, ComboCounter.HitCombo - 1) / 25 * ScoreMultiplier))
it becomes clear that that assumption is actually _incorrect_,
and the `ScoreMultiplier` _must_ be applied to every score increase
individually.
The above was cross-checked experimentally against stable source
on an example test map with 100 objects, and a replay hitting them
perfectly.
2023-09-13 02:31:49 +08:00
|
|
|
// this corresponds to stable's `ScoreMultiplier`.
|
|
|
|
// value is chosen arbitrarily, towards the upper range.
|
|
|
|
const float score_multiplier = 4;
|
2022-10-18 16:23:23 +08:00
|
|
|
|
2022-10-18 17:27:05 +08:00
|
|
|
totalScore += baseScore;
|
2022-10-18 16:23:23 +08:00
|
|
|
|
|
|
|
// combo multiplier
|
|
|
|
// ReSharper disable once PossibleLossOfFraction
|
2022-10-18 17:27:05 +08:00
|
|
|
totalScore += (int)(Math.Max(0, currentCombo - 1) * (baseScore / 25 * score_multiplier));
|
2022-10-18 16:23:23 +08:00
|
|
|
|
|
|
|
currentCombo++;
|
2022-10-18 17:27:05 +08:00
|
|
|
}
|
2022-10-18 17:05:54 +08:00
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
runForAlgorithm(new ScoringAlgorithm
|
|
|
|
{
|
|
|
|
Name = "ScoreV1 (classic)",
|
|
|
|
Colour = colours.Purple1,
|
|
|
|
ApplyHit = () => applyHitV1(base_great),
|
|
|
|
ApplyNonPerfect = () => applyHitV1(base_ok),
|
|
|
|
ApplyMiss = () => applyHitV1(0),
|
Fix Score V1 simulation in scoring test scene incorrectly applying multiplier
`TestSceneScoring` included a local simulation of stable's Score V1
algorithm. One of the parts of said algorithm is a mysterious
"score multiplier", influenced by - among others - the beatmap's drain
rate, overall difficulty, circle size, object count, drain length,
and active mods. (An implementation of this already exists in lazer
source, in `OsuLegacyScoreSimulator`, but more on this later.)
However, `TestSceneScoring` had this multiplier in _two_ places, with
_two_ distinct values, one of which being 1 (i.e. basically off).
Unfortunately, the place that had 1 as the multiplier was the wrong one.
Stable calculates the score increase for every hit in two stages;
first, it takes the raw numerical value of the judgement, but then
applies a combo-based bonus on top of it:
scoreIncrease += (int)(Math.Max(0, ComboCounter.HitCombo - 1) * (scoreIncrease / 25 * ScoreMultiplier));
On the face of it, it may appear that the `ScoreMultiplier` factor
can be factored out and applied at the end only when returning total
score. However, once the above formula is rewritten as:
scoreIncrease = scoreIncrease + (int)(Math.Max(0, ComboCounter.HitCombo - 1) * (scoreIncrease / 25 * ScoreMultiplier));
= scoreIncrease * (1 + (Math.Max(0, ComboCounter.HitCombo - 1) / 25 * ScoreMultiplier))
it becomes clear that that assumption is actually _incorrect_,
and the `ScoreMultiplier` _must_ be applied to every score increase
individually.
The above was cross-checked experimentally against stable source
on an example test map with 100 objects, and a replay hitting them
perfectly.
2023-09-13 02:31:49 +08:00
|
|
|
GetTotalScore = () => totalScore,
|
2023-09-12 18:19:50 +08:00
|
|
|
Visible = scoreV1Visible
|
|
|
|
});
|
2022-10-18 17:27:05 +08:00
|
|
|
}
|
2022-10-18 16:50:51 +08:00
|
|
|
|
2022-10-18 17:27:05 +08:00
|
|
|
private void runScoreV2()
|
|
|
|
{
|
2022-10-18 16:50:51 +08:00
|
|
|
int maxCombo = sliderMaxCombo.Current.Value;
|
|
|
|
|
2022-10-18 17:30:18 +08:00
|
|
|
int currentCombo = 0;
|
|
|
|
double comboPortion = 0;
|
2022-10-18 16:50:51 +08:00
|
|
|
double currentBaseScore = 0;
|
|
|
|
double maxBaseScore = 0;
|
|
|
|
int currentHits = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < maxCombo; i++)
|
2022-10-18 17:27:05 +08:00
|
|
|
applyHitV2(base_great);
|
2022-10-18 16:50:51 +08:00
|
|
|
|
2022-10-18 17:27:05 +08:00
|
|
|
double comboPortionMax = comboPortion;
|
2022-10-18 16:50:51 +08:00
|
|
|
|
2022-10-18 17:30:18 +08:00
|
|
|
currentCombo = 0;
|
2022-10-18 17:27:05 +08:00
|
|
|
comboPortion = 0;
|
|
|
|
currentBaseScore = 0;
|
2022-10-18 17:30:18 +08:00
|
|
|
maxBaseScore = 0;
|
2022-10-18 17:27:05 +08:00
|
|
|
currentHits = 0;
|
|
|
|
|
|
|
|
void applyHitV2(int baseScore)
|
2022-10-18 16:50:51 +08:00
|
|
|
{
|
2022-10-24 14:54:09 +08:00
|
|
|
maxBaseScore += base_great;
|
2022-10-18 17:27:05 +08:00
|
|
|
currentBaseScore += baseScore;
|
|
|
|
comboPortion += baseScore * (1 + ++currentCombo / 10.0);
|
|
|
|
|
2022-10-18 16:50:51 +08:00
|
|
|
currentHits++;
|
2022-10-18 17:27:05 +08:00
|
|
|
}
|
2022-10-18 16:50:51 +08:00
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
runForAlgorithm(new ScoringAlgorithm
|
|
|
|
{
|
|
|
|
Name = "ScoreV2",
|
|
|
|
Colour = colours.Red1,
|
|
|
|
ApplyHit = () => applyHitV2(base_great),
|
|
|
|
ApplyNonPerfect = () => applyHitV2(base_ok),
|
|
|
|
ApplyMiss = () =>
|
2022-10-18 17:27:05 +08:00
|
|
|
{
|
|
|
|
currentHits++;
|
|
|
|
maxBaseScore += base_great;
|
|
|
|
currentCombo = 0;
|
2023-09-12 18:19:50 +08:00
|
|
|
},
|
|
|
|
GetTotalScore = () =>
|
2022-10-18 17:27:05 +08:00
|
|
|
{
|
|
|
|
double accuracy = currentBaseScore / maxBaseScore;
|
2022-10-18 16:50:51 +08:00
|
|
|
|
2022-10-18 17:27:05 +08:00
|
|
|
return (int)Math.Round
|
|
|
|
(
|
|
|
|
700000 * comboPortion / comboPortionMax +
|
|
|
|
300000 * Math.Pow(accuracy, 10) * ((double)currentHits / maxCombo)
|
|
|
|
);
|
2023-09-12 18:19:50 +08:00
|
|
|
},
|
|
|
|
Visible = scoreV2Visible
|
|
|
|
});
|
2022-10-16 17:39:25 +08:00
|
|
|
}
|
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
private void runForProcessor(string name, Color4 colour, ScoreProcessor processor, ScoringMode mode, BindableBool visibility)
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
|
|
|
int maxCombo = sliderMaxCombo.Current.Value;
|
|
|
|
|
|
|
|
var beatmap = new OsuBeatmap();
|
|
|
|
for (int i = 0; i < maxCombo; i++)
|
|
|
|
beatmap.HitObjects.Add(new HitCircle());
|
|
|
|
|
|
|
|
processor.ApplyBeatmap(beatmap);
|
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
runForAlgorithm(new ScoringAlgorithm
|
|
|
|
{
|
|
|
|
Name = name,
|
|
|
|
Colour = colour,
|
|
|
|
ApplyHit = () => processor.ApplyResult(new OsuJudgementResult(new HitCircle(), new OsuJudgement()) { Type = HitResult.Great }),
|
|
|
|
ApplyNonPerfect = () => processor.ApplyResult(new OsuJudgementResult(new HitCircle(), new OsuJudgement()) { Type = HitResult.Ok }),
|
|
|
|
ApplyMiss = () => processor.ApplyResult(new OsuJudgementResult(new HitCircle(), new OsuJudgement()) { Type = HitResult.Miss }),
|
|
|
|
GetTotalScore = () => processor.GetDisplayScore(mode),
|
|
|
|
Visible = visibility
|
|
|
|
});
|
2022-10-18 16:23:23 +08:00
|
|
|
}
|
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
private void runForAlgorithm(ScoringAlgorithm scoringAlgorithm)
|
2022-10-18 16:23:23 +08:00
|
|
|
{
|
|
|
|
int maxCombo = sliderMaxCombo.Current.Value;
|
|
|
|
|
2022-10-16 17:39:25 +08:00
|
|
|
List<float> results = new List<float>();
|
|
|
|
|
|
|
|
for (int i = 0; i < maxCombo; i++)
|
|
|
|
{
|
2022-10-17 22:27:26 +08:00
|
|
|
if (graphs.MissLocations.Contains(i))
|
2023-09-12 18:19:50 +08:00
|
|
|
scoringAlgorithm.ApplyMiss();
|
2022-10-18 17:27:05 +08:00
|
|
|
else if (graphs.NonPerfectLocations.Contains(i))
|
2023-09-12 18:19:50 +08:00
|
|
|
scoringAlgorithm.ApplyNonPerfect();
|
2022-10-16 17:39:25 +08:00
|
|
|
else
|
2023-09-12 18:19:50 +08:00
|
|
|
scoringAlgorithm.ApplyHit();
|
2022-10-16 17:39:25 +08:00
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
results.Add(scoringAlgorithm.GetTotalScore());
|
2022-10-16 17:39:25 +08:00
|
|
|
}
|
|
|
|
|
2023-09-12 18:07:12 +08:00
|
|
|
LineGraph graph;
|
|
|
|
graphs.Add(graph = new LineGraph
|
2022-10-16 17:39:25 +08:00
|
|
|
{
|
2023-09-12 18:19:50 +08:00
|
|
|
Name = scoringAlgorithm.Name,
|
2023-09-12 19:27:40 +08:00
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
2022-10-16 17:39:25 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2023-09-12 18:19:50 +08:00
|
|
|
LineColour = scoringAlgorithm.Colour,
|
2022-10-16 17:39:25 +08:00
|
|
|
Values = results
|
|
|
|
});
|
2022-10-17 22:41:07 +08:00
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
legend.Add(new LegendEntry(scoringAlgorithm, graph)
|
2022-10-17 22:41:07 +08:00
|
|
|
{
|
2023-09-12 18:19:50 +08:00
|
|
|
AccentColour = scoringAlgorithm.Colour,
|
2022-10-18 17:05:54 +08:00
|
|
|
});
|
2022-10-16 17:39:25 +08:00
|
|
|
}
|
|
|
|
}
|
2022-10-17 22:27:26 +08:00
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
public class ScoringAlgorithm
|
|
|
|
{
|
|
|
|
public string Name { get; init; } = null!;
|
|
|
|
public Color4 Colour { get; init; }
|
|
|
|
public Action ApplyHit { get; init; } = () => { };
|
|
|
|
public Action ApplyNonPerfect { get; init; } = () => { };
|
|
|
|
public Action ApplyMiss { get; init; } = () => { };
|
|
|
|
public Func<long> GetTotalScore { get; init; } = null!;
|
|
|
|
public BindableBool Visible { get; init; } = null!;
|
|
|
|
}
|
|
|
|
|
2023-09-12 19:27:40 +08:00
|
|
|
public partial class GraphContainer : Container<LineGraph>, IHasCustomTooltip<IEnumerable<LineGraph>>
|
2022-10-17 22:27:26 +08:00
|
|
|
{
|
|
|
|
public readonly BindableList<double> MissLocations = new BindableList<double>();
|
2022-10-18 17:27:05 +08:00
|
|
|
public readonly BindableList<double> NonPerfectLocations = new BindableList<double>();
|
2022-10-17 22:27:26 +08:00
|
|
|
|
|
|
|
public Bindable<int> MaxCombo = new Bindable<int>();
|
|
|
|
|
2023-09-12 19:27:40 +08:00
|
|
|
protected override Container<LineGraph> Content { get; } = new Container<LineGraph> { RelativeSizeAxes = Axes.Both };
|
2022-10-17 22:27:26 +08:00
|
|
|
|
|
|
|
private readonly Box hoverLine;
|
|
|
|
|
|
|
|
private readonly Container missLines;
|
2022-10-17 22:49:15 +08:00
|
|
|
private readonly Container verticalGridLines;
|
2022-10-17 22:27:26 +08:00
|
|
|
|
2022-10-18 18:01:43 +08:00
|
|
|
public int CurrentHoverCombo { get; private set; }
|
|
|
|
|
2022-10-17 22:27:26 +08:00
|
|
|
public GraphContainer()
|
|
|
|
{
|
|
|
|
InternalChild = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = OsuColour.Gray(0.1f),
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2022-10-17 22:49:15 +08:00
|
|
|
verticalGridLines = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2022-10-17 22:27:26 +08:00
|
|
|
hoverLine = new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.Yellow,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2022-10-18 17:13:13 +08:00
|
|
|
Origin = Anchor.TopCentre,
|
2022-10-17 22:27:26 +08:00
|
|
|
Alpha = 0,
|
|
|
|
Width = 1,
|
|
|
|
},
|
|
|
|
missLines = new Container
|
|
|
|
{
|
2022-10-18 17:13:13 +08:00
|
|
|
Alpha = 0.6f,
|
2022-10-17 22:27:26 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2022-10-18 17:13:13 +08:00
|
|
|
Content,
|
2022-10-17 22:27:26 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-17 22:49:15 +08:00
|
|
|
MissLocations.BindCollectionChanged((_, _) => updateMissLocations());
|
2022-10-18 17:27:05 +08:00
|
|
|
NonPerfectLocations.BindCollectionChanged((_, _) => updateMissLocations());
|
2022-10-17 22:49:15 +08:00
|
|
|
|
|
|
|
MaxCombo.BindValueChanged(_ =>
|
|
|
|
{
|
|
|
|
updateMissLocations();
|
|
|
|
updateVerticalGridLines();
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateVerticalGridLines()
|
|
|
|
{
|
|
|
|
verticalGridLines.Clear();
|
2022-10-17 22:27:26 +08:00
|
|
|
|
2022-10-17 22:49:15 +08:00
|
|
|
for (int i = 0; i < MaxCombo.Value; i++)
|
|
|
|
{
|
|
|
|
if (i % 100 == 0)
|
|
|
|
{
|
2022-10-18 15:50:30 +08:00
|
|
|
verticalGridLines.AddRange(new Drawable[]
|
2022-10-17 22:49:15 +08:00
|
|
|
{
|
2022-10-18 15:50:30 +08:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = OsuColour.Gray(0.2f),
|
2022-10-18 17:13:13 +08:00
|
|
|
Origin = Anchor.TopCentre,
|
2022-10-18 15:50:30 +08:00
|
|
|
Width = 1,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
X = (float)i / MaxCombo.Value,
|
|
|
|
},
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
X = (float)i / MaxCombo.Value,
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
Text = $"{i:#,0}",
|
|
|
|
Rotation = -30,
|
|
|
|
Y = -20,
|
|
|
|
}
|
2022-10-17 22:49:15 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2022-10-17 22:27:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateMissLocations()
|
|
|
|
{
|
|
|
|
missLines.Clear();
|
|
|
|
|
|
|
|
foreach (int miss in MissLocations)
|
|
|
|
{
|
|
|
|
missLines.Add(new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.Red,
|
2022-10-18 17:13:13 +08:00
|
|
|
Origin = Anchor.TopCentre,
|
2022-10-17 22:27:26 +08:00
|
|
|
Width = 1,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
X = (float)miss / MaxCombo.Value,
|
|
|
|
});
|
|
|
|
}
|
2022-10-18 17:27:05 +08:00
|
|
|
|
|
|
|
foreach (int miss in NonPerfectLocations)
|
|
|
|
{
|
|
|
|
missLines.Add(new Box
|
|
|
|
{
|
|
|
|
Colour = Color4.Orange,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Width = 1,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
X = (float)miss / MaxCombo.Value,
|
|
|
|
});
|
|
|
|
}
|
2022-10-17 22:27:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
hoverLine.Show();
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
hoverLine.Hide();
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
|
|
|
{
|
2022-10-18 18:01:43 +08:00
|
|
|
CurrentHoverCombo = (int)(e.MousePosition.X / DrawWidth * MaxCombo.Value);
|
|
|
|
|
2022-10-17 22:27:26 +08:00
|
|
|
hoverLine.X = e.MousePosition.X;
|
|
|
|
return base.OnMouseMove(e);
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:27:05 +08:00
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
2022-10-17 22:27:26 +08:00
|
|
|
{
|
2022-10-18 17:27:05 +08:00
|
|
|
if (e.Button == MouseButton.Left)
|
2022-10-18 18:01:43 +08:00
|
|
|
MissLocations.Add(CurrentHoverCombo);
|
2022-10-18 17:27:05 +08:00
|
|
|
else
|
2022-10-18 18:01:43 +08:00
|
|
|
NonPerfectLocations.Add(CurrentHoverCombo);
|
|
|
|
|
2022-10-17 22:27:26 +08:00
|
|
|
return true;
|
|
|
|
}
|
2022-10-18 18:01:43 +08:00
|
|
|
|
|
|
|
private GraphTooltip? tooltip;
|
|
|
|
|
|
|
|
public ITooltip<IEnumerable<LineGraph>> GetCustomTooltip() => tooltip ??= new GraphTooltip(this);
|
|
|
|
|
2023-09-12 19:27:40 +08:00
|
|
|
public IEnumerable<LineGraph> TooltipContent => Content;
|
2022-10-18 18:01:43 +08:00
|
|
|
|
|
|
|
public partial class GraphTooltip : CompositeDrawable, ITooltip<IEnumerable<LineGraph>>
|
|
|
|
{
|
|
|
|
private readonly GraphContainer graphContainer;
|
|
|
|
|
|
|
|
private readonly OsuTextFlowContainer textFlow;
|
|
|
|
|
|
|
|
public GraphTooltip(GraphContainer graphContainer)
|
|
|
|
{
|
|
|
|
this.graphContainer = graphContainer;
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
Masking = true;
|
|
|
|
CornerRadius = 10;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = OsuColour.Gray(0.15f),
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
textFlow = new OsuTextFlowContainer
|
|
|
|
{
|
|
|
|
Colour = Color4.White,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private int? lastContentCombo;
|
|
|
|
|
|
|
|
public void SetContent(IEnumerable<LineGraph> content)
|
|
|
|
{
|
|
|
|
int relevantCombo = graphContainer.CurrentHoverCombo;
|
|
|
|
|
|
|
|
if (lastContentCombo == relevantCombo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
lastContentCombo = relevantCombo;
|
|
|
|
textFlow.Clear();
|
|
|
|
|
|
|
|
textFlow.AddParagraph($"At combo {relevantCombo}:");
|
|
|
|
|
|
|
|
foreach (var graph in content)
|
|
|
|
{
|
2023-09-12 19:29:02 +08:00
|
|
|
if (graph.Alpha == 0) continue;
|
|
|
|
|
2022-10-18 18:01:43 +08:00
|
|
|
float valueAtHover = graph.Values.ElementAt(relevantCombo);
|
|
|
|
float ofTotal = valueAtHover / graph.Values.Last();
|
|
|
|
|
|
|
|
textFlow.AddParagraph($"{graph.Name}: {valueAtHover:#,0} ({ofTotal * 100:N0}% of final)\n", st => st.Colour = graph.LineColour);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Move(Vector2 pos) => this.MoveTo(pos);
|
|
|
|
}
|
2022-10-17 22:27:26 +08:00
|
|
|
}
|
2023-09-12 18:07:12 +08:00
|
|
|
|
|
|
|
public partial class LegendEntry : OsuClickableContainer, IHasAccentColour
|
|
|
|
{
|
|
|
|
public Color4 AccentColour { get; set; }
|
|
|
|
|
|
|
|
public BindableBool Visible { get; } = new BindableBool(true);
|
|
|
|
|
2023-09-12 19:27:40 +08:00
|
|
|
public readonly long FinalScore;
|
|
|
|
|
2023-09-12 18:07:12 +08:00
|
|
|
private readonly string description;
|
|
|
|
private readonly LineGraph lineGraph;
|
|
|
|
|
|
|
|
private OsuSpriteText descriptionText = null!;
|
|
|
|
private OsuSpriteText finalScoreText = null!;
|
|
|
|
|
2023-09-12 18:19:50 +08:00
|
|
|
public LegendEntry(ScoringAlgorithm scoringAlgorithm, LineGraph lineGraph)
|
2023-09-12 18:07:12 +08:00
|
|
|
{
|
2023-09-12 18:19:50 +08:00
|
|
|
description = scoringAlgorithm.Name;
|
2023-09-12 19:27:40 +08:00
|
|
|
FinalScore = scoringAlgorithm.GetTotalScore();
|
2023-09-12 18:19:50 +08:00
|
|
|
AccentColour = scoringAlgorithm.Colour;
|
|
|
|
Visible.BindTo(scoringAlgorithm.Visible);
|
|
|
|
|
2023-09-12 18:07:12 +08:00
|
|
|
this.lineGraph = lineGraph;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Content.RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Content.AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
descriptionText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
},
|
|
|
|
finalScoreText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
Font = OsuFont.Default.With(fixedWidth: true)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
Visible.BindValueChanged(_ => updateState(), true);
|
|
|
|
Action = Visible.Toggle;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
updateState();
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
Colour = IsHovered ? AccentColour.Lighten(0.2f) : AccentColour;
|
|
|
|
|
|
|
|
descriptionText.Text = $"{(Visible.Value ? FontAwesome.Solid.CheckCircle.Icon : FontAwesome.Solid.Circle.Icon)} {description}";
|
2023-09-12 19:27:40 +08:00
|
|
|
finalScoreText.Text = FinalScore.ToString("#,0");
|
2023-09-12 18:07:12 +08:00
|
|
|
lineGraph.Alpha = Visible.Value ? 1 : 0;
|
|
|
|
}
|
|
|
|
}
|
2022-10-16 17:39:25 +08:00
|
|
|
}
|