1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Merge branch 'master' into triangles-v2

This commit is contained in:
Andrei Zavatski 2022-11-16 14:53:32 +03:00
commit d94c624ee4
10 changed files with 153 additions and 98 deletions

View File

@ -56,6 +56,8 @@ namespace osu.Game.Rulesets.Osu.Mods
{
switch (nested)
{
//Freezing the SliderTicks doesnt play well with snaking sliders
case SliderTick:
//SliderRepeat wont layer correctly if preempt is changed.
case SliderRepeat:
break;

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Taiko.Skinning.Argon
@ -81,12 +82,15 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Argon
updateStateTransforms(drawableHitObject, drawableHitObject.State.Value);
}
private void updateStateTransforms(DrawableHitObject drawableHitObject, ArmedState state)
private void updateStateTransforms(DrawableHitObject h, ArmedState state)
{
if (h.HitObject is not Hit)
return;
switch (state)
{
case ArmedState.Hit:
using (BeginAbsoluteSequence(drawableHitObject.HitStateUpdateTime))
using (BeginAbsoluteSequence(h.HitStateUpdateTime))
{
flash.FadeTo(0.9f).FadeOut(500, Easing.OutQuint);
}

View File

@ -153,12 +153,15 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Default
updateStateTransforms(drawableHitObject, drawableHitObject.State.Value);
}
private void updateStateTransforms(DrawableHitObject drawableHitObject, ArmedState state)
private void updateStateTransforms(DrawableHitObject h, ArmedState state)
{
if (h.HitObject is not Hit)
return;
switch (state)
{
case ArmedState.Hit:
using (BeginAbsoluteSequence(drawableHitObject.HitStateUpdateTime))
using (BeginAbsoluteSequence(h.HitStateUpdateTime))
flashBox.FadeTo(0.9f).FadeOut(300);
break;
}

View File

@ -1,43 +1,40 @@
// 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 osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osuTK;
using osuTK.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Framework.Graphics;
using osuTK.Graphics;
using osu.Framework.Graphics.Shapes;
namespace osu.Game.Tests.Visual.Background
{
public class TestSceneTrianglesBackground : OsuTestScene
{
private readonly Triangles triangles;
public TestSceneTrianglesBackground()
{
AddRange(new Drawable[]
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Gray
Colour = Color4.Black
},
new Container
triangles = new Triangles
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(200),
Masking = true,
CornerRadius = 40,
Child = new TrianglesV2
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
ColourTop = Color4.Red,
ColourBottom = Color4.Orange
}
RelativeSizeAxes = Axes.Both,
ColourLight = Color4.White,
ColourDark = Color4.Gray
}
});
};
}
protected override void LoadComplete()
{
base.LoadComplete();
AddSliderStep("Triangle scale", 0f, 10f, 1f, s => triangles.TriangleScale = s);
}
}
}

View File

@ -163,10 +163,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddUntilStep("wait for bars to disappear", () => !this.ChildrenOfType<BarHitErrorMeter.JudgementLine>().Any());
AddUntilStep("ensure max circles not exceeded", () =>
{
return this.ChildrenOfType<ColourHitErrorMeter>()
.All(m => m.ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Count() <= max_displayed_judgements);
});
this.ChildrenOfType<ColourHitErrorMeter>().First().ChildrenOfType<ColourHitErrorMeter.HitErrorShape>().Count(), () => Is.LessThanOrEqualTo(max_displayed_judgements));
AddStep("show displays", () =>
{

View File

@ -59,6 +59,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards
return base.OnScroll(e);
}
protected override bool OnClick(ClickEvent e) => true;
private class ExpandedContentScrollbar : OsuScrollbar
{
public ExpandedContentScrollbar(Direction scrollDir)

View File

@ -17,6 +17,7 @@ using System.Collections.Generic;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Rendering.Vertices;
using osu.Framework.Lists;
using osu.Framework.Bindables;
namespace osu.Game.Graphics.Backgrounds
{
@ -25,6 +26,11 @@ namespace osu.Game.Graphics.Backgrounds
private const float triangle_size = 100;
private const float base_velocity = 50;
/// <summary>
/// sqrt(3) / 2
/// </summary>
private const float equilateral_triangle_ratio = 0.866f;
/// <summary>
/// How many screen-space pixels are smoothed over.
/// Same behavior as Sprite's EdgeSmoothness.
@ -69,7 +75,13 @@ namespace osu.Game.Graphics.Backgrounds
/// </summary>
protected virtual float SpawnRatio => 1;
private float triangleScale = 1;
private readonly BindableFloat triangleScale = new BindableFloat(1f);
public float TriangleScale
{
get => triangleScale.Value;
set => triangleScale.Value = value;
}
/// <summary>
/// Whether we should drop-off alpha values of triangles more quickly to improve
@ -109,24 +121,7 @@ namespace osu.Game.Graphics.Backgrounds
protected override void LoadComplete()
{
base.LoadComplete();
addTriangles(true);
}
public float TriangleScale
{
get => triangleScale;
set
{
float change = value / triangleScale;
triangleScale = value;
for (int i = 0; i < parts.Count; i++)
{
TriangleParticle newParticle = parts[i];
newParticle.Scale *= change;
parts[i] = newParticle;
}
}
triangleScale.BindValueChanged(_ => Reset(), true);
}
protected override void Update()
@ -147,7 +142,7 @@ namespace osu.Game.Graphics.Backgrounds
// Since position is relative, the velocity needs to scale inversely with DrawHeight.
// Since we will later multiply by the scale of individual triangles we normalize by
// dividing by triangleScale.
float movedDistance = -elapsedSeconds * Velocity * base_velocity / (DrawHeight * triangleScale);
float movedDistance = -elapsedSeconds * Velocity * base_velocity / (DrawHeight * TriangleScale);
for (int i = 0; i < parts.Count; i++)
{
@ -159,7 +154,7 @@ namespace osu.Game.Graphics.Backgrounds
parts[i] = newParticle;
float bottomPos = parts[i].Position.Y + triangle_size * parts[i].Scale * 0.866f / DrawHeight;
float bottomPos = parts[i].Position.Y + triangle_size * parts[i].Scale * equilateral_triangle_ratio / DrawHeight;
if (bottomPos < 0)
parts.RemoveAt(i);
}
@ -185,9 +180,11 @@ namespace osu.Game.Graphics.Backgrounds
// Limited by the maximum size of QuadVertexBuffer for safety.
const int max_triangles = ushort.MaxValue / (IRenderer.VERTICES_PER_QUAD + 2);
AimCount = (int)Math.Min(max_triangles, (DrawWidth * DrawHeight * 0.002f / (triangleScale * triangleScale) * SpawnRatio));
AimCount = (int)Math.Min(max_triangles, DrawWidth * DrawHeight * 0.002f / (TriangleScale * TriangleScale) * SpawnRatio);
for (int i = 0; i < AimCount - parts.Count; i++)
int currentCount = parts.Count;
for (int i = 0; i < AimCount - currentCount; i++)
parts.Add(createTriangle(randomY));
}
@ -195,13 +192,27 @@ namespace osu.Game.Graphics.Backgrounds
{
TriangleParticle particle = CreateTriangle();
particle.Position = new Vector2(nextRandom(), randomY ? nextRandom() : 1);
particle.Position = getRandomPosition(randomY, particle.Scale);
particle.ColourShade = nextRandom();
particle.Colour = CreateTriangleShade(particle.ColourShade);
return particle;
}
private Vector2 getRandomPosition(bool randomY, float scale)
{
float y = 1;
if (randomY)
{
// since triangles are drawn from the top - allow them to be positioned a bit above the screen
float maxOffset = triangle_size * scale * equilateral_triangle_ratio / DrawHeight;
y = Interpolation.ValueAt(nextRandom(), -maxOffset, 1f, 0f, 1f);
}
return new Vector2(nextRandom(), y);
}
/// <summary>
/// Creates a triangle particle with a random scale.
/// </summary>
@ -214,7 +225,7 @@ namespace osu.Game.Graphics.Backgrounds
float u1 = 1 - nextRandom(); //uniform(0,1] random floats
float u2 = 1 - nextRandom();
float randStdNormal = (float)(Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2)); // random normal(0,1)
float scale = Math.Max(triangleScale * (mean + std_dev * randStdNormal), 0.1f); // random normal(mean,stdDev^2)
float scale = Math.Max(TriangleScale * (mean + std_dev * randStdNormal), 0.1f); // random normal(mean,stdDev^2)
return new TriangleParticle { Scale = scale };
}
@ -284,7 +295,7 @@ namespace osu.Game.Graphics.Backgrounds
foreach (TriangleParticle particle in parts)
{
var offset = triangle_size * new Vector2(particle.Scale * 0.5f, particle.Scale * 0.866f);
var offset = triangle_size * new Vector2(particle.Scale * 0.5f, particle.Scale * equilateral_triangle_ratio);
var triangle = new Triangle(
Vector2Extensions.Transform(particle.Position * size, DrawInfo.Matrix),

View File

@ -115,7 +115,11 @@ namespace osu.Game.Rulesets.UI
public Sample Get(string name) => primary.Get(name) ?? fallback.Get(name);
public Task<Sample> GetAsync(string name, CancellationToken cancellationToken = default) => primary.GetAsync(name, cancellationToken) ?? fallback.GetAsync(name, cancellationToken);
public async Task<Sample> GetAsync(string name, CancellationToken cancellationToken = default)
{
return await primary.GetAsync(name, cancellationToken).ConfigureAwait(false)
?? await fallback.GetAsync(name, cancellationToken).ConfigureAwait(false);
}
public Stream GetStream(string name) => primary.GetStream(name) ?? fallback.GetStream(name);

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using System.Linq;
using osu.Framework.Allocation;
@ -11,6 +9,7 @@ using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Configuration;
@ -23,10 +22,9 @@ using osuTK;
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{
[Cached]
public class BarHitErrorMeter : HitErrorMeter
{
private const int judgement_line_width = 14;
[SettingSource("Judgement line thickness", "How thick the individual lines should be.")]
public BindableNumber<float> JudgementLineThickness { get; } = new BindableNumber<float>(4)
{
@ -44,28 +42,33 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
[SettingSource("Label style", "How to show early/late extremities")]
public Bindable<LabelStyles> LabelStyle { get; } = new Bindable<LabelStyles>(LabelStyles.Icons);
private SpriteIcon arrow;
private UprightAspectMaintainingContainer labelEarly;
private UprightAspectMaintainingContainer labelLate;
private const int judgement_line_width = 14;
private Container colourBarsEarly;
private Container colourBarsLate;
private const int max_concurrent_judgements = 50;
private Container judgementsContainer;
private const int centre_marker_size = 8;
private double maxHitWindow;
private double floatingAverage;
private Container colourBars;
private Container arrowContainer;
private (HitResult result, double length)[] hitWindows;
private readonly DrawablePool<JudgementLine> judgementLinePool = new DrawablePool<JudgementLine>(50);
private const int max_concurrent_judgements = 50;
private SpriteIcon arrow = null!;
private UprightAspectMaintainingContainer labelEarly = null!;
private UprightAspectMaintainingContainer labelLate = null!;
private Drawable[] centreMarkerDrawables;
private Container colourBarsEarly = null!;
private Container colourBarsLate = null!;
private const int centre_marker_size = 8;
private Container judgementsContainer = null!;
private Container colourBars = null!;
private Container arrowContainer = null!;
private (HitResult result, double length)[] hitWindows = null!;
private Drawable[]? centreMarkerDrawables;
public BarHitErrorMeter()
{
@ -88,6 +91,7 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
Margin = new MarginPadding(2),
Children = new Drawable[]
{
judgementLinePool,
colourBars = new Container
{
Name = "colour axis",
@ -403,11 +407,12 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
}
}
judgementsContainer.Add(new JudgementLine
judgementLinePool.Get(drawableJudgement =>
{
JudgementLineThickness = { BindTarget = JudgementLineThickness },
Y = getRelativeJudgementPosition(judgement.TimeOffset),
Colour = GetColourForHitResult(judgement.Type),
drawableJudgement.Y = getRelativeJudgementPosition(judgement.TimeOffset);
drawableJudgement.Colour = GetColourForHitResult(judgement.Type);
judgementsContainer.Add(drawableJudgement);
});
arrow.MoveToY(
@ -417,10 +422,13 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
private float getRelativeJudgementPosition(double value) => Math.Clamp((float)((value / maxHitWindow) + 1) / 2, 0, 1);
internal class JudgementLine : CompositeDrawable
internal class JudgementLine : PoolableDrawable
{
public readonly BindableNumber<float> JudgementLineThickness = new BindableFloat();
[Resolved]
private BarHitErrorMeter barHitErrorMeter { get; set; } = null!;
public JudgementLine()
{
RelativeSizeAxes = Axes.X;
@ -439,16 +447,22 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
protected override void LoadComplete()
{
base.LoadComplete();
JudgementLineThickness.BindTo(barHitErrorMeter.JudgementLineThickness);
JudgementLineThickness.BindValueChanged(thickness => Height = thickness.NewValue, true);
}
protected override void PrepareForUse()
{
base.PrepareForUse();
const int judgement_fade_in_duration = 100;
const int judgement_fade_out_duration = 5000;
base.LoadComplete();
Alpha = 0;
Width = 0;
JudgementLineThickness.BindValueChanged(thickness => Height = thickness.NewValue, true);
this
.FadeTo(0.6f, judgement_fade_in_duration, Easing.OutQuint)
.ResizeWidthTo(1, judgement_fade_in_duration, Easing.OutQuint)

View File

@ -3,9 +3,11 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Graphics.Shapes;
using osu.Game.Configuration;
using osu.Game.Rulesets.Judgements;
@ -15,6 +17,7 @@ using osuTK.Graphics;
namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{
[Cached]
public class ColourHitErrorMeter : HitErrorMeter
{
private const int animation_duration = 200;
@ -82,7 +85,7 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
{
base.LoadComplete();
JudgementCount.BindValueChanged(count =>
JudgementCount.BindValueChanged(_ =>
{
removeExtraJudgements();
updateMetrics();
@ -91,14 +94,17 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
JudgementSpacing.BindValueChanged(_ => updateMetrics(), true);
}
private readonly DrawablePool<HitErrorShape> judgementLinePool = new DrawablePool<HitErrorShape>(50);
public void Push(Color4 colour)
{
Add(new HitErrorShape(colour, drawable_judgement_size)
judgementLinePool.Get(shape =>
{
Shape = { BindTarget = JudgementShape },
});
shape.Colour = colour;
Add(shape);
removeExtraJudgements();
removeExtraJudgements();
});
}
private void removeExtraJudgements()
@ -116,32 +122,32 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
}
}
public class HitErrorShape : Container
public class HitErrorShape : PoolableDrawable
{
public bool IsRemoved { get; private set; }
public readonly Bindable<ShapeStyle> Shape = new Bindable<ShapeStyle>();
private readonly Color4 colour;
[Resolved]
private ColourHitErrorMeter hitErrorMeter { get; set; } = null!;
private Container content = null!;
public HitErrorShape(Color4 colour, int size)
public HitErrorShape()
{
this.colour = colour;
Size = new Vector2(size);
Size = new Vector2(drawable_judgement_size);
}
protected override void LoadComplete()
{
base.LoadComplete();
Child = content = new Container
InternalChild = content = new Container
{
RelativeSizeAxes = Axes.Both,
Colour = colour
};
Shape.BindTo(hitErrorMeter.JudgementShape);
Shape.BindValueChanged(shape =>
{
switch (shape.NewValue)
@ -155,17 +161,32 @@ namespace osu.Game.Screens.Play.HUD.HitErrorMeters
break;
}
}, true);
}
content.FadeInFromZero(animation_duration, Easing.OutQuint);
content.MoveToY(-DrawSize.Y);
content.MoveToY(0, animation_duration, Easing.OutQuint);
protected override void PrepareForUse()
{
base.PrepareForUse();
this.FadeInFromZero(animation_duration, Easing.OutQuint)
// On pool re-use, start flow animation from (0,0).
.MoveTo(Vector2.Zero);
content.MoveToY(-DrawSize.Y)
.MoveToY(0, animation_duration, Easing.OutQuint);
}
protected override void FreeAfterUse()
{
base.FreeAfterUse();
IsRemoved = false;
}
public void Remove()
{
IsRemoved = true;
this.FadeOut(animation_duration, Easing.OutQuint).Expire();
this.FadeOut(animation_duration, Easing.OutQuint)
.Expire();
}
}