2018-01-05 11:21:19 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-07 04:59:30 +00:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-06 09:54:32 +00:00
|
|
|
|
|
2017-08-18 10:49:23 +00:00
|
|
|
|
using System.Linq;
|
2016-12-06 09:54:32 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 05:54:23 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2016-12-06 09:54:32 +00:00
|
|
|
|
using osu.Framework.Input;
|
2018-02-23 11:51:26 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2017-08-19 02:49:37 +00:00
|
|
|
|
using OpenTK;
|
2016-12-06 09:54:32 +00:00
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
2017-04-18 07:05:58 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
2017-02-15 12:51:16 +00:00
|
|
|
|
public class SliderBall : CircularContainer, ISliderProgress
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
2017-03-23 06:37:16 +00: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 09:54:32 +00:00
|
|
|
|
private readonly Slider slider;
|
2018-01-04 11:43:42 +00:00
|
|
|
|
public readonly Box FollowCircle;
|
2017-03-23 06:37:16 +00:00
|
|
|
|
private readonly Box ball;
|
2016-12-07 07:37:03 +00:00
|
|
|
|
|
2016-12-06 09:54:32 +00:00
|
|
|
|
public SliderBall(Slider slider)
|
|
|
|
|
{
|
|
|
|
|
this.slider = slider;
|
|
|
|
|
Masking = true;
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2017-09-07 13:46:21 +00:00
|
|
|
|
Blending = BlendingMode.Additive;
|
2016-12-06 09:54:32 +00:00
|
|
|
|
Origin = Anchor.Centre;
|
2016-12-11 09:11:22 +00:00
|
|
|
|
BorderThickness = 10;
|
2016-12-07 07:37:03 +00:00
|
|
|
|
BorderColour = Color4.Orange;
|
2016-12-06 09:54:32 +00:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-01-04 11:43:42 +00:00
|
|
|
|
FollowCircle = new Box
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Colour = Color4.Orange,
|
2016-12-07 07:37:03 +00:00
|
|
|
|
Width = width,
|
|
|
|
|
Height = width,
|
|
|
|
|
Alpha = 0,
|
2016-12-06 09:54:32 +00:00
|
|
|
|
},
|
2017-02-15 12:51:16 +00:00
|
|
|
|
new CircularContainer
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
|
|
|
|
Masking = true,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-02-06 13:17:29 +00:00
|
|
|
|
BorderThickness = 10,
|
2016-12-07 07:37:03 +00:00
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
|
Alpha = 1,
|
2016-12-06 09:54:32 +00:00
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
2017-03-23 06:37:16 +00:00
|
|
|
|
ball = new Box
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
2017-03-23 06:37:16 +00:00
|
|
|
|
Colour = AccentColour,
|
2016-12-07 07:37:03 +00:00
|
|
|
|
Alpha = 0.4f,
|
|
|
|
|
Width = width,
|
|
|
|
|
Height = width,
|
2016-12-06 09:54:32 +00: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 04:30:53 +00: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 02:49:37 +00:00
|
|
|
|
|
2018-01-03 12:55:24 +00:00
|
|
|
|
public override void ClearTransformsAfter(double time, bool propagateChildren = false, string targetMember = null)
|
2017-11-03 06:58:12 +00:00
|
|
|
|
{
|
|
|
|
|
// 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.
|
2018-01-03 07:13:58 +00:00
|
|
|
|
base.ClearTransformsAfter(time, false, targetMember);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-07 01:59:19 +00:00
|
|
|
|
private bool tracking;
|
2016-12-08 10:54:22 +00:00
|
|
|
|
public bool Tracking
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
|
|
|
|
get { return tracking; }
|
2017-08-20 04:30:53 +00:00
|
|
|
|
private set
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
2017-11-03 06:58:12 +00:00
|
|
|
|
if (value == tracking)
|
|
|
|
|
return;
|
2016-12-06 09:54:32 +00:00
|
|
|
|
tracking = value;
|
|
|
|
|
|
2018-01-04 11:43:42 +00:00
|
|
|
|
FollowCircle.ScaleTo(tracking ? 2.8f : 1, 300, Easing.OutQuint);
|
|
|
|
|
FollowCircle.FadeTo(tracking ? 0.2f : 0, 300, Easing.OutQuint);
|
2016-12-06 09:54:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-13 09:12:35 +00:00
|
|
|
|
private bool canCurrentlyTrack => Time.Current >= slider.StartTime && Time.Current < slider.EndTime;
|
2016-12-08 12:07:20 +00:00
|
|
|
|
|
2016-12-06 09:54:32 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2018-01-04 11:09:58 +00:00
|
|
|
|
if (Time.Current < slider.EndTime)
|
|
|
|
|
{
|
|
|
|
|
// Make sure to use the base version of ReceiveMouseInputAt so that we correctly check the position.
|
|
|
|
|
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 09:54:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 08:10:18 +00:00
|
|
|
|
public void UpdateProgress(double completionProgress)
|
2016-12-06 09:54:32 +00:00
|
|
|
|
{
|
2018-02-23 17:43:36 +00:00
|
|
|
|
Position = slider.CurvePositionAt(completionProgress);
|
2016-12-06 09:54:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-03 07:13:58 +00:00
|
|
|
|
}
|