feat: add options for behaviour when closed
This commit is contained in:
parent
1c31f19b89
commit
cc9b66c216
|
@ -25,6 +25,7 @@ namespace PeepingTom {
|
||||||
public bool DebugMarkers { get; set; } = false;
|
public bool DebugMarkers { get; set; } = false;
|
||||||
|
|
||||||
public bool KeepHistory { get; set; } = true;
|
public bool KeepHistory { get; set; } = true;
|
||||||
|
public bool HistoryWhenClosed { get; set; } = true;
|
||||||
public int NumHistory { get; set; } = 5;
|
public int NumHistory { get; set; } = 5;
|
||||||
|
|
||||||
public bool LogParty { get; set; } = true;
|
public bool LogParty { get; set; } = true;
|
||||||
|
@ -36,6 +37,7 @@ namespace PeepingTom {
|
||||||
public bool PlaySoundOnTarget { get; set; } = false;
|
public bool PlaySoundOnTarget { get; set; } = false;
|
||||||
public string SoundPath { get; set; } = null;
|
public string SoundPath { get; set; } = null;
|
||||||
public float SoundCooldown { get; set; } = 10f;
|
public float SoundCooldown { get; set; } = 10f;
|
||||||
|
public bool PlaySoundWhenClosed { get; set; } = false;
|
||||||
|
|
||||||
public bool OpenOnLogin { get; set; } = false;
|
public bool OpenOnLogin { get; set; } = false;
|
||||||
public bool AllowMovement { get; set; } = true;
|
public bool AllowMovement { get; set; } = true;
|
||||||
|
|
|
@ -6,33 +6,33 @@ namespace PeepingTom {
|
||||||
public class PeepingTomPlugin : IDalamudPlugin, IDisposable {
|
public class PeepingTomPlugin : IDalamudPlugin, IDisposable {
|
||||||
public string Name => "Peeping Tom";
|
public string Name => "Peeping Tom";
|
||||||
|
|
||||||
private DalamudPluginInterface pi;
|
internal DalamudPluginInterface Interface { get; private set; }
|
||||||
private Configuration config;
|
internal Configuration config;
|
||||||
private PluginUI ui;
|
internal PluginUI ui;
|
||||||
private HookManager hookManager;
|
private HookManager hookManager;
|
||||||
private TargetWatcher watcher;
|
private TargetWatcher watcher;
|
||||||
|
|
||||||
public void Initialize(DalamudPluginInterface pluginInterface) {
|
public void Initialize(DalamudPluginInterface pluginInterface) {
|
||||||
this.pi = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface argument was null");
|
this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface argument was null");
|
||||||
this.config = this.pi.GetPluginConfig() as Configuration ?? new Configuration();
|
this.config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
|
||||||
this.config.Initialize(this.pi);
|
this.config.Initialize(this.Interface);
|
||||||
this.watcher = new TargetWatcher(this.pi, this.config);
|
this.watcher = new TargetWatcher(this);
|
||||||
this.ui = new PluginUI(this, this.config, this.pi, this.watcher);
|
this.ui = new PluginUI(this, this.config, this.Interface, this.watcher);
|
||||||
this.hookManager = new HookManager(this.pi, this.ui, this.config);
|
this.hookManager = new HookManager(this.Interface, this.ui, this.config);
|
||||||
|
|
||||||
this.pi.CommandManager.AddHandler("/ppeepingtom", new CommandInfo(this.OnCommand) {
|
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"
|
HelpMessage = "Use with no arguments to show the list. Use with \"c\" or \"config\" to show the config"
|
||||||
});
|
});
|
||||||
this.pi.CommandManager.AddHandler("/ptom", new CommandInfo(this.OnCommand) {
|
this.Interface.CommandManager.AddHandler("/ptom", new CommandInfo(this.OnCommand) {
|
||||||
HelpMessage = "Alias for /ppeepingtom"
|
HelpMessage = "Alias for /ppeepingtom"
|
||||||
});
|
});
|
||||||
this.pi.CommandManager.AddHandler("/ppeep", new CommandInfo(this.OnCommand) {
|
this.Interface.CommandManager.AddHandler("/ppeep", new CommandInfo(this.OnCommand) {
|
||||||
HelpMessage = "Alias for /ppeepingtom"
|
HelpMessage = "Alias for /ppeepingtom"
|
||||||
});
|
});
|
||||||
|
|
||||||
this.pi.Framework.OnUpdateEvent += this.watcher.OnFrameworkUpdate;
|
this.Interface.Framework.OnUpdateEvent += this.watcher.OnFrameworkUpdate;
|
||||||
this.pi.UiBuilder.OnBuildUi += this.DrawUI;
|
this.Interface.UiBuilder.OnBuildUi += this.DrawUI;
|
||||||
this.pi.UiBuilder.OnOpenConfigUi += this.ConfigUI;
|
this.Interface.UiBuilder.OnOpenConfigUi += this.ConfigUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCommand(string command, string args) {
|
private void OnCommand(string command, string args) {
|
||||||
|
@ -45,13 +45,13 @@ namespace PeepingTom {
|
||||||
|
|
||||||
protected virtual void Dispose(bool includeManaged) {
|
protected virtual void Dispose(bool includeManaged) {
|
||||||
this.hookManager.Dispose();
|
this.hookManager.Dispose();
|
||||||
this.pi.Framework.OnUpdateEvent -= this.watcher.OnFrameworkUpdate;
|
this.Interface.Framework.OnUpdateEvent -= this.watcher.OnFrameworkUpdate;
|
||||||
this.watcher.Dispose();
|
this.watcher.Dispose();
|
||||||
this.pi.UiBuilder.OnBuildUi -= DrawUI;
|
this.Interface.UiBuilder.OnBuildUi -= DrawUI;
|
||||||
this.pi.UiBuilder.OnOpenConfigUi -= ConfigUI;
|
this.Interface.UiBuilder.OnOpenConfigUi -= ConfigUI;
|
||||||
this.pi.CommandManager.RemoveHandler("/ppeepingtom");
|
this.Interface.CommandManager.RemoveHandler("/ppeepingtom");
|
||||||
this.pi.CommandManager.RemoveHandler("/ptom");
|
this.Interface.CommandManager.RemoveHandler("/ptom");
|
||||||
this.pi.CommandManager.RemoveHandler("/ppeep");
|
this.Interface.CommandManager.RemoveHandler("/ppeep");
|
||||||
this.ui.Dispose();
|
this.ui.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,10 +7,7 @@ using Dalamud.Plugin;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Media;
|
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
@ -195,6 +192,12 @@ namespace PeepingTom {
|
||||||
this.config.Save();
|
this.config.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool playWhenClosed = this.config.PlaySoundWhenClosed;
|
||||||
|
if (ImGui.Checkbox("Play sound when window is closed", ref playWhenClosed)) {
|
||||||
|
this.config.PlaySoundWhenClosed = playWhenClosed;
|
||||||
|
this.config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.EndTabItem();
|
ImGui.EndTabItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,6 +244,12 @@ namespace PeepingTom {
|
||||||
this.config.Save();
|
this.config.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool historyWhenClosed = this.config.HistoryWhenClosed;
|
||||||
|
if (ImGui.Checkbox("Record history when window is closed", ref historyWhenClosed)) {
|
||||||
|
this.config.HistoryWhenClosed = historyWhenClosed;
|
||||||
|
this.config.Save();
|
||||||
|
}
|
||||||
|
|
||||||
int numHistory = this.config.NumHistory;
|
int numHistory = this.config.NumHistory;
|
||||||
if (ImGui.InputInt("Number of previous targeters to keep", ref numHistory)) {
|
if (ImGui.InputInt("Number of previous targeters to keep", ref numHistory)) {
|
||||||
numHistory = Math.Max(0, Math.Min(10, numHistory));
|
numHistory = Math.Max(0, Math.Min(10, numHistory));
|
||||||
|
|
|
@ -11,14 +11,11 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Media;
|
using System.Media;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace PeepingTom {
|
namespace PeepingTom {
|
||||||
class TargetWatcher : IDisposable {
|
class TargetWatcher : IDisposable {
|
||||||
private readonly DalamudPluginInterface pi;
|
private readonly PeepingTomPlugin plugin;
|
||||||
private readonly Configuration config;
|
|
||||||
|
|
||||||
private long soundLastPlayed = 0;
|
private long soundLastPlayed = 0;
|
||||||
private int lastTargetAmount = 0;
|
private int lastTargetAmount = 0;
|
||||||
|
@ -45,9 +42,8 @@ namespace PeepingTom {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TargetWatcher(DalamudPluginInterface pi, Configuration config) {
|
public TargetWatcher(PeepingTomPlugin plugin) {
|
||||||
this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null");
|
this.plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "PeepingTomPlugin cannot be null");
|
||||||
this.config = config ?? throw new ArgumentNullException(nameof(config), "Configuration cannot be null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Out WithCurrent<Out>(Func<IReadOnlyCollection<PlayerCharacter>, Out> func) {
|
public Out WithCurrent<Out>(Func<IReadOnlyCollection<PlayerCharacter>, Out> func) {
|
||||||
|
@ -58,7 +54,7 @@ namespace PeepingTom {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnFrameworkUpdate(Framework framework) {
|
public void OnFrameworkUpdate(Framework framework) {
|
||||||
PlayerCharacter player = this.pi.ClientState.LocalPlayer;
|
PlayerCharacter player = this.plugin.Interface.ClientState.LocalPlayer;
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +72,7 @@ namespace PeepingTom {
|
||||||
this.HandleHistory(current);
|
this.HandleHistory(current);
|
||||||
|
|
||||||
// play sound if necessary
|
// play sound if necessary
|
||||||
if (this.config.PlaySoundOnTarget && this.current.Length > this.lastTargetAmount && this.CanPlaySound()) {
|
if (this.CanPlaySound()) {
|
||||||
this.soundLastPlayed = Stopwatch.GetTimestamp();
|
this.soundLastPlayed = Stopwatch.GetTimestamp();
|
||||||
this.PlaySound();
|
this.PlaySound();
|
||||||
}
|
}
|
||||||
|
@ -84,7 +80,7 @@ namespace PeepingTom {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleHistory(PlayerCharacter[] targeting) {
|
private void HandleHistory(PlayerCharacter[] targeting) {
|
||||||
if (!this.config.KeepHistory) {
|
if (!this.plugin.Config.KeepHistory || (!this.plugin.Config.HistoryWhenClosed && !this.plugin.Ui.Visible)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,24 +93,24 @@ namespace PeepingTom {
|
||||||
}
|
}
|
||||||
|
|
||||||
// only keep the configured number of previous targeters (ignoring ones that are currently targeting)
|
// only keep the configured number of previous targeters (ignoring ones that are currently targeting)
|
||||||
while (this.previousTargeters.Where(old => targeting.All(actor => actor.ActorId != old.ActorId)).Count() > this.config.NumHistory) {
|
while (this.previousTargeters.Where(old => targeting.All(actor => actor.ActorId != old.ActorId)).Count() > this.plugin.Config.NumHistory) {
|
||||||
this.previousTargeters.RemoveAt(this.previousTargeters.Count - 1);
|
this.previousTargeters.RemoveAt(this.previousTargeters.Count - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayerCharacter[] GetTargeting(Actor player) {
|
private PlayerCharacter[] GetTargeting(Actor player) {
|
||||||
return this.pi.ClientState.Actors
|
return this.plugin.Interface.ClientState.Actors
|
||||||
.Where(actor => actor.TargetActorID == player.ActorId && actor is PlayerCharacter)
|
.Where(actor => actor.TargetActorID == player.ActorId && actor is PlayerCharacter)
|
||||||
.Select(actor => actor as PlayerCharacter)
|
.Select(actor => actor as PlayerCharacter)
|
||||||
.Where(actor => this.config.LogParty || this.pi.ClientState.PartyList.All(member => member.Actor?.ActorId != actor.ActorId))
|
.Where(actor => this.plugin.Config.LogParty || this.plugin.Interface.ClientState.PartyList.All(member => member.Actor?.ActorId != actor.ActorId))
|
||||||
.Where(actor => this.config.LogAlliance || !this.InAlliance(actor))
|
.Where(actor => this.plugin.Config.LogAlliance || !this.InAlliance(actor))
|
||||||
.Where(actor => this.config.LogInCombat || !this.InCombat(actor))
|
.Where(actor => this.plugin.Config.LogInCombat || !this.InCombat(actor))
|
||||||
.Where(actor => this.config.LogSelf || actor.ActorId != player.ActorId)
|
.Where(actor => this.plugin.Config.LogSelf || actor.ActorId != player.ActorId)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte GetStatus(Actor actor) {
|
private byte GetStatus(Actor actor) {
|
||||||
IntPtr statusPtr = this.pi.TargetModuleScanner.ResolveRelativeAddress(actor.Address, 0x1901);
|
IntPtr statusPtr = this.plugin.Interface.TargetModuleScanner.ResolveRelativeAddress(actor.Address, 0x1901);
|
||||||
return Marshal.ReadByte(statusPtr);
|
return Marshal.ReadByte(statusPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +123,18 @@ namespace PeepingTom {
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanPlaySound() {
|
private bool CanPlaySound() {
|
||||||
|
if (!this.plugin.Config.PlaySoundOnTarget) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.current.Length <= this.lastTargetAmount) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.plugin.Config.PlaySoundWhenClosed && !this.plugin.Ui.Visible) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.soundLastPlayed == 0) {
|
if (this.soundLastPlayed == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -135,15 +143,15 @@ namespace PeepingTom {
|
||||||
long diff = current - this.soundLastPlayed;
|
long diff = current - this.soundLastPlayed;
|
||||||
// only play every 10 seconds?
|
// only play every 10 seconds?
|
||||||
float secs = (float)diff / Stopwatch.Frequency;
|
float secs = (float)diff / Stopwatch.Frequency;
|
||||||
return secs >= this.config.SoundCooldown;
|
return secs >= this.plugin.Config.SoundCooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlaySound() {
|
private void PlaySound() {
|
||||||
SoundPlayer player;
|
SoundPlayer player;
|
||||||
if (this.config.SoundPath == null) {
|
if (this.plugin.Config.SoundPath == null) {
|
||||||
player = new SoundPlayer(Properties.Resources.Target);
|
player = new SoundPlayer(Properties.Resources.Target);
|
||||||
} else {
|
} else {
|
||||||
player = new SoundPlayer(this.config.SoundPath);
|
player = new SoundPlayer(this.plugin.Config.SoundPath);
|
||||||
}
|
}
|
||||||
using (player) {
|
using (player) {
|
||||||
try {
|
try {
|
||||||
|
@ -158,7 +166,7 @@ namespace PeepingTom {
|
||||||
|
|
||||||
private void SendError(string message) {
|
private void SendError(string message) {
|
||||||
Payload[] payloads = { new TextPayload($"[Who's Looking] {message}") };
|
Payload[] payloads = { new TextPayload($"[Who's Looking] {message}") };
|
||||||
this.pi.Framework.Gui.Chat.PrintChat(new XivChatEntry {
|
this.plugin.Interface.Framework.Gui.Chat.PrintChat(new XivChatEntry {
|
||||||
MessageBytes = new SeString(payloads).Encode(),
|
MessageBytes = new SeString(payloads).Encode(),
|
||||||
Type = XivChatType.ErrorMessage
|
Type = XivChatType.ErrorMessage
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user