2016-12-06 17:54:32 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Transformations;
|
|
|
|
|
using osu.Framework.Input;
|
2016-12-06 23:02:27 +08:00
|
|
|
|
using OpenTK;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces
|
|
|
|
|
{
|
|
|
|
|
public class SliderBall : Container, ISliderProgress
|
|
|
|
|
{
|
|
|
|
|
private readonly Slider slider;
|
|
|
|
|
private Box follow;
|
|
|
|
|
|
2016-12-07 15:37:03 +08:00
|
|
|
|
const float width = 70;
|
|
|
|
|
|
2016-12-06 17:54:32 +08:00
|
|
|
|
public SliderBall(Slider slider)
|
|
|
|
|
{
|
|
|
|
|
this.slider = slider;
|
|
|
|
|
Masking = true;
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
BlendingMode = BlendingMode.Additive;
|
|
|
|
|
Origin = Anchor.Centre;
|
2016-12-07 15:37:03 +08:00
|
|
|
|
BorderThickness = 5;
|
|
|
|
|
BorderColour = Color4.Orange;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
follow = new Box
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Colour = Color4.Orange,
|
2016-12-07 15:37:03 +08:00
|
|
|
|
Width = width,
|
|
|
|
|
Height = width,
|
|
|
|
|
Alpha = 0,
|
2016-12-06 17:54:32 +08:00
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Masking = true,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2016-12-07 15:37:03 +08:00
|
|
|
|
BorderThickness = 7,
|
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
|
Alpha = 1,
|
|
|
|
|
CornerRadius = width / 2,
|
2016-12-06 17:54:32 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
2016-12-07 15:37:03 +08:00
|
|
|
|
Colour = slider.Colour,
|
|
|
|
|
Alpha = 0.4f,
|
|
|
|
|
Width = width,
|
|
|
|
|
Height = width,
|
2016-12-06 17:54:32 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2016-12-08 18:54:22 +08:00
|
|
|
|
public bool Tracking
|
2016-12-06 17:54:32 +08:00
|
|
|
|
{
|
|
|
|
|
get { return tracking; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == tracking) return;
|
|
|
|
|
|
|
|
|
|
tracking = value;
|
|
|
|
|
|
2016-12-07 15:37:03 +08:00
|
|
|
|
follow.ScaleTo(tracking ? 2.8f : 1, 300, EasingTypes.OutQuint);
|
|
|
|
|
follow.FadeTo(tracking ? 0.2f : 0, 300, EasingTypes.OutQuint);
|
2016-12-06 17:54:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-08 20:07:20 +08:00
|
|
|
|
private bool validTrackingTime => Time.Current >= slider.StartTime && Time.Current <= slider.EndTime;
|
|
|
|
|
|
2016-12-06 17:54:32 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
CornerRadius = DrawWidth / 2;
|
2016-12-08 20:07:20 +08:00
|
|
|
|
Tracking = validTrackingTime && lastState != null && Contains(lastState.Mouse.NativeState.Position) && lastState.Mouse.HasMainButtonPressed;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateProgress(double progress, int repeat)
|
|
|
|
|
{
|
|
|
|
|
Position = slider.Curve.PositionAt(progress);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|