refactor: make other classes access plugin class
This commit is contained in:
parent
cc9b66c216
commit
420f03e78e
|
@ -4,9 +4,7 @@ using System;
|
|||
|
||||
namespace PeepingTom {
|
||||
class HookManager : IDisposable {
|
||||
private readonly DalamudPluginInterface pi;
|
||||
private readonly PluginUI ui;
|
||||
private readonly Configuration config;
|
||||
private readonly PeepingTomPlugin plugin;
|
||||
|
||||
private readonly Hook<LoginDelegate> loginHook;
|
||||
private readonly Hook<LogoutDelegate> logoutHook;
|
||||
|
@ -14,12 +12,10 @@ namespace PeepingTom {
|
|||
private delegate void LoginDelegate(IntPtr ptr, IntPtr ptr2);
|
||||
private delegate void LogoutDelegate(IntPtr ptr);
|
||||
|
||||
public HookManager(DalamudPluginInterface pi, PluginUI ui, Configuration config) {
|
||||
this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null");
|
||||
this.ui = ui ?? throw new ArgumentNullException(nameof(ui), "PluginUI cannot be null");
|
||||
this.config = config ?? throw new ArgumentNullException(nameof(config), "Configuration cannot be null");
|
||||
public HookManager(PeepingTomPlugin plugin) {
|
||||
this.plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "PeepingTomPlugin cannot be null");
|
||||
|
||||
IntPtr loginPtr = this.pi.TargetModuleScanner.ScanText("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 41 54 41 56 41 57 48 83 EC 20 48 8B F2");
|
||||
IntPtr loginPtr = this.plugin.Interface.TargetModuleScanner.ScanText("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 41 54 41 56 41 57 48 83 EC 20 48 8B F2");
|
||||
if (loginPtr != IntPtr.Zero) {
|
||||
this.loginHook = new Hook<LoginDelegate>(loginPtr, new LoginDelegate(this.OnLogin), this);
|
||||
this.loginHook.Enable();
|
||||
|
@ -27,7 +23,7 @@ namespace PeepingTom {
|
|||
PluginLog.Log("Could not hook LoginDelegate");
|
||||
}
|
||||
|
||||
IntPtr logoutPtr = this.pi.TargetModuleScanner.ScanText("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 48 8B D9 E8 ?? ?? ?? ?? 33 ED 66 C7 03 00 00");
|
||||
IntPtr logoutPtr = this.plugin.Interface.TargetModuleScanner.ScanText("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 48 8B D9 E8 ?? ?? ?? ?? 33 ED 66 C7 03 00 00");
|
||||
if (logoutPtr != IntPtr.Zero) {
|
||||
this.logoutHook = new Hook<LogoutDelegate>(logoutPtr, new LogoutDelegate(this.OnLogout), this);
|
||||
this.logoutHook.Enable();
|
||||
|
@ -39,17 +35,17 @@ namespace PeepingTom {
|
|||
private void OnLogin(IntPtr ptr, IntPtr ptr2) {
|
||||
this.loginHook.Original(ptr, ptr2);
|
||||
|
||||
if (!this.config.OpenOnLogin) {
|
||||
if (!this.plugin.Config.OpenOnLogin) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.ui.Visible = true;
|
||||
this.plugin.Ui.Visible = true;
|
||||
}
|
||||
|
||||
private void OnLogout(IntPtr ptr) {
|
||||
this.logoutHook.Original(ptr);
|
||||
|
||||
this.ui.Visible = false;
|
||||
this.plugin.Ui.Visible = false;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
|
|
|
@ -7,18 +7,18 @@ namespace PeepingTom {
|
|||
public string Name => "Peeping Tom";
|
||||
|
||||
internal DalamudPluginInterface Interface { get; private set; }
|
||||
internal Configuration config;
|
||||
internal PluginUI ui;
|
||||
internal Configuration Config { get; private set; }
|
||||
internal PluginUI Ui { get; private set; }
|
||||
internal TargetWatcher Watcher { get; private set; }
|
||||
private HookManager hookManager;
|
||||
private TargetWatcher watcher;
|
||||
|
||||
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.config, this.Interface, this.watcher);
|
||||
this.hookManager = new HookManager(this.Interface, this.ui, this.config);
|
||||
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"
|
||||
|
@ -30,29 +30,29 @@ namespace PeepingTom {
|
|||
HelpMessage = "Alias for /ppeepingtom"
|
||||
});
|
||||
|
||||
this.Interface.Framework.OnUpdateEvent += this.watcher.OnFrameworkUpdate;
|
||||
this.Interface.Framework.OnUpdateEvent += this.Watcher.OnFrameworkUpdate;
|
||||
this.Interface.UiBuilder.OnBuildUi += this.DrawUI;
|
||||
this.Interface.UiBuilder.OnOpenConfigUi += this.ConfigUI;
|
||||
}
|
||||
|
||||
private void OnCommand(string command, string args) {
|
||||
if (args == "config" || args == "c") {
|
||||
this.ui.SettingsVisible = true;
|
||||
this.Ui.SettingsVisible = true;
|
||||
} else {
|
||||
this.ui.Visible = true;
|
||||
this.Ui.Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool includeManaged) {
|
||||
this.hookManager.Dispose();
|
||||
this.Interface.Framework.OnUpdateEvent -= this.watcher.OnFrameworkUpdate;
|
||||
this.watcher.Dispose();
|
||||
this.Interface.Framework.OnUpdateEvent -= this.Watcher.OnFrameworkUpdate;
|
||||
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();
|
||||
this.Ui.Dispose();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
|
@ -61,11 +61,11 @@ namespace PeepingTom {
|
|||
}
|
||||
|
||||
private void DrawUI() {
|
||||
this.ui.Draw();
|
||||
this.Ui.Draw();
|
||||
}
|
||||
|
||||
private void ConfigUI(object sender, EventArgs args) {
|
||||
this.ui.SettingsVisible = true;
|
||||
this.Ui.SettingsVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,6 @@ using System.Runtime.InteropServices;
|
|||
namespace PeepingTom {
|
||||
class PluginUI : IDisposable {
|
||||
private readonly PeepingTomPlugin plugin;
|
||||
private readonly Configuration config;
|
||||
private readonly DalamudPluginInterface pi;
|
||||
private readonly TargetWatcher watcher;
|
||||
|
||||
private Optional<Actor> previousFocus = new Optional<Actor>();
|
||||
|
||||
|
@ -32,11 +29,8 @@ namespace PeepingTom {
|
|||
set { this.settingsVisible = value; }
|
||||
}
|
||||
|
||||
public PluginUI(PeepingTomPlugin plugin, Configuration config, DalamudPluginInterface pluginInterface, TargetWatcher watcher) {
|
||||
this.plugin = plugin;
|
||||
this.config = config;
|
||||
this.pi = pluginInterface;
|
||||
this.watcher = watcher;
|
||||
public PluginUI(PeepingTomPlugin plugin) {
|
||||
this.plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "PeepingTomPlugin cannot be null");
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
|
@ -49,21 +43,21 @@ namespace PeepingTom {
|
|||
ShowSettings();
|
||||
}
|
||||
|
||||
bool inCombat = this.pi.ClientState.Condition[ConditionFlag.InCombat];
|
||||
bool inInstance = this.pi.ClientState.Condition[ConditionFlag.BoundByDuty]
|
||||
|| this.pi.ClientState.Condition[ConditionFlag.BoundByDuty56]
|
||||
|| this.pi.ClientState.Condition[ConditionFlag.BoundByDuty95];
|
||||
bool inCutscene = this.pi.ClientState.Condition[ConditionFlag.WatchingCutscene]
|
||||
|| this.pi.ClientState.Condition[ConditionFlag.WatchingCutscene78]
|
||||
|| this.pi.ClientState.Condition[ConditionFlag.OccupiedInCutSceneEvent];
|
||||
bool inCombat = this.plugin.Interface.ClientState.Condition[ConditionFlag.InCombat];
|
||||
bool inInstance = this.plugin.Interface.ClientState.Condition[ConditionFlag.BoundByDuty]
|
||||
|| this.plugin.Interface.ClientState.Condition[ConditionFlag.BoundByDuty56]
|
||||
|| this.plugin.Interface.ClientState.Condition[ConditionFlag.BoundByDuty95];
|
||||
bool inCutscene = this.plugin.Interface.ClientState.Condition[ConditionFlag.WatchingCutscene]
|
||||
|| this.plugin.Interface.ClientState.Condition[ConditionFlag.WatchingCutscene78]
|
||||
|| this.plugin.Interface.ClientState.Condition[ConditionFlag.OccupiedInCutSceneEvent];
|
||||
|
||||
// FIXME: this could just be a boolean expression
|
||||
bool shouldBeShown = this.Visible;
|
||||
if (inCombat && !this.config.ShowInCombat) {
|
||||
if (inCombat && !this.plugin.Config.ShowInCombat) {
|
||||
shouldBeShown = false;
|
||||
} else if (inInstance && !this.config.ShowInInstance) {
|
||||
} else if (inInstance && !this.plugin.Config.ShowInInstance) {
|
||||
shouldBeShown = false;
|
||||
} else if (inCutscene && !this.config.ShowInCutscenes) {
|
||||
} else if (inCutscene && !this.plugin.Config.ShowInCutscenes) {
|
||||
shouldBeShown = false;
|
||||
}
|
||||
|
||||
|
@ -71,16 +65,16 @@ namespace PeepingTom {
|
|||
ShowMainWindow();
|
||||
}
|
||||
|
||||
if (this.config.MarkTargeted) {
|
||||
MarkPlayer(GetCurrentTarget(), this.config.TargetedColour, this.config.TargetedSize);
|
||||
if (this.plugin.Config.MarkTargeted) {
|
||||
MarkPlayer(GetCurrentTarget(), this.plugin.Config.TargetedColour, this.plugin.Config.TargetedSize);
|
||||
}
|
||||
|
||||
if (this.config.MarkTargeting) {
|
||||
PlayerCharacter player = this.pi.ClientState.LocalPlayer;
|
||||
if (this.plugin.Config.MarkTargeting) {
|
||||
PlayerCharacter player = this.plugin.Interface.ClientState.LocalPlayer;
|
||||
if (player != null) {
|
||||
IReadOnlyCollection<PlayerCharacter> targeting = this.watcher.CurrentTargeters;
|
||||
IReadOnlyCollection<PlayerCharacter> targeting = this.plugin.Watcher.CurrentTargeters;
|
||||
foreach (PlayerCharacter targeter in targeting) {
|
||||
MarkPlayer(targeter, this.config.TargetingColour, this.config.TargetingSize);
|
||||
MarkPlayer(targeter, this.plugin.Config.TargetingColour, this.plugin.Config.TargetingSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,194 +86,194 @@ namespace PeepingTom {
|
|||
if (ImGui.Begin($"{this.plugin.Name} settings", ref this.settingsVisible)) {
|
||||
if (ImGui.BeginTabBar("##settings-tabs")) {
|
||||
if (ImGui.BeginTabItem("Markers")) {
|
||||
bool markTargeted = this.config.MarkTargeted;
|
||||
bool markTargeted = this.plugin.Config.MarkTargeted;
|
||||
if (ImGui.Checkbox("Mark your target", ref markTargeted)) {
|
||||
this.config.MarkTargeted = markTargeted;
|
||||
this.config.Save();
|
||||
this.plugin.Config.MarkTargeted = markTargeted;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
Vector4 targetedColour = this.config.TargetedColour;
|
||||
Vector4 targetedColour = this.plugin.Config.TargetedColour;
|
||||
if (ImGui.ColorEdit4("Target mark colour", ref targetedColour)) {
|
||||
this.config.TargetedColour = targetedColour;
|
||||
this.config.Save();
|
||||
this.plugin.Config.TargetedColour = targetedColour;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
float targetedSize = this.config.TargetedSize;
|
||||
float targetedSize = this.plugin.Config.TargetedSize;
|
||||
if (ImGui.DragFloat("Target mark size", ref targetedSize, 0.01f, 0f, 15f)) {
|
||||
targetedSize = Math.Max(0f, targetedSize);
|
||||
this.config.TargetedSize = targetedSize;
|
||||
this.config.Save();
|
||||
this.plugin.Config.TargetedSize = targetedSize;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
ImGui.Spacing();
|
||||
|
||||
bool markTargeting = this.config.MarkTargeting;
|
||||
bool markTargeting = this.plugin.Config.MarkTargeting;
|
||||
if (ImGui.Checkbox("Mark targeting you", ref markTargeting)) {
|
||||
this.config.MarkTargeting = markTargeting;
|
||||
this.config.Save();
|
||||
this.plugin.Config.MarkTargeting = markTargeting;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
Vector4 targetingColour = this.config.TargetingColour;
|
||||
Vector4 targetingColour = this.plugin.Config.TargetingColour;
|
||||
if (ImGui.ColorEdit4("Targeting mark colour", ref targetingColour)) {
|
||||
this.config.TargetingColour = targetingColour;
|
||||
this.config.Save();
|
||||
this.plugin.Config.TargetingColour = targetingColour;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
float targetingSize = this.config.TargetingSize;
|
||||
float targetingSize = this.plugin.Config.TargetingSize;
|
||||
if (ImGui.DragFloat("Targeting mark size", ref targetingSize, 0.01f, 0f, 15f)) {
|
||||
targetingSize = Math.Max(0f, targetingSize);
|
||||
this.config.TargetingSize = targetingSize;
|
||||
this.config.Save();
|
||||
this.plugin.Config.TargetingSize = targetingSize;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Filters")) {
|
||||
bool showParty = this.config.LogParty;
|
||||
bool showParty = this.plugin.Config.LogParty;
|
||||
if (ImGui.Checkbox("Log party members", ref showParty)) {
|
||||
this.config.LogParty = showParty;
|
||||
this.config.Save();
|
||||
this.plugin.Config.LogParty = showParty;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
bool logAlliance = this.config.LogAlliance;
|
||||
bool logAlliance = this.plugin.Config.LogAlliance;
|
||||
if (ImGui.Checkbox("Log alliance members", ref logAlliance)) {
|
||||
this.config.LogAlliance = logAlliance;
|
||||
this.config.Save();
|
||||
this.plugin.Config.LogAlliance = logAlliance;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
bool logInCombat = this.config.LogInCombat;
|
||||
bool logInCombat = this.plugin.Config.LogInCombat;
|
||||
if (ImGui.Checkbox("Log targeters engaged in combat", ref logInCombat)) {
|
||||
this.config.LogInCombat = logInCombat;
|
||||
this.config.Save();
|
||||
this.plugin.Config.LogInCombat = logInCombat;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
bool logSelf = this.config.LogSelf;
|
||||
bool logSelf = this.plugin.Config.LogSelf;
|
||||
if (ImGui.Checkbox("Log yourself", ref logSelf)) {
|
||||
this.config.LogSelf = logSelf;
|
||||
this.config.Save();
|
||||
this.plugin.Config.LogSelf = logSelf;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Behaviour")) {
|
||||
bool focusTarget = this.config.FocusTargetOnHover;
|
||||
bool focusTarget = this.plugin.Config.FocusTargetOnHover;
|
||||
if (ImGui.Checkbox("Focus target on hover", ref focusTarget)) {
|
||||
this.config.FocusTargetOnHover = focusTarget;
|
||||
this.config.Save();
|
||||
this.plugin.Config.FocusTargetOnHover = focusTarget;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
bool playSound = this.config.PlaySoundOnTarget;
|
||||
bool playSound = this.plugin.Config.PlaySoundOnTarget;
|
||||
if (ImGui.Checkbox("Play sound when targeted", ref playSound)) {
|
||||
this.config.PlaySoundOnTarget = playSound;
|
||||
this.config.Save();
|
||||
this.plugin.Config.PlaySoundOnTarget = playSound;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
string path = this.config.SoundPath ?? "";
|
||||
string path = this.plugin.Config.SoundPath ?? "";
|
||||
if (ImGui.InputText("Path to WAV file", ref path, 1_000)) {
|
||||
path = path.Trim();
|
||||
this.config.SoundPath = path.Length == 0 ? null : path;
|
||||
this.config.Save();
|
||||
this.plugin.Config.SoundPath = path.Length == 0 ? null : path;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
ImGui.Text("Leave this blank to use a built-in sound.");
|
||||
|
||||
float soundCooldown = this.config.SoundCooldown;
|
||||
float soundCooldown = this.plugin.Config.SoundCooldown;
|
||||
if (ImGui.DragFloat("Cooldown for sound (seconds)", ref soundCooldown, .01f, 0f, 30f)) {
|
||||
soundCooldown = Math.Max(0f, soundCooldown);
|
||||
this.config.SoundCooldown = soundCooldown;
|
||||
this.config.Save();
|
||||
this.plugin.Config.SoundCooldown = soundCooldown;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
bool playWhenClosed = this.config.PlaySoundWhenClosed;
|
||||
bool playWhenClosed = this.plugin.Config.PlaySoundWhenClosed;
|
||||
if (ImGui.Checkbox("Play sound when window is closed", ref playWhenClosed)) {
|
||||
this.config.PlaySoundWhenClosed = playWhenClosed;
|
||||
this.config.Save();
|
||||
this.plugin.Config.PlaySoundWhenClosed = playWhenClosed;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Window")) {
|
||||
bool openOnLogin = this.config.OpenOnLogin;
|
||||
bool openOnLogin = this.plugin.Config.OpenOnLogin;
|
||||
if (ImGui.Checkbox("Open on login", ref openOnLogin)) {
|
||||
this.config.OpenOnLogin = openOnLogin;
|
||||
this.config.Save();
|
||||
this.plugin.Config.OpenOnLogin = openOnLogin;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
bool allowMovement = this.config.AllowMovement;
|
||||
bool allowMovement = this.plugin.Config.AllowMovement;
|
||||
if (ImGui.Checkbox("Allow moving the main window", ref allowMovement)) {
|
||||
this.config.AllowMovement = allowMovement;
|
||||
this.config.Save();
|
||||
this.plugin.Config.AllowMovement = allowMovement;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
ImGui.Spacing();
|
||||
|
||||
bool showInCombat = this.config.ShowInCombat;
|
||||
bool showInCombat = this.plugin.Config.ShowInCombat;
|
||||
if (ImGui.Checkbox("Show window while in combat", ref showInCombat)) {
|
||||
this.config.ShowInCombat = showInCombat;
|
||||
this.config.Save();
|
||||
this.plugin.Config.ShowInCombat = showInCombat;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
bool showInInstance = this.config.ShowInInstance;
|
||||
bool showInInstance = this.plugin.Config.ShowInInstance;
|
||||
if (ImGui.Checkbox("Show window while in instance", ref showInInstance)) {
|
||||
this.config.ShowInInstance = showInInstance;
|
||||
this.config.Save();
|
||||
this.plugin.Config.ShowInInstance = showInInstance;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
bool showInCutscenes = this.config.ShowInCutscenes;
|
||||
bool showInCutscenes = this.plugin.Config.ShowInCutscenes;
|
||||
if (ImGui.Checkbox("Show window while in cutscenes", ref showInCutscenes)) {
|
||||
this.config.ShowInCutscenes = showInCutscenes;
|
||||
this.config.Save();
|
||||
this.plugin.Config.ShowInCutscenes = showInCutscenes;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("History")) {
|
||||
bool keepHistory = this.config.KeepHistory;
|
||||
bool keepHistory = this.plugin.Config.KeepHistory;
|
||||
if (ImGui.Checkbox("Show previous targeters", ref keepHistory)) {
|
||||
this.config.KeepHistory = keepHistory;
|
||||
this.config.Save();
|
||||
this.plugin.Config.KeepHistory = keepHistory;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
bool historyWhenClosed = this.config.HistoryWhenClosed;
|
||||
bool historyWhenClosed = this.plugin.Config.HistoryWhenClosed;
|
||||
if (ImGui.Checkbox("Record history when window is closed", ref historyWhenClosed)) {
|
||||
this.config.HistoryWhenClosed = historyWhenClosed;
|
||||
this.config.Save();
|
||||
this.plugin.Config.HistoryWhenClosed = historyWhenClosed;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
int numHistory = this.config.NumHistory;
|
||||
int numHistory = this.plugin.Config.NumHistory;
|
||||
if (ImGui.InputInt("Number of previous targeters to keep", ref numHistory)) {
|
||||
numHistory = Math.Max(0, Math.Min(10, numHistory));
|
||||
this.config.NumHistory = numHistory;
|
||||
this.config.Save();
|
||||
this.plugin.Config.NumHistory = numHistory;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
ImGui.EndTabItem();
|
||||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Debug")) {
|
||||
bool debugMarkers = this.config.DebugMarkers;
|
||||
bool debugMarkers = this.plugin.Config.DebugMarkers;
|
||||
if (ImGui.Checkbox("Debug markers", ref debugMarkers)) {
|
||||
this.config.DebugMarkers = debugMarkers;
|
||||
this.config.Save();
|
||||
this.plugin.Config.DebugMarkers = debugMarkers;
|
||||
this.plugin.Config.Save();
|
||||
}
|
||||
|
||||
ImGui.Separator();
|
||||
|
||||
if (ImGui.Button("Log targeting you")) {
|
||||
PlayerCharacter player = this.pi.ClientState.LocalPlayer;
|
||||
PlayerCharacter player = this.plugin.Interface.ClientState.LocalPlayer;
|
||||
if (player != null) {
|
||||
// loop over all players looking at the current player
|
||||
var actors = this.pi.ClientState.Actors
|
||||
var actors = this.plugin.Interface.ClientState.Actors
|
||||
.Where(actor => actor.TargetActorID == player.ActorId && actor is PlayerCharacter)
|
||||
.Select(actor => actor as PlayerCharacter);
|
||||
foreach (PlayerCharacter actor in actors) {
|
||||
PlayerPayload payload = new PlayerPayload(this.pi.Data, actor.Name, actor.HomeWorld.Id);
|
||||
PlayerPayload payload = new PlayerPayload(this.plugin.Interface.Data, actor.Name, actor.HomeWorld.Id);
|
||||
Payload[] payloads = { payload };
|
||||
this.pi.Framework.Gui.Chat.PrintChat(new XivChatEntry {
|
||||
this.plugin.Interface.Framework.Gui.Chat.PrintChat(new XivChatEntry {
|
||||
MessageBytes = new SeString(payloads).Encode()
|
||||
});
|
||||
}
|
||||
|
@ -290,17 +284,17 @@ namespace PeepingTom {
|
|||
PlayerCharacter target = GetCurrentTarget();
|
||||
|
||||
if (target != null) {
|
||||
PlayerPayload payload = new PlayerPayload(this.pi.Data, target.Name, target.HomeWorld.Id);
|
||||
PlayerPayload payload = new PlayerPayload(this.plugin.Interface.Data, target.Name, target.HomeWorld.Id);
|
||||
Payload[] payloads = { payload };
|
||||
this.pi.Framework.Gui.Chat.PrintChat(new XivChatEntry {
|
||||
this.plugin.Interface.Framework.Gui.Chat.PrintChat(new XivChatEntry {
|
||||
MessageBytes = new SeString(payloads).Encode()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (this.pi.ClientState.LocalPlayer != null) {
|
||||
PlayerCharacter player = this.pi.ClientState.LocalPlayer;
|
||||
IntPtr statusPtr = this.pi.TargetModuleScanner.ResolveRelativeAddress(player.Address, 0x1901);
|
||||
if (this.plugin.Interface.ClientState.LocalPlayer != null) {
|
||||
PlayerCharacter player = this.plugin.Interface.ClientState.LocalPlayer;
|
||||
IntPtr statusPtr = this.plugin.Interface.TargetModuleScanner.ResolveRelativeAddress(player.Address, 0x1901);
|
||||
byte status = Marshal.ReadByte(statusPtr);
|
||||
ImGui.Text($"Status: {status}");
|
||||
}
|
||||
|
@ -316,10 +310,10 @@ namespace PeepingTom {
|
|||
}
|
||||
|
||||
private void ShowMainWindow() {
|
||||
IReadOnlyCollection<PlayerCharacter> targeting = this.watcher.CurrentTargeters;
|
||||
IReadOnlyCollection<PlayerCharacter> targeting = this.plugin.Watcher.CurrentTargeters;
|
||||
|
||||
ImGuiWindowFlags flags = ImGuiWindowFlags.AlwaysAutoResize;
|
||||
if (!this.config.AllowMovement) {
|
||||
if (!this.plugin.Config.AllowMovement) {
|
||||
flags |= ImGuiWindowFlags.NoMove;
|
||||
}
|
||||
if (ImGui.Begin(this.plugin.Name, ref this.visible, flags)) {
|
||||
|
@ -327,7 +321,7 @@ namespace PeepingTom {
|
|||
bool anyHovered = false;
|
||||
if (ImGui.ListBoxHeader("##targeting", targeting.Count, 5)) {
|
||||
// add the two first players for testing
|
||||
//foreach (PlayerCharacter p in this.pi.ClientState.Actors
|
||||
//foreach (PlayerCharacter p in this.plugin.Interface.ClientState.Actors
|
||||
// .Where(actor => actor is PlayerCharacter)
|
||||
// .Skip(1)
|
||||
// .Select(actor => actor as PlayerCharacter)
|
||||
|
@ -337,11 +331,11 @@ namespace PeepingTom {
|
|||
foreach (PlayerCharacter targeter in targeting) {
|
||||
this.AddEntry(new Targeter(targeter), targeter, ref anyHovered);
|
||||
}
|
||||
if (this.config.KeepHistory) {
|
||||
if (this.plugin.Config.KeepHistory) {
|
||||
// get a list of the previous targeters that aren't currently targeting
|
||||
Targeter[] previous = this.watcher.PreviousTargeters
|
||||
Targeter[] previous = this.plugin.Watcher.PreviousTargeters
|
||||
.Where(old => targeting.All(actor => actor.ActorId != old.ActorId))
|
||||
.Take(this.config.NumHistory)
|
||||
.Take(this.plugin.Config.NumHistory)
|
||||
.ToArray();
|
||||
// add previous targeters to the list
|
||||
foreach (Targeter oldTargeter in previous) {
|
||||
|
@ -350,13 +344,13 @@ namespace PeepingTom {
|
|||
}
|
||||
ImGui.ListBoxFooter();
|
||||
}
|
||||
if (this.config.FocusTargetOnHover && !anyHovered && this.previousFocus.Get(out Actor previousFocus)) {
|
||||
if (this.plugin.Config.FocusTargetOnHover && !anyHovered && this.previousFocus.Get(out Actor previousFocus)) {
|
||||
if (previousFocus == null) {
|
||||
this.pi.ClientState.Targets.SetFocusTarget(null);
|
||||
this.plugin.Interface.ClientState.Targets.SetFocusTarget(null);
|
||||
} else {
|
||||
Actor actor = this.pi.ClientState.Actors.FirstOrDefault(a => a.ActorId == previousFocus.ActorId);
|
||||
Actor actor = this.plugin.Interface.ClientState.Actors.FirstOrDefault(a => a.ActorId == previousFocus.ActorId);
|
||||
// either target the actor if still present or target nothing
|
||||
this.pi.ClientState.Targets.SetFocusTarget(actor);
|
||||
this.plugin.Interface.ClientState.Targets.SetFocusTarget(actor);
|
||||
}
|
||||
this.previousFocus = new Optional<Actor>();
|
||||
}
|
||||
|
@ -371,7 +365,7 @@ namespace PeepingTom {
|
|||
bool left = hover && ImGui.IsMouseClicked(0);
|
||||
bool right = hover && ImGui.IsMouseClicked(1);
|
||||
if (actor == null) {
|
||||
actor = this.pi.ClientState.Actors
|
||||
actor = this.plugin.Interface.ClientState.Actors
|
||||
.Where(a => a.ActorId == targeter.ActorId)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
@ -381,21 +375,21 @@ namespace PeepingTom {
|
|||
anyHovered |= hover;
|
||||
}
|
||||
|
||||
if (this.config.FocusTargetOnHover && hover && actor != null) {
|
||||
if (this.plugin.Config.FocusTargetOnHover && hover && actor != null) {
|
||||
if (!this.previousFocus.Present) {
|
||||
this.previousFocus = new Optional<Actor>(this.pi.ClientState.Targets.FocusTarget);
|
||||
this.previousFocus = new Optional<Actor>(this.plugin.Interface.ClientState.Targets.FocusTarget);
|
||||
}
|
||||
this.pi.ClientState.Targets.SetFocusTarget(actor);
|
||||
this.plugin.Interface.ClientState.Targets.SetFocusTarget(actor);
|
||||
}
|
||||
|
||||
if (left) {
|
||||
PlayerPayload payload = new PlayerPayload(this.pi.Data, targeter.Name, targeter.HomeWorld.Id);
|
||||
PlayerPayload payload = new PlayerPayload(this.plugin.Interface.Data, targeter.Name, targeter.HomeWorld.Id);
|
||||
Payload[] payloads = { payload };
|
||||
this.pi.Framework.Gui.Chat.PrintChat(new XivChatEntry {
|
||||
this.plugin.Interface.Framework.Gui.Chat.PrintChat(new XivChatEntry {
|
||||
MessageBytes = new SeString(payloads).Encode()
|
||||
});
|
||||
} else if (right && actor != null) {
|
||||
this.pi.ClientState.Targets.SetCurrentTarget(actor);
|
||||
this.plugin.Interface.ClientState.Targets.SetCurrentTarget(actor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -404,12 +398,12 @@ namespace PeepingTom {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!this.pi.Framework.Gui.WorldToScreen(player.Position, out SharpDX.Vector2 screenPos)) {
|
||||
if (!this.plugin.Interface.Framework.Gui.WorldToScreen(player.Position, out SharpDX.Vector2 screenPos)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ImGuiWindowFlags flags = ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoInputs | ImGuiWindowFlags.NoFocusOnAppearing;
|
||||
if (this.config.DebugMarkers) {
|
||||
if (this.plugin.Config.DebugMarkers) {
|
||||
flags &= ~ImGuiWindowFlags.NoBackground;
|
||||
}
|
||||
|
||||
|
@ -430,7 +424,7 @@ namespace PeepingTom {
|
|||
}
|
||||
|
||||
private PlayerCharacter GetCurrentTarget() {
|
||||
PlayerCharacter player = this.pi.ClientState.LocalPlayer;
|
||||
PlayerCharacter player = this.plugin.Interface.ClientState.LocalPlayer;
|
||||
if (player == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -440,7 +434,7 @@ namespace PeepingTom {
|
|||
return null;
|
||||
}
|
||||
|
||||
return this.pi.ClientState.Actors
|
||||
return this.plugin.Interface.ClientState.Actors
|
||||
.Where(actor => actor.ActorId == targetId && actor is PlayerCharacter)
|
||||
.Select(actor => actor as PlayerCharacter)
|
||||
.FirstOrDefault();
|
||||
|
|
Loading…
Reference in New Issue