1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 15:53:00 +08:00
osu-lazer/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursor.cs

141 lines
5.1 KiB
C#
Raw Normal View History

2019-03-19 16:39:53 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-04-09 15:27:10 +08:00
using osu.Framework.Graphics.Effects;
2019-03-19 16:39:53 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Osu.Skinning;
2019-03-19 16:39:53 +08:00
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.UI.Cursor
{
public class OsuCursor : SkinReloadableDrawable
{
2019-07-25 15:17:02 +08:00
private const float size = 28;
2019-03-19 16:39:53 +08:00
private bool cursorExpand;
2019-12-10 19:45:06 +08:00
private SkinnableDrawable cursorSprite;
2019-12-10 20:40:10 +08:00
private Drawable expandTarget => (cursorSprite.Drawable as OsuCursorSprite)?.ExpandTarget ?? cursorSprite;
2019-03-19 16:39:53 +08:00
public OsuCursor()
{
Origin = Anchor.Centre;
2019-07-25 15:17:02 +08:00
Size = new Vector2(size);
2019-03-19 16:39:53 +08:00
}
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
{
cursorExpand = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.CursorExpand)?.Value ?? true;
2019-03-19 16:39:53 +08:00
}
[BackgroundDependencyLoader]
private void load()
2019-03-19 16:39:53 +08:00
{
InternalChild = new Container
2019-03-19 16:39:53 +08:00
{
RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
2019-12-10 19:45:06 +08:00
Child = cursorSprite = new SkinnableDrawable(new OsuSkinComponent(OsuSkinComponents.Cursor), _ => new DefaultCursor(), confineMode: ConfineMode.NoScaling)
2019-03-19 16:39:53 +08:00
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
}
};
}
private const float pressed_scale = 1.2f;
private const float released_scale = 1f;
public void Expand()
{
if (!cursorExpand) return;
2019-12-10 20:40:10 +08:00
expandTarget.ScaleTo(released_scale).ScaleTo(pressed_scale, 100, Easing.OutQuad);
2019-03-19 16:39:53 +08:00
}
2019-12-10 20:40:10 +08:00
public void Contract() => expandTarget.ScaleTo(released_scale, 100, Easing.OutQuad);
2019-07-25 15:17:02 +08:00
private class DefaultCursor : OsuCursorSprite
2019-07-25 15:17:02 +08:00
{
public DefaultCursor()
{
RelativeSizeAxes = Axes.Both;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
2019-12-10 20:40:10 +08:00
InternalChildren = new[]
2019-07-25 15:17:02 +08:00
{
ExpandTarget = new CircularContainer
2019-07-25 15:17:02 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2019-07-25 15:17:02 +08:00
RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = size / 6,
BorderColour = Color4.White,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Pink.Opacity(0.5f),
Radius = 5,
},
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true,
},
new CircularContainer
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Masking = true,
BorderThickness = size / 3,
BorderColour = Color4.White.Opacity(0.5f),
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
AlwaysPresent = true,
},
},
},
new CircularContainer
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Scale = new Vector2(0.1f),
Masking = true,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White,
},
},
},
}
}
};
}
}
2019-03-19 16:39:53 +08:00
}
}