-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
103 lines (83 loc) · 2.61 KB
/
Plugin.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
99
100
101
102
103
using CombatCursorContainment.Windows;
using Dalamud.Game.Command;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
namespace CombatCursorContainment;
internal sealed class Plugin : IDalamudPlugin
{
private const string ConfigWindowCommandName = "/ccc";
private readonly ConfigWindow _configWindow;
private readonly WindowSystem _windowSystem;
public Plugin(IDalamudPluginInterface pluginInterface)
{
pluginInterface.Create<Services>();
Services.Config = Services.PluginInterface.GetPluginConfig() as Configuration ?? new Configuration();
_configWindow = new ConfigWindow();
_windowSystem = new WindowSystem("CombatCursorContainment");
_windowSystem.AddWindow(_configWindow);
Services.CommandManager.AddHandler(ConfigWindowCommandName, new CommandInfo(OnConfigWindowCommand)
{
HelpMessage = "Opens the Combat Cursor Containment config window." +
"\n/ccc <enable|on|1> → Enables locking cursor during combat." +
"\n/ccc <disable|off|0> → Disables locking cursor during combat."
});
Services.PluginInterface.UiBuilder.Draw += DrawUi;
Services.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUi;
if (Services.Config.EnableLocking) MouseLock.EnableMouseAutoLock();
}
public void Dispose()
{
MouseLock.DisableMouseAutoLock();
_windowSystem.RemoveAllWindows();
_configWindow.Dispose();
Services.CommandManager.RemoveHandler(ConfigWindowCommandName);
Services.PluginInterface.UiBuilder.Draw -= DrawUi;
Services.PluginInterface.UiBuilder.OpenConfigUi -= DrawConfigUi;
}
private void OnConfigWindowCommand(string command, string args)
{
switch (args)
{
case "":
DrawConfigUi();
break;
case "enable" or "on" or "1":
if (Services.Config.EnableLocking)
{
Services.ChatGui.Print("Combat Cursor Containment was already enabled.");
}
else
{
Services.ChatGui.Print("Combat Cursor Containment now enabled.");
Services.Config.EnableLocking = true;
Services.Config.Save();
MouseLock.EnableMouseAutoLock();
}
break;
case "disable" or "off" or "0":
if (Services.Config.EnableLocking)
{
Services.ChatGui.Print("Combat Cursor Containment now disabled.");
Services.Config.EnableLocking = false;
Services.Config.Save();
MouseLock.DisableMouseAutoLock();
}
else
{
Services.ChatGui.Print("Combat Cursor Containment was already disabled.");
}
break;
default:
Services.ChatGui.PrintError($"Unknown command: '/{command} {args}'");
break;
}
}
private void DrawUi()
{
_windowSystem.Draw();
}
private void DrawConfigUi()
{
_configWindow.IsOpen = true;
}
}