1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 07:43:00 +08:00

Merge branch 'master' into update-framework

This commit is contained in:
Dean Herbert 2022-11-25 01:00:08 +09:00
commit 2b2beadd06
19 changed files with 902 additions and 28 deletions

View File

@ -51,7 +51,7 @@
<Reference Include="Java.Interop" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.1113.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.1124.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2022.1124.0" />
</ItemGroup>
<ItemGroup Label="Transitive Dependencies">

View File

@ -83,5 +83,41 @@ namespace osu.Game.Rulesets.Taiko.Tests
AddAssert("first barline ommited", () => barlines.All(b => b.StartTime != start_time));
AddAssert("second barline generated", () => barlines.Any(b => b.StartTime == start_time + (beat_length * time_signature_numerator)));
}
[Test]
public void TestNegativeStartTimeTimingPoint()
{
const double beat_length = 250;
const int time_signature_numerator = 4;
var beatmap = new Beatmap<TaikoHitObject>
{
HitObjects =
{
new Hit
{
Type = HitType.Centre,
StartTime = 1000
}
},
BeatmapInfo =
{
Difficulty = new BeatmapDifficulty { SliderTickRate = 4 },
Ruleset = new TaikoRuleset().RulesetInfo
},
};
beatmap.ControlPointInfo.Add(-100, new TimingControlPoint
{
BeatLength = beat_length,
TimeSignature = new TimeSignature(time_signature_numerator)
});
var barlines = new BarLineGenerator<BarLine>(beatmap).BarLines;
AddAssert("bar line generated at t=900", () => barlines.Any(line => line.StartTime == 900));
AddAssert("bar line generated at t=1900", () => barlines.Any(line => line.StartTime == 1900));
}
}
}

View File

@ -40,7 +40,9 @@ namespace osu.Game.Tests.Skins
// Covers clicks/s counter
"Archives/modified-default-20220818.osk",
// Covers longest combo counter
"Archives/modified-default-20221012.osk"
"Archives/modified-default-20221012.osk",
// Covers TextElement and BeatmapInfoDrawable
"Archives/modified-default-20221102.osk"
};
/// <summary>

View File

@ -0,0 +1,96 @@
// 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.Allocation;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Rendering;
namespace osu.Game.Tests.Visual.Background
{
public class TestSceneTriangleBorderShader : OsuTestScene
{
private readonly TriangleBorder border;
public TestSceneTriangleBorderShader()
{
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.DarkGreen
},
border = new TriangleBorder
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(100)
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
AddSliderStep("Thickness", 0f, 1f, 0.02f, t => border.Thickness = t);
}
private class TriangleBorder : Sprite
{
private float thickness = 0.02f;
public float Thickness
{
get => thickness;
set
{
thickness = value;
Invalidate(Invalidation.DrawNode);
}
}
[BackgroundDependencyLoader]
private void load(ShaderManager shaders, IRenderer renderer)
{
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "TriangleBorder");
Texture = renderer.WhitePixel;
}
protected override DrawNode CreateDrawNode() => new TriangleBorderDrawNode(this);
private class TriangleBorderDrawNode : SpriteDrawNode
{
public new TriangleBorder Source => (TriangleBorder)base.Source;
public TriangleBorderDrawNode(TriangleBorder source)
: base(source)
{
}
private float thickness;
public override void ApplyState()
{
base.ApplyState();
thickness = Source.thickness;
}
public override void Draw(IRenderer renderer)
{
TextureShader.GetUniform<float>("thickness").UpdateValue(ref thickness);
base.Draw(renderer);
}
protected override bool CanDrawOpaqueInterior => false;
}
}
}
}

View File

@ -0,0 +1,61 @@
// 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;
namespace osu.Game.Tests.Visual.Background
{
public class TestSceneTrianglesV2Background : OsuTestScene
{
private readonly TrianglesV2 triangles;
public TestSceneTrianglesV2Background()
{
AddRange(new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Gray
},
new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(500, 100),
Masking = true,
CornerRadius = 40,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Red
},
triangles = new TrianglesV2
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
ColourTop = Color4.White,
ColourBottom = Color4.Red
}
}
}
});
}
protected override void LoadComplete()
{
base.LoadComplete();
AddSliderStep("Spawn ratio", 0f, 2f, 1f, s => triangles.SpawnRatio = s);
AddSliderStep("Thickness", 0f, 1f, 0.02f, t => triangles.Thickness = t);
}
}
}

View File

@ -18,6 +18,7 @@ using osu.Game.Overlays;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Timing;
using osuTK;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Editing
{
@ -125,6 +126,41 @@ namespace osu.Game.Tests.Visual.Editing
AddUntilStep("wait for track stopped", () => !EditorClock.IsRunning);
}
[Test]
public void TestNoCrashesWhenNoGroupSelected()
{
AddStep("unset selected group", () => selectedGroup.Value = null);
AddStep("press T to tap", () => InputManager.Key(Key.T));
AddStep("click tap button", () =>
{
control.ChildrenOfType<OsuButton>()
.Last()
.TriggerClick();
});
AddStep("click reset button", () =>
{
control.ChildrenOfType<OsuButton>()
.First()
.TriggerClick();
});
AddStep("adjust offset", () =>
{
var adjustOffsetButton = control.ChildrenOfType<TimingAdjustButton>().First();
InputManager.MoveMouseTo(adjustOffsetButton);
InputManager.Click(MouseButton.Left);
});
AddStep("adjust BPM", () =>
{
var adjustBPMButton = control.ChildrenOfType<TimingAdjustButton>().Last();
InputManager.MoveMouseTo(adjustBPMButton);
InputManager.Click(MouseButton.Left);
});
}
protected override void Dispose(bool isDisposing)
{
Beatmap.Disabled = false;

View File

@ -0,0 +1,87 @@
// 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 NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osu.Game.Overlays.Chat;
namespace osu.Game.Tests.Visual.Online
{
[TestFixture]
public class TestSceneDrawableChannel : OsuTestScene
{
private Channel channel = null!;
private DrawableChannel drawableChannel = null!;
[SetUpSteps]
public void SetUpSteps()
{
AddStep("create channel", () => channel = new Channel
{
Id = 1,
Name = "Test channel"
});
AddStep("create drawable channel", () => Child = drawableChannel = new DrawableChannel(channel)
{
RelativeSizeAxes = Axes.Both
});
}
[Test]
public void TestDaySeparators()
{
var localUser = new APIUser
{
Id = 3,
Username = "LocalUser"
};
string uuid = Guid.NewGuid().ToString();
AddStep("add local echo message", () => channel.AddLocalEcho(new LocalEchoMessage
{
Sender = localUser,
Content = "Hi there all!",
Timestamp = new DateTimeOffset(2022, 11, 21, 20, 11, 13, TimeSpan.Zero),
Uuid = uuid
}));
AddUntilStep("one day separator present", () => drawableChannel.ChildrenOfType<DaySeparator>().Count() == 1);
AddStep("add two prior messages to channel", () => channel.AddNewMessages(
new Message(1)
{
Sender = new APIUser
{
Id = 1,
Username = "TestUser"
},
Content = "This is a message",
Timestamp = new DateTimeOffset(2021, 10, 10, 13, 33, 23, TimeSpan.Zero),
},
new Message(2)
{
Sender = new APIUser
{
Id = 2,
Username = "TestUser2"
},
Content = "This is another message",
Timestamp = new DateTimeOffset(2021, 10, 11, 13, 33, 23, TimeSpan.Zero)
}));
AddUntilStep("three day separators present", () => drawableChannel.ChildrenOfType<DaySeparator>().Count() == 3);
AddStep("resolve pending message", () => channel.ReplaceMessage(channel.Messages.OfType<LocalEchoMessage>().Single(), new Message(3)
{
Sender = localUser,
Content = "Hi there all!",
Timestamp = new DateTimeOffset(2022, 11, 22, 20, 11, 16, TimeSpan.Zero),
Uuid = uuid
}));
AddUntilStep("three day separators present", () => drawableChannel.ChildrenOfType<DaySeparator>().Count() == 3);
AddAssert("last day separator is from correct day", () => drawableChannel.ChildrenOfType<DaySeparator>().Last().Date.Date == new DateTime(2022, 11, 22));
}
}
}

View File

@ -0,0 +1,319 @@
// 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.Utils;
using osuTK;
using System;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Allocation;
using System.Collections.Generic;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Rendering.Vertices;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp;
using osuTK.Graphics;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
namespace osu.Game.Graphics.Backgrounds
{
public class TrianglesV2 : Drawable
{
private const float triangle_size = 100;
private const float base_velocity = 50;
private const int texture_height = 128;
/// <summary>
/// sqrt(3) / 2
/// </summary>
private const float equilateral_triangle_ratio = 0.866f;
private readonly Bindable<Color4> colourTop = new Bindable<Color4>(Color4.White);
private readonly Bindable<Color4> colourBottom = new Bindable<Color4>(Color4.Black);
public Color4 ColourTop
{
get => colourTop.Value;
set => colourTop.Value = value;
}
public Color4 ColourBottom
{
get => colourBottom.Value;
set => colourBottom.Value = value;
}
public float Thickness { get; set; } = 0.02f; // No need for invalidation since it's happening in Update()
/// <summary>
/// Whether we should create new triangles as others expire.
/// </summary>
protected virtual bool CreateNewTriangles => true;
private readonly BindableFloat spawnRatio = new BindableFloat(1f);
/// <summary>
/// The amount of triangles we want compared to the default distribution.
/// </summary>
public float SpawnRatio
{
get => spawnRatio.Value;
set => spawnRatio.Value = value;
}
/// <summary>
/// The relative velocity of the triangles. Default is 1.
/// </summary>
public float Velocity = 1;
private readonly List<TriangleParticle> parts = new List<TriangleParticle>();
[Resolved]
private IRenderer renderer { get; set; } = null!;
private Random? stableRandom;
private IShader shader = null!;
private Texture texture = null!;
/// <summary>
/// Construct a new triangle visualisation.
/// </summary>
/// <param name="seed">An optional seed to stabilise random positions / attributes. Note that this does not guarantee stable playback when seeking in time.</param>
public TrianglesV2(int? seed = null)
{
if (seed != null)
stableRandom = new Random(seed.Value);
}
[BackgroundDependencyLoader]
private void load(ShaderManager shaders)
{
shader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "TriangleBorder");
}
protected override void LoadComplete()
{
base.LoadComplete();
colourTop.BindValueChanged(_ => updateTexture());
colourBottom.BindValueChanged(_ => updateTexture(), true);
spawnRatio.BindValueChanged(_ => Reset(), true);
}
private void updateTexture()
{
var image = new Image<Rgba32>(texture_height, 1);
texture = renderer.CreateTexture(1, texture_height, true);
for (int i = 0; i < texture_height; i++)
{
float ratio = (float)i / texture_height;
image[i, 0] = new Rgba32(
colourBottom.Value.R * ratio + colourTop.Value.R * (1f - ratio),
colourBottom.Value.G * ratio + colourTop.Value.G * (1f - ratio),
colourBottom.Value.B * ratio + colourTop.Value.B * (1f - ratio)
);
}
texture.SetData(new TextureUpload(image));
Invalidate(Invalidation.DrawNode);
}
protected override void Update()
{
base.Update();
Invalidate(Invalidation.DrawNode);
if (CreateNewTriangles)
addTriangles(false);
float elapsedSeconds = (float)Time.Elapsed / 1000;
// Since position is relative, the velocity needs to scale inversely with DrawHeight.
float movedDistance = -elapsedSeconds * Velocity * base_velocity / DrawHeight;
for (int i = 0; i < parts.Count; i++)
{
TriangleParticle newParticle = parts[i];
newParticle.Position.Y += Math.Max(0.5f, parts[i].SpeedMultiplier) * movedDistance;
parts[i] = newParticle;
float bottomPos = parts[i].Position.Y + triangle_size * equilateral_triangle_ratio / DrawHeight;
if (bottomPos < 0)
parts.RemoveAt(i);
}
}
/// <summary>
/// Clears and re-initialises triangles according to a given seed.
/// </summary>
/// <param name="seed">An optional seed to stabilise random positions / attributes. Note that this does not guarantee stable playback when seeking in time.</param>
public void Reset(int? seed = null)
{
if (seed != null)
stableRandom = new Random(seed.Value);
parts.Clear();
addTriangles(true);
}
protected int AimCount { get; private set; }
private void addTriangles(bool randomY)
{
// 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.0005f * SpawnRatio);
int currentCount = parts.Count;
for (int i = 0; i < AimCount - currentCount; i++)
parts.Add(createTriangle(randomY));
}
private TriangleParticle createTriangle(bool randomY)
{
TriangleParticle particle = CreateTriangle();
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 * equilateral_triangle_ratio / DrawHeight;
y = Interpolation.ValueAt(nextRandom(), -maxOffset, 1f, 0f, 1f);
}
particle.Position = new Vector2(nextRandom(), y);
return particle;
}
/// <summary>
/// Creates a triangle particle with a random speed multiplier.
/// </summary>
/// <returns>The triangle particle.</returns>
protected virtual TriangleParticle CreateTriangle()
{
const float std_dev = 0.16f;
const float mean = 0.5f;
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 speedMultiplier = Math.Max(mean + std_dev * randStdNormal, 0.1f); // random normal(mean,stdDev^2)
return new TriangleParticle { SpeedMultiplier = speedMultiplier };
}
private float nextRandom() => (float)(stableRandom?.NextDouble() ?? RNG.NextSingle());
protected override DrawNode CreateDrawNode() => new TrianglesDrawNode(this);
private class TrianglesDrawNode : DrawNode
{
protected new TrianglesV2 Source => (TrianglesV2)base.Source;
private IShader shader = null!;
private Texture texture = null!;
private readonly List<TriangleParticle> parts = new List<TriangleParticle>();
private Vector2 size;
private float thickness;
private IVertexBatch<TexturedVertex2D>? vertexBatch;
public TrianglesDrawNode(TrianglesV2 source)
: base(source)
{
}
public override void ApplyState()
{
base.ApplyState();
shader = Source.shader;
texture = Source.texture;
size = Source.DrawSize;
thickness = Source.Thickness;
parts.Clear();
parts.AddRange(Source.parts);
}
public override void Draw(IRenderer renderer)
{
base.Draw(renderer);
if (Source.AimCount == 0)
return;
if (vertexBatch == null || vertexBatch.Size != Source.AimCount)
{
vertexBatch?.Dispose();
vertexBatch = renderer.CreateQuadBatch<TexturedVertex2D>(Source.AimCount, 1);
}
shader.Bind();
shader.GetUniform<float>("thickness").UpdateValue(ref thickness);
foreach (TriangleParticle particle in parts)
{
var offset = triangle_size * new Vector2(0.5f, equilateral_triangle_ratio);
Vector2 topLeft = particle.Position * size + new Vector2(-offset.X, 0f);
Vector2 topRight = particle.Position * size + new Vector2(offset.X, 0);
Vector2 bottomLeft = particle.Position * size + new Vector2(-offset.X, offset.Y);
Vector2 bottomRight = particle.Position * size + new Vector2(offset.X, offset.Y);
var drawQuad = new Quad(
Vector2Extensions.Transform(topLeft, DrawInfo.Matrix),
Vector2Extensions.Transform(topRight, DrawInfo.Matrix),
Vector2Extensions.Transform(bottomLeft, DrawInfo.Matrix),
Vector2Extensions.Transform(bottomRight, DrawInfo.Matrix)
);
var tRect = new Quad(
topLeft.X / size.X,
topLeft.Y / size.Y * texture_height,
(topRight.X - topLeft.X) / size.X,
(bottomRight.Y - topRight.Y) / size.Y * texture_height
).AABBFloat;
renderer.DrawQuad(texture, drawQuad, DrawColourInfo.Colour, tRect, vertexBatch.AddAction, textureCoords: tRect);
}
shader.Unbind();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
vertexBatch?.Dispose();
}
}
protected struct TriangleParticle
{
/// <summary>
/// The position of the top vertex of the triangle.
/// </summary>
public Vector2 Position;
/// <summary>
/// The speed multiplier of the triangle.
/// </summary>
public float SpeedMultiplier;
}
}
}

View File

@ -177,8 +177,8 @@ namespace osu.Game.Online.Chat
protected override float Spacing => 5;
protected override float DateAlign => 125;
public StandAloneDaySeparator(DateTimeOffset time)
: base(time)
public StandAloneDaySeparator(DateTimeOffset date)
: base(date)
{
}

View File

@ -22,14 +22,14 @@ namespace osu.Game.Overlays.Chat
protected virtual float Spacing => 15;
private readonly DateTimeOffset time;
public readonly DateTimeOffset Date;
[Resolved(CanBeNull = true)]
private OverlayColourProvider? colourProvider { get; set; }
public DaySeparator(DateTimeOffset time)
public DaySeparator(DateTimeOffset date)
{
this.time = time;
Date = date;
Height = 40;
}
@ -80,7 +80,7 @@ namespace osu.Game.Overlays.Chat
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Text = time.ToLocalTime().ToLocalisableString(@"dd MMMM yyyy").ToUpper(),
Text = Date.ToLocalTime().ToLocalisableString(@"dd MMMM yyyy").ToUpper(),
Font = OsuFont.Torus.With(size: TextSize, weight: FontWeight.SemiBold),
Colour = colourProvider?.Content1 ?? Colour4.White,
},

View File

@ -134,35 +134,22 @@ namespace osu.Game.Overlays.Chat
foreach (var message in displayMessages)
{
if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != message.Timestamp.ToLocalTime().Date)
ChatLineFlow.Add(CreateDaySeparator(message.Timestamp));
addDaySeparatorIfRequired(lastMessage, message);
ChatLineFlow.Add(CreateChatLine(message));
lastMessage = message;
}
var staleMessages = chatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray();
int count = staleMessages.Length - Channel.MAX_HISTORY;
if (count > 0)
{
void expireAndAdjustScroll(Drawable d)
{
scroll.OffsetScrollPosition(-d.DrawHeight);
d.Expire();
}
for (int i = 0; i < count; i++)
expireAndAdjustScroll(staleMessages[i]);
// remove all adjacent day separators after stale message removal
for (int i = 0; i < ChatLineFlow.Count - 1; i++)
{
if (!(ChatLineFlow[i] is DaySeparator)) break;
if (!(ChatLineFlow[i + 1] is DaySeparator)) break;
expireAndAdjustScroll(ChatLineFlow[i]);
}
removeAdjacentDaySeparators();
}
// due to the scroll adjusts from old messages removal above, a scroll-to-end must be enforced,
@ -183,10 +170,46 @@ namespace osu.Game.Overlays.Chat
ChatLineFlow.Remove(found, false);
found.Message = updated;
addDaySeparatorIfRequired(chatLines.LastOrDefault()?.Message, updated);
ChatLineFlow.Add(found);
}
});
private void addDaySeparatorIfRequired(Message lastMessage, Message message)
{
if (lastMessage == null || lastMessage.Timestamp.ToLocalTime().Date != message.Timestamp.ToLocalTime().Date)
{
// A day separator is displayed even if no messages are in the channel.
// If there are no messages after it, the simplest way to ensure it is fresh is to remove it
// and add a new one instead.
if (ChatLineFlow.LastOrDefault() is DaySeparator ds)
ChatLineFlow.Remove(ds, true);
ChatLineFlow.Add(CreateDaySeparator(message.Timestamp));
removeAdjacentDaySeparators();
}
}
private void removeAdjacentDaySeparators()
{
// remove all adjacent day separators after stale message removal
for (int i = 0; i < ChatLineFlow.Count - 1; i++)
{
if (!(ChatLineFlow[i] is DaySeparator)) break;
if (!(ChatLineFlow[i + 1] is DaySeparator)) break;
expireAndAdjustScroll(ChatLineFlow[i]);
}
}
private void expireAndAdjustScroll(Drawable d)
{
scroll.OffsetScrollPosition(-d.DrawHeight);
d.Expire();
}
private void messageRemoved(Message removed) => Schedule(() =>
{
chatLines.FirstOrDefault(c => c.Message == removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire();

View File

@ -27,7 +27,10 @@ namespace osu.Game.Rulesets.Objects
if (beatmap.HitObjects.Count == 0)
return;
HitObject firstObject = beatmap.HitObjects.First();
HitObject lastObject = beatmap.HitObjects.Last();
double firstHitTime = firstObject.StartTime;
double lastHitTime = 1 + lastObject.GetEndTime();
var timingPoints = beatmap.ControlPointInfo.TimingPoints;
@ -41,12 +44,31 @@ namespace osu.Game.Rulesets.Objects
EffectControlPoint currentEffectPoint = beatmap.ControlPointInfo.EffectPointAt(currentTimingPoint.Time);
int currentBeat = 0;
// Don't generate barlines before the hit object or t=0 (whichever is earliest). Some beatmaps use very unrealistic values here (although none are ranked).
// I'm not sure we ever want barlines to appear before the first hitobject, but let's keep some degree of compatibility for now.
// Of note, this will still differ from stable if the first timing control point is t<0 and is not near the first hitobject.
double generationStartTime = Math.Min(0, firstHitTime);
// Stop on the next timing point, or if there is no next timing point stop slightly past the last object
double endTime = i < timingPoints.Count - 1 ? timingPoints[i + 1].Time : lastHitTime + currentTimingPoint.BeatLength * currentTimingPoint.TimeSignature.Numerator;
double startTime = currentTimingPoint.Time;
double barLength = currentTimingPoint.BeatLength * currentTimingPoint.TimeSignature.Numerator;
double startTime;
if (currentTimingPoint.Time > generationStartTime)
{
startTime = currentTimingPoint.Time;
}
else
{
// If the timing point starts before the minimum allowable time for bar lines,
// we still need to compute a start time for generation that is actually properly aligned with the timing point.
int barCount = (int)Math.Ceiling((generationStartTime - currentTimingPoint.Time) / barLength);
startTime = currentTimingPoint.Time + barCount * barLength;
}
if (currentEffectPoint.OmitFirstBarLine)
{
startTime += barLength;

View File

@ -295,6 +295,9 @@ namespace osu.Game.Screens.Edit.Timing
private void handleTap()
{
if (selectedGroup?.Value == null)
return;
tapTimings.Add(Clock.CurrentTime);
if (tapTimings.Count > initial_taps_to_ignore + max_taps_to_consider)

View File

@ -183,18 +183,27 @@ namespace osu.Game.Screens.Edit.Timing
private void start()
{
if (selectedGroup.Value == null)
return;
editorClock.Seek(selectedGroup.Value.Time);
editorClock.Start();
}
private void reset()
{
if (selectedGroup.Value == null)
return;
editorClock.Stop();
editorClock.Seek(selectedGroup.Value.Time);
}
private void adjustOffset(double adjust)
{
if (selectedGroup.Value == null)
return;
bool wasAtStart = editorClock.CurrentTimeAccurate == selectedGroup.Value.Time;
// VERY TEMPORARY
@ -216,7 +225,7 @@ namespace osu.Game.Screens.Edit.Timing
private void adjustBpm(double adjust)
{
var timing = selectedGroup.Value.ControlPoints.OfType<TimingControlPoint>().FirstOrDefault();
var timing = selectedGroup.Value?.ControlPoints.OfType<TimingControlPoint>().FirstOrDefault();
if (timing == null)
return;

View File

@ -0,0 +1,142 @@
// 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 System.Collections.Immutable;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Extensions;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Localisation;
using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Skinning.Components
{
[UsedImplicitly]
public class BeatmapAttributeText : Container, ISkinnableDrawable
{
public bool UsesFixedAnchor { get; set; }
[SettingSource("Attribute", "The attribute to be displayed.")]
public Bindable<BeatmapAttribute> Attribute { get; } = new Bindable<BeatmapAttribute>(BeatmapAttribute.StarRating);
[SettingSource("Template", "Supports {Label} and {Value}, but also including arbitrary attributes like {StarRating} (see attribute list for supported values).")]
public Bindable<string> Template { get; set; } = new Bindable<string>("{Label}: {Value}");
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
private readonly Dictionary<BeatmapAttribute, LocalisableString> valueDictionary = new Dictionary<BeatmapAttribute, LocalisableString>();
private static readonly ImmutableDictionary<BeatmapAttribute, LocalisableString> label_dictionary = new Dictionary<BeatmapAttribute, LocalisableString>
{
[BeatmapAttribute.CircleSize] = BeatmapsetsStrings.ShowStatsCs,
[BeatmapAttribute.Accuracy] = BeatmapsetsStrings.ShowStatsAccuracy,
[BeatmapAttribute.HPDrain] = BeatmapsetsStrings.ShowStatsDrain,
[BeatmapAttribute.ApproachRate] = BeatmapsetsStrings.ShowStatsAr,
[BeatmapAttribute.StarRating] = BeatmapsetsStrings.ShowStatsStars,
[BeatmapAttribute.Title] = EditorSetupStrings.Title,
[BeatmapAttribute.Artist] = EditorSetupStrings.Artist,
[BeatmapAttribute.DifficultyName] = EditorSetupStrings.DifficultyHeader,
[BeatmapAttribute.Creator] = EditorSetupStrings.Creator,
[BeatmapAttribute.Length] = ArtistStrings.TracklistLength.ToTitle(),
[BeatmapAttribute.RankedStatus] = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault,
[BeatmapAttribute.BPM] = BeatmapsetsStrings.ShowStatsBpm,
}.ToImmutableDictionary();
private readonly OsuSpriteText text;
public BeatmapAttributeText()
{
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
text = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Font = OsuFont.Default.With(size: 40)
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Attribute.BindValueChanged(_ => updateLabel());
Template.BindValueChanged(_ => updateLabel());
beatmap.BindValueChanged(b =>
{
updateBeatmapContent(b.NewValue);
updateLabel();
}, true);
}
private void updateBeatmapContent(WorkingBeatmap workingBeatmap)
{
valueDictionary[BeatmapAttribute.Title] = workingBeatmap.BeatmapInfo.Metadata.Title;
valueDictionary[BeatmapAttribute.Artist] = workingBeatmap.BeatmapInfo.Metadata.Artist;
valueDictionary[BeatmapAttribute.DifficultyName] = workingBeatmap.BeatmapInfo.DifficultyName;
valueDictionary[BeatmapAttribute.Creator] = workingBeatmap.BeatmapInfo.Metadata.Author.Username;
valueDictionary[BeatmapAttribute.Length] = TimeSpan.FromMilliseconds(workingBeatmap.BeatmapInfo.Length).ToFormattedDuration();
valueDictionary[BeatmapAttribute.RankedStatus] = workingBeatmap.BeatmapInfo.Status.GetLocalisableDescription();
valueDictionary[BeatmapAttribute.BPM] = workingBeatmap.BeatmapInfo.BPM.ToLocalisableString(@"F2");
valueDictionary[BeatmapAttribute.CircleSize] = ((double)workingBeatmap.BeatmapInfo.Difficulty.CircleSize).ToLocalisableString(@"F2");
valueDictionary[BeatmapAttribute.HPDrain] = ((double)workingBeatmap.BeatmapInfo.Difficulty.DrainRate).ToLocalisableString(@"F2");
valueDictionary[BeatmapAttribute.Accuracy] = ((double)workingBeatmap.BeatmapInfo.Difficulty.OverallDifficulty).ToLocalisableString(@"F2");
valueDictionary[BeatmapAttribute.ApproachRate] = ((double)workingBeatmap.BeatmapInfo.Difficulty.ApproachRate).ToLocalisableString(@"F2");
valueDictionary[BeatmapAttribute.StarRating] = workingBeatmap.BeatmapInfo.StarRating.ToLocalisableString(@"F2");
}
private void updateLabel()
{
string numberedTemplate = Template.Value
.Replace("{", "{{")
.Replace("}", "}}")
.Replace(@"{{Label}}", "{0}")
.Replace(@"{{Value}}", $"{{{1 + (int)Attribute.Value}}}");
object?[] args = valueDictionary.OrderBy(pair => pair.Key)
.Select(pair => pair.Value)
.Prepend(label_dictionary[Attribute.Value])
.Cast<object?>()
.ToArray();
foreach (var type in Enum.GetValues(typeof(BeatmapAttribute)).Cast<BeatmapAttribute>())
{
numberedTemplate = numberedTemplate.Replace($"{{{{{type}}}}}", $"{{{1 + (int)type}}}");
}
text.Text = LocalisableString.Format(numberedTemplate, args);
}
}
public enum BeatmapAttribute
{
CircleSize,
HPDrain,
Accuracy,
ApproachRate,
StarRating,
Title,
Artist,
DifficultyName,
Creator,
Length,
RankedStatus,
BPM,
}
}

View File

@ -0,0 +1,38 @@
// 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.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Skinning.Components
{
[UsedImplicitly]
public class TextElement : Container, ISkinnableDrawable
{
public bool UsesFixedAnchor { get; set; }
[SettingSource("Text", "The text to be displayed.")]
public Bindable<string> Text { get; } = new Bindable<string>("Circles!");
public TextElement()
{
AutoSizeAxes = Axes.Both;
OsuSpriteText text;
InternalChildren = new Drawable[]
{
text = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Default.With(size: 40)
}
};
text.Current.BindTo(Text);
}
}
}

View File

@ -36,7 +36,7 @@
</PackageReference>
<PackageReference Include="Realm" Version="10.18.0" />
<PackageReference Include="ppy.osu.Framework" Version="2022.1124.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.1113.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.1124.0" />
<PackageReference Include="Sentry" Version="3.23.1" />
<PackageReference Include="SharpCompress" Version="0.32.2" />
<PackageReference Include="NUnit" Version="3.13.3" />

View File

@ -61,7 +61,7 @@
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.1113.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.1124.0" />
<PackageReference Include="ppy.osu.Framework.iOS" Version="2022.1124.0" />
</ItemGroup>
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net6.0) -->