From 02e2b8546c4089598a60fe99e18a813b59e7ea1b Mon Sep 17 00:00:00 2001 From: Givikap120 Date: Fri, 8 Sep 2023 20:32:55 +0300 Subject: [PATCH] fixed all stated problems --- osu.Game/Beatmaps/BeatmapShortInfo.cs | 29 ------- ...oContainer.cs => ModEffectPreviewPanel.cs} | 82 +++++++++++++++---- osu.Game/Overlays/Mods/ModSelectOverlay.cs | 38 +++++---- osu.Game/Screens/Select/BeatmapDetails.cs | 1 - .../Screens/Select/Details/AdvancedStats.cs | 33 -------- osu.Game/Screens/Select/SongSelect.cs | 5 +- 6 files changed, 90 insertions(+), 98 deletions(-) delete mode 100644 osu.Game/Beatmaps/BeatmapShortInfo.cs rename osu.Game/Overlays/Mods/{ModMapInfoContainer.cs => ModEffectPreviewPanel.cs} (75%) diff --git a/osu.Game/Beatmaps/BeatmapShortInfo.cs b/osu.Game/Beatmaps/BeatmapShortInfo.cs deleted file mode 100644 index 633e12d1b2..0000000000 --- a/osu.Game/Beatmaps/BeatmapShortInfo.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using System; - -namespace osu.Game.Beatmaps -{ - public class BeatmapShortInfo : IEquatable - { - public StarDifficulty StarDifficulty; - public float CircleSize; - public float DrainRate; - public float ApproachRate; - public float OverallDifficulty; - public double BPM; - public bool Equals(BeatmapShortInfo? other) - { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; - - return StarDifficulty.Stars == other.StarDifficulty.Stars && - CircleSize.Equals(other.CircleSize) && - DrainRate.Equals(other.DrainRate) && - ApproachRate.Equals(other.ApproachRate) && - OverallDifficulty.Equals(other.OverallDifficulty) && - BPM.Equals(other.BPM); - } - } -} diff --git a/osu.Game/Overlays/Mods/ModMapInfoContainer.cs b/osu.Game/Overlays/Mods/ModEffectPreviewPanel.cs similarity index 75% rename from osu.Game/Overlays/Mods/ModMapInfoContainer.cs rename to osu.Game/Overlays/Mods/ModEffectPreviewPanel.cs index 281fe8abe5..b6a8dfe827 100644 --- a/osu.Game/Overlays/Mods/ModMapInfoContainer.cs +++ b/osu.Game/Overlays/Mods/ModEffectPreviewPanel.cs @@ -1,8 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - +using System.Collections.Generic; +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.LocalisationExtensions; @@ -16,12 +16,14 @@ using osu.Game.Beatmaps.Drawables; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; +using osu.Game.Rulesets.Mods; using osuTK; using osuTK.Graphics; +using System.Threading; namespace osu.Game.Overlays.Mods { - public partial class ModMapInfoContainer : Container + public partial class ModEffectPreviewPanel : CompositeDrawable { private Container content; private Container innerContent; @@ -37,13 +39,37 @@ namespace osu.Game.Overlays.Mods private VerticalAttributeDisplay approachRateDisplay; private VerticalAttributeDisplay overallDifficultyDisplay; - [Resolved] - private OverlayColourProvider colourProvider { get; set; } + public const float HEIGHT = 50; // as ModSelectOverlay footer buttons + private const float transition_duration = 250; + + private IBeatmapInfo beatmapInfo = null!; + + public IBeatmapInfo BeatmapInfo + { + get => beatmapInfo; + set + { + if (value == beatmapInfo) return; + + beatmapInfo = value; + updateStarDifficultyBind(); + UpdateValues(); + } + } [Resolved] - private Bindable adjustedInfo { get; set; } + private Bindable> mods { get; set; } = null!; - public ModMapInfoContainer() + [Resolved] + private OverlayColourProvider colourProvider { get; set; } = null!; + + [Resolved] + private BeatmapDifficultyCache difficultyCache { get; set; } = null!; + + private CancellationTokenSource cancellationSource = null!; + private IBindable starDifficulty = null!; + + public ModEffectPreviewPanel() { // values as ModSelectOverlay footer buttons const float shear = ShearedOverlayContainer.SHEAR; @@ -56,7 +82,7 @@ namespace osu.Game.Overlays.Mods Origin = Anchor.BottomRight, Anchor = Anchor.BottomRight, AutoSizeAxes = Axes.X, - Height = 50, // as ModSelectOverlay footer buttons + Height = HEIGHT, Shear = new Vector2(shear, 0), CornerRadius = corner_radius, BorderThickness = border_thickness, @@ -146,27 +172,47 @@ namespace osu.Game.Overlays.Mods } protected override void LoadComplete() { - adjustedInfo.BindValueChanged(e => { UpdateValues(); }, true); - background.Colour = colourProvider.Background4; innerBackground.Colour = colourProvider.Background3; Color4 glow_colour = colourProvider.Background1; content.BorderColour = ColourInfo.GradientVertical(background.Colour, glow_colour); innerContent.BorderColour = ColourInfo.GradientVertical(innerBackground.Colour, glow_colour); - } + updateStarDifficultyBind(); + } + private void updateStarDifficultyBind() + { + if (cancellationSource != null) cancellationSource.Cancel(); + starDifficulty = difficultyCache.GetBindableDifficulty(beatmapInfo, (cancellationSource = new CancellationTokenSource()).Token); + starDifficulty.BindValueChanged(s => + { + starRatingDisplay.Current.Value = s.NewValue ?? default; + + if (!starRatingDisplay.IsPresent) + starRatingDisplay.FinishTransforms(true); + + starRatingDisplay.FadeIn(transition_duration); + }); + } public void UpdateValues() { - if (adjustedInfo.Value == null) return; + if (beatmapInfo == null) return; - starRatingDisplay.Current.Value = adjustedInfo.Value.StarDifficulty; - bpmDisplay.Current.Value = adjustedInfo.Value.BPM; + double rate = 1; + foreach (var mod in mods.Value.OfType()) + rate = mod.ApplyToRate(0, rate); - circleSizeDisplay.Current.Value = adjustedInfo.Value.CircleSize; - drainRateDisplay.Current.Value = adjustedInfo.Value.DrainRate; - approachRateDisplay.Current.Value = adjustedInfo.Value.ApproachRate; - overallDifficultyDisplay.Current.Value = adjustedInfo.Value.OverallDifficulty; + bpmDisplay.Current.Value = beatmapInfo.BPM * rate; + + BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(BeatmapInfo.Difficulty); + foreach (var mod in mods.Value.OfType()) + mod.ApplyToDifficulty(adjustedDifficulty); + + circleSizeDisplay.Current.Value = adjustedDifficulty.CircleSize; + drainRateDisplay.Current.Value = adjustedDifficulty.DrainRate; + approachRateDisplay.Current.Value = adjustedDifficulty.ApproachRate; + overallDifficultyDisplay.Current.Value = adjustedDifficulty.OverallDifficulty; } private partial class BPMDisplay : RollingCounter diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index 8de4447b31..4989c55d49 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -17,6 +17,7 @@ using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Framework.Utils; using osu.Game.Audio; +using osu.Game.Beatmaps; using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Containers; @@ -27,7 +28,6 @@ using osu.Game.Localisation; using osu.Game.Rulesets.Mods; using osu.Game.Utils; using osuTK; -using osuTK.Graphics; using osuTK.Input; namespace osu.Game.Overlays.Mods @@ -125,7 +125,7 @@ namespace osu.Game.Overlays.Mods private Container aboveColumnsContent = null!; private DifficultyMultiplierDisplay? multiplierDisplay; - private ModMapInfoContainer mapInfoContainer = null!; + private ModEffectPreviewPanel modEffectPreviewPanel = null!; protected ShearedButton BackButton { get; private set; } = null!; protected ShearedToggleButton? CustomisationButton { get; private set; } @@ -133,6 +133,20 @@ namespace osu.Game.Overlays.Mods private Sample? columnAppearSample; + private WorkingBeatmap beatmap = null!; + + public WorkingBeatmap Beatmap + { + get => beatmap; + set + { + if (beatmap == value) return; + + beatmap = value; + modEffectPreviewPanel.BeatmapInfo = beatmap.BeatmapInfo; + } + } + protected ModSelectOverlay(OverlayColourScheme colourScheme = OverlayColourScheme.Green) : base(colourScheme) { @@ -224,11 +238,11 @@ namespace osu.Game.Overlays.Mods FooterContent.Children = new Drawable[] { - mapInfoContainer = new ModMapInfoContainer + modEffectPreviewPanel = new ModEffectPreviewPanel { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, - Padding = new MarginPadding + Margin = new MarginPadding { Vertical = PADDING, Horizontal = 70 @@ -286,7 +300,7 @@ namespace osu.Game.Overlays.Mods SelectedMods.BindValueChanged(_ => { - updateMapInfo(); + modEffectPreviewPanel.UpdateValues(); updateMultiplier(); updateFromExternalSelection(); updateCustomisation(); @@ -300,7 +314,11 @@ namespace osu.Game.Overlays.Mods // // See https://github.com/ppy/osu/pull/23284#issuecomment-1529056988 modSettingChangeTracker = new ModSettingChangeTracker(SelectedMods.Value); - modSettingChangeTracker.SettingChanged += _ => updateMultiplier(); + modSettingChangeTracker.SettingChanged += _ => + { + modEffectPreviewPanel.UpdateValues(); + updateMultiplier(); + }; } }, true); @@ -416,14 +434,6 @@ namespace osu.Game.Overlays.Mods multiplierDisplay.Current.Value = multiplier; } - private void updateMapInfo() - { - if (mapInfoContainer == null) - return; - - mapInfoContainer.UpdateValues(); - } - private void updateCustomisation() { if (CustomisationButton == null) diff --git a/osu.Game/Screens/Select/BeatmapDetails.cs b/osu.Game/Screens/Select/BeatmapDetails.cs index 6ebdca1b8d..712b610515 100644 --- a/osu.Game/Screens/Select/BeatmapDetails.cs +++ b/osu.Game/Screens/Select/BeatmapDetails.cs @@ -3,7 +3,6 @@ using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Game/Screens/Select/Details/AdvancedStats.cs b/osu.Game/Screens/Select/Details/AdvancedStats.cs index a12323ab70..f77ed28dae 100644 --- a/osu.Game/Screens/Select/Details/AdvancedStats.cs +++ b/osu.Game/Screens/Select/Details/AdvancedStats.cs @@ -46,9 +46,6 @@ namespace osu.Game.Screens.Select.Details private IBeatmapInfo beatmapInfo; - [Resolved(canBeNull: true)] - private Bindable adjustedInfo { get; set; } = null; - public IBeatmapInfo BeatmapInfo { get => beatmapInfo; @@ -101,33 +98,6 @@ namespace osu.Game.Screens.Select.Details private ModSettingChangeTracker modSettingChangeTracker; private ScheduledDelegate debouncedStatisticsUpdate; - - private StarDifficulty latestStarDifficulty = new StarDifficulty(); - private void updateBindedInfo() - { - if (adjustedInfo == null) return; - - // sadly need to calculate this to prevent additional data transportation - double rate = 1; - foreach (var mod in mods.Value.OfType()) - rate = mod.ApplyToRate(0, rate); - - double bpm = 0; - if (beatmapInfo != null) bpm = beatmapInfo.BPM * rate; - - BeatmapShortInfo adjusted = new BeatmapShortInfo() - { - CircleSize = FirstValue.Value.adjustedValue ?? FirstValue.Value.baseValue, - DrainRate = HpDrain.Value.adjustedValue ?? HpDrain.Value.baseValue, - ApproachRate = ApproachRate.Value.adjustedValue ?? ApproachRate.Value.baseValue, - OverallDifficulty = Accuracy.Value.adjustedValue ?? Accuracy.Value.baseValue, - BPM = bpm, - StarDifficulty = latestStarDifficulty - }; - - adjustedInfo.Value = adjusted; - } - private void modsChanged(ValueChangedEvent> mods) { modSettingChangeTracker?.Dispose(); @@ -174,7 +144,6 @@ namespace osu.Game.Screens.Select.Details Accuracy.Value = (baseDifficulty?.OverallDifficulty ?? 0, adjustedDifficulty?.OverallDifficulty); ApproachRate.Value = (baseDifficulty?.ApproachRate ?? 0, adjustedDifficulty?.ApproachRate); - updateBindedInfo(); // to faster UI response (without SR calculation) updateStarDifficulty(); } @@ -208,8 +177,6 @@ namespace osu.Game.Screens.Select.Details return; starDifficulty.Value = ((float)normalDifficulty.Value.Stars, (float)moddedDifficulty.Value.Stars); - latestStarDifficulty = moddedDifficulty ?? default; - updateBindedInfo(); }), starDifficultyCancellationSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current); }); diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 7749e3937a..f9d41f98ea 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -99,9 +99,6 @@ namespace osu.Game.Screens.Select [Resolved] private Bindable> selectedMods { get; set; } = null!; - [Cached] - private Bindable adjustedInfo { get; set; } = new Bindable(); - protected BeatmapCarousel Carousel { get; private set; } = null!; private ParallaxContainer wedgeBackground = null!; @@ -786,6 +783,8 @@ namespace osu.Game.Screens.Select BeatmapDetails.Beatmap = beatmap; + ModSelect.Beatmap = beatmap; + bool beatmapSelected = beatmap is not DummyWorkingBeatmap; if (beatmapSelected)