Anna
e9a2fb11a8
Also make the poll interval configurable. For the case of one targeter, the UI scans through the ActorTable to find the relevant Actor, achieving either a partial or full scan. In the case of more than one targeter, the UI constructs a Dictionary mapping ActorId to Actor, then indexes that dictionary for each targeter. This achieves one full scan, which may or may not be more efficient than multiple partial scans, depending on where the actors are located in the table. The UI must do this because current targeters are no longer guaranteed to be spawned anymore, especially with a high polling frequency, and the UI needs accurate information about the targeters' address in memory.
75 lines
3.0 KiB
C#
75 lines
3.0 KiB
C#
using Dalamud.Game.Command;
|
|
using Dalamud.Plugin;
|
|
using System;
|
|
|
|
namespace PeepingTom {
|
|
public class PeepingTomPlugin : IDalamudPlugin, IDisposable {
|
|
public string Name => "Peeping Tom";
|
|
|
|
internal DalamudPluginInterface Interface { get; private set; }
|
|
internal Configuration Config { get; private set; }
|
|
internal PluginUI Ui { get; private set; }
|
|
internal TargetWatcher Watcher { get; private set; }
|
|
private HookManager hookManager;
|
|
|
|
public void Initialize(DalamudPluginInterface pluginInterface) {
|
|
this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface argument was null");
|
|
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
|
|
this.Config.Initialize(this.Interface);
|
|
this.Watcher = new TargetWatcher(this);
|
|
this.Ui = new PluginUI(this);
|
|
this.hookManager = new HookManager(this);
|
|
|
|
this.Interface.CommandManager.AddHandler("/ppeepingtom", new CommandInfo(this.OnCommand) {
|
|
HelpMessage = "Use with no arguments to show the list. Use with \"c\" or \"config\" to show the config"
|
|
});
|
|
this.Interface.CommandManager.AddHandler("/ptom", new CommandInfo(this.OnCommand) {
|
|
HelpMessage = "Alias for /ppeepingtom"
|
|
});
|
|
this.Interface.CommandManager.AddHandler("/ppeep", new CommandInfo(this.OnCommand) {
|
|
HelpMessage = "Alias for /ppeepingtom"
|
|
});
|
|
|
|
this.Interface.Framework.OnUpdateEvent += this.Watcher.OnFrameworkUpdate;
|
|
this.Interface.UiBuilder.OnBuildUi += this.DrawUI;
|
|
this.Interface.UiBuilder.OnOpenConfigUi += this.ConfigUI;
|
|
|
|
this.Watcher.StartThread();
|
|
}
|
|
|
|
private void OnCommand(string command, string args) {
|
|
if (args == "config" || args == "c") {
|
|
this.Ui.SettingsVisible = true;
|
|
} else {
|
|
this.Ui.Visible = true;
|
|
}
|
|
}
|
|
|
|
protected virtual void Dispose(bool includeManaged) {
|
|
this.hookManager.Dispose();
|
|
this.Interface.Framework.OnUpdateEvent -= this.Watcher.OnFrameworkUpdate;
|
|
this.Watcher.WaitStopThread();
|
|
this.Watcher.Dispose();
|
|
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");
|
|
this.Ui.Dispose();
|
|
}
|
|
|
|
public void Dispose() {
|
|
this.Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
private void DrawUI() {
|
|
this.Ui.Draw();
|
|
}
|
|
|
|
private void ConfigUI(object sender, EventArgs args) {
|
|
this.Ui.SettingsVisible = true;
|
|
}
|
|
}
|
|
}
|