2017-03-16 21:41:07 +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
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2017-04-03 00:19:59 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Threading;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
using System.Collections.Generic;
|
2017-03-16 21:41:07 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Cursor
|
|
|
|
|
{
|
|
|
|
|
public class MenuCursor : CursorContainer
|
|
|
|
|
{
|
|
|
|
|
protected override Drawable CreateCursor() => new Cursor();
|
|
|
|
|
|
2017-04-03 00:19:59 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuGameBase game)
|
|
|
|
|
{
|
|
|
|
|
this.game = game;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-27 16:48:18 +08:00
|
|
|
|
private bool dragging;
|
|
|
|
|
|
2017-04-03 00:19:59 +08:00
|
|
|
|
private ScheduledDelegate show;
|
|
|
|
|
private OsuGameBase game;
|
|
|
|
|
|
2017-03-18 19:47:49 +08:00
|
|
|
|
protected override bool OnMouseMove(InputState state)
|
|
|
|
|
{
|
2017-04-03 00:19:59 +08:00
|
|
|
|
if (state.Mouse.Position != state.Mouse.LastPosition)
|
|
|
|
|
{
|
|
|
|
|
Tooltip tooltip = ((Cursor)ActiveCursor).Tooltip;
|
|
|
|
|
show?.Cancel();
|
|
|
|
|
tooltip.Hide();
|
|
|
|
|
Delay(250);
|
|
|
|
|
show = Schedule(delegate
|
|
|
|
|
{
|
|
|
|
|
tooltip.TooltipText = "";
|
|
|
|
|
searchTooltip(tooltip, ToScreenSpace(state.Mouse.Position), game);
|
|
|
|
|
if (tooltip.TooltipText != "")
|
|
|
|
|
tooltip.Show();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-27 16:48:18 +08:00
|
|
|
|
if (dragging)
|
2017-03-18 19:47:49 +08:00
|
|
|
|
{
|
2017-03-18 21:23:53 +08:00
|
|
|
|
Vector2 offset = state.Mouse.Position - state.Mouse.PositionMouseDown ?? state.Mouse.Delta;
|
2017-03-18 19:47:49 +08:00
|
|
|
|
float degrees = (float)MathHelper.RadiansToDegrees(Math.Atan2(-offset.X, offset.Y)) + 24.3f;
|
|
|
|
|
|
|
|
|
|
// Always rotate in the direction of least distance
|
|
|
|
|
float diff = (degrees - ActiveCursor.Rotation) % 360;
|
|
|
|
|
if (diff < -180) diff += 360;
|
|
|
|
|
if (diff > 180) diff -= 360;
|
|
|
|
|
degrees = ActiveCursor.Rotation + diff;
|
|
|
|
|
|
|
|
|
|
ActiveCursor.RotateTo(degrees, 600, EasingTypes.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnMouseMove(state);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 00:19:59 +08:00
|
|
|
|
private void searchTooltip(Tooltip tooltip, Vector2 mousePosition, IContainerEnumerable<Drawable> children)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<Drawable> next = children.Children.Where(drawable => drawable.Contains(mousePosition) && !(drawable is CursorContainer));
|
|
|
|
|
|
|
|
|
|
foreach (Drawable drawable in next)
|
|
|
|
|
{
|
|
|
|
|
string tooltipText = (drawable as IHasTooltip)?.Tooltip ?? "";
|
|
|
|
|
if (tooltipText != "") tooltip.TooltipText = tooltipText;
|
|
|
|
|
|
|
|
|
|
var childScreen = (drawable as Screen)?.ChildScreen;
|
|
|
|
|
if (childScreen != null)
|
|
|
|
|
searchTooltip(tooltip, mousePosition, childScreen);
|
|
|
|
|
else if (drawable is IContainer)
|
|
|
|
|
searchTooltip(tooltip, mousePosition, drawable as IContainerEnumerable<Drawable>);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-27 16:48:18 +08:00
|
|
|
|
protected override bool OnDragStart(InputState state)
|
|
|
|
|
{
|
|
|
|
|
dragging = true;
|
|
|
|
|
return base.OnDragStart(state);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 21:41:07 +08:00
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
ActiveCursor.Scale = new Vector2(1);
|
|
|
|
|
ActiveCursor.ScaleTo(0.90f, 800, EasingTypes.OutQuint);
|
|
|
|
|
|
|
|
|
|
((Cursor)ActiveCursor).AdditiveLayer.Alpha = 0;
|
|
|
|
|
((Cursor)ActiveCursor).AdditiveLayer.FadeInFromZero(800, EasingTypes.OutQuint);
|
|
|
|
|
return base.OnMouseDown(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (!state.Mouse.HasMainButtonPressed)
|
|
|
|
|
{
|
2017-03-27 16:48:18 +08:00
|
|
|
|
dragging = false;
|
|
|
|
|
|
2017-03-16 21:41:07 +08:00
|
|
|
|
((Cursor)ActiveCursor).AdditiveLayer.FadeOut(500, EasingTypes.OutQuint);
|
2017-03-18 21:37:50 +08:00
|
|
|
|
ActiveCursor.RotateTo(0, 600 * (1 + Math.Abs(ActiveCursor.Rotation / 720)), EasingTypes.OutElasticHalf);
|
2017-03-16 21:41:07 +08:00
|
|
|
|
ActiveCursor.ScaleTo(1, 500, EasingTypes.OutElastic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnMouseUp(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
|
|
|
|
((Cursor)ActiveCursor).AdditiveLayer.FadeOutFromOne(500, EasingTypes.OutQuint);
|
|
|
|
|
|
|
|
|
|
return base.OnClick(state);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 22:58:36 +08:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
ActiveCursor.FadeTo(1, 250, EasingTypes.OutQuint);
|
|
|
|
|
ActiveCursor.ScaleTo(1, 1000, EasingTypes.OutElastic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
ActiveCursor.FadeTo(0, 1400, EasingTypes.OutQuint);
|
|
|
|
|
ActiveCursor.ScaleTo(1.1f, 100, EasingTypes.Out);
|
|
|
|
|
ActiveCursor.Delay(100);
|
|
|
|
|
ActiveCursor.ScaleTo(0, 500, EasingTypes.In);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-16 21:41:07 +08:00
|
|
|
|
public class Cursor : Container
|
|
|
|
|
{
|
|
|
|
|
private Container cursorContainer;
|
2017-04-03 00:19:59 +08:00
|
|
|
|
public Tooltip Tooltip;
|
2017-03-16 21:41:07 +08:00
|
|
|
|
private Bindable<double> cursorScale;
|
|
|
|
|
|
|
|
|
|
public Sprite AdditiveLayer;
|
|
|
|
|
|
|
|
|
|
public Cursor()
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(42);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
cursorContainer = new Container
|
|
|
|
|
{
|
2017-03-17 20:04:46 +08:00
|
|
|
|
Size = new Vector2(32),
|
2017-03-16 21:41:07 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Sprite
|
|
|
|
|
{
|
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
|
Texture = textures.Get(@"Cursor/menu-cursor"),
|
|
|
|
|
},
|
|
|
|
|
AdditiveLayer = new Sprite
|
|
|
|
|
{
|
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
|
BlendingMode = BlendingMode.Additive,
|
2017-03-17 20:04:46 +08:00
|
|
|
|
Colour = colour.Pink,
|
2017-03-16 21:41:07 +08:00
|
|
|
|
Alpha = 0,
|
2017-03-17 20:04:46 +08:00
|
|
|
|
Texture = textures.Get(@"Cursor/menu-cursor-additive"),
|
2017-03-16 21:41:07 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2017-04-03 00:19:59 +08:00
|
|
|
|
},
|
|
|
|
|
Tooltip = new Tooltip
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
2017-03-16 21:41:07 +08:00
|
|
|
|
};
|
2017-03-23 07:07:59 +08:00
|
|
|
|
|
|
|
|
|
cursorScale = config.GetBindable<double>(OsuConfig.MenuCursorSize);
|
2017-03-16 21:41:07 +08:00
|
|
|
|
cursorScale.ValueChanged += scaleChanged;
|
2017-03-23 07:07:59 +08:00
|
|
|
|
cursorScale.TriggerChange();
|
2017-03-16 21:41:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void scaleChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
cursorContainer.Scale = new Vector2((float)cursorScale);
|
2017-04-03 00:19:59 +08:00
|
|
|
|
Tooltip.Y = cursorContainer.Height * (float)cursorScale;
|
2017-03-16 21:41:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|