Remove BubbleInfo struct and consume DrawableOsuHitObjects directly

This commit is contained in:
mk56-spn
2023-02-15 10:00:46 +01:00
parent 1d1c794ccf
commit 297963b461

View File

@ -2,8 +2,11 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Diagnostics;
using System.Linq; using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -98,35 +101,14 @@ namespace osu.Game.Rulesets.Osu.Mods
void addBubble() void addBubble()
{ {
BubbleDrawable bubble = bubblePool.Get(); BubbleDrawable bubble = bubblePool.Get();
bubble.Info = new BubbleInfo
{ bubble.DrawableOsuHitObject = drawableOsuHitObject;
InitialSize = new Vector2(bubbleRadius), bubble.InitialSize = new Vector2(bubbleRadius);
MaxSize = maxSize, bubble.FadeTime = bubbleFade;
Position = getPosition(), bubble.MaxSize = maxSize;
FadeTime = bubbleFade,
Colour = drawableOsuHitObject.AccentColour.Value,
IsHit = drawableOsuHitObject.IsHit,
};
bubbleContainer.Add(bubble); 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, _) => drawableObject.OnRevertResult += (drawable, _) =>
@ -148,11 +130,15 @@ namespace osu.Game.Rulesets.Osu.Mods
private partial class BubbleDrawable : PoolableDrawable 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 Box colourBox;
private readonly CircularContainer content; private readonly CircularContainer content;
public BubbleInfo Info { get; set; }
public BubbleDrawable() public BubbleDrawable()
{ {
Origin = Anchor.Centre; Origin = Anchor.Centre;
@ -177,27 +163,30 @@ namespace osu.Game.Rulesets.Osu.Mods
protected override void PrepareForUse() 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); Scale = new Vector2(1);
Position = Info.Position; Position = getPosition();
Size = Info.InitialSize; Size = InitialSize;
content.BorderThickness = Info.InitialSize.X / 3.5f; content.BorderThickness = InitialSize.X / 3.5f;
content.BorderColour = Colour4.White; content.BorderColour = Colour4.White;
//We want to fade to a darker colour to avoid colours such as white hiding the "ripple" effect. //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 // 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 // Main bubble scaling based on combo
this.ScaleTo(Info.MaxSize, getAnimationDuration * 0.8f) this.ScaleTo(MaxSize, getAnimationDuration * 0.8f)
.Then() .Then()
// Pop at the end of the bubbles life time // Pop at the end of the bubbles life time
.ScaleTo(Info.MaxSize * 1.5f, getAnimationDuration * 0.2f, Easing.OutQuint) .ScaleTo(MaxSize * 1.5f, getAnimationDuration * 0.2f, Easing.OutQuint)
.FadeOutFromOne(getAnimationDuration * 0.2f, Easing.OutCirc).Expire(); .FadeOut(getAnimationDuration * 0.2f, Easing.OutCirc).Expire();
if (!Info.IsHit) return; if (!DrawableOsuHitObject.IsHit) return;
colourBox.FadeColour(colourDarker); colourBox.FadeColour(colourDarker);
@ -206,24 +195,25 @@ namespace osu.Game.Rulesets.Osu.Mods
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" // Avoids transparency overlap issues during the bubble "pop"
.Then().Schedule(() => content.BorderThickness = 0); .Then().Schedule(() => content.BorderThickness = 0);
}
}
private struct BubbleInfo Vector2 getPosition()
{ {
public Vector2 InitialSize { get; set; } 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;
public float MaxSize { get; set; } // Using hitobject position will cause issues with HitCircle placement due to stack leniency.
case DrawableHitCircle:
return DrawableOsuHitObject.Position;
public Vector2 Position { get; set; } default:
return DrawableOsuHitObject.HitObject.Position;
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 #endregion