diff --git a/osu.Game/Overlays/Mods/ModMapInfoContainer.cs b/osu.Game/Overlays/Mods/ModMapInfoContainer.cs new file mode 100644 index 0000000000..eb5291b0a8 --- /dev/null +++ b/osu.Game/Overlays/Mods/ModMapInfoContainer.cs @@ -0,0 +1,58 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +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; +using osu.Framework.Graphics.Shapes; +using osu.Game.Beatmaps; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using osu.Game.Online; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; +using osu.Game.Overlays.BeatmapSet; +using osu.Game.Resources.Localisation.Web; +using osu.Game.Screens.Select.Details; +using osuTK; +using osuTK.Graphics; + +namespace osu.Game.Overlays.Mods +{ + public partial class ModMapInfoContainer : Container + { + private ModMapInfoDisplay starRatingDisplay = null!; + + [Resolved] + private OsuColour colours { get; set; } = null!; + + [Resolved] + private Bindable adjustedInfo { get; set; } = null!; + private Bindable starRatingValue = new Bindable(); + + //public ModMapInfoContainer() + //{ + // + //} + + protected override void LoadComplete() + { + starRatingDisplay = new ModMapInfoDisplay("Star Rating", colours.ForStarDifficulty); + starRatingDisplay.Current.BindTo(starRatingValue); + + Content.Add(starRatingDisplay); + + adjustedInfo.BindValueChanged(e => { updateValues(); }, true); + } + + private void updateValues() + { + starRatingValue.Value = adjustedInfo.Value.StarRating; + } + } +} diff --git a/osu.Game/Overlays/Mods/ModMapInfoDisplay.cs b/osu.Game/Overlays/Mods/ModMapInfoDisplay.cs index 20666391d6..ca815984ce 100644 --- a/osu.Game/Overlays/Mods/ModMapInfoDisplay.cs +++ b/osu.Game/Overlays/Mods/ModMapInfoDisplay.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.LocalisationExtensions; @@ -12,14 +13,13 @@ using osu.Framework.Localisation; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.UserInterface; -using osu.Game.Screens.Select.Details; using osu.Game.Localisation; using osuTK; namespace osu.Game.Overlays.Mods { - public partial class ModMapInfoDisplay : Container, IHasCurrentValue + public partial class ModMapInfoDisplay : Container, IHasCurrentValue { public const float HEIGHT = 42; private const float transition_duration = 200; @@ -28,36 +28,40 @@ namespace osu.Game.Overlays.Mods private readonly Box labelBackground; private readonly FillFlowContainer content; - public Bindable Current - { - get => current.Current; - set => current.Current = value; - } - private readonly BindableWithCurrent current = new BindableWithCurrent(); + //public Bindable Current + //{ + // get => current.Current; + // set => current.Current = value; + //} + //private readonly BindableWithCurrent current = new BindableWithCurrent(); - [Resolved] - private OsuColour colours { get; set; } = null!; + public Bindable Current { get; set; } = new BindableWithCurrent(); + + //[Resolved] + //private OsuColour colours { get; set; } = null!; [Resolved] private OverlayColourProvider colourProvider { get; set; } = null!; + protected Func GetColor; + /// /// Text to display in the left area of the display. /// - //protected abstract LocalisableString Label { get; } - protected LocalisableString Label => CommonStrings.Finish; - //protected string Label { get; } + protected LocalisableString Label; protected virtual float ValueAreaWidth => 56; - protected virtual string CounterFormat => @"N0"; + protected virtual string CounterFormat => @"0.00"; protected override Container Content => content; protected readonly RollingCounter Counter; - public ModMapInfoDisplay() + public ModMapInfoDisplay(LocalisableString label, Func colorFunc) { + Label = label; + GetColor = colorFunc; Height = HEIGHT; AutoSizeAxes = Axes.X; @@ -125,7 +129,7 @@ namespace osu.Game.Overlays.Mods { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - Current = { BindTarget = Current.Value.StarRating } + Current = { BindTarget = Current } } } } @@ -146,39 +150,17 @@ namespace osu.Game.Overlays.Mods Current.BindValueChanged(e => { //var effect = CalculateEffectForComparison(e.NewValue.CompareTo(Current.Default)); - setColours(e.NewValue.StarRating.Value); + setColours(e.NewValue); }, true); } /// /// Fades colours of text and its background according to displayed value. /// - /// random number. - private void setColours(double stars) + /// value + private void setColours(double value) { - contentBackground.FadeColour(colours.ForStarDifficulty(stars), transition_duration, Easing.OutQuint); - } - - /// - /// Converts signed integer into . Negative values are counted as difficulty reduction, positive as increase. - /// - /// Value to convert. Will arrive from comparison between bindable once it changes and it's . - /// Effect of the value. - protected virtual ModEffect CalculateEffectForComparison(int comparison) - { - if (comparison == 0) - return ModEffect.NotChanged; - if (comparison < 0) - return ModEffect.DifficultyReduction; - - return ModEffect.DifficultyIncrease; - } - - protected enum ModEffect - { - NotChanged, - DifficultyReduction, - DifficultyIncrease + contentBackground.FadeColour(GetColor(value), transition_duration, Easing.OutQuint); } private partial class EffectCounter : RollingCounter diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index ef5f6cf323..a178f2e9dc 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -25,9 +25,9 @@ using osu.Game.Graphics.UserInterface; using osu.Game.Input.Bindings; using osu.Game.Localisation; using osu.Game.Rulesets.Mods; -using osu.Game.Screens.Select.Details; using osu.Game.Utils; using osuTK; +using osuTK.Graphics; using osuTK.Input; namespace osu.Game.Overlays.Mods @@ -124,7 +124,8 @@ namespace osu.Game.Overlays.Mods private Container aboveColumnsContent = null!; private DifficultyMultiplierDisplay? multiplierDisplay; - private ModMapInfoDisplay mapInfoDisplay = null!; + + private ModMapInfoContainer mapInfoContainer = null!; protected ShearedButton BackButton { get; private set; } = null!; protected ShearedToggleButton? CustomisationButton { get; private set; } @@ -221,7 +222,7 @@ namespace osu.Game.Overlays.Mods }); } - aboveColumnsContent.Add(mapInfoDisplay = new ModMapInfoDisplay + aboveColumnsContent.Add(mapInfoContainer = new ModMapInfoContainer { Anchor = Anchor.TopLeft, Origin = Anchor.TopLeft @@ -251,11 +252,6 @@ namespace osu.Game.Overlays.Mods globalAvailableMods.BindTo(game.AvailableMods); } - - public void SetBindedMapStats(Bindable stats) - { - mapInfoDisplay.Current = stats; - } public override void Hide() { base.Hide(); @@ -282,6 +278,7 @@ namespace osu.Game.Overlays.Mods SelectedMods.BindValueChanged(_ => { + updateMapInfo(); updateMultiplier(); updateFromExternalSelection(); updateCustomisation(); @@ -413,8 +410,10 @@ namespace osu.Game.Overlays.Mods private void updateMapInfo() { - if (mapInfoDisplay == null) + if (mapInfoContainer == null) return; + + //mapInfoDisplay.Current.Value = 5; } private void updateCustomisation() diff --git a/osu.Game/Screens/Select/BeatmapDetailArea.cs b/osu.Game/Screens/Select/BeatmapDetailArea.cs index 595b86924b..d43831e576 100644 --- a/osu.Game/Screens/Select/BeatmapDetailArea.cs +++ b/osu.Game/Screens/Select/BeatmapDetailArea.cs @@ -4,6 +4,7 @@ #nullable disable using System; +using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -30,6 +31,9 @@ namespace osu.Game.Screens.Select public readonly BeatmapDetails Details; + //[Cached] + //public Bindable AdjustedInfo { get; private set; } = new Bindable(); + protected Bindable CurrentTab => tabControl.Current; protected Bindable CurrentModsFilter => tabControl.CurrentModsFilter; diff --git a/osu.Game/Screens/Select/BeatmapDetails.cs b/osu.Game/Screens/Select/BeatmapDetails.cs index c56411bef5..6ebdca1b8d 100644 --- a/osu.Game/Screens/Select/BeatmapDetails.cs +++ b/osu.Game/Screens/Select/BeatmapDetails.cs @@ -274,11 +274,6 @@ namespace osu.Game.Screens.Select loading.Hide(); } - public Bindable GetBindedAdjustedMapStats() - { - return advanced.AdjustedMapStats.GetBoundCopy(); - } - private partial class DetailBox : Container { private readonly Container content; diff --git a/osu.Game/Screens/Select/Details/AdvancedStats.cs b/osu.Game/Screens/Select/Details/AdvancedStats.cs index 016e4ff2df..8f609888df 100644 --- a/osu.Game/Screens/Select/Details/AdvancedStats.cs +++ b/osu.Game/Screens/Select/Details/AdvancedStats.cs @@ -46,6 +46,11 @@ namespace osu.Game.Screens.Select.Details private IBeatmapInfo beatmapInfo; +#nullable enable + [Resolved] + private Bindable? adjustedInfo { get; set; } = null; +#nullable disable + public IBeatmapInfo BeatmapInfo { get => beatmapInfo; @@ -99,6 +104,21 @@ namespace osu.Game.Screens.Select.Details private ModSettingChangeTracker modSettingChangeTracker; private ScheduledDelegate debouncedStatisticsUpdate; + private void updateBindedInfo() + { + if (adjustedInfo == null) return; + + BeatmapInfo adjusted = (BeatmapInfo)beatmapInfo; + adjusted.Difficulty.CircleSize = FirstValue.Value.adjustedValue ?? 0; + adjusted.Difficulty.DrainRate = HpDrain.Value.adjustedValue ?? 0; + adjusted.Difficulty.ApproachRate = ApproachRate.Value.adjustedValue ?? 5; + adjusted.Difficulty.OverallDifficulty = Accuracy.Value.adjustedValue ?? 0; + adjusted.StarRating = starDifficulty.Value.adjustedValue ?? 0; + + adjustedInfo.Value = adjusted; + adjustedInfo.TriggerChange(); + } + private void modsChanged(ValueChangedEvent> mods) { modSettingChangeTracker?.Dispose(); @@ -113,8 +133,6 @@ namespace osu.Game.Screens.Select.Details updateStatistics(); } - public Bindable AdjustedMapStats = new Bindable(); - private void updateStatistics() { IBeatmapDifficultyInfo baseDifficulty = BeatmapInfo?.Difficulty; @@ -149,13 +167,6 @@ namespace osu.Game.Screens.Select.Details updateStarDifficulty(); - var temp = AdjustedMapStats.Value; - temp.CS.Value = FirstValue.Value.adjustedValue ?? 0; - temp.HP.Value = HpDrain.Value.adjustedValue ?? 0; - temp.OD.Value = Accuracy.Value.adjustedValue ?? 0; - temp.AR.Value = ApproachRate.Value.adjustedValue ?? 5; - AdjustedMapStats.Value = temp; - } private CancellationTokenSource starDifficultyCancellationSource; @@ -188,10 +199,7 @@ namespace osu.Game.Screens.Select.Details return; starDifficulty.Value = ((float)normalDifficulty.Value.Stars, (float)moddedDifficulty.Value.Stars); - - var temp = AdjustedMapStats.Value; - temp.StarRating.Value = moddedDifficulty.Value.Stars; - AdjustedMapStats.Value = temp; + updateBindedInfo(); }), starDifficultyCancellationSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current); }); @@ -311,10 +319,4 @@ namespace osu.Game.Screens.Select.Details } } } - public struct MapStats - { - public Bindable StarRating; - public Bindable MinBPM, MaxBPM, AvgBPM; - public Bindable CS, HP, AR, OD; - } } diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 17b1b1f870..4567869e8e 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -99,6 +99,9 @@ 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!; @@ -305,8 +308,8 @@ namespace osu.Game.Screens.Select // therein it will be registered at the `OsuGame` level to properly function as a blocking overlay. LoadComponent(ModSelect = CreateModSelectOverlay()); - var bindedStats = BeatmapDetails.Details.GetBindedAdjustedMapStats(); - ModSelect.SetBindedMapStats(bindedStats); + //var bindedStats = BeatmapDetails.Details.GetBindedAdjustedMapStats(); + //ModSelect.SetBindedMapStats(bindedStats); if (Footer != null) { @@ -583,6 +586,7 @@ namespace osu.Game.Screens.Select FilterControl.Activate(); ModSelect.SelectedMods.BindTo(selectedMods); + //BeatmapDetails.AdjustedInfo.BindTo(adjustedInfo); beginLooping(); }