1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 01:17:27 +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.

101 lines
2.9 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;
2023-04-29 15:06:08 +08:00
using osu.Game.Rulesets.Osu.Skinning.Default;
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;
}
[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);
}
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
{
if (showRipples.Value)
{
AddInternal(ripplePool.Get(r =>
{
r.Position = e.MousePosition;
}));
}
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
{
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
Origin = Anchor.Centre;
InternalChildren = new Drawable[]
{
new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.CursorRipple), _ => new DefaultCursorRipple())
{
Blending = BlendingParameters.Additive,
}
};
}
protected override void PrepareForUse()
{
base.PrepareForUse();
ClearTransforms(true);
this.ScaleTo(0.05f)
.ScaleTo(0.5f, 700, Easing.Out)
.FadeTo(0.2f)
.FadeOut(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)
{
Size = new Vector2(512),
}
};
}
}
}
}