2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK.Graphics;
|
2017-09-08 01:53:53 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Beatmaps;
|
2019-12-12 23:41:46 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using System.Linq;
|
2020-07-16 20:08:08 +08:00
|
|
|
|
using System.Threading;
|
2021-02-25 15:05:08 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2022-01-03 16:31:12 +08:00
|
|
|
|
using osu.Framework.Extensions;
|
2021-02-22 16:14:00 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2019-12-20 17:00:04 +08:00
|
|
|
|
using osu.Framework.Threading;
|
2020-02-01 23:16:15 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2019-12-20 17:00:04 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2022-01-28 12:53:48 +08:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2020-07-16 20:08:08 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
namespace osu.Game.Screens.Select.Details
|
|
|
|
|
{
|
|
|
|
|
public partial class AdvancedStats : Container
|
|
|
|
|
{
|
2019-12-12 23:41:46 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IBindable<IReadOnlyList<Mod>> mods { get; set; }
|
|
|
|
|
|
2020-07-16 20:08:08 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
2020-11-06 12:14:23 +08:00
|
|
|
|
private BeatmapDifficultyCache difficultyCache { get; set; }
|
2020-07-16 20:08:08 +08:00
|
|
|
|
|
2020-02-01 22:50:33 +08:00
|
|
|
|
protected readonly StatisticRow FirstValue, HpDrain, Accuracy, ApproachRate;
|
|
|
|
|
private readonly StatisticRow starDifficulty;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-10-29 16:58:46 +08:00
|
|
|
|
private IBeatmapInfo beatmapInfo;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2021-10-29 16:58:46 +08:00
|
|
|
|
public IBeatmapInfo BeatmapInfo
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2021-10-02 11:44:22 +08:00
|
|
|
|
get => beatmapInfo;
|
2017-09-08 01:53:53 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2021-10-02 11:44:22 +08:00
|
|
|
|
if (value == beatmapInfo) return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2021-10-02 11:44:22 +08:00
|
|
|
|
beatmapInfo = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-12 23:41:46 +08:00
|
|
|
|
updateStatistics();
|
2017-09-08 01:53:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
public AdvancedStats()
|
|
|
|
|
{
|
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2020-05-05 09:31:11 +08:00
|
|
|
|
FirstValue = new StatisticRow(), // circle size/key amount
|
2022-01-28 12:53:48 +08:00
|
|
|
|
HpDrain = new StatisticRow { Title = BeatmapsetsStrings.ShowStatsDrain },
|
|
|
|
|
Accuracy = new StatisticRow { Title = BeatmapsetsStrings.ShowStatsAccuracy },
|
|
|
|
|
ApproachRate = new StatisticRow { Title = BeatmapsetsStrings.ShowStatsAr },
|
|
|
|
|
starDifficulty = new StatisticRow(10, true) { Title = BeatmapsetsStrings.ShowStatsStars },
|
2017-09-08 01:53:53 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2019-12-13 09:39:54 +08:00
|
|
|
|
private void load(OsuColour colours)
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
|
|
|
|
starDifficulty.AccentColour = colours.Yellow;
|
2019-12-18 16:41:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2020-07-16 20:08:08 +08:00
|
|
|
|
ruleset.BindValueChanged(_ => updateStatistics());
|
2019-12-20 17:00:04 +08:00
|
|
|
|
mods.BindValueChanged(modsChanged, true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 13:54:50 +08:00
|
|
|
|
private ModSettingChangeTracker modSettingChangeTracker;
|
2021-02-10 18:39:47 +08:00
|
|
|
|
private ScheduledDelegate debouncedStatisticsUpdate;
|
2019-12-20 17:00:04 +08:00
|
|
|
|
|
|
|
|
|
private void modsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
|
|
|
|
{
|
2021-02-11 13:54:50 +08:00
|
|
|
|
modSettingChangeTracker?.Dispose();
|
2019-12-20 17:00:04 +08:00
|
|
|
|
|
2021-02-11 13:54:50 +08:00
|
|
|
|
modSettingChangeTracker = new ModSettingChangeTracker(mods.NewValue);
|
2022-06-24 20:25:23 +08:00
|
|
|
|
modSettingChangeTracker.SettingChanged += _ =>
|
2019-12-20 17:00:04 +08:00
|
|
|
|
{
|
2021-02-10 18:39:47 +08:00
|
|
|
|
debouncedStatisticsUpdate?.Cancel();
|
|
|
|
|
debouncedStatisticsUpdate = Scheduler.AddDelayed(updateStatistics, 100);
|
|
|
|
|
};
|
2019-12-20 17:00:04 +08:00
|
|
|
|
|
|
|
|
|
updateStatistics();
|
2019-12-12 23:41:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateStatistics()
|
|
|
|
|
{
|
2021-10-29 16:58:46 +08:00
|
|
|
|
IBeatmapDifficultyInfo baseDifficulty = BeatmapInfo?.Difficulty;
|
2019-12-18 16:12:41 +08:00
|
|
|
|
BeatmapDifficulty adjustedDifficulty = null;
|
2019-12-12 23:41:46 +08:00
|
|
|
|
|
2019-12-18 16:00:35 +08:00
|
|
|
|
if (baseDifficulty != null && mods.Value.Any(m => m is IApplicableToDifficulty))
|
2019-12-12 23:41:46 +08:00
|
|
|
|
{
|
2021-10-01 13:56:42 +08:00
|
|
|
|
adjustedDifficulty = new BeatmapDifficulty(baseDifficulty);
|
2019-12-12 23:41:46 +08:00
|
|
|
|
|
|
|
|
|
foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
|
2019-12-18 16:00:35 +08:00
|
|
|
|
mod.ApplyToDifficulty(adjustedDifficulty);
|
2019-12-12 23:41:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 16:58:46 +08:00
|
|
|
|
switch (BeatmapInfo?.Ruleset.OnlineID)
|
2020-01-28 16:21:24 +08:00
|
|
|
|
{
|
|
|
|
|
case 3:
|
|
|
|
|
// Account for mania differences locally for now
|
|
|
|
|
// Eventually this should be handled in a more modular way, allowing rulesets to return arbitrary difficulty attributes
|
2022-01-28 12:53:48 +08:00
|
|
|
|
FirstValue.Title = BeatmapsetsStrings.ShowStatsCsMania;
|
2020-02-01 22:50:33 +08:00
|
|
|
|
FirstValue.Value = (baseDifficulty?.CircleSize ?? 0, null);
|
2020-01-28 16:21:24 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2022-01-28 12:53:48 +08:00
|
|
|
|
FirstValue.Title = BeatmapsetsStrings.ShowStatsCs;
|
2020-02-01 22:50:33 +08:00
|
|
|
|
FirstValue.Value = (baseDifficulty?.CircleSize ?? 0, adjustedDifficulty?.CircleSize);
|
2020-01-28 16:21:24 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2019-12-12 23:41:46 +08:00
|
|
|
|
|
2020-02-01 22:50:33 +08:00
|
|
|
|
HpDrain.Value = (baseDifficulty?.DrainRate ?? 0, adjustedDifficulty?.DrainRate);
|
|
|
|
|
Accuracy.Value = (baseDifficulty?.OverallDifficulty ?? 0, adjustedDifficulty?.OverallDifficulty);
|
|
|
|
|
ApproachRate.Value = (baseDifficulty?.ApproachRate ?? 0, adjustedDifficulty?.ApproachRate);
|
2020-07-16 20:08:08 +08:00
|
|
|
|
|
|
|
|
|
updateStarDifficulty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CancellationTokenSource starDifficultyCancellationSource;
|
|
|
|
|
|
|
|
|
|
private void updateStarDifficulty()
|
|
|
|
|
{
|
|
|
|
|
starDifficultyCancellationSource?.Cancel();
|
|
|
|
|
|
2021-10-02 11:44:22 +08:00
|
|
|
|
if (BeatmapInfo == null)
|
2020-07-16 20:08:08 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2020-07-24 15:11:28 +08:00
|
|
|
|
starDifficultyCancellationSource = new CancellationTokenSource();
|
2020-07-16 20:08:08 +08:00
|
|
|
|
|
2022-01-03 16:31:12 +08:00
|
|
|
|
var normalStarDifficultyTask = difficultyCache.GetDifficultyAsync(BeatmapInfo, ruleset.Value, null, starDifficultyCancellationSource.Token);
|
|
|
|
|
var moddedStarDifficultyTask = difficultyCache.GetDifficultyAsync(BeatmapInfo, ruleset.Value, mods.Value, starDifficultyCancellationSource.Token);
|
2020-07-21 22:13:04 +08:00
|
|
|
|
|
2022-01-03 16:31:12 +08:00
|
|
|
|
Task.WhenAll(normalStarDifficultyTask, moddedStarDifficultyTask).ContinueWith(_ => Schedule(() =>
|
2021-02-25 15:05:08 +08:00
|
|
|
|
{
|
2022-01-06 21:54:43 +08:00
|
|
|
|
var normalDifficulty = normalStarDifficultyTask.GetResultSafely();
|
2022-01-07 16:33:38 +08:00
|
|
|
|
var moddedDifficulty = moddedStarDifficultyTask.GetResultSafely();
|
2022-01-03 16:31:12 +08:00
|
|
|
|
|
2022-01-07 16:33:38 +08:00
|
|
|
|
if (normalDifficulty == null || moddedDifficulty == null)
|
2021-11-20 23:54:58 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2022-01-07 16:33:38 +08:00
|
|
|
|
starDifficulty.Value = ((float)normalDifficulty.Value.Stars, (float)moddedDifficulty.Value.Stars);
|
2021-02-25 15:05:08 +08:00
|
|
|
|
}), starDifficultyCancellationSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current);
|
2020-07-21 22:13:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
2021-02-11 13:54:50 +08:00
|
|
|
|
modSettingChangeTracker?.Dispose();
|
2020-07-21 22:13:04 +08:00
|
|
|
|
starDifficultyCancellationSource?.Cancel();
|
2017-09-08 01:53:53 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-02-01 22:50:33 +08:00
|
|
|
|
public partial class StatisticRow : Container, IHasAccentColour
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
|
|
|
|
private const float value_width = 25;
|
|
|
|
|
private const float name_width = 70;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
private readonly float maxValue;
|
|
|
|
|
private readonly bool forceDecimalPlaces;
|
2019-12-18 16:12:41 +08:00
|
|
|
|
private readonly OsuSpriteText name, valueText;
|
2020-02-01 22:50:33 +08:00
|
|
|
|
private readonly Bar bar;
|
|
|
|
|
public readonly Bar ModBar;
|
2019-12-13 09:39:54 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-02-22 16:14:00 +08:00
|
|
|
|
public LocalisableString Title
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => name.Text;
|
|
|
|
|
set => name.Text = value;
|
2017-09-08 01:53:53 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-06-03 00:58:50 +08:00
|
|
|
|
private (float baseValue, float? adjustedValue)? value;
|
2019-12-13 09:39:54 +08:00
|
|
|
|
|
2019-12-18 16:12:41 +08:00
|
|
|
|
public (float baseValue, float? adjustedValue) Value
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2021-06-03 00:58:50 +08:00
|
|
|
|
get => value ?? (0, null);
|
2017-09-08 01:53:53 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2019-12-18 16:12:41 +08:00
|
|
|
|
if (value == this.value)
|
|
|
|
|
return;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-12-18 16:12:41 +08:00
|
|
|
|
this.value = value;
|
|
|
|
|
|
|
|
|
|
bar.Length = value.baseValue / maxValue;
|
|
|
|
|
|
|
|
|
|
valueText.Text = (value.adjustedValue ?? value.baseValue).ToString(forceDecimalPlaces ? "0.00" : "0.##");
|
2020-02-01 22:50:33 +08:00
|
|
|
|
ModBar.Length = (value.adjustedValue ?? 0) / maxValue;
|
2019-12-18 16:12:41 +08:00
|
|
|
|
|
2020-02-01 23:16:15 +08:00
|
|
|
|
if (Precision.AlmostEquals(value.baseValue, value.adjustedValue ?? value.baseValue, 0.05f))
|
|
|
|
|
ModBar.AccentColour = valueText.Colour = Color4.White;
|
|
|
|
|
else if (value.adjustedValue > value.baseValue)
|
2020-02-01 22:50:33 +08:00
|
|
|
|
ModBar.AccentColour = valueText.Colour = colours.Red;
|
2019-12-18 16:12:41 +08:00
|
|
|
|
else if (value.adjustedValue < value.baseValue)
|
2020-02-01 22:50:33 +08:00
|
|
|
|
ModBar.AccentColour = valueText.Colour = colours.BlueDark;
|
2019-12-13 09:39:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => bar.AccentColour;
|
|
|
|
|
set => bar.AccentColour = value;
|
2017-09-08 01:53:53 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 02:21:18 +08:00
|
|
|
|
public StatisticRow(float maxValue = 10, bool forceDecimalPlaces = false)
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
|
|
|
|
this.maxValue = maxValue;
|
|
|
|
|
this.forceDecimalPlaces = forceDecimalPlaces;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Padding = new MarginPadding { Vertical = 2.5f };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-08 01:53:53 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Width = name_width,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2020-02-17 04:43:33 +08:00
|
|
|
|
// osu-web uses 1.25 line-height, which at 12px font size makes the element 14px tall - this compentates that difference
|
|
|
|
|
Padding = new MarginPadding { Vertical = 1 },
|
2017-09-08 02:38:23 +08:00
|
|
|
|
Child = name = new OsuSpriteText
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 12)
|
2017-09-08 01:53:53 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
bar = new Bar
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 5,
|
|
|
|
|
BackgroundColour = Color4.White.Opacity(0.5f),
|
|
|
|
|
Padding = new MarginPadding { Left = name_width + 10, Right = value_width + 10 },
|
|
|
|
|
},
|
2020-02-01 22:50:33 +08:00
|
|
|
|
ModBar = new Bar
|
2019-12-13 09:39:54 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Alpha = 0.5f,
|
|
|
|
|
Height = 5,
|
|
|
|
|
Padding = new MarginPadding { Left = name_width + 10, Right = value_width + 10 },
|
|
|
|
|
},
|
2017-09-08 01:53:53 +08:00
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Width = value_width,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2019-12-18 16:12:41 +08:00
|
|
|
|
Child = valueText = new OsuSpriteText
|
2017-09-08 01:53:53 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2020-02-17 04:43:33 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 12)
|
2017-09-08 01:53:53 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|