2019-09-09 16:53:51 +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.
|
|
|
|
|
2020-10-03 00:34:06 +08:00
|
|
|
using System;
|
2019-09-09 16:53:51 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-10-03 00:34:06 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-09-09 16:53:51 +08:00
|
|
|
using osu.Framework.Graphics;
|
2019-09-09 18:23:02 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2020-10-03 00:34:06 +08:00
|
|
|
using osu.Game.Configuration;
|
2019-09-09 16:53:51 +08:00
|
|
|
using osu.Game.Rulesets.Osu.UI.Cursor;
|
|
|
|
using osu.Game.Skinning;
|
2021-08-12 22:13:03 +08:00
|
|
|
using osuTK;
|
2019-09-09 16:53:51 +08:00
|
|
|
|
2020-12-04 19:21:53 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
2019-09-09 16:53:51 +08:00
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class LegacyCursorTrail : CursorTrail
|
2019-09-09 16:53:51 +08:00
|
|
|
{
|
2021-06-06 21:26:27 +08:00
|
|
|
private readonly ISkin skin;
|
2019-09-09 18:23:02 +08:00
|
|
|
private const double disjoint_trail_time_separation = 1000 / 60.0;
|
|
|
|
|
|
|
|
private bool disjointTrail;
|
|
|
|
private double lastTrailTime;
|
2022-11-09 12:36:52 +08:00
|
|
|
|
|
|
|
private IBindable<float> cursorSize = null!;
|
2019-09-09 18:23:02 +08:00
|
|
|
|
2021-08-12 22:13:03 +08:00
|
|
|
private Vector2? currentPosition;
|
|
|
|
|
2021-06-06 21:26:27 +08:00
|
|
|
public LegacyCursorTrail(ISkin skin)
|
|
|
|
{
|
|
|
|
this.skin = skin;
|
|
|
|
}
|
|
|
|
|
2019-09-09 16:53:51 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2021-08-13 09:27:26 +08:00
|
|
|
private void load(OsuConfigManager config)
|
2019-09-09 16:53:51 +08:00
|
|
|
{
|
2022-11-09 12:36:52 +08:00
|
|
|
cursorSize = config.GetBindable<float>(OsuSetting.GameplayCursorSize).GetBoundCopy();
|
|
|
|
|
2019-09-09 16:53:51 +08:00
|
|
|
Texture = skin.GetTexture("cursortrail");
|
2019-09-09 18:23:02 +08:00
|
|
|
disjointTrail = skin.GetTexture("cursormiddle") == null;
|
|
|
|
|
2021-04-14 13:20:18 +08:00
|
|
|
if (disjointTrail)
|
|
|
|
{
|
|
|
|
bool centre = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.CursorCentre)?.Value ?? true;
|
|
|
|
|
|
|
|
TrailOrigin = centre ? Anchor.Centre : Anchor.TopLeft;
|
|
|
|
Blending = BlendingParameters.Inherit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Blending = BlendingParameters.Additive;
|
|
|
|
}
|
2020-12-29 09:37:57 +08:00
|
|
|
|
2019-09-11 12:28:36 +08:00
|
|
|
if (Texture != null)
|
2019-09-09 18:23:02 +08:00
|
|
|
{
|
|
|
|
// stable "magic ratio". see OsuPlayfieldAdjustmentContainer for full explanation.
|
|
|
|
Texture.ScaleAdjust *= 1.6f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override double FadeDuration => disjointTrail ? 150 : 500;
|
2021-08-13 09:27:26 +08:00
|
|
|
protected override float FadeExponent => 1;
|
2019-09-09 18:23:02 +08:00
|
|
|
|
|
|
|
protected override bool InterpolateMovements => !disjointTrail;
|
|
|
|
|
2020-10-03 00:34:49 +08:00
|
|
|
protected override float IntervalMultiplier => 1 / Math.Max(cursorSize.Value, 1);
|
2021-08-17 03:52:19 +08:00
|
|
|
protected override bool AvoidDrawingNearCursor => !disjointTrail;
|
2020-10-03 00:34:06 +08:00
|
|
|
|
2021-08-12 22:13:03 +08:00
|
|
|
protected override void Update()
|
2019-09-09 18:23:02 +08:00
|
|
|
{
|
2021-08-12 22:13:03 +08:00
|
|
|
base.Update();
|
|
|
|
|
|
|
|
if (!disjointTrail || !currentPosition.HasValue)
|
|
|
|
return;
|
2019-09-09 18:23:02 +08:00
|
|
|
|
|
|
|
if (Time.Current - lastTrailTime >= disjoint_trail_time_separation)
|
|
|
|
{
|
|
|
|
lastTrailTime = Time.Current;
|
2021-08-12 22:13:03 +08:00
|
|
|
AddTrail(currentPosition.Value);
|
2019-09-09 18:23:02 +08:00
|
|
|
}
|
2021-08-12 22:13:03 +08:00
|
|
|
}
|
2019-09-09 18:23:02 +08:00
|
|
|
|
2021-08-12 22:13:03 +08:00
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
|
|
|
{
|
2021-08-13 11:10:33 +08:00
|
|
|
if (!disjointTrail)
|
|
|
|
return base.OnMouseMove(e);
|
|
|
|
|
2021-08-12 22:13:03 +08:00
|
|
|
currentPosition = e.ScreenSpaceMousePosition;
|
2021-08-13 11:10:33 +08:00
|
|
|
|
|
|
|
// Intentionally block the base call as we're adding the trails ourselves.
|
|
|
|
return false;
|
2019-09-09 16:53:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|