1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 15:27:26 +08:00
osu-lazer/osu.Game.Mode.Osu/Objects/Drawables/DrawableSlider.cs

128 lines
3.8 KiB
C#
Raw Normal View History

2016-11-28 15:52:57 +08:00
using System.Collections.Generic;
using osu.Framework.Graphics;
2016-11-28 11:40:24 +08:00
using osu.Framework.Graphics.Containers;
2016-11-17 20:29:35 +08:00
using osu.Game.Modes.Objects.Drawables;
using osu.Game.Modes.Osu.Objects.Drawables.Pieces;
using OpenTK;
using osu.Framework.Graphics.Sprites;
2016-11-28 11:40:24 +08:00
using OpenTK.Graphics;
namespace osu.Game.Modes.Osu.Objects.Drawables
{
class DrawableSlider : DrawableOsuHitObject
{
2016-11-28 11:40:24 +08:00
private Path path;
private DrawableHitCircle startCircle;
private Slider slider;
2016-11-28 15:31:19 +08:00
private Container ball;
2016-11-28 11:40:24 +08:00
public DrawableSlider(Slider s) : base(s)
{
2016-11-28 11:40:24 +08:00
slider = s;
2016-11-28 11:40:24 +08:00
Origin = Anchor.TopLeft;
Position = Vector2.Zero;
2016-11-28 11:40:24 +08:00
Children = new Drawable[]
{
2016-11-28 15:31:19 +08:00
path = new Path
{
Colour = s.Colour,
},
ball = new Container
{
Masking = true,
CornerRadius = 20,
AutoSizeAxes = Axes.Both,
Colour = Color4.Red,
Origin = Anchor.Centre,
Children = new []
{
new Box
{
Width = 40,
Height = 40,
}
}
},
2016-11-28 11:40:24 +08:00
startCircle = new DrawableHitCircle(new HitCircle
{
StartTime = s.StartTime,
Position = s.Position,
Colour = s.Colour,
})
{
Depth = 1 //override time-based depth.
},
};
2016-11-17 20:29:35 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2016-11-28 11:40:24 +08:00
path.PathWidth = startCircle.DrawWidth / 4;
2016-11-17 20:29:35 +08:00
//force application of the state that was set before we loaded.
UpdateState(State);
}
2016-11-28 15:52:57 +08:00
double snakeDrawn = 0;
2016-11-28 15:31:19 +08:00
protected override void Update()
{
base.Update();
ball.Alpha = Time.Current >= slider.StartTime && Time.Current <= slider.EndTime ? 1 : 0;
double t = (Time.Current - slider.StartTime) / slider.Duration;
if (slider.RepeatCount > 1)
{
double currentRepeat = (int)(t * slider.RepeatCount);
t = (t * slider.RepeatCount) % 1;
if (currentRepeat % 2 == 1)
t = 1 - t;
}
2016-11-28 15:52:57 +08:00
double snake = MathHelper.Clamp((Time.Current - slider.StartTime + 450) / 200, 0, 1);
if (snake != snakeDrawn)
{
if (snake < snakeDrawn)
{
//if we have gone backwards, just clear the path for now.
snakeDrawn = 0;
path.Positions.Clear();
}
const double segment_size = 10;
while (snakeDrawn < snake)
{
snakeDrawn += segment_size;
path.Positions.Add(slider.Curve.PositionAt(snake));
}
snakeDrawn = snake;
path.Positions.Add(slider.Curve.PositionAt(snake));
}
ball.Position = slider.Curve.PositionAt(t);
2016-11-28 15:31:19 +08:00
}
protected override void UpdateState(ArmedState state)
{
2016-11-17 20:29:35 +08:00
if (!IsLoaded) return;
Flush(true); //move to DrawableHitObject
Alpha = 0;
Delay(HitObject.StartTime - 450 - Time.Current, true);
2016-11-17 20:29:35 +08:00
FadeIn(200);
Delay(450 + HitObject.Duration);
2016-11-28 15:31:19 +08:00
FadeOut(100);
}
}
}