1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 02:47:30 +08:00
osu-lazer/osu.Game.Tournament/Screens/Drawings/Components/VisualiserContainer.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

127 lines
3.2 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Tournament.Screens.Drawings.Components
{
public partial class VisualiserContainer : Container
{
/// <summary>
/// Number of lines in the visualiser.
/// </summary>
public int Lines
{
get => allLines.Count;
set
{
while (value > allLines.Count)
addLine();
2018-04-13 17:19:50 +08:00
while (value < allLines.Count)
removeLine();
}
}
2018-04-13 17:19:50 +08:00
private readonly List<VisualiserLine> allLines = new List<VisualiserLine>();
2018-04-13 17:19:50 +08:00
private float offset;
2018-04-13 17:19:50 +08:00
private void addLine()
{
2017-03-07 09:59:19 +08:00
VisualiserLine newLine = new VisualiserLine
{
RelativeSizeAxes = Axes.Both,
2018-04-13 17:19:50 +08:00
Offset = offset,
CycleTime = RNG.Next(10000, 12000),
};
2018-04-13 17:19:50 +08:00
allLines.Add(newLine);
Add(newLine);
2018-04-13 17:19:50 +08:00
offset += RNG.Next(100, 5000);
}
2018-04-13 17:19:50 +08:00
private void removeLine()
{
if (allLines.Count == 0)
return;
2018-04-13 17:19:50 +08:00
Remove(allLines.First(), true);
allLines.Remove(allLines.First());
}
2018-04-13 17:19:50 +08:00
2017-03-07 09:59:19 +08:00
private partial class VisualiserLine : Container
{
/// <summary>
/// Time offset.
/// </summary>
public float Offset;
2018-04-13 17:19:50 +08:00
public double CycleTime;
2018-04-13 17:19:50 +08:00
private float leftPos => -(float)((Time.Current + Offset) / CycleTime) + expiredCount;
2018-04-13 17:19:50 +08:00
private Texture texture;
2018-04-13 17:19:50 +08:00
2017-03-07 09:59:19 +08:00
private int expiredCount;
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
2018-08-31 06:04:40 +08:00
private void load(TextureStore textures)
{
2018-08-31 06:04:40 +08:00
texture = textures.Get("Drawings/visualiser-line");
}
2018-04-13 17:19:50 +08:00
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
2018-04-13 17:19:50 +08:00
2017-06-25 13:46:59 +08:00
while (Children.Count < 3)
addLine();
2018-04-13 17:19:50 +08:00
float pos = leftPos;
2018-04-13 17:19:50 +08:00
foreach (var c in Children)
{
if (c.Position.X < -1)
{
c.ClearTransforms();
c.Expire();
expiredCount++;
}
else
c.MoveToX(pos, 100);
2018-04-13 17:19:50 +08:00
pos += 1;
}
}
2018-04-13 17:19:50 +08:00
private void addLine()
{
2017-03-07 09:59:19 +08:00
Add(new Sprite
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
2018-04-13 17:19:50 +08:00
RelativePositionAxes = Axes.Both,
RelativeSizeAxes = Axes.Both,
2018-04-13 17:19:50 +08:00
Texture = texture,
2018-04-13 17:19:50 +08:00
X = leftPos + 1
});
}
}
}
}