-
Notifications
You must be signed in to change notification settings - Fork 0
/
MouseLock.cs
98 lines (84 loc) · 2.72 KB
/
MouseLock.cs
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
97
98
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Game.Config;
using Dalamud.Plugin.Services;
namespace CombatCursorContainment;
internal static class MouseLock
{
internal static bool GetMouseLimit()
{
return Services.GameConfig.System.GetBool(SystemConfigOption.MouseOpeLimit.ToString());
}
internal static void SetMouseLimit(bool value)
{
if (GetMouseLimit() == value) return;
Services.PluginLog.Debug($"Toggled mouse lock {(value ? "on" : "off")}");
Services.GameConfig.System.Set(SystemConfigOption.MouseOpeLimit.ToString(), value);
}
internal static void EnableMouseAutoLock()
{
Services.Condition.ConditionChange += OnConditionChange;
OnConditionChange(ConditionFlag.InCombat, Services.Condition[ConditionFlag.InCombat]);
}
internal static void DisableMouseAutoLock()
{
Services.Condition.ConditionChange -= OnConditionChange;
Services.Framework.Update -= CombatFrameworkTick;
SetMouseLimit(false);
}
private static void OnConditionChange(ConditionFlag flag, bool value)
{
if (flag != ConditionFlag.InCombat) return;
Services.Framework.Update -= CombatFrameworkTick;
if (value)
{
Services.Framework.Update += CombatFrameworkTick;
}
else
{
Services.Framework.RunOnTick(() => { SetMouseLimit(false); });
}
}
private static void CombatFrameworkTick(IFramework _)
{
SetMouseLimit(ShouldLockMouse());
}
private static bool ShouldLockMouse()
{
if (Services.Config.DoNotLockDuringCutscene && IsInCutscene()) return false;
if (Services.Config.DoNotLockIfDead && IsDead()) return false;
if (Services.Config.DoNotLockIfOutsideDuty && !IsInDuty()) return false;
if (Services.Config.DoNotLockIfWeaponSheathed && !IsWeaponOut()) return false;
if (Services.Config.DoNotLockIfMounted && IsMounted()) return false;
if (Services.Config.DoNotLockIfGathererCrafter && IsCraftingJob()) return false;
return true;
}
private static bool IsInCutscene()
{
return Services.Condition[ConditionFlag.OccupiedInCutSceneEvent]
|| Services.Condition[ConditionFlag.WatchingCutscene];
}
private static bool IsDead()
{
return Services.ClientState.LocalPlayer?.IsDead == true;
}
private static bool IsInDuty()
{
return Services.DutyState.IsDutyStarted;
}
private static bool IsWeaponOut()
{
return Services.ClientState.LocalPlayer?.StatusFlags.HasFlag(StatusFlags.WeaponOut) == true;
}
private static bool IsMounted()
{
return Services.Condition[ConditionFlag.Mounted]
|| Services.Condition[ConditionFlag.Mounted2]
|| Services.Condition[ConditionFlag.Mounting]
|| Services.Condition[ConditionFlag.Mounting71];
}
private static bool IsCraftingJob()
{
return Services.ClientState.LocalPlayer?.ClassJob.Value.Role == 0;
}
}