-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
90 lines (73 loc) · 2.15 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
using Dalamud.Game.Addon.Lifecycle;
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using Dalamud.Game.Command;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
using MinimapMarkerMagnitude.Config;
using MinimapMarkerMagnitude.Windows;
namespace MinimapMarkerMagnitude;
internal sealed class Plugin : IDalamudPlugin
{
private const string ConfigWindowCommandName = "/mmm";
private readonly ConfigWindow _configWindow;
private readonly WindowSystem _windowSystem;
public Plugin(IDalamudPluginInterface pluginInterface)
{
pluginInterface.Create<Services>();
Configuration.Load();
SeenIconSet.Load();
ResizeUtil.CompileIconSizes();
_windowSystem = new WindowSystem("MinimapMarkerMagnitude");
_configWindow = new ConfigWindow(this);
_windowSystem.AddWindow(_configWindow);
Services.CommandManager.AddHandler(ConfigWindowCommandName, new CommandInfo(OnConfigWindowCommand)
{
HelpMessage = "Opens the Minimap Marker Magnitude config window."
});
Services.PluginInterface.UiBuilder.Draw += DrawUi;
Services.PluginInterface.UiBuilder.OpenConfigUi += DrawConfigUi;
if (Services.Config.EnableResizing) Enable();
}
public void Dispose()
{
Disable();
_windowSystem.RemoveAllWindows();
_configWindow.Dispose();
Services.CommandManager.RemoveHandler(ConfigWindowCommandName);
Services.PluginInterface.UiBuilder.Draw -= DrawUi;
Services.PluginInterface.UiBuilder.OpenConfigUi -= DrawConfigUi;
}
internal void Enable()
{
Services.AddonLifecycle.RegisterListener(AddonEvent.PreUpdate, "_NaviMap", NaviMapPreUpdateListener);
}
internal void Disable()
{
Services.AddonLifecycle.UnregisterListener(NaviMapPreUpdateListener);
ResizeUtil.ResizeIcons(true);
}
private void NaviMapPreUpdateListener(AddonEvent addonEvent, AddonArgs addonArgs)
{
try
{
ResizeUtil.ResizeIcons();
}
catch (Exception ex)
{
Services.PluginLog.Error(ex, "An error occurred when handling _NaviMap PostUpdate.");
Disable();
}
}
private void OnConfigWindowCommand(string command, string args)
{
DrawConfigUi();
}
private void DrawUi()
{
_windowSystem.Draw();
}
private void DrawConfigUi()
{
_configWindow.IsOpen = true;
}
}