2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-03-16 21:41:07 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
using System;
|
2017-08-22 16:38:51 +08:00
|
|
|
|
using System.Diagnostics;
|
2017-03-16 21:41:07 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Cursor
|
|
|
|
|
{
|
|
|
|
|
public class MenuCursor : CursorContainer
|
|
|
|
|
{
|
2017-09-17 07:44:49 +08:00
|
|
|
|
protected override Drawable CreateCursor() => new Cursor();
|
2017-03-16 21:41:07 +08:00
|
|
|
|
|
2017-09-17 07:14:33 +08:00
|
|
|
|
private Bindable<bool> cursorRotate;
|
2017-03-27 16:48:18 +08:00
|
|
|
|
private bool dragging;
|
2017-04-03 00:19:59 +08:00
|
|
|
|
|
2017-08-22 16:38:51 +08:00
|
|
|
|
private bool startRotation;
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
protected override bool OnMouseMove(InputState state)
|
2017-03-18 19:47:49 +08:00
|
|
|
|
{
|
2017-09-17 07:44:49 +08:00
|
|
|
|
if (cursorRotate && dragging)
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(state.Mouse.PositionMouseDown != null);
|
2017-09-17 07:28:02 +08:00
|
|
|
|
|
|
|
|
|
// don't start rotating until we're moved a minimum distance away from the mouse down location,
|
|
|
|
|
// else it can have an annoying effect.
|
2017-11-20 17:55:48 +08:00
|
|
|
|
// ReSharper disable once PossibleInvalidOperationException
|
2017-09-17 07:44:49 +08:00
|
|
|
|
startRotation |= Vector2Extensions.Distance(state.Mouse.Position, state.Mouse.PositionMouseDown.Value) > 30;
|
2017-09-17 07:28:02 +08:00
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
if (startRotation)
|
|
|
|
|
{
|
2017-09-17 07:28:02 +08:00
|
|
|
|
Vector2 offset = state.Mouse.Position - state.Mouse.PositionMouseDown.Value;
|
2017-09-17 07:44:49 +08:00
|
|
|
|
float degrees = (float)MathHelper.RadiansToDegrees(Math.Atan2(-offset.X, offset.Y)) + 24.3f;
|
2017-09-17 07:28:02 +08:00
|
|
|
|
|
|
|
|
|
// Always rotate in the direction of least distance
|
|
|
|
|
float diff = (degrees - ActiveCursor.Rotation) % 360;
|
2017-09-22 04:11:35 +08:00
|
|
|
|
if (diff < -180) diff += 360;
|
|
|
|
|
if (diff > 180) diff -= 360;
|
2017-09-17 07:28:02 +08:00
|
|
|
|
degrees = ActiveCursor.Rotation + diff;
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
ActiveCursor.RotateTo(degrees, 600, Easing.OutQuint);
|
2017-08-22 16:38:51 +08:00
|
|
|
|
}
|
2017-03-18 19:47:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
return base.OnMouseMove(state);
|
2017-04-03 00:19:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
protected override bool OnDragStart(InputState state)
|
2017-03-27 16:48:18 +08:00
|
|
|
|
{
|
|
|
|
|
dragging = true;
|
2017-09-17 07:44:49 +08:00
|
|
|
|
return base.OnDragStart(state);
|
2017-03-27 16:48:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
2017-03-16 21:41:07 +08:00
|
|
|
|
{
|
2017-09-17 07:44:49 +08:00
|
|
|
|
ActiveCursor.Scale = new Vector2(1);
|
|
|
|
|
ActiveCursor.ScaleTo(0.90f, 800, Easing.OutQuint);
|
2017-03-16 21:41:07 +08:00
|
|
|
|
|
|
|
|
|
((Cursor)ActiveCursor).AdditiveLayer.Alpha = 0;
|
2017-09-17 07:44:49 +08:00
|
|
|
|
((Cursor)ActiveCursor).AdditiveLayer.FadeInFromZero(800, Easing.OutQuint);
|
|
|
|
|
return base.OnMouseDown(state, args);
|
2017-03-16 21:41:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
2017-03-16 21:41:07 +08:00
|
|
|
|
{
|
2017-09-17 07:44:49 +08:00
|
|
|
|
if (!state.Mouse.HasMainButtonPressed)
|
|
|
|
|
{
|
2017-03-27 16:48:18 +08:00
|
|
|
|
dragging = false;
|
2017-08-22 16:38:51 +08:00
|
|
|
|
startRotation = false;
|
2017-03-27 16:48:18 +08:00
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
((Cursor)ActiveCursor).AdditiveLayer.FadeOut(500, Easing.OutQuint);
|
|
|
|
|
ActiveCursor.RotateTo(0, 600 * (1 + Math.Abs(ActiveCursor.Rotation / 720)), Easing.OutElasticHalf);
|
|
|
|
|
ActiveCursor.ScaleTo(1, 500, Easing.OutElastic);
|
2017-03-16 21:41:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
return base.OnMouseUp(state, args);
|
2017-03-16 21:41:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
protected override bool OnClick(InputState state)
|
2017-03-16 21:41:07 +08:00
|
|
|
|
{
|
2017-09-17 07:44:49 +08:00
|
|
|
|
((Cursor)ActiveCursor).AdditiveLayer.FadeOutFromOne(500, Easing.OutQuint);
|
2017-03-16 21:41:07 +08:00
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
return base.OnClick(state);
|
2017-03-16 21:41:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
protected override void PopIn()
|
2017-03-16 22:58:36 +08:00
|
|
|
|
{
|
2017-09-17 07:44:49 +08:00
|
|
|
|
ActiveCursor.FadeTo(1, 250, Easing.OutQuint);
|
|
|
|
|
ActiveCursor.ScaleTo(1, 400, Easing.OutQuint);
|
2017-03-16 22:58:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
protected override void PopOut()
|
2017-03-16 22:58:36 +08:00
|
|
|
|
{
|
2018-01-12 18:34:14 +08:00
|
|
|
|
ActiveCursor.FadeTo(0, 250, Easing.OutQuint);
|
|
|
|
|
ActiveCursor.ScaleTo(0.6f, 250, Easing.In);
|
2017-03-16 22:58:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-17 07:14:33 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-09-17 07:44:49 +08:00
|
|
|
|
private void load(OsuConfigManager config)
|
2017-09-17 07:14:33 +08:00
|
|
|
|
{
|
2017-09-17 07:44:49 +08:00
|
|
|
|
cursorRotate = config.GetBindable<bool>(OsuSetting.CursorRotation);
|
2017-09-17 07:14:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 21:41:07 +08:00
|
|
|
|
public class Cursor : Container
|
|
|
|
|
{
|
|
|
|
|
private Container cursorContainer;
|
|
|
|
|
private Bindable<double> cursorScale;
|
2017-06-03 22:34:00 +08:00
|
|
|
|
private const float base_scale = 0.15f;
|
2017-03-16 21:41:07 +08:00
|
|
|
|
|
|
|
|
|
public Sprite AdditiveLayer;
|
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
public Cursor()
|
2017-03-16 21:41:07 +08:00
|
|
|
|
{
|
2017-04-20 06:42:40 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
2017-03-16 21:41:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-03-17 20:04:46 +08:00
|
|
|
|
private void load(OsuConfigManager config, TextureStore textures, OsuColour colour)
|
2017-03-16 21:41:07 +08:00
|
|
|
|
{
|
2017-09-17 07:44:49 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
cursorContainer = new Container
|
|
|
|
|
{
|
2017-06-03 22:34:00 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2017-09-17 07:44:49 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Sprite
|
|
|
|
|
{
|
|
|
|
|
Texture = textures.Get(@"Cursor/menu-cursor"),
|
2017-03-16 21:41:07 +08:00
|
|
|
|
},
|
2017-09-17 07:44:49 +08:00
|
|
|
|
AdditiveLayer = new Sprite
|
|
|
|
|
{
|
2017-09-07 21:46:21 +08:00
|
|
|
|
Blending = BlendingMode.Additive,
|
2017-03-17 20:04:46 +08:00
|
|
|
|
Colour = colour.Pink,
|
2017-03-16 21:41:07 +08:00
|
|
|
|
Alpha = 0,
|
2017-09-17 07:44:49 +08:00
|
|
|
|
Texture = textures.Get(@"Cursor/menu-cursor-additive"),
|
2017-03-16 21:41:07 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2017-04-17 23:10:55 +08:00
|
|
|
|
}
|
2017-03-16 21:41:07 +08:00
|
|
|
|
};
|
2017-03-23 07:07:59 +08:00
|
|
|
|
|
2017-09-17 07:44:49 +08:00
|
|
|
|
cursorScale = config.GetBindable<double>(OsuSetting.MenuCursorSize);
|
|
|
|
|
cursorScale.ValueChanged += newScale => cursorContainer.Scale = new Vector2((float)newScale * base_scale);
|
2017-03-23 07:07:59 +08:00
|
|
|
|
cursorScale.TriggerChange();
|
2017-03-16 21:41:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|