2019-01-24 08:43:03 +00: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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2019-06-25 06:47:32 +00:00
|
|
|
|
using System;
|
2019-04-04 08:09:11 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
2017-03-16 13:41:07 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-09-09 08:53:51 +00:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2017-08-11 07:11:46 +00:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-09-16 09:26:12 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-04-04 08:09:11 +00:00
|
|
|
|
using osu.Game.Rulesets.Osu.Configuration;
|
2019-03-25 11:25:16 +00:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
2019-09-09 08:53:51 +00:00
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-08-10 09:37:41 +00:00
|
|
|
|
namespace osu.Game.Rulesets.Osu.UI.Cursor
|
2017-03-16 13:41:07 +00:00
|
|
|
|
{
|
2019-03-25 11:25:16 +00:00
|
|
|
|
public partial class OsuCursorContainer : GameplayCursorContainer, IKeyBindingHandler<OsuAction>
|
2017-03-16 13:41:07 +00:00
|
|
|
|
{
|
2023-11-06 15:28:51 +00:00
|
|
|
|
public new OsuCursor ActiveCursor => (OsuCursor)base.ActiveCursor;
|
|
|
|
|
|
2017-03-16 13:41:07 +00:00
|
|
|
|
protected override Drawable CreateCursor() => new OsuCursor();
|
2018-03-05 11:06:08 +00:00
|
|
|
|
protected override Container<Drawable> Content => fadeContainer;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-03-05 11:06:08 +00:00
|
|
|
|
private readonly Container<Drawable> fadeContainer;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-04-04 08:09:11 +00:00
|
|
|
|
private readonly Bindable<bool> showTrail = new Bindable<bool>(true);
|
|
|
|
|
|
2024-08-19 13:21:06 +00:00
|
|
|
|
private readonly SkinnableDrawable cursorTrail;
|
2019-04-04 08:09:11 +00:00
|
|
|
|
|
2023-05-01 05:40:48 +00:00
|
|
|
|
private readonly CursorRippleVisualiser rippleVisualiser;
|
|
|
|
|
|
2019-03-25 11:25:16 +00:00
|
|
|
|
public OsuCursorContainer()
|
2017-03-16 13:41:07 +00:00
|
|
|
|
{
|
2019-01-10 05:20:44 +00:00
|
|
|
|
InternalChild = fadeContainer = new Container
|
2018-03-05 11:06:08 +00:00
|
|
|
|
{
|
2019-01-10 05:20:44 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2024-08-19 13:21:06 +00:00
|
|
|
|
Children = new CompositeDrawable[]
|
2021-09-09 21:18:19 +00:00
|
|
|
|
{
|
2022-11-09 07:04:56 +00:00
|
|
|
|
cursorTrail = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.CursorTrail), _ => new DefaultCursorTrail(), confineMode: ConfineMode.NoScaling),
|
2023-05-01 05:40:48 +00:00
|
|
|
|
rippleVisualiser = new CursorRippleVisualiser(),
|
2022-11-09 07:04:56 +00:00
|
|
|
|
new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.CursorParticles), confineMode: ConfineMode.NoScaling),
|
2021-09-09 21:18:19 +00:00
|
|
|
|
}
|
2018-03-05 11:06:08 +00:00
|
|
|
|
};
|
2017-03-16 13:41:07 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-04-04 08:09:11 +00:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2022-01-15 00:06:39 +00:00
|
|
|
|
private void load(OsuRulesetConfigManager rulesetConfig)
|
2019-04-04 08:09:11 +00:00
|
|
|
|
{
|
2019-10-08 17:39:54 +00:00
|
|
|
|
rulesetConfig?.BindWith(OsuRulesetSetting.ShowCursorTrail, showTrail);
|
2020-02-14 03:30:11 +00:00
|
|
|
|
}
|
2019-10-08 17:39:54 +00:00
|
|
|
|
|
2020-02-14 03:30:11 +00:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2020-02-14 06:59:59 +00:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2020-02-14 03:30:11 +00:00
|
|
|
|
showTrail.BindValueChanged(v => cursorTrail.FadeTo(v.NewValue ? 1 : 0, 200), true);
|
2019-10-08 17:39:54 +00:00
|
|
|
|
|
2023-11-06 15:28:51 +00:00
|
|
|
|
ActiveCursor.CursorScale.BindValueChanged(e =>
|
2020-02-14 03:30:11 +00:00
|
|
|
|
{
|
|
|
|
|
var newScale = new Vector2(e.NewValue);
|
|
|
|
|
|
2023-05-01 05:40:48 +00:00
|
|
|
|
rippleVisualiser.CursorScale = newScale;
|
2020-02-14 03:30:11 +00:00
|
|
|
|
cursorTrail.Scale = newScale;
|
2020-07-10 05:43:30 +00:00
|
|
|
|
}, true);
|
2019-04-04 08:09:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 09:37:41 +00:00
|
|
|
|
private int downCount;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-01-07 09:28:22 +00:00
|
|
|
|
private void updateExpandedState()
|
|
|
|
|
{
|
|
|
|
|
if (downCount > 0)
|
2023-11-06 15:28:51 +00:00
|
|
|
|
ActiveCursor.Expand();
|
2019-01-07 09:28:22 +00:00
|
|
|
|
else
|
2023-11-06 15:28:51 +00:00
|
|
|
|
ActiveCursor.Contract();
|
2019-01-07 09:28:22 +00:00
|
|
|
|
}
|
2018-07-10 05:41:07 +00:00
|
|
|
|
|
2024-08-19 13:21:06 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2024-08-20 05:20:52 +00:00
|
|
|
|
if (cursorTrail.Drawable is CursorTrail trail)
|
|
|
|
|
trail.NewPartScale = ActiveCursor.CurrentExpandedScale;
|
2024-08-19 13:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<OsuAction> e)
|
2018-03-05 11:06:08 +00:00
|
|
|
|
{
|
2021-09-16 09:26:12 +00:00
|
|
|
|
switch (e.Action)
|
2018-12-11 20:02:12 +00:00
|
|
|
|
{
|
|
|
|
|
case OsuAction.LeftButton:
|
|
|
|
|
case OsuAction.RightButton:
|
|
|
|
|
downCount++;
|
2019-01-07 09:28:22 +00:00
|
|
|
|
updateExpandedState();
|
2018-12-11 20:02:12 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-03-05 11:06:08 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<OsuAction> e)
|
2018-03-05 11:06:08 +00:00
|
|
|
|
{
|
2021-09-16 09:26:12 +00:00
|
|
|
|
switch (e.Action)
|
2018-12-10 23:38:03 +00:00
|
|
|
|
{
|
|
|
|
|
case OsuAction.LeftButton:
|
|
|
|
|
case OsuAction.RightButton:
|
2019-06-25 06:47:32 +00:00
|
|
|
|
// 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)
|
2019-01-07 09:28:22 +00:00
|
|
|
|
updateExpandedState();
|
2018-12-10 23:38:03 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-03-05 11:06:08 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-09-26 05:01:15 +00: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 09:19:50 +00:00
|
|
|
|
|
2018-03-05 11:06:08 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
fadeContainer.FadeTo(1, 300, Easing.OutQuint);
|
2023-11-06 15:28:51 +00:00
|
|
|
|
ActiveCursor.ScaleTo(1f, 400, Easing.OutQuint);
|
2018-03-05 11:06:08 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-03-05 11:06:08 +00:00
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
fadeContainer.FadeTo(0.05f, 450, Easing.OutQuint);
|
2023-11-06 15:28:51 +00:00
|
|
|
|
ActiveCursor.ScaleTo(0.8f, 450, Easing.OutQuint);
|
2018-03-05 11:06:08 +00:00
|
|
|
|
}
|
2019-09-09 08:53:51 +00:00
|
|
|
|
|
|
|
|
|
private partial class DefaultCursorTrail : CursorTrail
|
|
|
|
|
{
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(TextureStore textures)
|
|
|
|
|
{
|
|
|
|
|
Texture = textures.Get(@"Cursor/cursortrail");
|
|
|
|
|
Scale = new Vector2(1 / Texture.ScaleAdjust);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-11 17:06:41 +00:00
|
|
|
|
}
|
2017-03-16 13:41:07 +00:00
|
|
|
|
}
|