1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 12:27:26 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyCursorTrail.cs

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

99 lines
3.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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Configuration;
using osu.Game.Rulesets.Osu.UI.Cursor;
using osu.Game.Skinning;
using osuTK;
2020-12-04 19:21:53 +08:00
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
public partial class LegacyCursorTrail : CursorTrail
{
2021-06-06 21:26:27 +08:00
private readonly ISkin skin;
private const double disjoint_trail_time_separation = 1000 / 60.0;
2024-04-22 13:58:45 +08:00
public bool DisjointTrail { get; private set; }
private double lastTrailTime;
private IBindable<float> cursorSize = null!;
private Vector2? currentPosition;
2021-06-06 21:26:27 +08:00
public LegacyCursorTrail(ISkin skin)
{
this.skin = skin;
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, ISkinSource skinSource)
{
cursorSize = config.GetBindable<float>(OsuSetting.GameplayCursorSize).GetBoundCopy();
Texture = skin.GetTexture("cursortrail");
2024-04-22 15:07:11 +08:00
// Cursor and cursor trail components are sourced from potentially different skin sources.
// Stable always chooses cursor trail disjoint behaviour based on the cursor texture lookup source, so we need to fetch where that occurred.
// See https://github.com/peppy/osu-stable-reference/blob/3ea48705eb67172c430371dcfc8a16a002ed0d3d/osu!/Graphics/Skinning/SkinManager.cs#L269
var cursorProvider = skinSource.FindProvider(s => s.GetTexture("cursor") != null);
DisjointTrail = cursorProvider?.GetTexture("cursormiddle") == null;
2024-04-22 13:58:45 +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;
}
2019-09-11 12:28:36 +08:00
if (Texture != null)
{
// stable "magic ratio". see OsuPlayfieldAdjustmentContainer for full explanation.
Texture.ScaleAdjust *= 1.6f;
}
}
2024-04-22 13:58:45 +08:00
protected override double FadeDuration => DisjointTrail ? 150 : 500;
2021-08-13 09:27:26 +08:00
protected override float FadeExponent => 1;
2024-04-22 13:58:45 +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);
2024-04-22 13:58:45 +08:00
protected override bool AvoidDrawingNearCursor => !DisjointTrail;
protected override void Update()
{
base.Update();
2024-04-22 13:58:45 +08:00
if (!DisjointTrail || !currentPosition.HasValue)
return;
if (Time.Current - lastTrailTime >= disjoint_trail_time_separation)
{
lastTrailTime = Time.Current;
AddTrail(currentPosition.Value);
}
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
2024-04-22 13:58:45 +08:00
if (!DisjointTrail)
return base.OnMouseMove(e);
currentPosition = e.ScreenSpaceMousePosition;
// Intentionally block the base call as we're adding the trails ourselves.
return false;
}
}
}