2022-12-25 20:32:47 +00: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;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2023-01-28 21:44:57 +00:00
|
|
|
using osu.Framework.Graphics.Colour;
|
2022-12-25 20:32:47 +00:00
|
|
|
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;
|
2023-01-28 16:38:24 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Skinning.Default;
|
2022-12-25 20:32:47 +00:00
|
|
|
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<OsuHitObject>, 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<int> 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<OsuHitObject> 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<HitCircle>().First().Radius * 1.85f);
|
2023-01-27 10:21:11 +00:00
|
|
|
bubbleFade = drawableRuleset.Beatmap.HitObjects.OfType<HitCircle>().First().TimePreempt * 2;
|
2022-12-25 20:32:47 +00:00
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
2023-01-28 16:38:24 +00:00
|
|
|
if (drawableObject is DrawableSlider slider)
|
|
|
|
{
|
|
|
|
slider.Body.OnSkinChanged += () => applySliderState(slider);
|
|
|
|
applySliderState(slider);
|
|
|
|
}
|
|
|
|
|
2022-12-25 20:32:47 +00:00
|
|
|
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:
|
2022-12-25 20:33:10 +00:00
|
|
|
addBubbleContainer(hitObject.Position, drawableOsuObject);
|
2023-01-28 21:44:57 +00:00
|
|
|
return;
|
2022-12-25 20:32:47 +00:00
|
|
|
|
|
|
|
//Stack leniency causes placement issues if this isn't handled as such.
|
|
|
|
case DrawableHitCircle hitCircle:
|
2022-12-25 20:33:10 +00:00
|
|
|
addBubbleContainer(hitCircle.Position, drawableOsuObject);
|
2022-12-25 20:32:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DrawableSlider:
|
2023-01-28 16:38:24 +00:00
|
|
|
case DrawableSpinnerTick:
|
|
|
|
break;
|
2022-12-25 20:32:47 +00:00
|
|
|
|
|
|
|
default:
|
2022-12-25 20:33:10 +00:00
|
|
|
addBubbleContainer(hitObject.Position, drawableOsuObject);
|
2022-12-25 20:32:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-12-25 20:33:10 +00:00
|
|
|
}
|
2022-12-25 20:32:47 +00:00
|
|
|
|
2023-01-28 16:38:24 +00:00
|
|
|
private void applySliderState(DrawableSlider slider) =>
|
|
|
|
((PlaySliderBody)slider.Body.Drawable).BorderColour = slider.AccentColour.Value;
|
|
|
|
|
2022-12-25 20:33:10 +00:00
|
|
|
private void addBubbleContainer(Vector2 position, DrawableHitObject hitObject)
|
|
|
|
{
|
|
|
|
bubbleContainer.Add
|
|
|
|
(
|
|
|
|
new BubbleLifeTimeEntry
|
2022-12-25 20:32:47 +00:00
|
|
|
{
|
|
|
|
LifetimeStart = bubbleContainer.Time.Current,
|
2022-12-25 20:33:10 +00:00
|
|
|
Colour = hitObject.AccentColour.Value,
|
2022-12-25 20:32:47 +00:00
|
|
|
Position = position,
|
|
|
|
InitialSize = new Vector2(bubbleRadius),
|
|
|
|
MaxSize = maxSize,
|
|
|
|
FadeTime = bubbleFade,
|
2022-12-25 20:33:10 +00:00
|
|
|
IsHit = hitObject.IsHit
|
2022-12-25 20:32:47 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#region Pooled Bubble drawable
|
|
|
|
|
2023-01-27 10:21:11 +00:00
|
|
|
// 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"
|
2022-12-25 20:32:47 +00:00
|
|
|
private sealed partial class BubbleContainer : PooledDrawableWithLifetimeContainer<BubbleLifeTimeEntry, BubbleObject>
|
|
|
|
{
|
|
|
|
protected override bool RemoveRewoundEntry => true;
|
|
|
|
|
|
|
|
private readonly DrawablePool<BubbleObject> pool;
|
|
|
|
|
|
|
|
public BubbleContainer()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
AddInternal(pool = new DrawablePool<BubbleObject>(10, 1000));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override BubbleObject GetDrawable(BubbleLifeTimeEntry entry) => pool.Get(d => d.Apply(entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
private sealed partial class BubbleObject : PoolableDrawableWithLifetime<BubbleLifeTimeEntry>
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2023-01-27 10:21:11 +00:00
|
|
|
if (entry == null) return;
|
2022-12-25 20:32:47 +00:00
|
|
|
|
|
|
|
ApplyTransformsAt(float.MinValue, true);
|
|
|
|
ClearTransforms(true);
|
|
|
|
|
|
|
|
Position = entry.Position;
|
|
|
|
|
|
|
|
bubbleDrawable.Animate(entry);
|
|
|
|
|
|
|
|
LifetimeEnd = bubbleDrawable.LatestTransformEndTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-27 10:21:11 +00:00
|
|
|
private partial class BubbleDrawable : CircularContainer
|
2022-12-25 20:32:47 +00:00
|
|
|
{
|
2023-01-27 10:21:11 +00:00
|
|
|
private readonly Box colourBox;
|
2023-01-11 16:51:41 +00:00
|
|
|
|
2023-01-27 10:21:11 +00:00
|
|
|
public BubbleDrawable()
|
2022-12-25 20:32:47 +00:00
|
|
|
{
|
2023-01-27 10:21:11 +00:00
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
MaskingSmoothness = 2;
|
|
|
|
BorderThickness = 0;
|
2023-01-28 21:44:57 +00:00
|
|
|
BorderColour = Colour4.White;
|
|
|
|
Masking = true;
|
2023-01-27 10:21:11 +00:00
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2022-12-25 20:32:47 +00:00
|
|
|
{
|
2023-01-27 10:21:11 +00:00
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Radius = 3,
|
|
|
|
Colour = Colour4.Black.Opacity(0.05f)
|
|
|
|
};
|
2023-01-28 21:44:57 +00:00
|
|
|
Child = colourBox = new Box { RelativeSizeAxes = Axes.Both, };
|
2022-12-25 20:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Animate(BubbleLifeTimeEntry entry)
|
|
|
|
{
|
|
|
|
Size = entry.InitialSize;
|
2023-01-28 21:44:57 +00:00
|
|
|
BorderThickness = Width / 3.5f;
|
2023-01-27 10:21:11 +00:00
|
|
|
|
2023-01-27 23:30:30 +00:00
|
|
|
//We want to fade to a darker colour to avoid colours such as white hiding the "ripple" effect.
|
2023-01-28 21:44:57 +00:00
|
|
|
ColourInfo colourDarker = entry.Colour.Darken(0.1f);
|
2023-01-27 23:30:30 +00:00
|
|
|
|
2023-01-28 21:44:57 +00:00
|
|
|
// Main bubble scaling based on combo
|
2023-01-28 16:38:24 +00:00
|
|
|
this.ScaleTo(entry.MaxSize, getAnimationDuration() * 0.8f)
|
2022-12-25 20:32:47 +00:00
|
|
|
.Then()
|
2023-01-28 21:44:57 +00:00
|
|
|
// Pop at the end of the bubbles life time
|
2023-01-28 16:38:24 +00:00
|
|
|
.ScaleTo(entry.MaxSize * 1.5f, getAnimationDuration() * 0.2f, Easing.OutQuint)
|
2023-01-28 21:44:57 +00:00
|
|
|
.FadeTo(0, getAnimationDuration() * 0.2f, Easing.OutCirc);
|
2023-01-11 16:51:41 +00:00
|
|
|
|
2023-01-27 23:30:30 +00:00
|
|
|
if (!entry.IsHit)
|
|
|
|
{
|
2023-01-28 21:44:57 +00:00
|
|
|
Colour = Colour4.Black;
|
|
|
|
BorderColour = Colour4.Black;
|
2023-01-11 16:51:41 +00:00
|
|
|
|
2023-01-27 23:30:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-01-11 16:51:41 +00:00
|
|
|
|
2023-01-28 21:44:57 +00:00
|
|
|
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;
|
|
|
|
});
|
2023-01-11 16:51:41 +00:00
|
|
|
|
2023-01-27 10:21:11 +00:00
|
|
|
// The absolute length of the bubble's animation, can be used in fractions for animations of partial length
|
2023-01-28 16:38:24 +00:00
|
|
|
double getAnimationDuration() => 1700 + Math.Pow(entry.FadeTime, 1.07f);
|
2022-12-25 20:32:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|