forked from ppy/osu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLegacyCursorTrail.cs
More file actions
96 lines (75 loc) · 3.48 KB
/
Copy pathLegacyCursorTrail.cs
File metadata and controls
96 lines (75 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 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 System.Numerics;
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;
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
public partial class LegacyCursorTrail : CursorTrail
{
private readonly ISkin skin;
private const double disjoint_trail_time_separation = 1000 / 60.0;
public bool DisjointTrail { get; private set; }
private double lastTrailTime;
private IBindable<float> cursorSize = null!;
private Vector2? currentPosition;
public LegacyCursorTrail(ISkin skin)
{
this.skin = skin;
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config, ISkinSource skinSource)
{
cursorSize = config.GetBindable<float>(OsuSetting.GameplayCursorSize).GetBoundCopy();
AllowPartRotation = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.CursorTrailRotate)?.Value ?? true;
Texture = skin.GetTexture("cursortrail");
// 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;
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;
}
// stable "magic ratio". see OsuPlayfieldAdjustmentContainer for full explanation.
Texture?.ScaleAdjust *= 1.6f;
}
protected override double FadeDuration => DisjointTrail ? 150 : 500;
protected override float FadeExponent => 1;
protected override bool InterpolateMovements => !DisjointTrail;
protected override float IntervalMultiplier => 1f / MathF.Max(cursorSize.Value, 1f);
protected override bool AvoidDrawingNearCursor => !DisjointTrail;
protected override void Update()
{
base.Update();
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)
{
if (!DisjointTrail)
return base.OnMouseMove(e);
currentPosition = e.ScreenSpaceMousePosition;
// Intentionally block the base call as we're adding the trails ourselves.
return false;
}
}
}