Globetrotter/Globetrotter/GlobetrotterPlugin.cs

87 lines
3.0 KiB
C#

using Dalamud.Game.Command;
using Dalamud.Plugin;
using System;
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Game.Gui;
namespace Globetrotter {
// ReSharper disable once ClassNeverInstantiated.Global
public class GlobetrotterPlugin : IDalamudPlugin {
private bool _disposedValue;
public string Name => "Globetrotter";
private DalamudPluginInterface Interface { get; }
private CommandManager CommandManager { get; }
internal DataManager DataManager { get; }
internal GameGui GameGui { get; }
internal SigScanner SigScanner { get; }
internal Configuration Config { get; }
private PluginUi Ui { get; }
private TreasureMaps Maps { get; }
public GlobetrotterPlugin(
DalamudPluginInterface pluginInterface,
CommandManager commandManager,
DataManager dataManager,
GameGui gameGui,
SigScanner scanner
) {
this.Interface = pluginInterface;
this.CommandManager = commandManager;
this.DataManager = dataManager;
this.GameGui = gameGui;
this.SigScanner = scanner;
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
this.Config.Initialize(this.Interface);
this.Ui = new PluginUi(this);
this.Maps = new TreasureMaps(this);
this.Interface.UiBuilder.Draw += this.Ui.Draw;
this.Interface.UiBuilder.OpenConfigUi += this.Ui.OpenSettings;
this.GameGui.HoveredItemChanged += this.Maps.OnHover;
this.CommandManager.AddHandler("/pglobetrotter", new CommandInfo(this.OnConfigCommand) {
HelpMessage = "Show the Globetrotter config",
});
this.CommandManager.AddHandler("/tmap", new CommandInfo(this.OnCommand) {
HelpMessage = "Open the map and place a flag at the location of your current treasure map",
});
}
private void OnConfigCommand(string command, string args) {
this.Ui.OpenSettings(null, null);
}
private void OnCommand(string command, string args) {
this.Maps.OpenMapLocation();
}
protected virtual void Dispose(bool disposing) {
if (this._disposedValue) {
return;
}
if (disposing) {
this.Interface.UiBuilder.Draw -= this.Ui.Draw;
this.Interface.UiBuilder.OpenConfigUi -= this.Ui.OpenSettings;
this.GameGui.HoveredItemChanged -= this.Maps.OnHover;
this.Maps.Dispose();
this.CommandManager.RemoveHandler("/pglobetrotter");
this.CommandManager.RemoveHandler("/tmap");
}
this._disposedValue = true;
}
public void Dispose() {
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
this.Dispose(true);
GC.SuppressFinalize(this);
}
}
}