1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-18 05:52:56 +08:00
osu-lazer/osu.Game.Rulesets.Osu/UI/Cursor/OsuCursorContainer.cs

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

136 lines
4.4 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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2017-03-16 21:41:07 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Textures;
2017-08-11 15:11:46 +08:00
using osu.Framework.Input.Bindings;
2021-09-16 17:26:12 +08:00
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Osu.Configuration;
using osu.Game.Rulesets.UI;
using osu.Game.Skinning;
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Osu.UI.Cursor
2017-03-16 21:41:07 +08:00
{
public partial class OsuCursorContainer : GameplayCursorContainer, IKeyBindingHandler<OsuAction>
2017-03-16 21:41:07 +08:00
{
public new OsuCursor ActiveCursor => (OsuCursor)base.ActiveCursor;
2017-03-16 21:41:07 +08:00
protected override Drawable CreateCursor() => new OsuCursor();
2018-04-13 17:19:50 +08:00
protected override Container<Drawable> Content => fadeContainer;
2018-04-13 17:19:50 +08:00
private readonly Container<Drawable> fadeContainer;
2018-04-13 17:19:50 +08:00
private readonly Bindable<bool> showTrail = new Bindable<bool>(true);
private readonly Drawable cursorTrail;
private readonly CursorRippleVisualiser rippleVisualiser;
public OsuCursorContainer()
2017-03-16 21:41:07 +08:00
{
2019-01-10 13:20:44 +08:00
InternalChild = fadeContainer = new Container
{
2019-01-10 13:20:44 +08:00
RelativeSizeAxes = Axes.Both,
Children = new[]
{
cursorTrail = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.CursorTrail), _ => new DefaultCursorTrail(), confineMode: ConfineMode.NoScaling),
rippleVisualiser = new CursorRippleVisualiser(),
new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.CursorParticles), confineMode: ConfineMode.NoScaling),
}
};
2017-03-16 21:41:07 +08:00
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader(true)]
2022-01-15 08:06:39 +08:00
private void load(OsuRulesetConfigManager rulesetConfig)
{
rulesetConfig?.BindWith(OsuRulesetSetting.ShowCursorTrail, showTrail);
}
protected override void LoadComplete()
{
base.LoadComplete();
showTrail.BindValueChanged(v => cursorTrail.FadeTo(v.NewValue ? 1 : 0, 200), true);
ActiveCursor.CursorScale.BindValueChanged(e =>
{
var newScale = new Vector2(e.NewValue);
rippleVisualiser.CursorScale = newScale;
cursorTrail.Scale = newScale;
}, true);
}
private int downCount;
2018-04-13 17:19:50 +08:00
private void updateExpandedState()
{
if (downCount > 0)
ActiveCursor.Expand();
else
ActiveCursor.Contract();
}
2021-09-16 17:26:12 +08:00
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
{
2021-09-16 17:26:12 +08:00
switch (e.Action)
2018-12-12 04:02:12 +08:00
{
case OsuAction.LeftButton:
case OsuAction.RightButton:
downCount++;
updateExpandedState();
2018-12-12 04:02:12 +08:00
break;
}
2018-04-13 17:19:50 +08:00
return false;
}
2018-04-13 17:19:50 +08:00
2021-09-16 17:26:12 +08:00
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
{
2021-09-16 17:26:12 +08:00
switch (e.Action)
2018-12-11 07:38:03 +08:00
{
case OsuAction.LeftButton:
case OsuAction.RightButton:
// Todo: Math.Max() is required as a temporary measure to address https://github.com/ppy/osu-framework/issues/2576
downCount = Math.Max(0, downCount - 1);
if (downCount == 0)
updateExpandedState();
2018-12-11 07:38:03 +08:00
break;
}
}
2018-04-13 17:19:50 +08:00
public override bool HandlePositionalInput => true; // OverlayContainer will set this false when we go hidden, but we always want to receive input.
2018-04-13 17:19:50 +08:00
protected override void PopIn()
{
fadeContainer.FadeTo(1, 300, Easing.OutQuint);
ActiveCursor.ScaleTo(1f, 400, Easing.OutQuint);
}
2018-04-13 17:19:50 +08:00
protected override void PopOut()
{
fadeContainer.FadeTo(0.05f, 450, Easing.OutQuint);
ActiveCursor.ScaleTo(0.8f, 450, Easing.OutQuint);
}
private partial class DefaultCursorTrail : CursorTrail
{
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
Texture = textures.Get(@"Cursor/cursortrail");
Scale = new Vector2(1 / Texture.ScaleAdjust);
}
}
2018-12-12 01:06:41 +08:00
}
2017-03-16 21:41:07 +08:00
}