From bbb22479a8aefd1b040d236dde395c0220ed4bc4 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Sun, 25 Dec 2022 21:32:47 +0100 Subject: [PATCH 01/25] Add "ModBubbles" for the osu ruleset. --- .../Mods/TestSceneOsuModBubbles.cs | 19 ++ osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 228 ++++++++++++++++++ osu.Game.Rulesets.Osu/OsuRuleset.cs | 3 +- osu.Game/Rulesets/Mods/ModFlashlight.cs | 3 + 4 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModBubbles.cs create mode 100644 osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModBubbles.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModBubbles.cs new file mode 100644 index 0000000000..e72a1f79f5 --- /dev/null +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModBubbles.cs @@ -0,0 +1,19 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Game.Rulesets.Osu.Mods; + +namespace osu.Game.Rulesets.Osu.Tests.Mods +{ + public partial class TestSceneOsuModBubbles : OsuModTestScene + { + [Test] + public void TestOsuModBubbles() => CreateModTest(new ModTestData + { + Mod = new OsuModBubbles(), + Autoplay = true, + PassCondition = () => true + }); + } +} diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs new file mode 100644 index 0000000000..c51ebde383 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -0,0 +1,228 @@ +// 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 System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Effects; +using osu.Framework.Graphics.Performance; +using osu.Framework.Graphics.Pooling; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Localisation; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Objects.Pooling; +using osu.Game.Rulesets.Osu.Objects; +using osu.Game.Rulesets.Osu.Objects.Drawables; +using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.UI; +using osu.Game.Scoring; +using osuTK; + +namespace osu.Game.Rulesets.Osu.Mods +{ + public partial class OsuModBubbles : ModWithVisibilityAdjustment, IApplicableToDrawableRuleset, IApplicableToScoreProcessor + { + public override string Name => "Bubbles"; + + public override string Acronym => "BB"; + + public override LocalisableString Description => "Dont let their popping distract you!"; + + public override double ScoreMultiplier => 1; + + public override ModType Type => ModType.Fun; + + // Compatibility with these seems potentially feasible in the future, blocked for now because they dont work as one would expect + public override Type[] IncompatibleMods => new[] { typeof(OsuModBarrelRoll), typeof(OsuModMagnetised), typeof(OsuModRepel) }; + + private PlayfieldAdjustmentContainer adjustmentContainer = null!; + private BubbleContainer bubbleContainer = null!; + + private readonly Bindable currentCombo = new BindableInt(); + + private float maxSize; + private float bubbleRadius; + private double bubbleFade; + + public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank; + + public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor) + { + currentCombo.BindTo(scoreProcessor.Combo); + currentCombo.BindValueChanged(combo => + maxSize = Math.Min(1.75f, (float)(1.25 + 0.005 * combo.NewValue)), true); + } + + public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) + { + // Multiplying by 2 results in an initial size that is too large, hence 1.85 has been chosen + bubbleRadius = (float)(drawableRuleset.Beatmap.HitObjects.OfType().First().Radius * 1.85f); + bubbleFade = drawableRuleset.Beatmap.HitObjects.OfType().First().TimeFadeIn * 2; + + // We want to hide the judgements since they are obscured by the BubbleDrawable (due to layering) + drawableRuleset.Playfield.DisplayJudgements.Value = false; + + adjustmentContainer = drawableRuleset.CreatePlayfieldAdjustmentContainer(); + + adjustmentContainer.Add(bubbleContainer = new BubbleContainer()); + drawableRuleset.KeyBindingInputManager.Add(adjustmentContainer); + } + + protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state) => applyBubbleState(hitObject); + + protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state) => applyBubbleState(hitObject); + + private void applyBubbleState(DrawableHitObject drawableObject) + { + if (drawableObject is not DrawableOsuHitObject drawableOsuObject || !drawableObject.Judged) return; + + OsuHitObject hitObject = drawableOsuObject.HitObject; + + switch (drawableOsuObject) + { + //Needs to be done explicitly to avoid being handled by DrawableHitCircle below + case DrawableSliderHead: + addBubbleContainer(hitObject.Position); + break; + + //Stack leniency causes placement issues if this isn't handled as such. + case DrawableHitCircle hitCircle: + addBubbleContainer(hitCircle.Position); + break; + + case DrawableSpinnerTick: + case DrawableSlider: + return; + + default: + addBubbleContainer(hitObject.Position); + break; + } + + void addBubbleContainer(Vector2 position) => bubbleContainer.Add(new BubbleLifeTimeEntry + { + LifetimeStart = bubbleContainer.Time.Current, + Colour = drawableOsuObject.AccentColour.Value, + Position = position, + InitialSize = new Vector2(bubbleRadius), + MaxSize = maxSize, + FadeTime = bubbleFade, + IsHit = drawableOsuObject.IsHit + } + ); + } + + #region Pooled Bubble drawable + + //LifetimeEntry flow is necessary to allow for correct rewind behaviour, can probably be made generic later if more mods are made requiring it + //Todo: find solution to bubbles rewinding in "groups" + private sealed partial class BubbleContainer : PooledDrawableWithLifetimeContainer + { + protected override bool RemoveRewoundEntry => true; + + private readonly DrawablePool pool; + + public BubbleContainer() + { + RelativeSizeAxes = Axes.Both; + AddInternal(pool = new DrawablePool(10, 1000)); + } + + protected override BubbleObject GetDrawable(BubbleLifeTimeEntry entry) => pool.Get(d => d.Apply(entry)); + } + + private sealed partial class BubbleObject : PoolableDrawableWithLifetime + { + private readonly BubbleDrawable bubbleDrawable; + + public BubbleObject() + { + InternalChild = bubbleDrawable = new BubbleDrawable(); + } + + protected override void OnApply(BubbleLifeTimeEntry entry) + { + base.OnApply(entry); + if (IsLoaded) + apply(entry); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + apply(Entry); + } + + private void apply(BubbleLifeTimeEntry? entry) + { + if (entry == null) + return; + + ApplyTransformsAt(float.MinValue, true); + ClearTransforms(true); + + Position = entry.Position; + + bubbleDrawable.Animate(entry); + + LifetimeEnd = bubbleDrawable.LatestTransformEndTime; + } + } + + private partial class BubbleDrawable : CompositeDrawable + { + [BackgroundDependencyLoader] + private void load() + { + InternalChild = new Circle + { + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Masking = true, + EdgeEffect = new EdgeEffectParameters + { + Colour = Colour4.Black.Opacity(0.05f), + Type = EdgeEffectType.Shadow, + Radius = 5 + } + }; + } + + public void Animate(BubbleLifeTimeEntry entry) + { + Size = entry.InitialSize; + this + .ScaleTo(entry.MaxSize, entry.FadeTime * 6, Easing.OutSine) + .FadeColour(entry.IsHit ? entry.Colour : Colour4.Black, entry.FadeTime, Easing.OutSine) + .Delay(entry.FadeTime) + .FadeColour(entry.IsHit ? entry.Colour.Darken(.4f) : Colour4.Black, entry.FadeTime * 5, Easing.OutSine) + .Then() + .ScaleTo(entry.MaxSize * 1.5f, entry.FadeTime, Easing.OutSine) + .FadeTo(0, entry.FadeTime, Easing.OutQuint); + } + } + + private class BubbleLifeTimeEntry : LifetimeEntry + { + public Vector2 InitialSize { get; set; } + + public float MaxSize { get; set; } + + public Vector2 Position { get; set; } + + public Colour4 Colour { get; set; } + + // FadeTime is based on the approach rate of the beatmap. + public double FadeTime { get; set; } + + // Whether the corresponding HitObject was hit + public bool IsHit { get; set; } + } + + #endregion + } +} diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 79a566e33c..0df1e4dfca 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -202,7 +202,8 @@ namespace osu.Game.Rulesets.Osu new OsuModNoScope(), new MultiMod(new OsuModMagnetised(), new OsuModRepel()), new ModAdaptiveSpeed(), - new OsuModFreezeFrame() + new OsuModFreezeFrame(), + new OsuModBubbles() }; case ModType.System: diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index 45fa55c7f2..2c9ef357b5 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -83,6 +83,9 @@ namespace osu.Game.Rulesets.Mods flashlight.Combo.BindTo(Combo); drawableRuleset.KeyBindingInputManager.Add(flashlight); + + // Stop flashlight from being drawn underneath other mods that generate HitObjects. + drawableRuleset.KeyBindingInputManager.ChangeChildDepth(flashlight, -1); } protected abstract Flashlight CreateFlashlight(); From 8a108b143e10bf80162eb0109aad7a68ae9692fc Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Sun, 25 Dec 2022 21:33:10 +0100 Subject: [PATCH 02/25] Address mod incompatibilities --- osu.Game.Rulesets.Osu/Mods/OsuModBarrelRoll.cs | 3 +++ osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 17 +++++++++++------ osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs | 2 +- osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBarrelRoll.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBarrelRoll.cs index 9e71f657ce..2394cf92fc 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBarrelRoll.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBarrelRoll.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.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects; @@ -10,6 +11,8 @@ namespace osu.Game.Rulesets.Osu.Mods { public class OsuModBarrelRoll : ModBarrelRoll, IApplicableToDrawableHitObject { + public override Type[] IncompatibleMods => new[] { typeof(OsuModBubbles) }; + public void ApplyToDrawableHitObject(DrawableHitObject d) { d.OnUpdate += _ => diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index c51ebde383..2e4d574148 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -86,12 +86,12 @@ namespace osu.Game.Rulesets.Osu.Mods { //Needs to be done explicitly to avoid being handled by DrawableHitCircle below case DrawableSliderHead: - addBubbleContainer(hitObject.Position); + addBubbleContainer(hitObject.Position, drawableOsuObject); break; //Stack leniency causes placement issues if this isn't handled as such. case DrawableHitCircle hitCircle: - addBubbleContainer(hitCircle.Position); + addBubbleContainer(hitCircle.Position, drawableOsuObject); break; case DrawableSpinnerTick: @@ -99,19 +99,24 @@ namespace osu.Game.Rulesets.Osu.Mods return; default: - addBubbleContainer(hitObject.Position); + addBubbleContainer(hitObject.Position, drawableOsuObject); break; } + } - void addBubbleContainer(Vector2 position) => bubbleContainer.Add(new BubbleLifeTimeEntry + private void addBubbleContainer(Vector2 position, DrawableHitObject hitObject) + { + bubbleContainer.Add + ( + new BubbleLifeTimeEntry { LifetimeStart = bubbleContainer.Time.Current, - Colour = drawableOsuObject.AccentColour.Value, + Colour = hitObject.AccentColour.Value, Position = position, InitialSize = new Vector2(bubbleRadius), MaxSize = maxSize, FadeTime = bubbleFade, - IsHit = drawableOsuObject.IsHit + IsHit = hitObject.IsHit } ); } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs b/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs index 38d90eb121..c8c4cd6a14 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModMagnetised.cs @@ -27,7 +27,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override ModType Type => ModType.Fun; public override LocalisableString Description => "No need to chase the circles – your cursor is a magnet!"; public override double ScoreMultiplier => 0.5; - public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModRelax), typeof(OsuModRepel) }; + public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModRelax), typeof(OsuModRepel), typeof(OsuModBubbles) }; [SettingSource("Attraction strength", "How strong the pull is.", 0)] public BindableFloat AttractionStrength { get; } = new BindableFloat(0.5f) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs b/osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs index 31a6b69d6b..28d459cedb 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModRepel.cs @@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override ModType Type => ModType.Fun; public override LocalisableString Description => "Hit objects run away!"; public override double ScoreMultiplier => 1; - public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModMagnetised) }; + public override Type[] IncompatibleMods => new[] { typeof(OsuModAutopilot), typeof(OsuModWiggle), typeof(OsuModTransform), typeof(ModAutoplay), typeof(OsuModMagnetised), typeof(OsuModBubbles) }; [SettingSource("Repulsion strength", "How strong the repulsion is.", 0)] public BindableFloat RepulsionStrength { get; } = new BindableFloat(0.5f) From ca84b885dcc6695cb7da3549757f7e6338bc37de Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Wed, 11 Jan 2023 17:51:41 +0100 Subject: [PATCH 03/25] Add more detail to bubbles --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 58 ++++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 2e4d574148..f5e7e035b2 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -12,6 +12,7 @@ using osu.Framework.Graphics.Performance; using osu.Framework.Graphics.Pooling; using osu.Framework.Graphics.Shapes; using osu.Framework.Localisation; +using osu.Game.Graphics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Pooling; @@ -21,6 +22,7 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Scoring; using osuTK; +using osuTK.Graphics; namespace osu.Game.Rulesets.Osu.Mods { @@ -178,21 +180,38 @@ namespace osu.Game.Rulesets.Osu.Mods } } - private partial class BubbleDrawable : CompositeDrawable + private partial class BubbleDrawable : CompositeDrawable, IHasAccentColour { + public Color4 AccentColour { get; set; } + + private Circle outerCircle = null!; + private Circle innerCircle = null!; + [BackgroundDependencyLoader] private void load() { - InternalChild = new Circle + InternalChildren = new Drawable[] { - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Masking = true, - EdgeEffect = new EdgeEffectParameters + outerCircle = new Circle { - Colour = Colour4.Black.Opacity(0.05f), - Type = EdgeEffectType.Shadow, - Radius = 5 + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Masking = true, + MaskingSmoothness = 2, + BorderThickness = 0, + BorderColour = Colour4.Transparent, + EdgeEffect = new EdgeEffectParameters + { + Type = EdgeEffectType.Shadow, + Radius = 3, + Colour = Colour4.Black.Opacity(0.05f) + } + }, + innerCircle = new Circle + { + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + Scale = new Vector2(0.5f) } }; } @@ -202,12 +221,25 @@ namespace osu.Game.Rulesets.Osu.Mods Size = entry.InitialSize; this .ScaleTo(entry.MaxSize, entry.FadeTime * 6, Easing.OutSine) - .FadeColour(entry.IsHit ? entry.Colour : Colour4.Black, entry.FadeTime, Easing.OutSine) - .Delay(entry.FadeTime) - .FadeColour(entry.IsHit ? entry.Colour.Darken(.4f) : Colour4.Black, entry.FadeTime * 5, Easing.OutSine) .Then() .ScaleTo(entry.MaxSize * 1.5f, entry.FadeTime, Easing.OutSine) - .FadeTo(0, entry.FadeTime, Easing.OutQuint); + .FadeTo(0, entry.FadeTime, Easing.OutExpo); + + animateCircles(entry); + } + + private void animateCircles(BubbleLifeTimeEntry entry) + { + innerCircle.FadeColour(entry.IsHit ? entry.Colour.Darken(0.2f) : Colour4.Black) + .FadeColour(entry.IsHit ? entry.Colour.Lighten(0.2f) : Colour4.Black, entry.FadeTime * 7); + + innerCircle.FadeTo(0.5f, entry.FadeTime * 7, Easing.InExpo) + .ScaleTo(1.1f, entry.FadeTime * 7, Easing.InSine); + + outerCircle + .FadeColour(entry.IsHit ? entry.Colour : Colour4.Black, entry.FadeTime, Easing.OutSine) + .Delay(entry.FadeTime) + .FadeColour(entry.IsHit ? entry.Colour.Darken(.4f) : Colour4.Black, entry.FadeTime * 5, Easing.OutSine); } } From 7c81f1e75bb40981a55f16a3544d9521280bf49c Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Fri, 27 Jan 2023 11:21:11 +0100 Subject: [PATCH 04/25] Remove unnecessary BDL from bubble drawable Improve animation duration formula --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 85 +++++++++------------ 1 file changed, 38 insertions(+), 47 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index f5e7e035b2..6613d84e0e 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -3,7 +3,6 @@ using System; using System.Linq; -using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -12,7 +11,6 @@ using osu.Framework.Graphics.Performance; using osu.Framework.Graphics.Pooling; using osu.Framework.Graphics.Shapes; using osu.Framework.Localisation; -using osu.Game.Graphics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Pooling; @@ -22,7 +20,6 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Scoring; using osuTK; -using osuTK.Graphics; namespace osu.Game.Rulesets.Osu.Mods { @@ -63,7 +60,7 @@ namespace osu.Game.Rulesets.Osu.Mods { // Multiplying by 2 results in an initial size that is too large, hence 1.85 has been chosen bubbleRadius = (float)(drawableRuleset.Beatmap.HitObjects.OfType().First().Radius * 1.85f); - bubbleFade = drawableRuleset.Beatmap.HitObjects.OfType().First().TimeFadeIn * 2; + bubbleFade = drawableRuleset.Beatmap.HitObjects.OfType().First().TimePreempt * 2; // We want to hide the judgements since they are obscured by the BubbleDrawable (due to layering) drawableRuleset.Playfield.DisplayJudgements.Value = false; @@ -125,8 +122,8 @@ namespace osu.Game.Rulesets.Osu.Mods #region Pooled Bubble drawable - //LifetimeEntry flow is necessary to allow for correct rewind behaviour, can probably be made generic later if more mods are made requiring it - //Todo: find solution to bubbles rewinding in "groups" + // LifetimeEntry flow is necessary to allow for correct rewind behaviour, can probably be made generic later if more mods are made requiring it + // Todo: find solution to bubbles rewinding in "groups" private sealed partial class BubbleContainer : PooledDrawableWithLifetimeContainer { protected override bool RemoveRewoundEntry => true; @@ -166,8 +163,7 @@ namespace osu.Game.Rulesets.Osu.Mods private void apply(BubbleLifeTimeEntry? entry) { - if (entry == null) - return; + if (entry == null) return; ApplyTransformsAt(float.MinValue, true); ClearTransforms(true); @@ -180,38 +176,36 @@ namespace osu.Game.Rulesets.Osu.Mods } } - private partial class BubbleDrawable : CompositeDrawable, IHasAccentColour + private partial class BubbleDrawable : CircularContainer { - public Color4 AccentColour { get; set; } + private readonly Circle innerCircle; + private readonly Box colourBox; - private Circle outerCircle = null!; - private Circle innerCircle = null!; - - [BackgroundDependencyLoader] - private void load() + public BubbleDrawable() { - InternalChildren = new Drawable[] + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + + Masking = true; + MaskingSmoothness = 2; + BorderThickness = 0; + BorderColour = Colour4.Transparent; + EdgeEffect = new EdgeEffectParameters { - outerCircle = new Circle - { - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Masking = true, - MaskingSmoothness = 2, - BorderThickness = 0, - BorderColour = Colour4.Transparent, - EdgeEffect = new EdgeEffectParameters - { - Type = EdgeEffectType.Shadow, - Radius = 3, - Colour = Colour4.Black.Opacity(0.05f) - } - }, + Type = EdgeEffectType.Shadow, + Radius = 3, + Colour = Colour4.Black.Opacity(0.05f) + }; + + Children = new Drawable[] + { + colourBox = new Box { RelativeSizeAxes = Axes.Both, }, innerCircle = new Circle { + Anchor = Anchor.Centre, Origin = Anchor.Centre, RelativeSizeAxes = Axes.Both, - Scale = new Vector2(0.5f) + Size = new Vector2(0.5f), } }; } @@ -219,27 +213,24 @@ namespace osu.Game.Rulesets.Osu.Mods public void Animate(BubbleLifeTimeEntry entry) { Size = entry.InitialSize; - this - .ScaleTo(entry.MaxSize, entry.FadeTime * 6, Easing.OutSine) + + this.ScaleTo(entry.MaxSize, getAnimationTime() * 0.8f, Easing.OutSine) .Then() - .ScaleTo(entry.MaxSize * 1.5f, entry.FadeTime, Easing.OutSine) - .FadeTo(0, entry.FadeTime, Easing.OutExpo); + .ScaleTo(entry.MaxSize * 1.5f, getAnimationTime() * 0.2f, Easing.OutSine) + .FadeTo(0, getAnimationTime() * 0.2f, Easing.OutExpo); - animateCircles(entry); - } + colourBox.FadeColour(entry.IsHit ? entry.Colour : Colour4.Black, getAnimationTime() * 0.1f, Easing.OutSine) + .Then() + .FadeColour(entry.IsHit ? entry.Colour.Darken(0.4f) : Colour4.Black, getAnimationTime() * 0.9f, Easing.OutSine); - private void animateCircles(BubbleLifeTimeEntry entry) - { innerCircle.FadeColour(entry.IsHit ? entry.Colour.Darken(0.2f) : Colour4.Black) - .FadeColour(entry.IsHit ? entry.Colour.Lighten(0.2f) : Colour4.Black, entry.FadeTime * 7); + .FadeColour(entry.IsHit ? entry.Colour.Lighten(0.2f) : Colour4.Black, getAnimationTime()); - innerCircle.FadeTo(0.5f, entry.FadeTime * 7, Easing.InExpo) - .ScaleTo(1.1f, entry.FadeTime * 7, Easing.InSine); + innerCircle.FadeTo(0.5f, getAnimationTime(), Easing.InExpo) + .ScaleTo(2.2f, getAnimationTime(), Easing.InSine); - outerCircle - .FadeColour(entry.IsHit ? entry.Colour : Colour4.Black, entry.FadeTime, Easing.OutSine) - .Delay(entry.FadeTime) - .FadeColour(entry.IsHit ? entry.Colour.Darken(.4f) : Colour4.Black, entry.FadeTime * 5, Easing.OutSine); + // The absolute length of the bubble's animation, can be used in fractions for animations of partial length + double getAnimationTime() => 2000 + 450 / (450 / entry.FadeTime); } } From c3090dea5f7bea51e2662cd82fc292d65c56d7ca Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Sat, 28 Jan 2023 00:30:30 +0100 Subject: [PATCH 05/25] Simplify animations --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 28 +++++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 6613d84e0e..479741b5b9 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -214,23 +214,29 @@ namespace osu.Game.Rulesets.Osu.Mods { Size = entry.InitialSize; - this.ScaleTo(entry.MaxSize, getAnimationTime() * 0.8f, Easing.OutSine) + //We want to fade to a darker colour to avoid colours such as white hiding the "ripple" effect. + var colourDarker = entry.Colour.Darken(0.1f); + + this.ScaleTo(entry.MaxSize, getAnimationDuration() * 0.8f, Easing.OutSine) .Then() - .ScaleTo(entry.MaxSize * 1.5f, getAnimationTime() * 0.2f, Easing.OutSine) - .FadeTo(0, getAnimationTime() * 0.2f, Easing.OutExpo); + .ScaleTo(entry.MaxSize * 1.5f, getAnimationDuration() * 0.2f, Easing.OutSine) + .FadeTo(0, getAnimationDuration() * 0.2f, Easing.OutExpo); - colourBox.FadeColour(entry.IsHit ? entry.Colour : Colour4.Black, getAnimationTime() * 0.1f, Easing.OutSine) - .Then() - .FadeColour(entry.IsHit ? entry.Colour.Darken(0.4f) : Colour4.Black, getAnimationTime() * 0.9f, Easing.OutSine); + innerCircle.ScaleTo(2f, getAnimationDuration() * 0.8f, Easing.OutCubic); - innerCircle.FadeColour(entry.IsHit ? entry.Colour.Darken(0.2f) : Colour4.Black) - .FadeColour(entry.IsHit ? entry.Colour.Lighten(0.2f) : Colour4.Black, getAnimationTime()); + if (!entry.IsHit) + { + colourBox.Colour = Colour4.Black; + innerCircle.Colour = Colour4.Black; - innerCircle.FadeTo(0.5f, getAnimationTime(), Easing.InExpo) - .ScaleTo(2.2f, getAnimationTime(), Easing.InSine); + return; + } + + colourBox.FadeColour(colourDarker, getAnimationDuration() * 0.2f, Easing.OutQuint); + innerCircle.FadeColour(colourDarker); // The absolute length of the bubble's animation, can be used in fractions for animations of partial length - double getAnimationTime() => 2000 + 450 / (450 / entry.FadeTime); + double getAnimationDuration() => 1700 + Math.Pow(entry.FadeTime, 1.15f); } } From 66da4c0288fd63d87fa7b4ea3547da39796e74e7 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Sat, 28 Jan 2023 17:38:24 +0100 Subject: [PATCH 06/25] Add colouration to the sliders to better match the vibrancy of the mod --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 27 +++++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 479741b5b9..0101427f7a 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -16,6 +16,7 @@ using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Pooling; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects.Drawables; +using osu.Game.Rulesets.Osu.Skinning.Default; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Scoring; @@ -77,6 +78,12 @@ namespace osu.Game.Rulesets.Osu.Mods private void applyBubbleState(DrawableHitObject drawableObject) { + if (drawableObject is DrawableSlider slider) + { + slider.Body.OnSkinChanged += () => applySliderState(slider); + applySliderState(slider); + } + if (drawableObject is not DrawableOsuHitObject drawableOsuObject || !drawableObject.Judged) return; OsuHitObject hitObject = drawableOsuObject.HitObject; @@ -93,9 +100,9 @@ namespace osu.Game.Rulesets.Osu.Mods addBubbleContainer(hitCircle.Position, drawableOsuObject); break; - case DrawableSpinnerTick: case DrawableSlider: - return; + case DrawableSpinnerTick: + break; default: addBubbleContainer(hitObject.Position, drawableOsuObject); @@ -103,6 +110,9 @@ namespace osu.Game.Rulesets.Osu.Mods } } + private void applySliderState(DrawableSlider slider) => + ((PlaySliderBody)slider.Body.Drawable).BorderColour = slider.AccentColour.Value; + private void addBubbleContainer(Vector2 position, DrawableHitObject hitObject) { bubbleContainer.Add @@ -217,12 +227,12 @@ namespace osu.Game.Rulesets.Osu.Mods //We want to fade to a darker colour to avoid colours such as white hiding the "ripple" effect. var colourDarker = entry.Colour.Darken(0.1f); - this.ScaleTo(entry.MaxSize, getAnimationDuration() * 0.8f, Easing.OutSine) + this.ScaleTo(entry.MaxSize, getAnimationDuration() * 0.8f) .Then() - .ScaleTo(entry.MaxSize * 1.5f, getAnimationDuration() * 0.2f, Easing.OutSine) - .FadeTo(0, getAnimationDuration() * 0.2f, Easing.OutExpo); + .ScaleTo(entry.MaxSize * 1.5f, getAnimationDuration() * 0.2f, Easing.OutQuint) + .FadeTo(0, getAnimationDuration() * 0.2f, Easing.OutQuint); - innerCircle.ScaleTo(2f, getAnimationDuration() * 0.8f, Easing.OutCubic); + innerCircle.ScaleTo(2f, getAnimationDuration() * 0.8f, Easing.OutQuint); if (!entry.IsHit) { @@ -232,11 +242,12 @@ namespace osu.Game.Rulesets.Osu.Mods return; } - colourBox.FadeColour(colourDarker, getAnimationDuration() * 0.2f, Easing.OutQuint); + colourBox.FadeColour(colourDarker, getAnimationDuration() * 0.2f, Easing.OutQuint + ); innerCircle.FadeColour(colourDarker); // The absolute length of the bubble's animation, can be used in fractions for animations of partial length - double getAnimationDuration() => 1700 + Math.Pow(entry.FadeTime, 1.15f); + double getAnimationDuration() => 1700 + Math.Pow(entry.FadeTime, 1.07f); } } From 3bdf83bf44e63000d2a4c23c7467a1aa24b87724 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Sat, 28 Jan 2023 22:44:57 +0100 Subject: [PATCH 07/25] Redo the drawable structure of bubbledrawable to run and look better --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 50 ++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 0101427f7a..2c90bfa399 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -5,6 +5,7 @@ using System; using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Performance; @@ -93,7 +94,7 @@ namespace osu.Game.Rulesets.Osu.Mods //Needs to be done explicitly to avoid being handled by DrawableHitCircle below case DrawableSliderHead: addBubbleContainer(hitObject.Position, drawableOsuObject); - break; + return; //Stack leniency causes placement issues if this isn't handled as such. case DrawableHitCircle hitCircle: @@ -188,7 +189,6 @@ namespace osu.Game.Rulesets.Osu.Mods private partial class BubbleDrawable : CircularContainer { - private readonly Circle innerCircle; private readonly Box colourBox; public BubbleDrawable() @@ -196,55 +196,55 @@ namespace osu.Game.Rulesets.Osu.Mods Anchor = Anchor.Centre; Origin = Anchor.Centre; - Masking = true; MaskingSmoothness = 2; BorderThickness = 0; - BorderColour = Colour4.Transparent; + BorderColour = Colour4.White; + Masking = true; EdgeEffect = new EdgeEffectParameters { Type = EdgeEffectType.Shadow, Radius = 3, Colour = Colour4.Black.Opacity(0.05f) }; - - Children = new Drawable[] - { - colourBox = new Box { RelativeSizeAxes = Axes.Both, }, - innerCircle = new Circle - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - Size = new Vector2(0.5f), - } - }; + Child = colourBox = new Box { RelativeSizeAxes = Axes.Both, }; } public void Animate(BubbleLifeTimeEntry entry) { Size = entry.InitialSize; + BorderThickness = Width / 3.5f; //We want to fade to a darker colour to avoid colours such as white hiding the "ripple" effect. - var colourDarker = entry.Colour.Darken(0.1f); + ColourInfo colourDarker = entry.Colour.Darken(0.1f); + // Main bubble scaling based on combo this.ScaleTo(entry.MaxSize, getAnimationDuration() * 0.8f) .Then() + // Pop at the end of the bubbles life time .ScaleTo(entry.MaxSize * 1.5f, getAnimationDuration() * 0.2f, Easing.OutQuint) - .FadeTo(0, getAnimationDuration() * 0.2f, Easing.OutQuint); - - innerCircle.ScaleTo(2f, getAnimationDuration() * 0.8f, Easing.OutQuint); + .FadeTo(0, getAnimationDuration() * 0.2f, Easing.OutCirc); if (!entry.IsHit) { - colourBox.Colour = Colour4.Black; - innerCircle.Colour = Colour4.Black; + Colour = Colour4.Black; + BorderColour = Colour4.Black; return; } - colourBox.FadeColour(colourDarker, getAnimationDuration() * 0.2f, Easing.OutQuint - ); - innerCircle.FadeColour(colourDarker); + colourBox.FadeColour(colourDarker); + + this.TransformTo(nameof(BorderColour), colourDarker, getAnimationDuration() * 0.3f, Easing.OutQuint); + + // Ripple effect utilises the border to reduce drawable count + this.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration() * 0.3f, Easing.OutQuint) + + // Avoids transparency overlap issues during the bubble "pop" + .Then().Schedule(() => + { + BorderThickness = 0; + BorderColour = Colour4.Transparent; + }); // The absolute length of the bubble's animation, can be used in fractions for animations of partial length double getAnimationDuration() => 1700 + Math.Pow(entry.FadeTime, 1.07f); From abcb564a74efeb3bb9e43ee1686f402297d416b5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 6 Feb 2023 17:32:17 +0900 Subject: [PATCH 08/25] Code quality pass of `OsuModBubbles` --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 24 ++++++--------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 2c90bfa399..3606434042 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -29,15 +29,15 @@ namespace osu.Game.Rulesets.Osu.Mods { public override string Name => "Bubbles"; - public override string Acronym => "BB"; + public override string Acronym => "BU"; - public override LocalisableString Description => "Dont let their popping distract you!"; + public override LocalisableString Description => "Don't let their popping distract you!"; public override double ScoreMultiplier => 1; public override ModType Type => ModType.Fun; - // Compatibility with these seems potentially feasible in the future, blocked for now because they dont work as one would expect + // Compatibility with these seems potentially feasible in the future, blocked for now because they don't work as one would expect public override Type[] IncompatibleMods => new[] { typeof(OsuModBarrelRoll), typeof(OsuModMagnetised), typeof(OsuModRepel) }; private PlayfieldAdjustmentContainer adjustmentContainer = null!; @@ -87,26 +87,14 @@ namespace osu.Game.Rulesets.Osu.Mods if (drawableObject is not DrawableOsuHitObject drawableOsuObject || !drawableObject.Judged) return; - OsuHitObject hitObject = drawableOsuObject.HitObject; - switch (drawableOsuObject) { - //Needs to be done explicitly to avoid being handled by DrawableHitCircle below - case DrawableSliderHead: - addBubbleContainer(hitObject.Position, drawableOsuObject); - return; - - //Stack leniency causes placement issues if this isn't handled as such. - case DrawableHitCircle hitCircle: - addBubbleContainer(hitCircle.Position, drawableOsuObject); - break; - case DrawableSlider: case DrawableSpinnerTick: break; default: - addBubbleContainer(hitObject.Position, drawableOsuObject); + addBubbleForObject(drawableOsuObject); break; } } @@ -114,7 +102,7 @@ namespace osu.Game.Rulesets.Osu.Mods private void applySliderState(DrawableSlider slider) => ((PlaySliderBody)slider.Body.Drawable).BorderColour = slider.AccentColour.Value; - private void addBubbleContainer(Vector2 position, DrawableHitObject hitObject) + private void addBubbleForObject(DrawableOsuHitObject hitObject) { bubbleContainer.Add ( @@ -122,7 +110,7 @@ namespace osu.Game.Rulesets.Osu.Mods { LifetimeStart = bubbleContainer.Time.Current, Colour = hitObject.AccentColour.Value, - Position = position, + Position = hitObject.HitObject.Position, InitialSize = new Vector2(bubbleRadius), MaxSize = maxSize, FadeTime = bubbleFade, From f0d4b9f0ca339c79c74fba39f1d9a97de37f5f6e Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Mon, 6 Feb 2023 17:00:47 +0100 Subject: [PATCH 09/25] Add inline comment for colour border override --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 3606434042..41430bb323 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -99,6 +99,7 @@ namespace osu.Game.Rulesets.Osu.Mods } } + // Makes the slider border coloured on all skins private void applySliderState(DrawableSlider slider) => ((PlaySliderBody)slider.Body.Drawable).BorderColour = slider.AccentColour.Value; From 5e0c4aa904f28435bb2ffad3967f2f4fe2b08802 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Wed, 8 Feb 2023 11:12:14 +0100 Subject: [PATCH 10/25] Refactor pooling for bubbles, tweak the animations a tad, add some clarifying comments --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 231 ++++++++++---------- 1 file changed, 114 insertions(+), 117 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 41430bb323..8cf9c619d7 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -8,13 +8,11 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; -using osu.Framework.Graphics.Performance; using osu.Framework.Graphics.Pooling; using osu.Framework.Graphics.Shapes; using osu.Framework.Localisation; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Objects.Pooling; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Skinning.Default; @@ -41,7 +39,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override Type[] IncompatibleMods => new[] { typeof(OsuModBarrelRoll), typeof(OsuModMagnetised), typeof(OsuModRepel) }; private PlayfieldAdjustmentContainer adjustmentContainer = null!; - private BubbleContainer bubbleContainer = null!; + private Container bubbleContainer = null!; private readonly Bindable currentCombo = new BindableInt(); @@ -49,6 +47,10 @@ namespace osu.Game.Rulesets.Osu.Mods private float bubbleRadius; private double bubbleFade; + private readonly DrawablePool bubblePool = new DrawablePool(100); + + private DrawableOsuHitObject lastJudgedHitobject = null!; + public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank; public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor) @@ -56,6 +58,63 @@ namespace osu.Game.Rulesets.Osu.Mods currentCombo.BindTo(scoreProcessor.Combo); currentCombo.BindValueChanged(combo => maxSize = Math.Min(1.75f, (float)(1.25 + 0.005 * combo.NewValue)), true); + + scoreProcessor.NewJudgement += result => + { + if (result.HitObject is not OsuHitObject osuHitObject) return; + + DrawableOsuHitObject drawableOsuHitObject = lastJudgedHitobject; + + switch (result.HitObject) + { + case Slider: + case SpinnerTick: + break; + + default: + addBubble(); + break; + } + + void addBubble() + { + BubbleDrawable bubble = bubblePool.Get(); + bubble.Info = new BubbleInfo + { + InitialSize = new Vector2(bubbleRadius), + MaxSize = maxSize, + Position = getPosition(), + FadeTime = bubbleFade, + Colour = drawableOsuHitObject.AccentColour.Value, + IsHit = drawableOsuHitObject.IsHit, + }; + bubbleContainer.Add(bubble); + } + + Vector2 getPosition() + { + switch (drawableOsuHitObject) + { + // SliderHeads are derived from HitCircles, + // so we must handle them before to avoid them using the wrong positioning logic + case DrawableSliderHead: + return osuHitObject.Position; + + // Using hitobject position will cause issues with HitCircle placement due to stack leniency. + case DrawableHitCircle: + return drawableOsuHitObject.Position; + + default: + return osuHitObject.Position; + } + } + }; + + scoreProcessor.JudgementReverted += _ => + { + bubbleContainer.LastOrDefault()?.FinishTransforms(); + bubbleContainer.LastOrDefault()?.Expire(); + }; } public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) @@ -69,178 +128,116 @@ namespace osu.Game.Rulesets.Osu.Mods adjustmentContainer = drawableRuleset.CreatePlayfieldAdjustmentContainer(); - adjustmentContainer.Add(bubbleContainer = new BubbleContainer()); + adjustmentContainer.Add(bubbleContainer = new Container + { + RelativeSizeAxes = Axes.Both, + }); drawableRuleset.KeyBindingInputManager.Add(adjustmentContainer); } protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state) => applyBubbleState(hitObject); - protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state) => applyBubbleState(hitObject); private void applyBubbleState(DrawableHitObject drawableObject) { + DrawableOsuHitObject osuHitObject = (DrawableOsuHitObject)drawableObject; + if (drawableObject is DrawableSlider slider) { slider.Body.OnSkinChanged += () => applySliderState(slider); applySliderState(slider); } - if (drawableObject is not DrawableOsuHitObject drawableOsuObject || !drawableObject.Judged) return; + if (osuHitObject == lastJudgedHitobject || !osuHitObject.Judged) return; - switch (drawableOsuObject) + switch (osuHitObject) { case DrawableSlider: case DrawableSpinnerTick: break; default: - addBubbleForObject(drawableOsuObject); + lastJudgedHitobject = osuHitObject; break; } } - // Makes the slider border coloured on all skins + // Makes the slider border coloured on all skins (for aesthetics) private void applySliderState(DrawableSlider slider) => ((PlaySliderBody)slider.Body.Drawable).BorderColour = slider.AccentColour.Value; - private void addBubbleForObject(DrawableOsuHitObject hitObject) - { - bubbleContainer.Add - ( - new BubbleLifeTimeEntry - { - LifetimeStart = bubbleContainer.Time.Current, - Colour = hitObject.AccentColour.Value, - Position = hitObject.HitObject.Position, - InitialSize = new Vector2(bubbleRadius), - MaxSize = maxSize, - FadeTime = bubbleFade, - IsHit = hitObject.IsHit - } - ); - } - #region Pooled Bubble drawable - // LifetimeEntry flow is necessary to allow for correct rewind behaviour, can probably be made generic later if more mods are made requiring it - // Todo: find solution to bubbles rewinding in "groups" - private sealed partial class BubbleContainer : PooledDrawableWithLifetimeContainer - { - protected override bool RemoveRewoundEntry => true; - - private readonly DrawablePool pool; - - public BubbleContainer() - { - RelativeSizeAxes = Axes.Both; - AddInternal(pool = new DrawablePool(10, 1000)); - } - - protected override BubbleObject GetDrawable(BubbleLifeTimeEntry entry) => pool.Get(d => d.Apply(entry)); - } - - private sealed partial class BubbleObject : PoolableDrawableWithLifetime - { - private readonly BubbleDrawable bubbleDrawable; - - public BubbleObject() - { - InternalChild = bubbleDrawable = new BubbleDrawable(); - } - - protected override void OnApply(BubbleLifeTimeEntry entry) - { - base.OnApply(entry); - if (IsLoaded) - apply(entry); - } - - protected override void LoadComplete() - { - base.LoadComplete(); - apply(Entry); - } - - private void apply(BubbleLifeTimeEntry? entry) - { - if (entry == null) return; - - ApplyTransformsAt(float.MinValue, true); - ClearTransforms(true); - - Position = entry.Position; - - bubbleDrawable.Animate(entry); - - LifetimeEnd = bubbleDrawable.LatestTransformEndTime; - } - } - - private partial class BubbleDrawable : CircularContainer + private partial class BubbleDrawable : PoolableDrawable { private readonly Box colourBox; + private readonly CircularContainer content; + + public BubbleInfo Info { get; set; } public BubbleDrawable() { - Anchor = Anchor.Centre; Origin = Anchor.Centre; - - MaskingSmoothness = 2; - BorderThickness = 0; - BorderColour = Colour4.White; - Masking = true; - EdgeEffect = new EdgeEffectParameters + InternalChild = content = new CircularContainer { - Type = EdgeEffectType.Shadow, - Radius = 3, - Colour = Colour4.Black.Opacity(0.05f) + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Both, + MaskingSmoothness = 2, + BorderThickness = 0, + BorderColour = Colour4.White, + Masking = true, + EdgeEffect = new EdgeEffectParameters + { + Type = EdgeEffectType.Shadow, + Radius = 3, + Colour = Colour4.Black.Opacity(0.05f), + }, + Child = colourBox = new Box { RelativeSizeAxes = Axes.Both, } }; - Child = colourBox = new Box { RelativeSizeAxes = Axes.Both, }; } - public void Animate(BubbleLifeTimeEntry entry) + protected override void PrepareForUse() { - Size = entry.InitialSize; - BorderThickness = Width / 3.5f; + Alpha = 1; + Colour = Colour4.White; + Scale = new Vector2(1); + Position = Info.Position; + Size = Info.InitialSize; + content.BorderThickness = Info.InitialSize.X / 3.5f; + content.BorderColour = Colour4.White; //We want to fade to a darker colour to avoid colours such as white hiding the "ripple" effect. - ColourInfo colourDarker = entry.Colour.Darken(0.1f); + ColourInfo colourDarker = Info.Colour.Darken(0.1f); // Main bubble scaling based on combo - this.ScaleTo(entry.MaxSize, getAnimationDuration() * 0.8f) + this.ScaleTo(Info.MaxSize, getAnimationDuration() * 0.8f) .Then() // Pop at the end of the bubbles life time - .ScaleTo(entry.MaxSize * 1.5f, getAnimationDuration() * 0.2f, Easing.OutQuint) - .FadeTo(0, getAnimationDuration() * 0.2f, Easing.OutCirc); + .ScaleTo(Info.MaxSize * 1.5f, getAnimationDuration() * 0.2f, Easing.OutQuint) + .FadeOutFromOne(getAnimationDuration() * 0.2f, Easing.OutCirc).Expire(); - if (!entry.IsHit) + if (Info.IsHit) { - Colour = Colour4.Black; - BorderColour = Colour4.Black; + colourBox.FadeColour(colourDarker); + + content.TransformTo(nameof(BorderColour), colourDarker, getAnimationDuration() * 0.3f, Easing.OutQuint); + // Ripple effect utilises the border to reduce drawable count + content.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration() * 0.3f, Easing.OutQuint) + // Avoids transparency overlap issues during the bubble "pop" + .Then().Schedule(() => content.BorderThickness = 0); return; } - colourBox.FadeColour(colourDarker); - - this.TransformTo(nameof(BorderColour), colourDarker, getAnimationDuration() * 0.3f, Easing.OutQuint); - - // Ripple effect utilises the border to reduce drawable count - this.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration() * 0.3f, Easing.OutQuint) - - // Avoids transparency overlap issues during the bubble "pop" - .Then().Schedule(() => - { - BorderThickness = 0; - BorderColour = Colour4.Transparent; - }); + Colour = Colour4.Black; // The absolute length of the bubble's animation, can be used in fractions for animations of partial length - double getAnimationDuration() => 1700 + Math.Pow(entry.FadeTime, 1.07f); + double getAnimationDuration() => 1700 + Math.Pow(Info.FadeTime, 1.07f); } } - private class BubbleLifeTimeEntry : LifetimeEntry + private struct BubbleInfo { public Vector2 InitialSize { get; set; } From 6ff6e06a69256987d7a409a154c021df9988df30 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Sun, 12 Feb 2023 11:37:07 +0100 Subject: [PATCH 11/25] Simplify bubble container structure, modify some comments --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 8cf9c619d7..3e3fce5c27 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -38,8 +38,7 @@ namespace osu.Game.Rulesets.Osu.Mods // Compatibility with these seems potentially feasible in the future, blocked for now because they don't work as one would expect public override Type[] IncompatibleMods => new[] { typeof(OsuModBarrelRoll), typeof(OsuModMagnetised), typeof(OsuModRepel) }; - private PlayfieldAdjustmentContainer adjustmentContainer = null!; - private Container bubbleContainer = null!; + private PlayfieldAdjustmentContainer bubbleContainer = null!; private readonly Bindable currentCombo = new BindableInt(); @@ -119,20 +118,17 @@ namespace osu.Game.Rulesets.Osu.Mods public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) { - // Multiplying by 2 results in an initial size that is too large, hence 1.85 has been chosen - bubbleRadius = (float)(drawableRuleset.Beatmap.HitObjects.OfType().First().Radius * 1.85f); + // Multiplying by 2 results in an initial size that is too large, hence 1.90 has been chosen + // Also avoids the HitObject bleeding around the edges of the bubble drawable at minimum size + bubbleRadius = (float)(drawableRuleset.Beatmap.HitObjects.OfType().First().Radius * 1.90f); bubbleFade = drawableRuleset.Beatmap.HitObjects.OfType().First().TimePreempt * 2; // We want to hide the judgements since they are obscured by the BubbleDrawable (due to layering) drawableRuleset.Playfield.DisplayJudgements.Value = false; - adjustmentContainer = drawableRuleset.CreatePlayfieldAdjustmentContainer(); + bubbleContainer = drawableRuleset.CreatePlayfieldAdjustmentContainer(); - adjustmentContainer.Add(bubbleContainer = new Container - { - RelativeSizeAxes = Axes.Both, - }); - drawableRuleset.KeyBindingInputManager.Add(adjustmentContainer); + drawableRuleset.KeyBindingInputManager.Add(bubbleContainer); } protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state) => applyBubbleState(hitObject); From d100a4a4915b3c67c48cf790822e93da90dc02be Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Tue, 14 Feb 2023 10:12:37 +0100 Subject: [PATCH 12/25] Make `lastJudgedHitObject` nullable, and fix typo in name. --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 23 ++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 3e3fce5c27..40c235911c 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -2,8 +2,10 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using System.Linq; using osu.Framework.Bindables; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; @@ -48,7 +50,7 @@ namespace osu.Game.Rulesets.Osu.Mods private readonly DrawablePool bubblePool = new DrawablePool(100); - private DrawableOsuHitObject lastJudgedHitobject = null!; + private DrawableOsuHitObject? lastJudgedHitObject; public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank; @@ -60,9 +62,11 @@ namespace osu.Game.Rulesets.Osu.Mods scoreProcessor.NewJudgement += result => { - if (result.HitObject is not OsuHitObject osuHitObject) return; + if (result.HitObject is not OsuHitObject osuHitObject || lastJudgedHitObject.IsNull()) return; - DrawableOsuHitObject drawableOsuHitObject = lastJudgedHitobject; + Debug.Assert(result.HitObject == lastJudgedHitObject.HitObject); + + DrawableOsuHitObject drawableOsuHitObject = lastJudgedHitObject; switch (result.HitObject) { @@ -144,18 +148,9 @@ namespace osu.Game.Rulesets.Osu.Mods applySliderState(slider); } - if (osuHitObject == lastJudgedHitobject || !osuHitObject.Judged) return; + if (osuHitObject == lastJudgedHitObject || !osuHitObject.Judged) return; - switch (osuHitObject) - { - case DrawableSlider: - case DrawableSpinnerTick: - break; - - default: - lastJudgedHitobject = osuHitObject; - break; - } + lastJudgedHitObject = osuHitObject; } // Makes the slider border coloured on all skins (for aesthetics) From 2d49b5f9d66150598260451250c11736bdad87bc Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Tue, 14 Feb 2023 14:03:48 +0100 Subject: [PATCH 13/25] Move bubbles to ruleset overlays container --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 40c235911c..732626b177 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -132,7 +132,7 @@ namespace osu.Game.Rulesets.Osu.Mods bubbleContainer = drawableRuleset.CreatePlayfieldAdjustmentContainer(); - drawableRuleset.KeyBindingInputManager.Add(bubbleContainer); + drawableRuleset.Overlays.Add(bubbleContainer); } protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state) => applyBubbleState(hitObject); From 92c61c73396939363b3c6bd7ffffb083e3c74116 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Tue, 14 Feb 2023 16:31:34 +0100 Subject: [PATCH 14/25] move logic for bubble invoking to `ApplyToDrawableHitobject()`` method --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 85 +++++++++------------ 1 file changed, 34 insertions(+), 51 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 732626b177..4a8c11e7ff 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -2,10 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Diagnostics; using System.Linq; using osu.Framework.Bindables; -using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; @@ -25,7 +23,7 @@ using osuTK; namespace osu.Game.Rulesets.Osu.Mods { - public partial class OsuModBubbles : ModWithVisibilityAdjustment, IApplicableToDrawableRuleset, IApplicableToScoreProcessor + public partial class OsuModBubbles : Mod, IApplicableToDrawableRuleset, IApplicableToDrawableHitObject, IApplicableToScoreProcessor { public override string Name => "Bubbles"; @@ -50,8 +48,6 @@ namespace osu.Game.Rulesets.Osu.Mods private readonly DrawablePool bubblePool = new DrawablePool(100); - private DrawableOsuHitObject? lastJudgedHitObject; - public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank; public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor) @@ -60,15 +56,41 @@ namespace osu.Game.Rulesets.Osu.Mods currentCombo.BindValueChanged(combo => maxSize = Math.Min(1.75f, (float)(1.25 + 0.005 * combo.NewValue)), true); - scoreProcessor.NewJudgement += result => + scoreProcessor.JudgementReverted += _ => { - if (result.HitObject is not OsuHitObject osuHitObject || lastJudgedHitObject.IsNull()) return; + bubbleContainer.LastOrDefault()?.ClearTransforms(); + bubbleContainer.LastOrDefault()?.Expire(); + }; + } - Debug.Assert(result.HitObject == lastJudgedHitObject.HitObject); + public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) + { + // Multiplying by 2 results in an initial size that is too large, hence 1.90 has been chosen + // Also avoids the HitObject bleeding around the edges of the bubble drawable at minimum size + bubbleRadius = (float)(drawableRuleset.Beatmap.HitObjects.OfType().First().Radius * 1.90f); + bubbleFade = drawableRuleset.Beatmap.HitObjects.OfType().First().TimePreempt * 2; - DrawableOsuHitObject drawableOsuHitObject = lastJudgedHitObject; + // We want to hide the judgements since they are obscured by the BubbleDrawable (due to layering) + drawableRuleset.Playfield.DisplayJudgements.Value = false; - switch (result.HitObject) + bubbleContainer = drawableRuleset.CreatePlayfieldAdjustmentContainer(); + + drawableRuleset.Overlays.Add(bubbleContainer); + } + + public void ApplyToDrawableHitObject(DrawableHitObject drawableObject) + { + if (drawableObject is DrawableSlider slider) + { + applySliderState(slider); + slider.Body.OnSkinChanged += () => applySliderState(slider); + } + + drawableObject.OnNewResult += (drawable, _) => + { + if (drawable is not DrawableOsuHitObject drawableOsuHitObject) return; + + switch (drawableOsuHitObject.HitObject) { case Slider: case SpinnerTick: @@ -101,56 +123,17 @@ namespace osu.Game.Rulesets.Osu.Mods // SliderHeads are derived from HitCircles, // so we must handle them before to avoid them using the wrong positioning logic case DrawableSliderHead: - return osuHitObject.Position; + return drawableOsuHitObject.HitObject.Position; // Using hitobject position will cause issues with HitCircle placement due to stack leniency. case DrawableHitCircle: return drawableOsuHitObject.Position; default: - return osuHitObject.Position; + return drawableOsuHitObject.HitObject.Position; } } }; - - scoreProcessor.JudgementReverted += _ => - { - bubbleContainer.LastOrDefault()?.FinishTransforms(); - bubbleContainer.LastOrDefault()?.Expire(); - }; - } - - public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) - { - // Multiplying by 2 results in an initial size that is too large, hence 1.90 has been chosen - // Also avoids the HitObject bleeding around the edges of the bubble drawable at minimum size - bubbleRadius = (float)(drawableRuleset.Beatmap.HitObjects.OfType().First().Radius * 1.90f); - bubbleFade = drawableRuleset.Beatmap.HitObjects.OfType().First().TimePreempt * 2; - - // We want to hide the judgements since they are obscured by the BubbleDrawable (due to layering) - drawableRuleset.Playfield.DisplayJudgements.Value = false; - - bubbleContainer = drawableRuleset.CreatePlayfieldAdjustmentContainer(); - - drawableRuleset.Overlays.Add(bubbleContainer); - } - - protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state) => applyBubbleState(hitObject); - protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state) => applyBubbleState(hitObject); - - private void applyBubbleState(DrawableHitObject drawableObject) - { - DrawableOsuHitObject osuHitObject = (DrawableOsuHitObject)drawableObject; - - if (drawableObject is DrawableSlider slider) - { - slider.Body.OnSkinChanged += () => applySliderState(slider); - applySliderState(slider); - } - - if (osuHitObject == lastJudgedHitObject || !osuHitObject.Judged) return; - - lastJudgedHitObject = osuHitObject; } // Makes the slider border coloured on all skins (for aesthetics) From 5db624159b1230e7ca522e9ab6cdec8194e8a0fa Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Tue, 14 Feb 2023 18:06:43 +0100 Subject: [PATCH 15/25] Change bubble rewind removal to be in `ApplyToDrawableHitObject` method. --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 4a8c11e7ff..f521dfb1f8 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -55,12 +55,6 @@ namespace osu.Game.Rulesets.Osu.Mods currentCombo.BindTo(scoreProcessor.Combo); currentCombo.BindValueChanged(combo => maxSize = Math.Min(1.75f, (float)(1.25 + 0.005 * combo.NewValue)), true); - - scoreProcessor.JudgementReverted += _ => - { - bubbleContainer.LastOrDefault()?.ClearTransforms(); - bubbleContainer.LastOrDefault()?.Expire(); - }; } public void ApplyToDrawableRuleset(DrawableRuleset drawableRuleset) @@ -134,6 +128,16 @@ namespace osu.Game.Rulesets.Osu.Mods } } }; + + drawableObject.OnRevertResult += (drawable, _) => + { + if (drawable.HitObject is SpinnerTick or Slider) return; + + BubbleDrawable? lastBubble = bubbleContainer.OfType().LastOrDefault(); + + lastBubble?.ClearTransforms(); + lastBubble?.Expire(); + }; } // Makes the slider border coloured on all skins (for aesthetics) From 82292d61621e49a158c576879ae56f47a9e52a84 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Wed, 15 Feb 2023 09:30:12 +0100 Subject: [PATCH 16/25] Make colouring for bubble more intuitive and remove unnecessary alpha assignment --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index f521dfb1f8..2a4208065d 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -177,8 +177,7 @@ namespace osu.Game.Rulesets.Osu.Mods protected override void PrepareForUse() { - Alpha = 1; - Colour = Colour4.White; + Colour = Info.IsHit ? Colour4.White : Colour4.Black; Scale = new Vector2(1); Position = Info.Position; Size = Info.InitialSize; @@ -204,12 +203,8 @@ namespace osu.Game.Rulesets.Osu.Mods content.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration() * 0.3f, Easing.OutQuint) // Avoids transparency overlap issues during the bubble "pop" .Then().Schedule(() => content.BorderThickness = 0); - - return; } - Colour = Colour4.Black; - // The absolute length of the bubble's animation, can be used in fractions for animations of partial length double getAnimationDuration() => 1700 + Math.Pow(Info.FadeTime, 1.07f); } From e9a7d90273c57dbd7dfb30ff32b9ca21dc9b6d39 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Wed, 15 Feb 2023 09:33:18 +0100 Subject: [PATCH 17/25] make transform duration for bubble a method instead of a variable --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 2a4208065d..a88bf6b813 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -187,26 +187,26 @@ namespace osu.Game.Rulesets.Osu.Mods //We want to fade to a darker colour to avoid colours such as white hiding the "ripple" effect. ColourInfo colourDarker = Info.Colour.Darken(0.1f); + // The absolute length of the bubble's animation, can be used in fractions for animations of partial length + double getAnimationDuration = 1700 + Math.Pow(Info.FadeTime, 1.07f); + // Main bubble scaling based on combo - this.ScaleTo(Info.MaxSize, getAnimationDuration() * 0.8f) + this.ScaleTo(Info.MaxSize, getAnimationDuration * 0.8f) .Then() // Pop at the end of the bubbles life time - .ScaleTo(Info.MaxSize * 1.5f, getAnimationDuration() * 0.2f, Easing.OutQuint) - .FadeOutFromOne(getAnimationDuration() * 0.2f, Easing.OutCirc).Expire(); + .ScaleTo(Info.MaxSize * 1.5f, getAnimationDuration * 0.2f, Easing.OutQuint) + .FadeOutFromOne(getAnimationDuration * 0.2f, Easing.OutCirc).Expire(); if (Info.IsHit) { colourBox.FadeColour(colourDarker); - content.TransformTo(nameof(BorderColour), colourDarker, getAnimationDuration() * 0.3f, Easing.OutQuint); + content.TransformTo(nameof(BorderColour), colourDarker, getAnimationDuration * 0.3f, Easing.OutQuint); // Ripple effect utilises the border to reduce drawable count - content.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration() * 0.3f, Easing.OutQuint) + content.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration * 0.3f, Easing.OutQuint) // Avoids transparency overlap issues during the bubble "pop" .Then().Schedule(() => content.BorderThickness = 0); } - - // The absolute length of the bubble's animation, can be used in fractions for animations of partial length - double getAnimationDuration() => 1700 + Math.Pow(Info.FadeTime, 1.07f); } } From 1d1c794ccfde23743574d8579da648cf42f4e4d4 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Wed, 15 Feb 2023 09:37:47 +0100 Subject: [PATCH 18/25] Invert pointless nested `if` statement --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index a88bf6b813..d75c82dc85 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -197,16 +197,15 @@ namespace osu.Game.Rulesets.Osu.Mods .ScaleTo(Info.MaxSize * 1.5f, getAnimationDuration * 0.2f, Easing.OutQuint) .FadeOutFromOne(getAnimationDuration * 0.2f, Easing.OutCirc).Expire(); - if (Info.IsHit) - { - colourBox.FadeColour(colourDarker); + if (!Info.IsHit) return; - content.TransformTo(nameof(BorderColour), colourDarker, getAnimationDuration * 0.3f, Easing.OutQuint); - // Ripple effect utilises the border to reduce drawable count - content.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration * 0.3f, Easing.OutQuint) - // Avoids transparency overlap issues during the bubble "pop" - .Then().Schedule(() => content.BorderThickness = 0); - } + colourBox.FadeColour(colourDarker); + + content.TransformTo(nameof(BorderColour), colourDarker, getAnimationDuration * 0.3f, Easing.OutQuint); + // Ripple effect utilises the border to reduce drawable count + content.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration * 0.3f, Easing.OutQuint) + // Avoids transparency overlap issues during the bubble "pop" + .Then().Schedule(() => content.BorderThickness = 0); } } From 297963b461cfdfd6083784ab0c4561c43c1d4a93 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Wed, 15 Feb 2023 10:00:46 +0100 Subject: [PATCH 19/25] Remove BubbleInfo struct and consume `DrawableOsuHitObject`s directly --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 102 +++++++++----------- 1 file changed, 46 insertions(+), 56 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index d75c82dc85..981932c580 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -2,8 +2,11 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Diagnostics; using System.Linq; using osu.Framework.Bindables; +using osu.Framework.Extensions.Color4Extensions; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; @@ -98,35 +101,14 @@ namespace osu.Game.Rulesets.Osu.Mods void addBubble() { BubbleDrawable bubble = bubblePool.Get(); - bubble.Info = new BubbleInfo - { - InitialSize = new Vector2(bubbleRadius), - MaxSize = maxSize, - Position = getPosition(), - FadeTime = bubbleFade, - Colour = drawableOsuHitObject.AccentColour.Value, - IsHit = drawableOsuHitObject.IsHit, - }; + + bubble.DrawableOsuHitObject = drawableOsuHitObject; + bubble.InitialSize = new Vector2(bubbleRadius); + bubble.FadeTime = bubbleFade; + bubble.MaxSize = maxSize; + bubbleContainer.Add(bubble); } - - Vector2 getPosition() - { - switch (drawableOsuHitObject) - { - // SliderHeads are derived from HitCircles, - // so we must handle them before to avoid them using the wrong positioning logic - case DrawableSliderHead: - return drawableOsuHitObject.HitObject.Position; - - // Using hitobject position will cause issues with HitCircle placement due to stack leniency. - case DrawableHitCircle: - return drawableOsuHitObject.Position; - - default: - return drawableOsuHitObject.HitObject.Position; - } - } }; drawableObject.OnRevertResult += (drawable, _) => @@ -148,11 +130,15 @@ namespace osu.Game.Rulesets.Osu.Mods private partial class BubbleDrawable : PoolableDrawable { + public DrawableOsuHitObject? DrawableOsuHitObject { get; set; } + + public Vector2 InitialSize { get; set; } + public double FadeTime { get; set; } + public float MaxSize { get; set; } + private readonly Box colourBox; private readonly CircularContainer content; - public BubbleInfo Info { get; set; } - public BubbleDrawable() { Origin = Anchor.Centre; @@ -177,27 +163,30 @@ namespace osu.Game.Rulesets.Osu.Mods protected override void PrepareForUse() { - Colour = Info.IsHit ? Colour4.White : Colour4.Black; + Debug.Assert(DrawableOsuHitObject.IsNotNull()); + + Colour = DrawableOsuHitObject.IsHit ? Colour4.White : Colour4.Black; + Alpha = 1; Scale = new Vector2(1); - Position = Info.Position; - Size = Info.InitialSize; - content.BorderThickness = Info.InitialSize.X / 3.5f; + Position = getPosition(); + Size = InitialSize; + content.BorderThickness = InitialSize.X / 3.5f; content.BorderColour = Colour4.White; //We want to fade to a darker colour to avoid colours such as white hiding the "ripple" effect. - ColourInfo colourDarker = Info.Colour.Darken(0.1f); + ColourInfo colourDarker = DrawableOsuHitObject.AccentColour.Value.Darken(0.1f); // The absolute length of the bubble's animation, can be used in fractions for animations of partial length - double getAnimationDuration = 1700 + Math.Pow(Info.FadeTime, 1.07f); + double getAnimationDuration = 1700 + Math.Pow(FadeTime, 1.07f); // Main bubble scaling based on combo - this.ScaleTo(Info.MaxSize, getAnimationDuration * 0.8f) + this.ScaleTo(MaxSize, getAnimationDuration * 0.8f) .Then() // Pop at the end of the bubbles life time - .ScaleTo(Info.MaxSize * 1.5f, getAnimationDuration * 0.2f, Easing.OutQuint) - .FadeOutFromOne(getAnimationDuration * 0.2f, Easing.OutCirc).Expire(); + .ScaleTo(MaxSize * 1.5f, getAnimationDuration * 0.2f, Easing.OutQuint) + .FadeOut(getAnimationDuration * 0.2f, Easing.OutCirc).Expire(); - if (!Info.IsHit) return; + if (!DrawableOsuHitObject.IsHit) return; colourBox.FadeColour(colourDarker); @@ -206,26 +195,27 @@ namespace osu.Game.Rulesets.Osu.Mods content.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration * 0.3f, Easing.OutQuint) // Avoids transparency overlap issues during the bubble "pop" .Then().Schedule(() => content.BorderThickness = 0); + + Vector2 getPosition() + { + switch (DrawableOsuHitObject) + { + // SliderHeads are derived from HitCircles, + // so we must handle them before to avoid them using the wrong positioning logic + case DrawableSliderHead: + return DrawableOsuHitObject.HitObject.Position; + + // Using hitobject position will cause issues with HitCircle placement due to stack leniency. + case DrawableHitCircle: + return DrawableOsuHitObject.Position; + + default: + return DrawableOsuHitObject.HitObject.Position; + } + } } } - private struct BubbleInfo - { - public Vector2 InitialSize { get; set; } - - public float MaxSize { get; set; } - - public Vector2 Position { get; set; } - - public Colour4 Colour { get; set; } - - // FadeTime is based on the approach rate of the beatmap. - public double FadeTime { get; set; } - - // Whether the corresponding HitObject was hit - public bool IsHit { get; set; } - } - #endregion } } From 8fc35b159f87a10a087c79c469d981ff9750bc95 Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Wed, 15 Feb 2023 10:04:50 +0100 Subject: [PATCH 20/25] Remove dysfunctional slider colouring --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 981932c580..4edf726f26 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -18,7 +18,6 @@ using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects.Drawables; -using osu.Game.Rulesets.Osu.Skinning.Default; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; using osu.Game.Scoring; @@ -77,12 +76,6 @@ namespace osu.Game.Rulesets.Osu.Mods public void ApplyToDrawableHitObject(DrawableHitObject drawableObject) { - if (drawableObject is DrawableSlider slider) - { - applySliderState(slider); - slider.Body.OnSkinChanged += () => applySliderState(slider); - } - drawableObject.OnNewResult += (drawable, _) => { if (drawable is not DrawableOsuHitObject drawableOsuHitObject) return; @@ -122,10 +115,6 @@ namespace osu.Game.Rulesets.Osu.Mods }; } - // Makes the slider border coloured on all skins (for aesthetics) - private void applySliderState(DrawableSlider slider) => - ((PlaySliderBody)slider.Body.Drawable).BorderColour = slider.AccentColour.Value; - #region Pooled Bubble drawable private partial class BubbleDrawable : PoolableDrawable From d5bc8e2941fc0a6d948fda24546cc976b12165fa Mon Sep 17 00:00:00 2001 From: mk56-spn Date: Thu, 16 Feb 2023 11:12:30 +0100 Subject: [PATCH 21/25] Code cleanup pass: Make bubble transform logic more sane. Extract bubble `getPosition()` method. Address poorly named variables. --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 47 +++++++++++---------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 4edf726f26..0fc27c8f1d 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Osu.Mods private readonly Bindable currentCombo = new BindableInt(); private float maxSize; - private float bubbleRadius; + private float bubbleSize; private double bubbleFade; private readonly DrawablePool bubblePool = new DrawablePool(100); @@ -63,7 +63,7 @@ namespace osu.Game.Rulesets.Osu.Mods { // Multiplying by 2 results in an initial size that is too large, hence 1.90 has been chosen // Also avoids the HitObject bleeding around the edges of the bubble drawable at minimum size - bubbleRadius = (float)(drawableRuleset.Beatmap.HitObjects.OfType().First().Radius * 1.90f); + bubbleSize = (float)(drawableRuleset.Beatmap.HitObjects.OfType().First().Radius * 1.90f); bubbleFade = drawableRuleset.Beatmap.HitObjects.OfType().First().TimePreempt * 2; // We want to hide the judgements since they are obscured by the BubbleDrawable (due to layering) @@ -96,7 +96,7 @@ namespace osu.Game.Rulesets.Osu.Mods BubbleDrawable bubble = bubblePool.Get(); bubble.DrawableOsuHitObject = drawableOsuHitObject; - bubble.InitialSize = new Vector2(bubbleRadius); + bubble.InitialSize = new Vector2(bubbleSize); bubble.FadeTime = bubbleFade; bubble.MaxSize = maxSize; @@ -122,9 +122,11 @@ namespace osu.Game.Rulesets.Osu.Mods public DrawableOsuHitObject? DrawableOsuHitObject { get; set; } public Vector2 InitialSize { get; set; } - public double FadeTime { get; set; } + public float MaxSize { get; set; } + public double FadeTime { get; set; } + private readonly Box colourBox; private readonly CircularContainer content; @@ -155,12 +157,9 @@ namespace osu.Game.Rulesets.Osu.Mods Debug.Assert(DrawableOsuHitObject.IsNotNull()); Colour = DrawableOsuHitObject.IsHit ? Colour4.White : Colour4.Black; - Alpha = 1; Scale = new Vector2(1); - Position = getPosition(); + Position = getPosition(DrawableOsuHitObject); Size = InitialSize; - content.BorderThickness = InitialSize.X / 3.5f; - content.BorderColour = Colour4.White; //We want to fade to a darker colour to avoid colours such as white hiding the "ripple" effect. ColourInfo colourDarker = DrawableOsuHitObject.AccentColour.Value.Darken(0.1f); @@ -169,7 +168,8 @@ namespace osu.Game.Rulesets.Osu.Mods double getAnimationDuration = 1700 + Math.Pow(FadeTime, 1.07f); // Main bubble scaling based on combo - this.ScaleTo(MaxSize, getAnimationDuration * 0.8f) + this.FadeTo(1) + .ScaleTo(MaxSize, getAnimationDuration * 0.8f) .Then() // Pop at the end of the bubbles life time .ScaleTo(MaxSize * 1.5f, getAnimationDuration * 0.2f, Easing.OutQuint) @@ -177,6 +177,9 @@ namespace osu.Game.Rulesets.Osu.Mods if (!DrawableOsuHitObject.IsHit) return; + content.BorderThickness = InitialSize.X / 3.5f; + content.BorderColour = Colour4.White; + colourBox.FadeColour(colourDarker); content.TransformTo(nameof(BorderColour), colourDarker, getAnimationDuration * 0.3f, Easing.OutQuint); @@ -184,23 +187,23 @@ namespace osu.Game.Rulesets.Osu.Mods content.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration * 0.3f, Easing.OutQuint) // Avoids transparency overlap issues during the bubble "pop" .Then().Schedule(() => content.BorderThickness = 0); + } - Vector2 getPosition() + private Vector2 getPosition(DrawableOsuHitObject drawableOsuHitObject) + { + switch (drawableOsuHitObject) { - switch (DrawableOsuHitObject) - { - // SliderHeads are derived from HitCircles, - // so we must handle them before to avoid them using the wrong positioning logic - case DrawableSliderHead: - return DrawableOsuHitObject.HitObject.Position; + // SliderHeads are derived from HitCircles, + // so we must handle them before to avoid them using the wrong positioning logic + case DrawableSliderHead: + return drawableOsuHitObject.HitObject.Position; - // Using hitobject position will cause issues with HitCircle placement due to stack leniency. - case DrawableHitCircle: - return DrawableOsuHitObject.Position; + // Using hitobject position will cause issues with HitCircle placement due to stack leniency. + case DrawableHitCircle: + return drawableOsuHitObject.Position; - default: - return DrawableOsuHitObject.HitObject.Position; - } + default: + return drawableOsuHitObject.HitObject.Position; } } } From 414b80d44e78ee5495aa18ae3afd7661b9fe32a7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 May 2023 17:00:54 +0900 Subject: [PATCH 22/25] Change flashlight depth in a more standard way --- osu.Game/Rulesets/Mods/ModFlashlight.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index 9527e8ab5d..215fc877dc 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -82,12 +82,12 @@ namespace osu.Game.Rulesets.Mods flashlight.RelativeSizeAxes = Axes.Both; flashlight.Colour = Color4.Black; + // Flashlight mods should always draw above any other mod adding overlays. + flashlight.Depth = float.MinValue; flashlight.Combo.BindTo(Combo); drawableRuleset.Overlays.Add(flashlight); - // Stop flashlight from being drawn underneath other mods that generate HitObjects. - drawableRuleset.Overlays.ChangeChildDepth(flashlight, float.MinValue); } protected abstract Flashlight CreateFlashlight(); From fb0e90913db89e8ffc80fc17056d8ed1f4cbfecc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 May 2023 17:07:12 +0900 Subject: [PATCH 23/25] Ensure lifetime start is also updated when reverting judgements --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 0fc27c8f1d..bfc6c24fa5 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -111,7 +111,7 @@ namespace osu.Game.Rulesets.Osu.Mods BubbleDrawable? lastBubble = bubbleContainer.OfType().LastOrDefault(); lastBubble?.ClearTransforms(); - lastBubble?.Expire(); + lastBubble?.Expire(true); }; } From 7830711c8e97b83852f705dbad25d50cc71a1604 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 May 2023 17:07:22 +0900 Subject: [PATCH 24/25] Tidy up various code quality issues in `OsuModBubbles` --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index bfc6c24fa5..9ae38de7c9 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -165,15 +165,15 @@ namespace osu.Game.Rulesets.Osu.Mods ColourInfo colourDarker = DrawableOsuHitObject.AccentColour.Value.Darken(0.1f); // The absolute length of the bubble's animation, can be used in fractions for animations of partial length - double getAnimationDuration = 1700 + Math.Pow(FadeTime, 1.07f); + double duration = 1700 + Math.Pow(FadeTime, 1.07f); // Main bubble scaling based on combo this.FadeTo(1) - .ScaleTo(MaxSize, getAnimationDuration * 0.8f) + .ScaleTo(MaxSize, duration * 0.8f) .Then() // Pop at the end of the bubbles life time - .ScaleTo(MaxSize * 1.5f, getAnimationDuration * 0.2f, Easing.OutQuint) - .FadeOut(getAnimationDuration * 0.2f, Easing.OutCirc).Expire(); + .ScaleTo(MaxSize * 1.5f, duration * 0.2f, Easing.OutQuint) + .FadeOut(duration * 0.2f, Easing.OutCirc).Expire(); if (!DrawableOsuHitObject.IsHit) return; @@ -182,28 +182,28 @@ namespace osu.Game.Rulesets.Osu.Mods colourBox.FadeColour(colourDarker); - content.TransformTo(nameof(BorderColour), colourDarker, getAnimationDuration * 0.3f, Easing.OutQuint); + content.TransformTo(nameof(BorderColour), colourDarker, duration * 0.3f, Easing.OutQuint); // Ripple effect utilises the border to reduce drawable count - content.TransformTo(nameof(BorderThickness), 2f, getAnimationDuration * 0.3f, Easing.OutQuint) + content.TransformTo(nameof(BorderThickness), 2f, duration * 0.3f, Easing.OutQuint) // Avoids transparency overlap issues during the bubble "pop" .Then().Schedule(() => content.BorderThickness = 0); } - private Vector2 getPosition(DrawableOsuHitObject drawableOsuHitObject) + private Vector2 getPosition(DrawableOsuHitObject drawableObject) { - switch (drawableOsuHitObject) + switch (drawableObject) { // SliderHeads are derived from HitCircles, // so we must handle them before to avoid them using the wrong positioning logic case DrawableSliderHead: - return drawableOsuHitObject.HitObject.Position; + return drawableObject.HitObject.Position; // Using hitobject position will cause issues with HitCircle placement due to stack leniency. case DrawableHitCircle: - return drawableOsuHitObject.Position; + return drawableObject.Position; default: - return drawableOsuHitObject.HitObject.Position; + return drawableObject.HitObject.Position; } } } From e44672bdd5f4f11ae0d309c20df29271d4203f05 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 2 May 2023 17:08:49 +0900 Subject: [PATCH 25/25] Avoid using `Schedule` in transforms (doesn't handle rewind well) --- osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs index 9ae38de7c9..12e2090f89 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModBubbles.cs @@ -185,8 +185,9 @@ namespace osu.Game.Rulesets.Osu.Mods content.TransformTo(nameof(BorderColour), colourDarker, duration * 0.3f, Easing.OutQuint); // Ripple effect utilises the border to reduce drawable count content.TransformTo(nameof(BorderThickness), 2f, duration * 0.3f, Easing.OutQuint) + .Then() // Avoids transparency overlap issues during the bubble "pop" - .Then().Schedule(() => content.BorderThickness = 0); + .TransformTo(nameof(BorderThickness), 0f); } private Vector2 getPosition(DrawableOsuHitObject drawableObject)