1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-24 13:22:55 +08:00
osu-lazer/osu.Game.Rulesets.Osu/UI/Cursor/CursorRippleVisualiser.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
3.2 KiB
C#
Raw Normal View History

// 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.Bindables;
2023-04-29 15:06:08 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2023-04-29 21:00:17 +08:00
using osu.Framework.Graphics.Pooling;
2023-04-29 15:06:08 +08:00
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Osu.Configuration;
using osu.Game.Rulesets.Osu.Objects;
2023-04-29 15:06:08 +08:00
using osu.Game.Rulesets.Osu.Skinning.Default;
using osu.Game.Screens.Play;
2023-04-29 15:06:08 +08:00
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Osu.UI.Cursor
{
2023-04-29 15:06:08 +08:00
public partial class CursorRippleVisualiser : CompositeDrawable, IKeyBindingHandler<OsuAction>
{
private readonly Bindable<bool> showRipples = new Bindable<bool>(true);
2023-04-29 21:00:17 +08:00
private readonly DrawablePool<CursorRipple> ripplePool = new DrawablePool<CursorRipple>(20);
public CursorRippleVisualiser()
{
RelativeSizeAxes = Axes.Both;
}
public Vector2 CursorScale { get; set; } = Vector2.One;
[BackgroundDependencyLoader(true)]
2023-04-29 15:06:08 +08:00
private void load(OsuRulesetConfigManager? rulesetConfig)
{
2023-04-29 15:06:08 +08:00
rulesetConfig?.BindWith(OsuRulesetSetting.ShowCursorRipples, showRipples);
AddInternal(ripplePool);
2023-04-29 15:06:08 +08:00
}
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
{
if ((Clock as IGameplayClock)?.IsRewinding == true)
return false;
2023-04-29 15:06:08 +08:00
if (showRipples.Value)
{
AddInternal(ripplePool.Get(r =>
{
r.Position = e.MousePosition;
r.Scale = CursorScale;
}));
}
2023-04-29 15:06:08 +08:00
return false;
}
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
{
}
2023-04-29 21:00:17 +08:00
private partial class CursorRipple : PoolableDrawable
{
private Drawable ripple = null!;
2023-04-29 21:00:17 +08:00
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
Origin = Anchor.Centre;
InternalChild = ripple = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.CursorRipple), _ => new DefaultCursorRipple())
2023-04-29 21:00:17 +08:00
{
Blending = BlendingParameters.Additive,
2023-04-29 21:00:17 +08:00
};
}
protected override void PrepareForUse()
{
base.PrepareForUse();
ClearTransforms(true);
ripple.ScaleTo(0.1f)
.ScaleTo(1, 700, Easing.Out);
this
.FadeOutFromOne(700)
.Expire(true);
2023-04-29 21:00:17 +08:00
}
}
2023-04-29 15:06:08 +08:00
public partial class DefaultCursorRipple : CompositeDrawable
{
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
2023-04-29 15:06:08 +08:00
InternalChildren = new Drawable[]
{
new RingPiece(3)
{
2023-09-20 11:48:15 +08:00
Size = OsuHitObject.OBJECT_DIMENSIONS,
Alpha = 0.1f,
2023-04-29 15:06:08 +08:00
}
};
}
}
}
}