2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-06 17:54:32 +08:00
|
|
|
|
|
2017-08-18 18:49:23 +08:00
|
|
|
|
using System.Linq;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-08-19 10:49:37 +08:00
|
|
|
|
using OpenTK;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
2017-04-18 15:05:58 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
2016-12-06 17:54:32 +08:00
|
|
|
|
{
|
2017-02-15 20:51:16 +08:00
|
|
|
|
public class SliderBall : CircularContainer, ISliderProgress
|
2016-12-06 17:54:32 +08:00
|
|
|
|
{
|
2017-03-23 14:37:16 +08:00
|
|
|
|
private const float width = 128;
|
|
|
|
|
|
|
|
|
|
private Color4 accentColour = Color4.Black;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The colour that is used for the slider ball.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
|
{
|
|
|
|
|
get { return accentColour; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
accentColour = value;
|
|
|
|
|
if (ball != null)
|
|
|
|
|
ball.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-06 17:54:32 +08:00
|
|
|
|
private readonly Slider slider;
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Box follow;
|
2017-03-23 14:37:16 +08:00
|
|
|
|
private readonly Box ball;
|
2016-12-07 15:37:03 +08:00
|
|
|
|
|
2016-12-06 17:54:32 +08:00
|
|
|
|
public SliderBall(Slider slider)
|
|
|
|
|
{
|
|
|
|
|
this.slider = slider;
|
|
|
|
|
Masking = true;
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2017-09-07 21:46:21 +08:00
|
|
|
|
Blending = BlendingMode.Additive;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
Origin = Anchor.Centre;
|
2016-12-11 17:11:22 +08:00
|
|
|
|
BorderThickness = 10;
|
2016-12-07 15:37:03 +08:00
|
|
|
|
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
|
|
|
|
},
|
2017-02-15 20:51:16 +08:00
|
|
|
|
new CircularContainer
|
2016-12-06 17:54:32 +08:00
|
|
|
|
{
|
|
|
|
|
Masking = true,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-02-06 21:17:29 +08:00
|
|
|
|
BorderThickness = 10,
|
2016-12-07 15:37:03 +08:00
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
|
Alpha = 1,
|
2016-12-06 17:54:32 +08:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-03-23 14:37:16 +08:00
|
|
|
|
ball = new Box
|
2016-12-06 17:54:32 +08:00
|
|
|
|
{
|
2017-03-23 14:37:16 +08:00
|
|
|
|
Colour = AccentColour,
|
2016-12-07 15:37:03 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-20 12:30:53 +08:00
|
|
|
|
// If the current time is between the start and end of the slider, we should track mouse input regardless of the cursor position.
|
|
|
|
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => canCurrentlyTrack || base.ReceiveMouseInputAt(screenSpacePos);
|
2017-08-19 10:49:37 +08:00
|
|
|
|
|
2017-11-03 14:58:12 +08:00
|
|
|
|
public override void ClearTransforms(bool propagateChildren = false, string targetMember = null)
|
|
|
|
|
{
|
|
|
|
|
// Consider the case of rewinding - children's transforms are handled internally, so propagating down
|
|
|
|
|
// any further will cause weirdness with the Tracking bool below. Let's not propagate further at this point.
|
|
|
|
|
base.ClearTransforms(false, targetMember);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 09:59:19 +08:00
|
|
|
|
private bool tracking;
|
2016-12-08 18:54:22 +08:00
|
|
|
|
public bool Tracking
|
2016-12-06 17:54:32 +08:00
|
|
|
|
{
|
|
|
|
|
get { return tracking; }
|
2017-08-20 12:30:53 +08:00
|
|
|
|
private set
|
2016-12-06 17:54:32 +08:00
|
|
|
|
{
|
2017-11-03 14:58:12 +08:00
|
|
|
|
if (value == tracking)
|
|
|
|
|
return;
|
2016-12-06 17:54:32 +08:00
|
|
|
|
tracking = value;
|
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
follow.ScaleTo(tracking ? 2.8f : 1, 300, Easing.OutQuint);
|
|
|
|
|
follow.FadeTo(tracking ? 0.2f : 0, 300, Easing.OutQuint);
|
2016-12-06 17:54:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-13 17:12:35 +08:00
|
|
|
|
private bool canCurrentlyTrack => Time.Current >= slider.StartTime && Time.Current < slider.EndTime;
|
2016-12-08 20:07:20 +08:00
|
|
|
|
|
2016-12-06 17:54:32 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2017-08-19 10:49:37 +08:00
|
|
|
|
// Make sure to use the base version of ReceiveMouseInputAt so that we correctly check the position.
|
2017-11-03 14:58:12 +08:00
|
|
|
|
Tracking = canCurrentlyTrack
|
|
|
|
|
&& lastState != null
|
|
|
|
|
&& base.ReceiveMouseInputAt(lastState.Mouse.NativeState.Position)
|
|
|
|
|
&& ((Parent as DrawableSlider)?.OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false);
|
2016-12-06 17:54:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateProgress(double progress, int repeat)
|
|
|
|
|
{
|
|
|
|
|
Position = slider.Curve.PositionAt(progress);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|