mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 13:32:54 +08:00
Further improvements to TestCasePerformancePoints
This commit is contained in:
parent
1e023f0419
commit
1ed2ce324f
@ -6,19 +6,23 @@ using System.Linq;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Caching;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Music;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
@ -27,50 +31,77 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public TestCasePerformancePoints(Ruleset ruleset)
|
||||
{
|
||||
Child = new FillFlowContainer
|
||||
Child = new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Children = new Drawable[]
|
||||
Content = new[]
|
||||
{
|
||||
new Container
|
||||
new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Width = 0.25f,
|
||||
Children = new Drawable[]
|
||||
new Container
|
||||
{
|
||||
new Box
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
new ScrollContainer(Direction.Vertical)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new BeatmapList(ruleset)
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
new ScrollContainer(Direction.Vertical)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new BeatmapList(ruleset)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Width = 0.75f,
|
||||
Children = new Drawable[]
|
||||
},
|
||||
null,
|
||||
new Container
|
||||
{
|
||||
new Box
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
new ScrollContainer(Direction.Vertical)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new ScoreList { RelativeSizeAxes = Axes.Both }
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
new ScrollContainer(Direction.Vertical)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new StarRatingGrid()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
null,
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.5f,
|
||||
},
|
||||
new ScrollContainer(Direction.Vertical)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new PerformanceList()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
ColumnDimensions = new[]
|
||||
{
|
||||
new Dimension(),
|
||||
new Dimension(GridSizeMode.Absolute, 20),
|
||||
new Dimension(),
|
||||
new Dimension(GridSizeMode.Absolute, 20)
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -104,7 +135,7 @@ namespace osu.Game.Tests.Visual
|
||||
allBeatmaps.ForEach(b => beatmapDisplays.Add(new BeatmapDisplay(b)));
|
||||
}
|
||||
|
||||
private class BeatmapDisplay : CompositeDrawable
|
||||
private class BeatmapDisplay : CompositeDrawable, IHasTooltip
|
||||
{
|
||||
private readonly OsuSpriteText text;
|
||||
private readonly BeatmapInfo beatmap;
|
||||
@ -114,6 +145,8 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
private bool isSelected;
|
||||
|
||||
public string TooltipText => text.Text;
|
||||
|
||||
public BeatmapDisplay(BeatmapInfo beatmap)
|
||||
{
|
||||
this.beatmap = beatmap;
|
||||
@ -168,16 +201,19 @@ namespace osu.Game.Tests.Visual
|
||||
}
|
||||
}
|
||||
|
||||
private class ScoreList : CompositeDrawable
|
||||
private class PerformanceList : CompositeDrawable
|
||||
{
|
||||
private readonly FillFlowContainer<ScoreDisplay> scores;
|
||||
private readonly FillFlowContainer<PerformanceDisplay> scores;
|
||||
private APIAccess api;
|
||||
|
||||
public ScoreList()
|
||||
public PerformanceList()
|
||||
{
|
||||
InternalChild = scores = new FillFlowContainer<ScoreDisplay>
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
InternalChild = scores = new FillFlowContainer<PerformanceDisplay>
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(0, 4)
|
||||
};
|
||||
@ -197,39 +233,25 @@ namespace osu.Game.Tests.Visual
|
||||
scores.Clear();
|
||||
|
||||
lastRequest = new GetScoresRequest(newBeatmap.BeatmapInfo);
|
||||
lastRequest.Success += res => res.Scores.ForEach(s => scores.Add(new ScoreDisplay(s, newBeatmap.Beatmap)));
|
||||
lastRequest.Success += res => res.Scores.ForEach(s => scores.Add(new PerformanceDisplay(s, newBeatmap.Beatmap)));
|
||||
api.Queue(lastRequest);
|
||||
}
|
||||
|
||||
private class ScoreDisplay : CompositeDrawable
|
||||
private class PerformanceDisplay : CompositeDrawable
|
||||
{
|
||||
private readonly OsuSpriteText playerName;
|
||||
private readonly GridContainer attributeGrid;
|
||||
private readonly OsuSpriteText text;
|
||||
|
||||
private readonly Score score;
|
||||
private readonly Beatmap beatmap;
|
||||
|
||||
public ScoreDisplay(Score score, Beatmap beatmap)
|
||||
public PerformanceDisplay(Score score, Beatmap beatmap)
|
||||
{
|
||||
this.score = score;
|
||||
this.beatmap = beatmap;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Height = 16;
|
||||
InternalChild = new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[] { playerName = new OsuSpriteText() },
|
||||
new Drawable[] { attributeGrid = new GridContainer { RelativeSizeAxes = Axes.Both } }
|
||||
},
|
||||
RowDimensions = new[]
|
||||
{
|
||||
new Dimension(GridSizeMode.Relative, 0.75f),
|
||||
new Dimension(GridSizeMode.Relative, 0.25f)
|
||||
}
|
||||
};
|
||||
AutoSizeAxes = Axes.Y;
|
||||
InternalChild = text = new OsuSpriteText();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -243,8 +265,117 @@ namespace osu.Game.Tests.Visual
|
||||
var attributes = new Dictionary<string, string>();
|
||||
double performance = calculator.Calculate(attributes);
|
||||
|
||||
playerName.Text = $"{score.PP} | {performance.ToString("0.00")} | {score.PP / performance}";
|
||||
// var attributeRow =
|
||||
text.Text = $"{score.User.Username} -> online: {score.PP:n2}pp | local: {performance:n2}pp";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class StarRatingGrid : CompositeDrawable
|
||||
{
|
||||
private readonly FillFlowContainer<OsuCheckbox> modFlow;
|
||||
private readonly OsuSpriteText totalText;
|
||||
private readonly FillFlowContainer categoryTexts;
|
||||
|
||||
public StarRatingGrid()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
InternalChild = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
modFlow = new FillFlowContainer<OsuCheckbox>
|
||||
{
|
||||
Name = "Checkbox flow",
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Spacing = new Vector2(4, 4)
|
||||
},
|
||||
new FillFlowContainer
|
||||
{
|
||||
Name = "Information display",
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Spacing = new Vector2(0, 4),
|
||||
Direction = FillDirection.Vertical,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
totalText = new OsuSpriteText { TextSize = 24 },
|
||||
categoryTexts = new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Vertical
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase osuGame)
|
||||
{
|
||||
osuGame.Beatmap.ValueChanged += beatmapChanged;
|
||||
}
|
||||
|
||||
private Cached informationCache = new Cached();
|
||||
|
||||
private Ruleset ruleset;
|
||||
private WorkingBeatmap beatmap;
|
||||
|
||||
private void beatmapChanged(WorkingBeatmap newBeatmap)
|
||||
{
|
||||
beatmap = newBeatmap;
|
||||
|
||||
modFlow.Clear();
|
||||
|
||||
ruleset = newBeatmap.BeatmapInfo.Ruleset.CreateInstance();
|
||||
foreach (var mod in ruleset.GetAllMods())
|
||||
{
|
||||
var checkBox = new OsuCheckbox
|
||||
{
|
||||
RelativeSizeAxes = Axes.None,
|
||||
Width = 50,
|
||||
LabelText = mod.ShortenedName
|
||||
};
|
||||
|
||||
checkBox.Current.ValueChanged += v => informationCache.Invalidate();
|
||||
modFlow.Add(checkBox);
|
||||
}
|
||||
|
||||
informationCache.Invalidate();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (ruleset == null)
|
||||
return;
|
||||
|
||||
if (!informationCache.IsValid)
|
||||
{
|
||||
totalText.Text = string.Empty;
|
||||
categoryTexts.Clear();
|
||||
|
||||
var allMods = ruleset.GetAllMods().ToList();
|
||||
Mod[] activeMods = modFlow.Where(c => c.Current.Value).Select(c => allMods.First(m => m.ShortenedName == c.LabelText)).ToArray();
|
||||
|
||||
var diffCalc = ruleset.CreateDifficultyCalculator(beatmap.Beatmap, activeMods);
|
||||
if (diffCalc != null)
|
||||
{
|
||||
var categories = new Dictionary<string, string>();
|
||||
double totalSr = diffCalc.Calculate(categories);
|
||||
|
||||
totalText.Text = $"Star rating: {totalSr:n2}";
|
||||
foreach (var kvp in categories)
|
||||
categoryTexts.Add(new OsuSpriteText { Text = $"{kvp.Key}: {kvp.Value:n2}" });
|
||||
}
|
||||
|
||||
informationCache.Validate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user