From 8a1fc7c340070e1f04d5ffca1488cfde70a054be Mon Sep 17 00:00:00 2001 From: Givikap120 Date: Sat, 26 Aug 2023 01:20:41 +0300 Subject: [PATCH] Basic stuff (not working for now) --- osu.Game/Overlays/Mods/ModMapInfoDisplay.cs | 203 ++++++++++++++++++ osu.Game/Overlays/Mods/ModSelectOverlay.cs | 18 ++ osu.Game/Screens/Select/BeatmapDetails.cs | 6 + .../Screens/Select/Details/AdvancedStats.cs | 21 ++ osu.Game/Screens/Select/SongSelect.cs | 3 + 5 files changed, 251 insertions(+) create mode 100644 osu.Game/Overlays/Mods/ModMapInfoDisplay.cs diff --git a/osu.Game/Overlays/Mods/ModMapInfoDisplay.cs b/osu.Game/Overlays/Mods/ModMapInfoDisplay.cs new file mode 100644 index 0000000000..20666391d6 --- /dev/null +++ b/osu.Game/Overlays/Mods/ModMapInfoDisplay.cs @@ -0,0 +1,203 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Extensions.LocalisationExtensions; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.UserInterface; +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 const float HEIGHT = 42; + private const float transition_duration = 200; + + private readonly Box contentBackground; + private readonly Box labelBackground; + private readonly FillFlowContainer content; + + public Bindable Current + { + get => current.Current; + set => current.Current = value; + } + private readonly BindableWithCurrent current = new BindableWithCurrent(); + + [Resolved] + private OsuColour colours { get; set; } = null!; + + [Resolved] + private OverlayColourProvider colourProvider { get; set; } = null!; + + /// + /// 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 virtual float ValueAreaWidth => 56; + + protected virtual string CounterFormat => @"N0"; + + protected override Container Content => content; + + protected readonly RollingCounter Counter; + + public ModMapInfoDisplay() + { + Height = HEIGHT; + AutoSizeAxes = Axes.X; + + InternalChild = new InputBlockingContainer + { + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + Masking = true, + CornerRadius = ModSelectPanel.CORNER_RADIUS, + Shear = new Vector2(ShearedOverlayContainer.SHEAR, 0), + Children = new Drawable[] + { + contentBackground = new Box + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + RelativeSizeAxes = Axes.Y, + Width = ValueAreaWidth + ModSelectPanel.CORNER_RADIUS + }, + new GridContainer + { + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + ColumnDimensions = new[] + { + new Dimension(GridSizeMode.AutoSize), + new Dimension(GridSizeMode.Absolute, ValueAreaWidth) + }, + Content = new[] + { + new Drawable[] + { + new Container + { + RelativeSizeAxes = Axes.Y, + AutoSizeAxes = Axes.X, + Masking = true, + CornerRadius = ModSelectPanel.CORNER_RADIUS, + Children = new Drawable[] + { + labelBackground = new Box + { + RelativeSizeAxes = Axes.Both + }, + new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Margin = new MarginPadding { Horizontal = 18 }, + Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0), + Text = Label, + Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold) + } + } + }, + content = new FillFlowContainer + { + AutoSizeAxes = Axes.Both, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Direction = FillDirection.Horizontal, + Shear = new Vector2(-ShearedOverlayContainer.SHEAR, 0), + Spacing = new Vector2(2, 0), + Child = Counter = new EffectCounter(CounterFormat) + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Current = { BindTarget = Current.Value.StarRating } + } + } + } + } + } + } + }; + } + + [BackgroundDependencyLoader] + private void load() + { + labelBackground.Colour = colourProvider.Background4; + } + + protected override void LoadComplete() + { + Current.BindValueChanged(e => + { + //var effect = CalculateEffectForComparison(e.NewValue.CompareTo(Current.Default)); + setColours(e.NewValue.StarRating.Value); + }, true); + } + + /// + /// Fades colours of text and its background according to displayed value. + /// + /// random number. + private void setColours(double stars) + { + 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 + } + + private partial class EffectCounter : RollingCounter + { + private readonly string? format; + + public EffectCounter(string? format) + { + this.format = format; + } + + protected override double RollingDuration => 500; + + protected override LocalisableString FormatCount(double count) => count.ToLocalisableString(format); + + protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText + { + Font = OsuFont.Default.With(size: 17, weight: FontWeight.SemiBold) + }; + } + } +} diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index 9e92e9d959..ef5f6cf323 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -25,6 +25,7 @@ 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.Input; @@ -123,6 +124,7 @@ namespace osu.Game.Overlays.Mods private Container aboveColumnsContent = null!; private DifficultyMultiplierDisplay? multiplierDisplay; + private ModMapInfoDisplay mapInfoDisplay = null!; protected ShearedButton BackButton { get; private set; } = null!; protected ShearedToggleButton? CustomisationButton { get; private set; } @@ -219,6 +221,12 @@ namespace osu.Game.Overlays.Mods }); } + aboveColumnsContent.Add(mapInfoDisplay = new ModMapInfoDisplay + { + Anchor = Anchor.TopLeft, + Origin = Anchor.TopLeft + }); + FooterContent.Child = footerButtonFlow = new FillFlowContainer { RelativeSizeAxes = Axes.X, @@ -244,6 +252,10 @@ namespace osu.Game.Overlays.Mods globalAvailableMods.BindTo(game.AvailableMods); } + public void SetBindedMapStats(Bindable stats) + { + mapInfoDisplay.Current = stats; + } public override void Hide() { base.Hide(); @@ -399,6 +411,12 @@ namespace osu.Game.Overlays.Mods multiplierDisplay.Current.Value = multiplier; } + private void updateMapInfo() + { + if (mapInfoDisplay == null) + return; + } + private void updateCustomisation() { if (CustomisationButton == null) diff --git a/osu.Game/Screens/Select/BeatmapDetails.cs b/osu.Game/Screens/Select/BeatmapDetails.cs index 712b610515..c56411bef5 100644 --- a/osu.Game/Screens/Select/BeatmapDetails.cs +++ b/osu.Game/Screens/Select/BeatmapDetails.cs @@ -3,6 +3,7 @@ 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; @@ -273,6 +274,11 @@ 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 a383298faa..016e4ff2df 100644 --- a/osu.Game/Screens/Select/Details/AdvancedStats.cs +++ b/osu.Game/Screens/Select/Details/AdvancedStats.cs @@ -113,6 +113,8 @@ namespace osu.Game.Screens.Select.Details updateStatistics(); } + public Bindable AdjustedMapStats = new Bindable(); + private void updateStatistics() { IBeatmapDifficultyInfo baseDifficulty = BeatmapInfo?.Difficulty; @@ -146,6 +148,14 @@ namespace osu.Game.Screens.Select.Details ApproachRate.Value = (baseDifficulty?.ApproachRate ?? 0, adjustedDifficulty?.ApproachRate); 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; @@ -178,6 +188,11 @@ 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; + }), starDifficultyCancellationSource.Token, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Current); }); @@ -296,4 +311,10 @@ 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 58755878d0..17b1b1f870 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -305,6 +305,9 @@ 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); + if (Footer != null) { foreach (var (button, overlay) in CreateFooterButtons())