2020-07-28 22:46:16 +00:00
|
|
|
|
using Dalamud.Game.Command;
|
|
|
|
|
using Dalamud.Plugin;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PeepingTom {
|
|
|
|
|
public class PeepingTomPlugin : IDalamudPlugin, IDisposable {
|
|
|
|
|
public string Name => "Peeping Tom";
|
|
|
|
|
|
2020-08-08 10:05:23 +00:00
|
|
|
|
internal DalamudPluginInterface Interface { get; private set; }
|
2020-08-08 10:11:52 +00:00
|
|
|
|
internal Configuration Config { get; private set; }
|
|
|
|
|
internal PluginUI Ui { get; private set; }
|
|
|
|
|
internal TargetWatcher Watcher { get; private set; }
|
2020-08-26 12:20:01 +00:00
|
|
|
|
internal GameFunctions GameFunctions { get; private set; }
|
2020-07-28 22:46:16 +00:00
|
|
|
|
|
|
|
|
|
public void Initialize(DalamudPluginInterface pluginInterface) {
|
2020-08-08 10:05:23 +00:00
|
|
|
|
this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface argument was null");
|
2020-08-08 10:11:52 +00:00
|
|
|
|
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
|
|
|
|
|
this.Config.Initialize(this.Interface);
|
|
|
|
|
this.Watcher = new TargetWatcher(this);
|
2020-08-26 12:20:01 +00:00
|
|
|
|
this.GameFunctions = new GameFunctions(this);
|
2020-08-08 10:11:52 +00:00
|
|
|
|
this.Ui = new PluginUI(this);
|
2020-07-28 22:46:16 +00:00
|
|
|
|
|
2020-08-08 10:05:23 +00:00
|
|
|
|
this.Interface.CommandManager.AddHandler("/ppeepingtom", new CommandInfo(this.OnCommand) {
|
2020-07-28 22:46:16 +00:00
|
|
|
|
HelpMessage = "Use with no arguments to show the list. Use with \"c\" or \"config\" to show the config"
|
|
|
|
|
});
|
2020-08-08 10:05:23 +00:00
|
|
|
|
this.Interface.CommandManager.AddHandler("/ptom", new CommandInfo(this.OnCommand) {
|
2020-07-28 22:46:16 +00:00
|
|
|
|
HelpMessage = "Alias for /ppeepingtom"
|
|
|
|
|
});
|
2020-08-08 10:05:23 +00:00
|
|
|
|
this.Interface.CommandManager.AddHandler("/ppeep", new CommandInfo(this.OnCommand) {
|
2020-07-28 22:46:16 +00:00
|
|
|
|
HelpMessage = "Alias for /ppeepingtom"
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-08 10:11:52 +00:00
|
|
|
|
this.Interface.Framework.OnUpdateEvent += this.Watcher.OnFrameworkUpdate;
|
2020-08-15 21:11:06 +00:00
|
|
|
|
this.Interface.ClientState.OnLogin += this.OnLogin;
|
|
|
|
|
this.Interface.ClientState.OnLogout += this.OnLogout;
|
2020-08-08 10:05:23 +00:00
|
|
|
|
this.Interface.UiBuilder.OnBuildUi += this.DrawUI;
|
|
|
|
|
this.Interface.UiBuilder.OnOpenConfigUi += this.ConfigUI;
|
2020-08-08 20:23:51 +00:00
|
|
|
|
|
|
|
|
|
this.Watcher.StartThread();
|
2020-07-28 22:46:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCommand(string command, string args) {
|
|
|
|
|
if (args == "config" || args == "c") {
|
2020-08-09 04:05:11 +00:00
|
|
|
|
this.Ui.SettingsOpen = true;
|
2020-07-28 22:46:16 +00:00
|
|
|
|
} else {
|
2020-08-09 04:05:11 +00:00
|
|
|
|
this.Ui.WantsOpen = true;
|
2020-07-28 22:46:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 21:11:06 +00:00
|
|
|
|
private void OnLogin(object sender, EventArgs args) {
|
|
|
|
|
if (!this.Config.OpenOnLogin) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.Ui.WantsOpen = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLogout(object sender, EventArgs args) {
|
|
|
|
|
this.Ui.WantsOpen = false;
|
|
|
|
|
this.Watcher.ClearPrevious();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 22:46:16 +00:00
|
|
|
|
protected virtual void Dispose(bool includeManaged) {
|
2020-08-08 10:11:52 +00:00
|
|
|
|
this.Interface.Framework.OnUpdateEvent -= this.Watcher.OnFrameworkUpdate;
|
2020-08-15 21:11:06 +00:00
|
|
|
|
this.Interface.ClientState.OnLogin -= this.OnLogin;
|
|
|
|
|
this.Interface.ClientState.OnLogout -= this.OnLogout;
|
2020-08-08 20:23:51 +00:00
|
|
|
|
this.Watcher.WaitStopThread();
|
2020-08-08 10:11:52 +00:00
|
|
|
|
this.Watcher.Dispose();
|
2020-08-08 10:05:23 +00:00
|
|
|
|
this.Interface.UiBuilder.OnBuildUi -= DrawUI;
|
|
|
|
|
this.Interface.UiBuilder.OnOpenConfigUi -= ConfigUI;
|
|
|
|
|
this.Interface.CommandManager.RemoveHandler("/ppeepingtom");
|
|
|
|
|
this.Interface.CommandManager.RemoveHandler("/ptom");
|
|
|
|
|
this.Interface.CommandManager.RemoveHandler("/ppeep");
|
2020-08-08 10:11:52 +00:00
|
|
|
|
this.Ui.Dispose();
|
2020-07-28 22:46:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose() {
|
|
|
|
|
this.Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawUI() {
|
2020-08-08 10:11:52 +00:00
|
|
|
|
this.Ui.Draw();
|
2020-07-28 22:46:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ConfigUI(object sender, EventArgs args) {
|
2020-08-09 04:05:11 +00:00
|
|
|
|
this.Ui.SettingsOpen = true;
|
2020-07-28 22:46:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|