mirror of
https://github.com/ppy/osu.git
synced 2024-11-15 02:17:46 +08:00
Refactor preview panel to be more self-contained
This commit is contained in:
parent
c1a2b86f3f
commit
f591a30ea7
@ -20,6 +20,7 @@ using osu.Game.Rulesets.Mods;
|
|||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Mods
|
namespace osu.Game.Overlays.Mods
|
||||||
{
|
{
|
||||||
@ -41,24 +42,13 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
private const float transition_duration = 250;
|
private const float transition_duration = 250;
|
||||||
|
|
||||||
private IBeatmapInfo? beatmapInfo;
|
public Bindable<IBeatmapInfo?> BeatmapInfo { get; } = new Bindable<IBeatmapInfo?>();
|
||||||
|
|
||||||
public IBeatmapInfo? BeatmapInfo
|
|
||||||
{
|
|
||||||
get => beatmapInfo;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == beatmapInfo) return;
|
|
||||||
|
|
||||||
beatmapInfo = value;
|
|
||||||
updateStarDifficultyBind();
|
|
||||||
UpdateValues();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private Bindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
|
private Bindable<IReadOnlyList<Mod>> mods { get; set; } = null!;
|
||||||
|
|
||||||
|
private ModSettingChangeTracker? modSettingChangeTracker;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OverlayColourProvider colourProvider { get; set; } = null!;
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
||||||
|
|
||||||
@ -178,16 +168,25 @@ namespace osu.Game.Overlays.Mods
|
|||||||
content.BorderColour = ColourInfo.GradientVertical(background.Colour, glowColour);
|
content.BorderColour = ColourInfo.GradientVertical(background.Colour, glowColour);
|
||||||
innerContent.BorderColour = ColourInfo.GradientVertical(innerBackground.Colour, glowColour);
|
innerContent.BorderColour = ColourInfo.GradientVertical(innerBackground.Colour, glowColour);
|
||||||
|
|
||||||
updateStarDifficultyBind();
|
BeatmapInfo.BindValueChanged(_ => updateValues(), true);
|
||||||
|
|
||||||
|
mods.BindValueChanged(_ =>
|
||||||
|
{
|
||||||
|
modSettingChangeTracker?.Dispose();
|
||||||
|
|
||||||
|
modSettingChangeTracker = new ModSettingChangeTracker(mods.Value);
|
||||||
|
modSettingChangeTracker.SettingChanged += _ => updateValues();
|
||||||
|
updateValues();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateStarDifficultyBind()
|
private void updateValues() => Scheduler.AddOnce(() =>
|
||||||
{
|
{
|
||||||
if (beatmapInfo == null)
|
if (BeatmapInfo.Value == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cancellationSource?.Cancel();
|
cancellationSource?.Cancel();
|
||||||
starDifficulty = difficultyCache.GetBindableDifficulty(beatmapInfo, (cancellationSource = new CancellationTokenSource()).Token);
|
starDifficulty = difficultyCache.GetBindableDifficulty(BeatmapInfo.Value, (cancellationSource = new CancellationTokenSource()).Token);
|
||||||
starDifficulty.BindValueChanged(s =>
|
starDifficulty.BindValueChanged(s =>
|
||||||
{
|
{
|
||||||
starRatingDisplay.Current.Value = s.NewValue ?? default;
|
starRatingDisplay.Current.Value = s.NewValue ?? default;
|
||||||
@ -197,20 +196,14 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
starRatingDisplay.FadeIn(transition_duration);
|
starRatingDisplay.FadeIn(transition_duration);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateValues()
|
|
||||||
{
|
|
||||||
if (beatmapInfo == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
double rate = 1;
|
double rate = 1;
|
||||||
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
|
foreach (var mod in mods.Value.OfType<IApplicableToRate>())
|
||||||
rate = mod.ApplyToRate(0, rate);
|
rate = mod.ApplyToRate(0, rate);
|
||||||
|
|
||||||
bpmDisplay.Current.Value = beatmapInfo.BPM * rate;
|
bpmDisplay.Current.Value = BeatmapInfo.Value.BPM * rate;
|
||||||
|
|
||||||
BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(beatmapInfo.Difficulty);
|
BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(BeatmapInfo.Value.Difficulty);
|
||||||
foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
|
foreach (var mod in mods.Value.OfType<IApplicableToDifficulty>())
|
||||||
mod.ApplyToDifficulty(adjustedDifficulty);
|
mod.ApplyToDifficulty(adjustedDifficulty);
|
||||||
|
|
||||||
@ -218,7 +211,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
drainRateDisplay.Current.Value = adjustedDifficulty.DrainRate;
|
drainRateDisplay.Current.Value = adjustedDifficulty.DrainRate;
|
||||||
approachRateDisplay.Current.Value = adjustedDifficulty.ApproachRate;
|
approachRateDisplay.Current.Value = adjustedDifficulty.ApproachRate;
|
||||||
overallDifficultyDisplay.Current.Value = adjustedDifficulty.OverallDifficulty;
|
overallDifficultyDisplay.Current.Value = adjustedDifficulty.OverallDifficulty;
|
||||||
}
|
});
|
||||||
|
|
||||||
private partial class BPMDisplay : RollingCounter<double>
|
private partial class BPMDisplay : RollingCounter<double>
|
||||||
{
|
{
|
||||||
|
@ -143,7 +143,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
if (beatmap == value) return;
|
if (beatmap == value) return;
|
||||||
|
|
||||||
beatmap = value;
|
beatmap = value;
|
||||||
modEffectPreviewPanel.BeatmapInfo = beatmap.BeatmapInfo;
|
modEffectPreviewPanel.BeatmapInfo.Value = beatmap.BeatmapInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +300,6 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
SelectedMods.BindValueChanged(_ =>
|
SelectedMods.BindValueChanged(_ =>
|
||||||
{
|
{
|
||||||
modEffectPreviewPanel.UpdateValues();
|
|
||||||
updateMultiplier();
|
updateMultiplier();
|
||||||
updateFromExternalSelection();
|
updateFromExternalSelection();
|
||||||
updateCustomisation();
|
updateCustomisation();
|
||||||
@ -314,11 +313,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
//
|
//
|
||||||
// See https://github.com/ppy/osu/pull/23284#issuecomment-1529056988
|
// See https://github.com/ppy/osu/pull/23284#issuecomment-1529056988
|
||||||
modSettingChangeTracker = new ModSettingChangeTracker(SelectedMods.Value);
|
modSettingChangeTracker = new ModSettingChangeTracker(SelectedMods.Value);
|
||||||
modSettingChangeTracker.SettingChanged += _ =>
|
modSettingChangeTracker.SettingChanged += _ => updateMultiplier();
|
||||||
{
|
|
||||||
modEffectPreviewPanel.UpdateValues();
|
|
||||||
updateMultiplier();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user