2022-03-01 14:40:19 +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-03-01 15:59:33 +08:00
|
|
|
using osu.Framework.Allocation;
|
2022-03-01 14:40:19 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-03-01 15:59:33 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Database;
|
2022-03-01 14:40:19 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Overlays.Settings;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2022-03-01 15:14:57 +08:00
|
|
|
using osu.Game.Scoring;
|
2022-03-01 14:40:19 +08:00
|
|
|
using osu.Game.Screens.Ranking.Statistics;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.PlayerSettings
|
|
|
|
{
|
|
|
|
public class BeatmapOffsetControl : CompositeDrawable
|
|
|
|
{
|
2022-03-01 15:14:57 +08:00
|
|
|
public Bindable<ScoreInfo> ReferenceScore { get; } = new Bindable<ScoreInfo>();
|
2022-03-01 14:40:19 +08:00
|
|
|
|
|
|
|
public Bindable<double> Current { get; } = new BindableDouble
|
|
|
|
{
|
|
|
|
Default = 0,
|
|
|
|
Value = 0,
|
|
|
|
MinValue = -50,
|
|
|
|
MaxValue = 50,
|
|
|
|
Precision = 0.1,
|
|
|
|
};
|
|
|
|
|
2022-03-01 15:14:57 +08:00
|
|
|
private SettingsButton useAverageButton;
|
|
|
|
|
|
|
|
private double lastPlayAverage;
|
|
|
|
|
|
|
|
private readonly FillFlowContainer referenceScoreContainer;
|
|
|
|
|
|
|
|
public BeatmapOffsetControl()
|
2022-03-01 14:40:19 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
2022-03-01 15:14:57 +08:00
|
|
|
InternalChild = new FillFlowContainer
|
2022-03-01 14:40:19 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(10),
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new PlayerSliderBar<double>
|
|
|
|
{
|
|
|
|
KeyboardStep = 5,
|
|
|
|
LabelText = "Beatmap offset",
|
|
|
|
Current = Current,
|
|
|
|
},
|
2022-03-01 15:14:57 +08:00
|
|
|
referenceScoreContainer = new FillFlowContainer
|
2022-03-01 14:40:19 +08:00
|
|
|
{
|
2022-03-01 15:14:57 +08:00
|
|
|
Spacing = new Vector2(10),
|
|
|
|
Direction = FillDirection.Vertical,
|
2022-03-01 14:40:19 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2022-03-01 15:14:57 +08:00
|
|
|
AutoSizeAxes = Axes.Y,
|
2022-03-01 14:40:19 +08:00
|
|
|
},
|
2022-03-01 15:14:57 +08:00
|
|
|
}
|
|
|
|
};
|
2022-03-01 15:59:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private RealmAccess realm { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private IBindable<WorkingBeatmap> beatmap { get; set; }
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-03-01 15:14:57 +08:00
|
|
|
|
|
|
|
ReferenceScore.BindValueChanged(scoreChanged, true);
|
2022-03-01 14:40:19 +08:00
|
|
|
|
2022-03-01 15:59:33 +08:00
|
|
|
Current.BindValueChanged(currentChanged);
|
|
|
|
Current.Value = realm.Run(r => r.Find<BeatmapInfo>(beatmap.Value.BeatmapInfo.ID).UserSettings?.Offset) ?? 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void currentChanged(ValueChangedEvent<double> offset)
|
|
|
|
{
|
|
|
|
if (useAverageButton != null)
|
2022-03-01 14:40:19 +08:00
|
|
|
{
|
2022-03-01 15:59:33 +08:00
|
|
|
useAverageButton.Enabled.Value = offset.NewValue != lastPlayAverage;
|
|
|
|
}
|
|
|
|
|
|
|
|
realm.Write(r =>
|
|
|
|
{
|
|
|
|
var settings = r.Find<BeatmapInfo>(beatmap.Value.BeatmapInfo.ID).UserSettings;
|
|
|
|
|
|
|
|
settings.Offset = offset.NewValue;
|
|
|
|
});
|
2022-03-01 14:40:19 +08:00
|
|
|
}
|
2022-03-01 15:14:57 +08:00
|
|
|
|
|
|
|
private void scoreChanged(ValueChangedEvent<ScoreInfo> score)
|
|
|
|
{
|
|
|
|
if (!(score.NewValue?.HitEvents.CalculateAverageHitError() is double average))
|
|
|
|
{
|
|
|
|
referenceScoreContainer.Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastPlayAverage = average;
|
|
|
|
|
|
|
|
referenceScoreContainer.Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = "Last play:"
|
|
|
|
},
|
|
|
|
new HitEventTimingDistributionGraph(score.NewValue.HitEvents)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = 50,
|
|
|
|
},
|
|
|
|
new AverageHitError(score.NewValue.HitEvents),
|
|
|
|
useAverageButton = new SettingsButton
|
|
|
|
{
|
|
|
|
Text = "Calibrate using last play",
|
|
|
|
Action = () => Current.Value = lastPlayAverage
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2022-03-01 14:40:19 +08:00
|
|
|
}
|
|
|
|
}
|