2022-12-26 04:32:47 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
2023-02-15 17:00:46 +08:00
|
|
|
using System.Diagnostics;
|
2022-12-26 04:32:47 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Bindables;
|
2023-02-15 17:00:46 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2022-12-26 04:32:47 +08:00
|
|
|
using osu.Framework.Graphics;
|
2023-01-29 05:44:57 +08:00
|
|
|
using osu.Framework.Graphics.Colour;
|
2022-12-26 04:32:47 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Effects;
|
|
|
|
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.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
|
|
|
|
{
|
2023-02-14 23:31:34 +08:00
|
|
|
public partial class OsuModBubbles : Mod, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToDrawableHitObject, IApplicableToScoreProcessor
|
2022-12-26 04:32:47 +08:00
|
|
|
{
|
|
|
|
public override string Name => "Bubbles";
|
|
|
|
|
2023-02-06 16:32:17 +08:00
|
|
|
public override string Acronym => "BU";
|
2022-12-26 04:32:47 +08:00
|
|
|
|
2023-02-06 16:32:17 +08:00
|
|
|
public override LocalisableString Description => "Don't let their popping distract you!";
|
2022-12-26 04:32:47 +08:00
|
|
|
|
|
|
|
public override double ScoreMultiplier => 1;
|
|
|
|
|
|
|
|
public override ModType Type => ModType.Fun;
|
|
|
|
|
2023-02-06 16:32:17 +08:00
|
|
|
// Compatibility with these seems potentially feasible in the future, blocked for now because they don't work as one would expect
|
2022-12-26 04:32:47 +08:00
|
|
|
public override Type[] IncompatibleMods => new[] { typeof(OsuModBarrelRoll), typeof(OsuModMagnetised), typeof(OsuModRepel) };
|
|
|
|
|
2023-02-12 18:37:07 +08:00
|
|
|
private PlayfieldAdjustmentContainer bubbleContainer = null!;
|
2022-12-26 04:32:47 +08:00
|
|
|
|
2023-06-02 22:01:03 +08:00
|
|
|
private DrawablePool<BubbleDrawable> bubblePool = null!;
|
|
|
|
|
2022-12-26 04:32:47 +08:00
|
|
|
private readonly Bindable<int> currentCombo = new BindableInt();
|
|
|
|
|
|
|
|
private float maxSize;
|
2023-02-16 18:12:30 +08:00
|
|
|
private float bubbleSize;
|
2022-12-26 04:32:47 +08:00
|
|
|
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);
|
2023-02-14 23:31:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> 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
|
2023-02-16 18:12:30 +08:00
|
|
|
bubbleSize = (float)(drawableRuleset.Beatmap.HitObjects.OfType<HitCircle>().First().Radius * 1.90f);
|
2023-02-14 23:31:34 +08:00
|
|
|
bubbleFade = drawableRuleset.Beatmap.HitObjects.OfType<HitCircle>().First().TimePreempt * 2;
|
|
|
|
|
|
|
|
// We want to hide the judgements since they are obscured by the BubbleDrawable (due to layering)
|
|
|
|
drawableRuleset.Playfield.DisplayJudgements.Value = false;
|
2023-02-08 18:12:14 +08:00
|
|
|
|
2023-02-14 23:31:34 +08:00
|
|
|
bubbleContainer = drawableRuleset.CreatePlayfieldAdjustmentContainer();
|
2023-02-14 17:12:37 +08:00
|
|
|
|
2023-02-14 23:31:34 +08:00
|
|
|
drawableRuleset.Overlays.Add(bubbleContainer);
|
2023-06-02 22:01:03 +08:00
|
|
|
drawableRuleset.Overlays.Add(bubblePool = new DrawablePool<BubbleDrawable>(100));
|
2023-02-14 23:31:34 +08:00
|
|
|
}
|
2023-02-08 18:12:14 +08:00
|
|
|
|
2023-02-14 23:31:34 +08:00
|
|
|
public void ApplyToDrawableHitObject(DrawableHitObject drawableObject)
|
|
|
|
{
|
|
|
|
drawableObject.OnNewResult += (drawable, _) =>
|
|
|
|
{
|
|
|
|
if (drawable is not DrawableOsuHitObject drawableOsuHitObject) return;
|
|
|
|
|
|
|
|
switch (drawableOsuHitObject.HitObject)
|
2023-02-08 18:12:14 +08:00
|
|
|
{
|
|
|
|
case Slider:
|
|
|
|
case SpinnerTick:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
addBubble();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addBubble()
|
|
|
|
{
|
|
|
|
BubbleDrawable bubble = bubblePool.Get();
|
|
|
|
|
2023-02-15 17:00:46 +08:00
|
|
|
bubble.DrawableOsuHitObject = drawableOsuHitObject;
|
2023-02-16 18:12:30 +08:00
|
|
|
bubble.InitialSize = new Vector2(bubbleSize);
|
2023-02-15 17:00:46 +08:00
|
|
|
bubble.FadeTime = bubbleFade;
|
|
|
|
bubble.MaxSize = maxSize;
|
2023-02-08 18:12:14 +08:00
|
|
|
|
2023-02-15 17:00:46 +08:00
|
|
|
bubbleContainer.Add(bubble);
|
2023-02-08 18:12:14 +08:00
|
|
|
}
|
|
|
|
};
|
2023-02-15 01:06:43 +08:00
|
|
|
|
|
|
|
drawableObject.OnRevertResult += (drawable, _) =>
|
|
|
|
{
|
|
|
|
if (drawable.HitObject is SpinnerTick or Slider) return;
|
|
|
|
|
|
|
|
BubbleDrawable? lastBubble = bubbleContainer.OfType<BubbleDrawable>().LastOrDefault();
|
|
|
|
|
|
|
|
lastBubble?.ClearTransforms();
|
2023-05-02 16:07:12 +08:00
|
|
|
lastBubble?.Expire(true);
|
2023-02-15 01:06:43 +08:00
|
|
|
};
|
2022-12-26 04:33:10 +08:00
|
|
|
}
|
2022-12-26 04:32:47 +08:00
|
|
|
|
|
|
|
#region Pooled Bubble drawable
|
|
|
|
|
2023-02-08 18:12:14 +08:00
|
|
|
private partial class BubbleDrawable : PoolableDrawable
|
2022-12-26 04:32:47 +08:00
|
|
|
{
|
2023-02-15 17:00:46 +08:00
|
|
|
public DrawableOsuHitObject? DrawableOsuHitObject { get; set; }
|
|
|
|
|
|
|
|
public Vector2 InitialSize { get; set; }
|
2023-02-16 18:12:30 +08:00
|
|
|
|
2023-02-15 17:00:46 +08:00
|
|
|
public float MaxSize { get; set; }
|
|
|
|
|
2023-02-16 18:12:30 +08:00
|
|
|
public double FadeTime { get; set; }
|
|
|
|
|
2023-01-27 18:21:11 +08:00
|
|
|
private readonly Box colourBox;
|
2023-02-08 18:12:14 +08:00
|
|
|
private readonly CircularContainer content;
|
|
|
|
|
2023-01-27 18:21:11 +08:00
|
|
|
public BubbleDrawable()
|
2022-12-26 04:32:47 +08:00
|
|
|
{
|
2023-01-27 18:21:11 +08:00
|
|
|
Origin = Anchor.Centre;
|
2023-02-08 18:12:14 +08:00
|
|
|
InternalChild = content = new CircularContainer
|
2022-12-26 04:32:47 +08:00
|
|
|
{
|
2023-02-08 18:12:14 +08:00
|
|
|
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, }
|
2023-01-27 18:21:11 +08:00
|
|
|
};
|
2022-12-26 04:32:47 +08:00
|
|
|
}
|
|
|
|
|
2023-02-08 18:12:14 +08:00
|
|
|
protected override void PrepareForUse()
|
2022-12-26 04:32:47 +08:00
|
|
|
{
|
2023-02-15 17:00:46 +08:00
|
|
|
Debug.Assert(DrawableOsuHitObject.IsNotNull());
|
|
|
|
|
|
|
|
Colour = DrawableOsuHitObject.IsHit ? Colour4.White : Colour4.Black;
|
2023-02-08 18:12:14 +08:00
|
|
|
Scale = new Vector2(1);
|
2023-02-16 18:12:30 +08:00
|
|
|
Position = getPosition(DrawableOsuHitObject);
|
2023-02-15 17:00:46 +08:00
|
|
|
Size = InitialSize;
|
2023-01-27 18:21:11 +08:00
|
|
|
|
2023-01-28 07:30:30 +08:00
|
|
|
//We want to fade to a darker colour to avoid colours such as white hiding the "ripple" effect.
|
2023-02-15 17:00:46 +08:00
|
|
|
ColourInfo colourDarker = DrawableOsuHitObject.AccentColour.Value.Darken(0.1f);
|
2023-01-28 07:30:30 +08:00
|
|
|
|
2023-02-15 16:33:18 +08:00
|
|
|
// The absolute length of the bubble's animation, can be used in fractions for animations of partial length
|
2023-05-02 16:07:22 +08:00
|
|
|
double duration = 1700 + Math.Pow(FadeTime, 1.07f);
|
2023-02-15 16:33:18 +08:00
|
|
|
|
2023-01-29 05:44:57 +08:00
|
|
|
// Main bubble scaling based on combo
|
2023-02-16 18:12:30 +08:00
|
|
|
this.FadeTo(1)
|
2023-05-02 16:07:22 +08:00
|
|
|
.ScaleTo(MaxSize, duration * 0.8f)
|
2022-12-26 04:32:47 +08:00
|
|
|
.Then()
|
2023-01-29 05:44:57 +08:00
|
|
|
// Pop at the end of the bubbles life time
|
2023-05-02 16:07:22 +08:00
|
|
|
.ScaleTo(MaxSize * 1.5f, duration * 0.2f, Easing.OutQuint)
|
|
|
|
.FadeOut(duration * 0.2f, Easing.OutCirc).Expire();
|
2023-01-12 00:51:41 +08:00
|
|
|
|
2023-02-15 17:00:46 +08:00
|
|
|
if (!DrawableOsuHitObject.IsHit) return;
|
2023-02-08 18:12:14 +08:00
|
|
|
|
2023-02-16 18:12:30 +08:00
|
|
|
content.BorderThickness = InitialSize.X / 3.5f;
|
|
|
|
content.BorderColour = Colour4.White;
|
|
|
|
|
2023-02-15 16:37:47 +08:00
|
|
|
colourBox.FadeColour(colourDarker);
|
|
|
|
|
2023-05-02 16:07:22 +08:00
|
|
|
content.TransformTo(nameof(BorderColour), colourDarker, duration * 0.3f, Easing.OutQuint);
|
2023-02-15 16:37:47 +08:00
|
|
|
// Ripple effect utilises the border to reduce drawable count
|
2023-05-02 16:07:22 +08:00
|
|
|
content.TransformTo(nameof(BorderThickness), 2f, duration * 0.3f, Easing.OutQuint)
|
2023-05-02 16:08:49 +08:00
|
|
|
.Then()
|
2023-02-15 16:37:47 +08:00
|
|
|
// Avoids transparency overlap issues during the bubble "pop"
|
2023-05-02 16:08:49 +08:00
|
|
|
.TransformTo(nameof(BorderThickness), 0f);
|
2023-02-16 18:12:30 +08:00
|
|
|
}
|
2022-12-26 04:32:47 +08:00
|
|
|
|
2023-05-02 16:07:22 +08:00
|
|
|
private Vector2 getPosition(DrawableOsuHitObject drawableObject)
|
2023-02-16 18:12:30 +08:00
|
|
|
{
|
2023-05-02 16:07:22 +08:00
|
|
|
switch (drawableObject)
|
2023-02-15 17:00:46 +08:00
|
|
|
{
|
2023-02-16 18:12:30 +08:00
|
|
|
// SliderHeads are derived from HitCircles,
|
|
|
|
// so we must handle them before to avoid them using the wrong positioning logic
|
|
|
|
case DrawableSliderHead:
|
2023-05-02 16:07:22 +08:00
|
|
|
return drawableObject.HitObject.Position;
|
2023-02-16 18:12:30 +08:00
|
|
|
|
|
|
|
// Using hitobject position will cause issues with HitCircle placement due to stack leniency.
|
|
|
|
case DrawableHitCircle:
|
2023-05-02 16:07:22 +08:00
|
|
|
return drawableObject.Position;
|
2023-02-16 18:12:30 +08:00
|
|
|
|
|
|
|
default:
|
2023-05-02 16:07:22 +08:00
|
|
|
return drawableObject.HitObject.Position;
|
2023-02-15 17:00:46 +08:00
|
|
|
}
|
|
|
|
}
|
2022-12-26 04:32:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|