2016-12-03 20:56:35 +08:00
|
|
|
|
// Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-11-28 15:52:57 +08:00
|
|
|
|
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 OpenTK;
|
2016-11-27 22:36:31 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-11-28 18:42:45 +08:00
|
|
|
|
using osu.Framework.Graphics.Transformations;
|
2016-11-28 11:40:24 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2016-11-28 18:42:45 +08:00
|
|
|
|
using osu.Framework.Input;
|
2016-11-29 02:04:03 +08:00
|
|
|
|
using OpenTK.Graphics.ES30;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2016-12-03 20:56:19 +08:00
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
using osu.Framework.Configuration;
|
2016-12-03 21:40:35 +08:00
|
|
|
|
using System;
|
2016-11-17 16:20:51 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Modes.Osu.Objects.Drawables
|
|
|
|
|
{
|
2016-11-26 15:51:51 +08:00
|
|
|
|
class DrawableSlider : DrawableOsuHitObject
|
2016-11-17 16:20:51 +08:00
|
|
|
|
{
|
2016-11-28 11:40:24 +08:00
|
|
|
|
private Slider slider;
|
2016-11-28 16:05:30 +08:00
|
|
|
|
|
|
|
|
|
private DrawableHitCircle startCircle;
|
2016-11-28 15:31:19 +08:00
|
|
|
|
private Container ball;
|
2016-11-28 18:42:45 +08:00
|
|
|
|
private Body body;
|
2016-11-28 11:40:24 +08:00
|
|
|
|
|
2016-11-28 11:15:25 +08:00
|
|
|
|
public DrawableSlider(Slider s) : base(s)
|
2016-11-17 16:20:51 +08:00
|
|
|
|
{
|
2016-11-28 11:40:24 +08:00
|
|
|
|
slider = s;
|
2016-11-27 22:36:31 +08:00
|
|
|
|
|
2016-11-28 11:40:24 +08:00
|
|
|
|
Origin = Anchor.TopLeft;
|
|
|
|
|
Position = Vector2.Zero;
|
2016-11-28 18:42:45 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2016-11-28 11:15:25 +08:00
|
|
|
|
|
2016-11-28 11:40:24 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-11-28 11:15:25 +08:00
|
|
|
|
{
|
2016-11-29 02:04:03 +08:00
|
|
|
|
body = new Body(s)
|
|
|
|
|
{
|
|
|
|
|
Position = s.Position,
|
|
|
|
|
},
|
2016-11-28 18:42:45 +08:00
|
|
|
|
ball = new Ball(),
|
2016-11-28 11:40:24 +08:00
|
|
|
|
startCircle = new DrawableHitCircle(new HitCircle
|
|
|
|
|
{
|
|
|
|
|
StartTime = s.StartTime,
|
|
|
|
|
Position = s.Position,
|
|
|
|
|
Colour = s.Colour,
|
|
|
|
|
})
|
|
|
|
|
{
|
2016-11-30 03:50:12 +08:00
|
|
|
|
Depth = -1 //override time-based depth.
|
2016-11-28 11:40:24 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
2016-11-17 20:29:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-03 20:56:19 +08:00
|
|
|
|
private Bindable<bool> snakingIn;
|
|
|
|
|
private Bindable<bool> snakingOut;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
|
{
|
|
|
|
|
snakingIn = config.GetBindable<bool>(OsuConfig.SnakingInSliders);
|
|
|
|
|
snakingOut = config.GetBindable<bool>(OsuConfig.SnakingOutSliders);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 20:29:35 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
//force application of the state that was set before we loaded.
|
|
|
|
|
UpdateState(State);
|
2016-12-03 20:56:19 +08:00
|
|
|
|
|
|
|
|
|
body.PathWidth = 32;
|
2016-11-17 16:20:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-03 21:40:35 +08:00
|
|
|
|
private void computeProgress(out int repeat, out double progress)
|
2016-11-28 15:31:19 +08:00
|
|
|
|
{
|
2016-12-03 21:40:35 +08:00
|
|
|
|
progress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
|
2016-11-28 15:31:19 +08:00
|
|
|
|
|
2016-12-03 21:40:35 +08:00
|
|
|
|
repeat = (int)(progress * slider.RepeatCount);
|
|
|
|
|
progress = (progress * slider.RepeatCount) % 1;
|
2016-11-28 15:31:19 +08:00
|
|
|
|
|
2016-12-03 21:40:35 +08:00
|
|
|
|
if (repeat % 2 == 1)
|
|
|
|
|
progress = 1 - progress;
|
|
|
|
|
}
|
2016-12-03 20:25:31 +08:00
|
|
|
|
|
2016-12-03 21:40:35 +08:00
|
|
|
|
private void updateBall(double progress)
|
|
|
|
|
{
|
|
|
|
|
ball.Alpha = Time.Current >= slider.StartTime && Time.Current <= slider.EndTime ? 1 : 0;
|
|
|
|
|
ball.Position = slider.Curve.PositionAt(progress);
|
|
|
|
|
}
|
2016-12-03 20:25:31 +08:00
|
|
|
|
|
2016-12-03 21:40:35 +08:00
|
|
|
|
private void updateBody(int repeat, double progress)
|
|
|
|
|
{
|
|
|
|
|
double drawStartProgress = 0;
|
|
|
|
|
double drawEndProgress = MathHelper.Clamp((Time.Current - slider.StartTime + TIME_PREEMPT) / TIME_FADEIN, 0, 1);
|
2016-11-28 15:31:19 +08:00
|
|
|
|
|
2016-12-03 21:40:35 +08:00
|
|
|
|
if (repeat >= slider.RepeatCount - 1)
|
|
|
|
|
{
|
|
|
|
|
if (Math.Min(repeat, slider.RepeatCount - 1) % 2 == 1)
|
|
|
|
|
{
|
|
|
|
|
drawStartProgress = 0;
|
|
|
|
|
drawEndProgress = progress;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
drawStartProgress = progress;
|
|
|
|
|
drawEndProgress = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-03 20:25:31 +08:00
|
|
|
|
|
2016-12-03 20:56:19 +08:00
|
|
|
|
body.SetRange(
|
|
|
|
|
snakingOut ? drawStartProgress : 0,
|
|
|
|
|
snakingIn ? drawEndProgress : 1);
|
2016-11-28 15:31:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-03 21:40:35 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
double progress;
|
|
|
|
|
int repeat;
|
|
|
|
|
computeProgress(out repeat, out progress);
|
|
|
|
|
|
|
|
|
|
updateBall(progress);
|
|
|
|
|
updateBody(repeat, progress);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-29 20:40:24 +08:00
|
|
|
|
protected override void CheckJudgement(bool userTriggered)
|
|
|
|
|
{
|
|
|
|
|
var j = Judgement as OsuJudgementInfo;
|
|
|
|
|
var sc = startCircle.Judgement as OsuJudgementInfo;
|
|
|
|
|
|
|
|
|
|
if (!userTriggered && Time.Current >= HitObject.EndTime)
|
|
|
|
|
{
|
|
|
|
|
j.Score = sc.Score;
|
|
|
|
|
j.Result = sc.Result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 16:20:51 +08:00
|
|
|
|
protected override void UpdateState(ArmedState state)
|
|
|
|
|
{
|
2016-11-28 17:40:54 +08:00
|
|
|
|
base.UpdateState(state);
|
2016-11-17 20:29:35 +08:00
|
|
|
|
|
2016-11-28 17:40:54 +08:00
|
|
|
|
Delay(HitObject.Duration);
|
2016-11-29 21:14:56 +08:00
|
|
|
|
FadeOut(300);
|
2016-11-17 16:20:51 +08:00
|
|
|
|
}
|
2016-11-28 16:05:30 +08:00
|
|
|
|
|
2016-11-28 18:42:45 +08:00
|
|
|
|
private class Ball : Container
|
|
|
|
|
{
|
|
|
|
|
private Box follow;
|
|
|
|
|
|
|
|
|
|
public Ball()
|
|
|
|
|
{
|
|
|
|
|
Masking = true;
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
BlendingMode = BlendingMode.Additive;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
follow = new Box
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Colour = Color4.Orange,
|
|
|
|
|
Width = 64,
|
|
|
|
|
Height = 64,
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Masking = true,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Colour = Color4.Cyan,
|
|
|
|
|
CornerRadius = 32,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Width = 64,
|
|
|
|
|
Height = 64,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private InputState lastState;
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
lastState = state;
|
|
|
|
|
return base.OnMouseDown(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
lastState = state;
|
|
|
|
|
return base.OnMouseUp(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseMove(InputState state)
|
|
|
|
|
{
|
|
|
|
|
lastState = state;
|
|
|
|
|
return base.OnMouseMove(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool tracking;
|
|
|
|
|
protected bool Tracking
|
|
|
|
|
{
|
|
|
|
|
get { return tracking; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == tracking) return;
|
|
|
|
|
|
|
|
|
|
tracking = value;
|
|
|
|
|
|
2016-11-28 18:51:50 +08:00
|
|
|
|
follow.ScaleTo(tracking ? 2.4f : 1, 140, EasingTypes.Out);
|
2016-11-28 18:42:45 +08:00
|
|
|
|
follow.FadeTo(tracking ? 0.8f : 0, 140, EasingTypes.Out);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
CornerRadius = DrawWidth / 2;
|
|
|
|
|
Tracking = lastState != null && Contains(lastState.Mouse.NativeState.Position) && lastState.Mouse.HasMainButtonPressed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class Body : Container
|
2016-11-28 16:05:30 +08:00
|
|
|
|
{
|
|
|
|
|
private Path path;
|
2016-11-29 02:04:03 +08:00
|
|
|
|
private BufferedContainer container;
|
2016-11-28 16:05:30 +08:00
|
|
|
|
|
2016-12-03 20:56:19 +08:00
|
|
|
|
public float PathWidth
|
|
|
|
|
{
|
|
|
|
|
get { return path.PathWidth; }
|
|
|
|
|
set { path.PathWidth = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double? drawnProgressStart;
|
|
|
|
|
private double? drawnProgressEnd;
|
2016-11-28 16:05:30 +08:00
|
|
|
|
|
2016-11-28 18:42:45 +08:00
|
|
|
|
private Slider slider;
|
|
|
|
|
public Body(Slider s)
|
2016-11-28 16:05:30 +08:00
|
|
|
|
{
|
|
|
|
|
slider = s;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2016-11-29 02:04:03 +08:00
|
|
|
|
container = new BufferedContainer
|
|
|
|
|
{
|
|
|
|
|
CacheDrawnFrameBuffer = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2016-11-28 16:05:30 +08:00
|
|
|
|
path = new Path
|
|
|
|
|
{
|
|
|
|
|
Colour = s.Colour,
|
2016-11-29 02:04:03 +08:00
|
|
|
|
BlendingMode = BlendingMode.None,
|
2016-11-28 16:05:30 +08:00
|
|
|
|
},
|
2016-11-29 02:04:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-28 16:05:30 +08:00
|
|
|
|
};
|
2016-11-29 02:04:03 +08:00
|
|
|
|
|
|
|
|
|
container.Attach(RenderbufferInternalFormat.DepthComponent16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(TextureStore textures)
|
|
|
|
|
{
|
|
|
|
|
// Surprisingly, this looks somewhat okay and works well as a test for self-overlaps.
|
|
|
|
|
// TODO: Don't do this.
|
|
|
|
|
path.Texture = textures.Get(@"Menu/logo");
|
2016-11-28 16:05:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-03 20:25:31 +08:00
|
|
|
|
public void SetRange(double p0, double p1)
|
2016-11-28 16:05:30 +08:00
|
|
|
|
{
|
2016-12-03 20:25:31 +08:00
|
|
|
|
if (p0 > p1)
|
|
|
|
|
MathHelper.Swap(ref p0, ref p1);
|
2016-11-28 16:05:30 +08:00
|
|
|
|
|
2016-12-03 20:25:31 +08:00
|
|
|
|
if (updateSnaking(p0, p1))
|
2016-11-29 02:04:03 +08:00
|
|
|
|
{
|
|
|
|
|
// Autosizing does not give us the desired behaviour here.
|
|
|
|
|
// We want the container to have the same size as the slider,
|
|
|
|
|
// and to be positioned such that the slider head is at (0,0).
|
|
|
|
|
container.Size = path.Size;
|
2016-12-03 20:25:31 +08:00
|
|
|
|
container.Position = -path.PositionInBoundingBox(slider.Curve.PositionAt(0) - currentCurve[0]);
|
2016-11-29 02:04:03 +08:00
|
|
|
|
|
|
|
|
|
container.ForceRedraw();
|
|
|
|
|
}
|
2016-11-28 18:42:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-03 20:25:31 +08:00
|
|
|
|
private List<Vector2> currentCurve = new List<Vector2>();
|
|
|
|
|
private bool updateSnaking(double p0, double p1)
|
2016-11-28 18:42:45 +08:00
|
|
|
|
{
|
2016-12-03 20:25:31 +08:00
|
|
|
|
if (drawnProgressStart == p0 && drawnProgressEnd == p1) return false;
|
2016-11-28 17:40:38 +08:00
|
|
|
|
|
2016-12-03 20:25:31 +08:00
|
|
|
|
drawnProgressStart = p0;
|
|
|
|
|
drawnProgressEnd = p1;
|
2016-11-28 16:05:30 +08:00
|
|
|
|
|
2016-12-03 20:25:31 +08:00
|
|
|
|
slider.Curve.GetPathToProgress(currentCurve, p0, p1);
|
2016-11-29 02:04:03 +08:00
|
|
|
|
|
2016-12-03 18:43:56 +08:00
|
|
|
|
path.ClearVertices();
|
2016-12-03 20:25:31 +08:00
|
|
|
|
foreach (Vector2 p in currentCurve)
|
|
|
|
|
path.AddVertex(p - currentCurve[0]);
|
|
|
|
|
|
2016-12-03 18:43:56 +08:00
|
|
|
|
return true;
|
2016-11-28 16:05:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-17 16:20:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|