1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 08:02:55 +08:00

Merge branch 'master' into fix-slider-selection-nre

This commit is contained in:
Bartłomiej Dach 2020-11-21 15:08:05 +01:00 committed by GitHub
commit e55326e7c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 260 additions and 8 deletions

View File

@ -40,6 +40,8 @@ namespace osu.Game.Rulesets.Osu.UI
private readonly IDictionary<HitResult, DrawablePool<DrawableOsuJudgement>> poolDictionary = new Dictionary<HitResult, DrawablePool<DrawableOsuJudgement>>();
private readonly Container judgementAboveHitObjectLayer;
public OsuPlayfield()
{
InternalChildren = new Drawable[]
@ -49,6 +51,7 @@ namespace osu.Game.Rulesets.Osu.UI
followPoints = new FollowPointRenderer { RelativeSizeAxes = Axes.Both },
judgementLayer = new JudgementContainer<DrawableOsuJudgement> { RelativeSizeAxes = Axes.Both },
HitObjectContainer,
judgementAboveHitObjectLayer = new Container { RelativeSizeAxes = Axes.Both },
approachCircles = new ProxyContainer { RelativeSizeAxes = Axes.Both },
};
@ -58,13 +61,18 @@ namespace osu.Game.Rulesets.Osu.UI
var hitWindows = new OsuHitWindows();
foreach (var result in Enum.GetValues(typeof(HitResult)).OfType<HitResult>().Where(r => r > HitResult.None && hitWindows.IsHitResultAllowed(r)))
poolDictionary.Add(result, new DrawableJudgementPool(result));
poolDictionary.Add(result, new DrawableJudgementPool(result, onJudgmentLoaded));
AddRangeInternal(poolDictionary.Values);
NewResult += onNewResult;
}
private void onJudgmentLoaded(DrawableOsuJudgement judgement)
{
judgementAboveHitObjectLayer.Add(judgement.GetProxyAboveHitObjectsContent());
}
[BackgroundDependencyLoader(true)]
private void load(OsuRulesetConfigManager config)
{
@ -150,11 +158,13 @@ namespace osu.Game.Rulesets.Osu.UI
private class DrawableJudgementPool : DrawablePool<DrawableOsuJudgement>
{
private readonly HitResult result;
private readonly Action<DrawableOsuJudgement> onLoaded;
public DrawableJudgementPool(HitResult result)
public DrawableJudgementPool(HitResult result, Action<DrawableOsuJudgement> onLoaded)
: base(10)
{
this.result = result;
this.onLoaded = onLoaded;
}
protected override DrawableOsuJudgement CreateNewDrawable()
@ -164,6 +174,8 @@ namespace osu.Game.Rulesets.Osu.UI
// just a placeholder to initialise the correct drawable hierarchy for this pool.
judgement.Apply(new JudgementResult(new HitObject(), new Judgement()) { Type = result }, null);
onLoaded?.Invoke(judgement);
return judgement;
}
}

View File

@ -0,0 +1,39 @@
// 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 NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Graphics;
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
[TestFixture]
public class TestSceneParticleExplosion : OsuTestScene
{
private ParticleExplosion explosion;
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
AddStep("create initial", () =>
{
Child = explosion = new ParticleExplosion(textures.Get("Cursor/cursortrail"), 150, 1200)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(400)
};
});
AddWaitStep("wait for playback", 5);
AddRepeatStep(@"restart animation", () =>
{
explosion.Restart();
}, 10);
}
}
}

View File

@ -0,0 +1,144 @@
// 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.Collections.Generic;
using osu.Framework.Graphics;
using osu.Framework.Graphics.OpenGL.Vertices;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Utils;
using osuTK;
namespace osu.Game.Graphics
{
/// <summary>
/// An explosion of textured particles based on how osu-stable randomises the explosion pattern.
/// </summary>
public class ParticleExplosion : Sprite
{
private readonly int particleCount;
private readonly double duration;
private double startTime;
private readonly List<ParticlePart> parts = new List<ParticlePart>();
public ParticleExplosion(Texture texture, int particleCount, double duration)
{
Texture = texture;
this.particleCount = particleCount;
this.duration = duration;
Blending = BlendingParameters.Additive;
}
protected override void LoadComplete()
{
base.LoadComplete();
Restart();
}
/// <summary>
/// Restart the animation from the current point in time.
/// Supports transform time offset chaining.
/// </summary>
public void Restart()
{
startTime = TransformStartTime;
this.FadeOutFromOne(duration);
parts.Clear();
for (int i = 0; i < particleCount; i++)
parts.Add(new ParticlePart(duration));
}
protected override void Update()
{
base.Update();
Invalidate(Invalidation.DrawNode);
}
protected override DrawNode CreateDrawNode() => new ParticleExplosionDrawNode(this);
private class ParticleExplosionDrawNode : SpriteDrawNode
{
private readonly List<ParticlePart> parts = new List<ParticlePart>();
private ParticleExplosion source => (ParticleExplosion)Source;
private double startTime;
private double currentTime;
private Vector2 sourceSize;
public ParticleExplosionDrawNode(Sprite source)
: base(source)
{
}
public override void ApplyState()
{
base.ApplyState();
parts.Clear();
parts.AddRange(source.parts);
sourceSize = source.Size;
startTime = source.startTime;
currentTime = source.Time.Current;
}
protected override void Blit(Action<TexturedVertex2D> vertexAction)
{
var time = currentTime - startTime;
foreach (var p in parts)
{
Vector2 pos = p.PositionAtTime(time);
float alpha = p.AlphaAtTime(time);
var rect = new RectangleF(
pos.X * sourceSize.X - Texture.DisplayWidth / 2,
pos.Y * sourceSize.Y - Texture.DisplayHeight / 2,
Texture.DisplayWidth,
Texture.DisplayHeight);
// convert to screen space.
var quad = new Quad(
Vector2Extensions.Transform(rect.TopLeft, DrawInfo.Matrix),
Vector2Extensions.Transform(rect.TopRight, DrawInfo.Matrix),
Vector2Extensions.Transform(rect.BottomLeft, DrawInfo.Matrix),
Vector2Extensions.Transform(rect.BottomRight, DrawInfo.Matrix)
);
DrawQuad(Texture, quad, DrawColourInfo.Colour.MultiplyAlpha(alpha), null, vertexAction,
new Vector2(InflationAmount.X / DrawRectangle.Width, InflationAmount.Y / DrawRectangle.Height),
null, TextureCoords);
}
}
}
private readonly struct ParticlePart
{
private readonly double duration;
private readonly float direction;
private readonly float distance;
public ParticlePart(double availableDuration)
{
distance = RNG.NextSingle(0.5f);
duration = RNG.NextDouble(availableDuration / 3, availableDuration);
direction = RNG.NextSingle(0, MathF.PI * 2);
}
public float AlphaAtTime(double time) => 1 - progressAtTime(time);
public Vector2 PositionAtTime(double time)
{
var travelledDistance = distance * progressAtTime(time);
return new Vector2(0.5f) + travelledDistance * new Vector2(MathF.Sin(direction), MathF.Cos(direction));
}
private float progressAtTime(double time) => (float)Math.Clamp(time / duration, 0, 1);
}
}
}

View File

@ -69,5 +69,7 @@ namespace osu.Game.Rulesets.Judgements
this.FadeOutFromOne(800);
}
public Drawable GetAboveHitObjectsProxiedContent() => null;
}
}

View File

@ -6,6 +6,7 @@ using System.Diagnostics;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Scoring;
@ -29,6 +30,8 @@ namespace osu.Game.Rulesets.Judgements
protected SkinnableDrawable JudgementBody { get; private set; }
private readonly Container aboveHitObjectsContent;
[Resolved]
private ISkinSource skinSource { get; set; }
@ -59,6 +62,12 @@ namespace osu.Game.Rulesets.Judgements
{
Size = new Vector2(judgement_size);
Origin = Anchor.Centre;
AddInternal(aboveHitObjectsContent = new Container
{
Depth = float.MinValue,
RelativeSizeAxes = Axes.Both
});
}
[BackgroundDependencyLoader]
@ -67,6 +76,8 @@ namespace osu.Game.Rulesets.Judgements
prepareDrawables();
}
public Drawable GetProxyAboveHitObjectsContent() => aboveHitObjectsContent.CreateProxy();
protected override void LoadComplete()
{
base.LoadComplete();
@ -189,6 +200,7 @@ namespace osu.Game.Rulesets.Judgements
if (JudgementBody != null)
RemoveInternal(JudgementBody);
aboveHitObjectsContent.Clear();
AddInternal(JudgementBody = new SkinnableDrawable(new GameplaySkinComponent<HitResult>(type), _ =>
CreateDefaultJudgement(type), confineMode: ConfineMode.NoScaling)
{
@ -196,6 +208,13 @@ namespace osu.Game.Rulesets.Judgements
Origin = Anchor.Centre,
});
if (JudgementBody.Drawable is IAnimatableJudgement animatable)
{
var proxiedContent = animatable.GetAboveHitObjectsProxiedContent();
if (proxiedContent != null)
aboveHitObjectsContent.Add(proxiedContent);
}
currentDrawableType = type;
}

View File

@ -1,6 +1,7 @@
// 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 JetBrains.Annotations;
using osu.Framework.Graphics;
namespace osu.Game.Rulesets.Judgements
@ -10,6 +11,15 @@ namespace osu.Game.Rulesets.Judgements
/// </summary>
public interface IAnimatableJudgement : IDrawable
{
/// <summary>
/// Start the animation for this judgement from the current point in time.
/// </summary>
void PlayAnimation();
/// <summary>
/// Get proxied content which should be displayed above all hitobjects.
/// </summary>
[CanBeNull]
Drawable GetAboveHitObjectsProxiedContent();
}
}

View File

@ -5,7 +5,9 @@ using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
using osu.Framework.Utils;
using osu.Game.Graphics;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osuTK;
@ -20,7 +22,9 @@ namespace osu.Game.Skinning
private readonly Drawable mainPiece;
public LegacyJudgementPieceNew(HitResult result, Func<Drawable> createMainDrawable, Func<Drawable> createParticleDrawable)
private readonly ParticleExplosion particles;
public LegacyJudgementPieceNew(HitResult result, Func<Drawable> createMainDrawable, Texture particleTexture)
{
this.result = result;
@ -36,6 +40,17 @@ namespace osu.Game.Skinning
})
};
if (particleTexture != null)
{
AddInternal(particles = new ParticleExplosion(particleTexture, 150, 1600)
{
Size = new Vector2(140),
Depth = float.MaxValue,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});
}
if (result != HitResult.Miss)
{
//new judgement shows old as a temporary effect
@ -54,6 +69,13 @@ namespace osu.Game.Skinning
animation?.GotoFrame(0);
if (particles != null)
{
// start the particles already some way into their animation to break cluster away from centre.
using (particles.BeginDelayedSequence(-100, true))
particles.Restart();
}
const double fade_in_length = 120;
const double fade_out_delay = 500;
const double fade_out_length = 600;
@ -99,5 +121,7 @@ namespace osu.Game.Skinning
break;
}
}
public Drawable GetAboveHitObjectsProxiedContent() => temporaryOldStyle?.CreateProxy(); // for new style judgements, only the old style temporary display is in front of objects.
}
}

View File

@ -69,5 +69,7 @@ namespace osu.Game.Skinning
break;
}
}
public Drawable GetAboveHitObjectsProxiedContent() => CreateProxy();
}
}

View File

@ -377,7 +377,7 @@ namespace osu.Game.Skinning
if (createDrawable() != null)
{
if (Configuration.LegacyVersion > 1)
return new LegacyJudgementPieceNew(resultComponent.Component, createDrawable, () => getParticleDrawable(resultComponent.Component));
return new LegacyJudgementPieceNew(resultComponent.Component, createDrawable, getParticleTexture(resultComponent.Component));
else
return new LegacyJudgementPieceOld(resultComponent.Component, createDrawable);
}
@ -388,18 +388,18 @@ namespace osu.Game.Skinning
return this.GetAnimation(component.LookupName, false, false);
}
private Drawable getParticleDrawable(HitResult result)
private Texture getParticleTexture(HitResult result)
{
switch (result)
{
case HitResult.Meh:
return this.GetAnimation("particle50", false, false);
return GetTexture("particle50");
case HitResult.Ok:
return this.GetAnimation("particle100", false, false);
return GetTexture("particle100");
case HitResult.Great:
return this.GetAnimation("particle300", false, false);
return GetTexture("particle300");
}
return null;