Globetrotter/Globetrotter/Plugin.cs

88 lines
2.9 KiB
C#
Raw Normal View History

2020-08-01 07:43:23 +00:00
using Dalamud.Game.Command;
using Dalamud.Plugin;
using System;
2021-08-23 01:48:54 +00:00
using Dalamud.Game;
2021-08-24 00:44:03 +00:00
using Dalamud.IoC;
2023-09-29 01:02:45 +00:00
using Dalamud.Plugin.Services;
2020-08-01 07:43:23 +00:00
namespace Globetrotter {
2021-08-23 01:48:54 +00:00
// ReSharper disable once ClassNeverInstantiated.Global
2023-09-29 01:02:45 +00:00
public class Plugin : IDalamudPlugin {
2021-03-19 20:06:45 +00:00
private bool _disposedValue;
2020-08-01 07:43:23 +00:00
2023-09-29 01:02:45 +00:00
[PluginService]
internal static IPluginLog Log { get; private set; } = null!;
2020-08-01 07:43:23 +00:00
2021-08-24 00:44:03 +00:00
[PluginService]
private DalamudPluginInterface Interface { get; init; } = null!;
[PluginService]
2023-09-29 01:02:45 +00:00
private ICommandManager CommandManager { get; init; } = null!;
[PluginService]
internal IDataManager DataManager { get; init; } = null!;
2021-08-24 00:44:03 +00:00
[PluginService]
2023-09-29 01:02:45 +00:00
internal IGameGui GameGui { get; init; } = null!;
2021-08-24 00:44:03 +00:00
[PluginService]
2023-09-29 01:02:45 +00:00
internal ISigScanner SigScanner { get; init; } = null!;
2021-08-24 00:44:03 +00:00
[PluginService]
2023-09-29 01:02:45 +00:00
internal IGameInteropProvider GameInteropProvider { get; init; } = null!;
2020-08-01 07:43:23 +00:00
2021-08-23 01:48:54 +00:00
internal Configuration Config { get; }
private PluginUi Ui { get; }
private TreasureMaps Maps { get; }
2020-08-01 07:43:23 +00:00
2023-09-29 01:02:45 +00:00
public Plugin() {
2021-08-23 01:48:54 +00:00
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
this.Config.Initialize(this.Interface);
2021-03-19 20:06:45 +00:00
2021-08-23 01:48:54 +00:00
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) {
2021-03-19 20:06:45 +00:00
HelpMessage = "Show the Globetrotter config",
2020-08-01 07:43:23 +00:00
});
2021-08-23 01:48:54 +00:00
this.CommandManager.AddHandler("/tmap", new CommandInfo(this.OnCommand) {
2021-03-19 20:06:45 +00:00
HelpMessage = "Open the map and place a flag at the location of your current treasure map",
2020-08-01 07:43:23 +00:00
});
}
private void OnConfigCommand(string command, string args) {
2021-08-24 18:40:46 +00:00
this.Ui.OpenSettings();
2020-08-01 07:43:23 +00:00
}
private void OnCommand(string command, string args) {
2021-08-23 01:48:54 +00:00
this.Maps.OpenMapLocation();
2020-08-01 07:43:23 +00:00
}
protected virtual void Dispose(bool disposing) {
2021-03-19 20:06:45 +00:00
if (this._disposedValue) {
return;
}
2020-08-01 07:43:23 +00:00
2021-03-19 20:06:45 +00:00
if (disposing) {
2021-08-23 01:48:54 +00:00
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");
2020-08-01 07:43:23 +00:00
}
2021-03-19 20:06:45 +00:00
this._disposedValue = true;
}
2020-08-01 07:43:23 +00:00
public void Dispose() {
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
2021-03-19 20:06:45 +00:00
this.Dispose(true);
2020-08-01 07:43:23 +00:00
GC.SuppressFinalize(this);
}
}
}