PeepingTom/Peeping Tom/PluginUi.cs

573 lines
25 KiB
C#
Raw Permalink Normal View History

2021-08-23 03:33:57 +00:00
using ImGuiNET;
2020-12-29 16:08:21 +00:00
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
2021-08-23 03:33:57 +00:00
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.ClientState.Objects.Types;
2021-04-05 19:13:41 +00:00
using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads;
2023-09-28 06:56:38 +00:00
using Dalamud.Interface.Utility;
2021-08-23 03:33:57 +00:00
using PeepingTom.Ipc;
2021-04-28 14:41:34 +00:00
using PeepingTom.Resources;
2020-12-29 16:08:21 +00:00
namespace PeepingTom {
internal class PluginUi : IDisposable {
2023-09-28 06:56:38 +00:00
private Plugin Plugin { get; }
2020-12-29 16:08:21 +00:00
2021-08-23 03:33:57 +00:00
private uint? PreviousFocus { get; set; } = new();
2020-12-29 16:08:21 +00:00
private bool _wantsOpen;
2021-02-01 19:37:08 +00:00
2020-12-29 16:08:21 +00:00
public bool WantsOpen {
get => this._wantsOpen;
set => this._wantsOpen = value;
}
public bool Visible { get; private set; }
private bool _settingsOpen;
2021-02-01 19:37:08 +00:00
2020-12-29 16:08:21 +00:00
public bool SettingsOpen {
get => this._settingsOpen;
set => this._settingsOpen = value;
}
2023-09-28 06:56:38 +00:00
public PluginUi(Plugin plugin) {
2021-04-28 14:41:34 +00:00
this.Plugin = plugin;
2020-12-29 16:08:21 +00:00
}
public void Dispose() {
this.WantsOpen = false;
this.SettingsOpen = false;
}
public void Draw() {
2021-01-27 03:37:09 +00:00
if (this.Plugin.InPvp) {
return;
}
2020-12-29 16:08:21 +00:00
if (this.SettingsOpen) {
this.ShowSettings();
}
2021-08-23 03:33:57 +00:00
var inCombat = this.Plugin.Condition[ConditionFlag.InCombat];
var inInstance = this.Plugin.Condition[ConditionFlag.BoundByDuty]
|| this.Plugin.Condition[ConditionFlag.BoundByDuty56]
|| this.Plugin.Condition[ConditionFlag.BoundByDuty95];
var inCutscene = this.Plugin.Condition[ConditionFlag.WatchingCutscene]
|| this.Plugin.Condition[ConditionFlag.WatchingCutscene78]
|| this.Plugin.Condition[ConditionFlag.OccupiedInCutSceneEvent];
2020-12-29 16:08:21 +00:00
// FIXME: this could just be a boolean expression
var shouldBeShown = this.WantsOpen;
if (inCombat && !this.Plugin.Config.ShowInCombat) {
shouldBeShown = false;
} else if (inInstance && !this.Plugin.Config.ShowInInstance) {
shouldBeShown = false;
} else if (inCutscene && !this.Plugin.Config.ShowInCutscenes) {
shouldBeShown = false;
}
this.Visible = shouldBeShown;
if (shouldBeShown) {
this.ShowMainWindow();
}
const ImGuiWindowFlags flags = ImGuiWindowFlags.NoBackground
| ImGuiWindowFlags.NoTitleBar
| ImGuiWindowFlags.NoNav
| ImGuiWindowFlags.NoNavInputs
| ImGuiWindowFlags.NoFocusOnAppearing
| ImGuiWindowFlags.NoNavFocus
| ImGuiWindowFlags.NoInputs
| ImGuiWindowFlags.NoMouseInputs
| ImGuiWindowFlags.NoSavedSettings
| ImGuiWindowFlags.NoDecoration
| ImGuiWindowFlags.NoScrollWithMouse;
ImGuiHelpers.ForceNextWindowMainViewport();
2020-12-29 16:08:21 +00:00
if (!ImGui.Begin("Peeping Tom targeting indicator dummy window", flags)) {
ImGui.End();
2020-12-29 16:08:21 +00:00
return;
}
if (this.Plugin.Config.MarkTargeted) {
this.MarkPlayer(this.GetCurrentTarget(), this.Plugin.Config.TargetedColour, this.Plugin.Config.TargetedSize);
}
if (!this.Plugin.Config.MarkTargeting) {
2021-01-22 19:16:16 +00:00
goto EndDummy;
2020-12-29 16:08:21 +00:00
}
2021-08-23 03:33:57 +00:00
var player = this.Plugin.ClientState.LocalPlayer;
2020-12-29 16:08:21 +00:00
if (player == null) {
2021-01-22 19:16:16 +00:00
goto EndDummy;
2020-12-29 16:08:21 +00:00
}
var targeting = this.Plugin.Watcher.CurrentTargeters
2021-08-23 03:33:57 +00:00
.Select(targeter => this.Plugin.ObjectTable.FirstOrDefault(obj => obj.ObjectId == targeter.ObjectId))
2021-01-22 19:28:02 +00:00
.Where(targeter => targeter is PlayerCharacter)
2020-12-29 16:08:21 +00:00
.Cast<PlayerCharacter>()
.ToArray();
foreach (var targeter in targeting) {
this.MarkPlayer(targeter, this.Plugin.Config.TargetingColour, this.Plugin.Config.TargetingSize);
}
2021-01-22 19:16:16 +00:00
EndDummy:
ImGui.End();
2020-12-29 16:08:21 +00:00
}
private void ShowSettings() {
ImGui.SetNextWindowSize(new Vector2(700, 250));
2023-09-28 06:56:38 +00:00
var windowTitle = string.Format(Language.SettingsTitle, Plugin.Name);
2021-04-28 17:18:48 +00:00
if (!ImGui.Begin($"{windowTitle}###ptom-settings", ref this._settingsOpen, ImGuiWindowFlags.NoResize)) {
ImGui.End();
2020-12-29 16:08:21 +00:00
return;
}
if (ImGui.BeginTabBar("##settings-tabs")) {
2021-04-28 17:18:48 +00:00
if (ImGui.BeginTabItem($"{Language.SettingsMarkersTab}###markers-tab")) {
2020-12-29 16:08:21 +00:00
var markTargeted = this.Plugin.Config.MarkTargeted;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsMarkersMarkTarget, ref markTargeted)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.MarkTargeted = markTargeted;
this.Plugin.Config.Save();
}
var targetedColour = this.Plugin.Config.TargetedColour;
2021-04-28 14:41:34 +00:00
if (ImGui.ColorEdit4(Language.SettingsMarkersMarkTargetColour, ref targetedColour)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.TargetedColour = targetedColour;
this.Plugin.Config.Save();
}
var targetedSize = this.Plugin.Config.TargetedSize;
2021-04-28 14:41:34 +00:00
if (ImGui.DragFloat(Language.SettingsMarkersMarkTargetSize, ref targetedSize, 0.01f, 0f, 15f)) {
2020-12-29 16:08:21 +00:00
targetedSize = Math.Max(0f, targetedSize);
this.Plugin.Config.TargetedSize = targetedSize;
this.Plugin.Config.Save();
}
ImGui.Spacing();
var markTargeting = this.Plugin.Config.MarkTargeting;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsMarkersMarkTargeting, ref markTargeting)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.MarkTargeting = markTargeting;
this.Plugin.Config.Save();
}
var targetingColour = this.Plugin.Config.TargetingColour;
2021-04-28 14:41:34 +00:00
if (ImGui.ColorEdit4(Language.SettingsMarkersMarkTargetingColour, ref targetingColour)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.TargetingColour = targetingColour;
this.Plugin.Config.Save();
}
var targetingSize = this.Plugin.Config.TargetingSize;
2021-04-28 14:41:34 +00:00
if (ImGui.DragFloat(Language.SettingsMarkersMarkTargetingSize, ref targetingSize, 0.01f, 0f, 15f)) {
2020-12-29 16:08:21 +00:00
targetingSize = Math.Max(0f, targetingSize);
this.Plugin.Config.TargetingSize = targetingSize;
this.Plugin.Config.Save();
}
ImGui.EndTabItem();
}
2021-04-28 17:18:48 +00:00
if (ImGui.BeginTabItem($"{Language.SettingsFilterTab}###filters-tab")) {
2020-12-29 16:08:21 +00:00
var showParty = this.Plugin.Config.LogParty;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsFilterLogParty, ref showParty)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.LogParty = showParty;
this.Plugin.Config.Save();
}
var logAlliance = this.Plugin.Config.LogAlliance;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsFilterLogAlliance, ref logAlliance)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.LogAlliance = logAlliance;
this.Plugin.Config.Save();
}
var logInCombat = this.Plugin.Config.LogInCombat;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsFilterLogCombat, ref logInCombat)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.LogInCombat = logInCombat;
this.Plugin.Config.Save();
}
var logSelf = this.Plugin.Config.LogSelf;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsFilterLogSelf, ref logSelf)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.LogSelf = logSelf;
this.Plugin.Config.Save();
}
ImGui.EndTabItem();
}
2021-04-28 17:18:48 +00:00
if (ImGui.BeginTabItem($"{Language.SettingsBehaviourTab}###behaviour-tab")) {
2020-12-29 16:08:21 +00:00
var focusTarget = this.Plugin.Config.FocusTargetOnHover;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsBehaviourFocusHover, ref focusTarget)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.FocusTargetOnHover = focusTarget;
this.Plugin.Config.Save();
}
2021-02-01 19:37:08 +00:00
var openExamine = this.Plugin.Config.OpenExamine;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsBehaviourExamineEnabled, ref openExamine)) {
2021-02-01 19:37:08 +00:00
this.Plugin.Config.OpenExamine = openExamine;
this.Plugin.Config.Save();
}
2020-12-29 16:08:21 +00:00
ImGui.EndTabItem();
}
2021-04-28 17:18:48 +00:00
if (ImGui.BeginTabItem($"{Language.SettingsSoundTab}###sound-tab")) {
2020-12-29 16:08:21 +00:00
var playSound = this.Plugin.Config.PlaySoundOnTarget;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsSoundEnabled, ref playSound)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.PlaySoundOnTarget = playSound;
this.Plugin.Config.Save();
}
var path = this.Plugin.Config.SoundPath ?? "";
2021-04-28 14:41:34 +00:00
if (ImGui.InputText(Language.SettingsSoundPath, ref path, 1_000)) {
2020-12-29 16:08:21 +00:00
path = path.Trim();
this.Plugin.Config.SoundPath = path.Length == 0 ? null : path;
this.Plugin.Config.Save();
}
2021-04-28 14:41:34 +00:00
ImGui.Text(Language.SettingsSoundPathHelp);
2020-12-29 16:08:21 +00:00
var volume = this.Plugin.Config.SoundVolume * 100f;
2021-04-28 14:41:34 +00:00
if (ImGui.DragFloat(Language.SettingsSoundVolume, ref volume, .1f, 0f, 100f, "%.1f%%")) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.SoundVolume = Math.Max(0f, Math.Min(1f, volume / 100f));
this.Plugin.Config.Save();
}
2022-08-21 19:30:25 +00:00
var devices = DirectSoundOut.Devices.ToList();
var soundDevice = devices.FirstOrDefault(d => d.Guid == this.Plugin.Config.SoundDeviceNew);
var name = soundDevice != null ? soundDevice.Description : Language.SettingsSoundInvalidDevice;
2021-02-01 19:37:08 +00:00
2021-04-28 17:18:48 +00:00
if (ImGui.BeginCombo($"{Language.SettingsSoundOutputDevice}###sound-output-device-combo", name)) {
2022-08-21 19:30:25 +00:00
for (var deviceNum = 0; deviceNum < devices.Count; deviceNum++) {
var info = devices[deviceNum];
if (!ImGui.Selectable($"{info.Description}##{deviceNum}")) {
2020-12-29 16:08:21 +00:00
continue;
}
2022-08-21 19:30:25 +00:00
this.Plugin.Config.SoundDeviceNew = info.Guid;
2020-12-29 16:08:21 +00:00
this.Plugin.Config.Save();
}
ImGui.EndCombo();
}
var soundCooldown = this.Plugin.Config.SoundCooldown;
2021-04-28 14:41:34 +00:00
if (ImGui.DragFloat(Language.SettingsSoundCooldown, ref soundCooldown, .01f, 0f, 30f)) {
2020-12-29 16:08:21 +00:00
soundCooldown = Math.Max(0f, soundCooldown);
this.Plugin.Config.SoundCooldown = soundCooldown;
this.Plugin.Config.Save();
}
var playWhenClosed = this.Plugin.Config.PlaySoundWhenClosed;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsSoundPlayWhenClosed, ref playWhenClosed)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.PlaySoundWhenClosed = playWhenClosed;
this.Plugin.Config.Save();
}
ImGui.EndTabItem();
}
2021-04-28 17:18:48 +00:00
if (ImGui.BeginTabItem($"{Language.SettingsWindowTab}###window-tab")) {
2020-12-29 16:08:21 +00:00
var openOnLogin = this.Plugin.Config.OpenOnLogin;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsWindowOpenLogin, ref openOnLogin)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.OpenOnLogin = openOnLogin;
this.Plugin.Config.Save();
}
var allowMovement = this.Plugin.Config.AllowMovement;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsWindowAllowMovement, ref allowMovement)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.AllowMovement = allowMovement;
this.Plugin.Config.Save();
}
var allowResizing = this.Plugin.Config.AllowResize;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsWindowAllowResize, ref allowResizing)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.AllowResize = allowResizing;
this.Plugin.Config.Save();
}
ImGui.Spacing();
var showInCombat = this.Plugin.Config.ShowInCombat;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsWindowShowCombat, ref showInCombat)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.ShowInCombat = showInCombat;
this.Plugin.Config.Save();
}
var showInInstance = this.Plugin.Config.ShowInInstance;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsWindowShowInstance, ref showInInstance)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.ShowInInstance = showInInstance;
this.Plugin.Config.Save();
}
var showInCutscenes = this.Plugin.Config.ShowInCutscenes;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsWindowShowCutscene, ref showInCutscenes)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.ShowInCutscenes = showInCutscenes;
this.Plugin.Config.Save();
}
ImGui.EndTabItem();
}
2021-04-28 17:18:48 +00:00
if (ImGui.BeginTabItem($"{Language.SettingsHistoryTab}###history-tab")) {
2020-12-29 16:08:21 +00:00
var keepHistory = this.Plugin.Config.KeepHistory;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsHistoryEnabled, ref keepHistory)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.KeepHistory = keepHistory;
this.Plugin.Config.Save();
}
var historyWhenClosed = this.Plugin.Config.HistoryWhenClosed;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsHistoryRecordClosed, ref historyWhenClosed)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.HistoryWhenClosed = historyWhenClosed;
this.Plugin.Config.Save();
}
var numHistory = this.Plugin.Config.NumHistory;
2021-04-28 14:41:34 +00:00
if (ImGui.InputInt(Language.SettingsHistoryAmount, ref numHistory)) {
2020-12-29 16:08:21 +00:00
numHistory = Math.Max(0, Math.Min(50, numHistory));
this.Plugin.Config.NumHistory = numHistory;
this.Plugin.Config.Save();
}
var showTimestamps = this.Plugin.Config.ShowTimestamps;
2021-04-28 14:41:34 +00:00
if (ImGui.Checkbox(Language.SettingsHistoryTimestamps, ref showTimestamps)) {
this.Plugin.Config.ShowTimestamps = showTimestamps;
this.Plugin.Config.Save();
}
2020-12-29 16:08:21 +00:00
ImGui.EndTabItem();
}
2021-04-28 17:18:48 +00:00
if (ImGui.BeginTabItem($"{Language.SettingsAdvancedTab}###advanced-tab")) {
2020-12-29 16:08:21 +00:00
var pollFrequency = this.Plugin.Config.PollFrequency;
2021-04-28 14:41:34 +00:00
if (ImGui.DragInt(Language.SettingsAdvancedPollFrequency, ref pollFrequency, .1f, 1, 1600)) {
2020-12-29 16:08:21 +00:00
this.Plugin.Config.PollFrequency = pollFrequency;
this.Plugin.Config.Save();
}
ImGui.EndTabItem();
}
ImGui.EndTabBar();
}
ImGui.End();
}
private void ShowMainWindow() {
var targeting = this.Plugin.Watcher.CurrentTargeters;
var previousTargeters = this.Plugin.Config.KeepHistory ? this.Plugin.Watcher.PreviousTargeters : null;
// to prevent looping over a subset of the actors repeatedly when multiple people are targeting,
// create a dictionary for O(1) lookups by actor id
2021-08-23 03:33:57 +00:00
Dictionary<uint, GameObject>? objects = null;
2020-12-29 16:08:21 +00:00
if (targeting.Count + (previousTargeters?.Count ?? 0) > 1) {
2021-08-23 03:33:57 +00:00
var dict = new Dictionary<uint, GameObject>();
foreach (var obj in this.Plugin.ObjectTable) {
if (dict.ContainsKey(obj.ObjectId) || obj.ObjectKind != ObjectKind.Player) {
2020-12-29 16:08:21 +00:00
continue;
}
2021-08-23 03:33:57 +00:00
dict.Add(obj.ObjectId, obj);
2020-12-29 16:08:21 +00:00
}
2021-02-01 19:37:08 +00:00
2021-08-23 03:33:57 +00:00
objects = dict;
2020-12-29 16:08:21 +00:00
}
var flags = ImGuiWindowFlags.None;
if (!this.Plugin.Config.AllowMovement) {
flags |= ImGuiWindowFlags.NoMove;
}
2021-02-01 19:37:08 +00:00
2020-12-29 16:08:21 +00:00
if (!this.Plugin.Config.AllowResize) {
flags |= ImGuiWindowFlags.NoResize;
}
2021-02-01 19:37:08 +00:00
2020-12-29 16:08:21 +00:00
ImGui.SetNextWindowSize(new Vector2(290, 195), ImGuiCond.FirstUseEver);
2023-09-28 06:56:38 +00:00
if (!ImGui.Begin(Plugin.Name, ref this._wantsOpen, flags)) {
ImGui.End();
2020-12-29 16:08:21 +00:00
return;
}
{
2021-04-28 14:41:34 +00:00
ImGui.Text(Language.MainTargetingYou);
2020-12-29 16:08:21 +00:00
ImGui.SameLine();
2021-04-28 14:41:34 +00:00
HelpMarker(this.Plugin.Config.OpenExamine
? Language.MainHelpExamine
: Language.MainHelpNoExamine);
2020-12-29 16:08:21 +00:00
var height = ImGui.GetContentRegionAvail().Y;
height -= ImGui.GetStyle().ItemSpacing.Y;
var anyHovered = false;
2021-04-05 19:13:41 +00:00
if (ImGui.BeginListBox("##targeting", new Vector2(-1, height))) {
2020-12-29 16:08:21 +00:00
// add the two first players for testing
2021-04-08 16:57:48 +00:00
// foreach (var p in this.Plugin.Interface.ClientState.Actors
// .Where(actor => actor is PlayerCharacter)
// .Skip(1)
// .Select(actor => actor as PlayerCharacter)
// .Take(2)) {
// this.AddEntry(new Targeter(p), p, ref anyHovered);
2021-04-08 16:57:48 +00:00
// }
2020-12-29 16:08:21 +00:00
foreach (var targeter in targeting) {
2021-08-23 03:33:57 +00:00
GameObject? obj = null;
objects?.TryGetValue(targeter.ObjectId, out obj);
this.AddEntry(targeter, obj, ref anyHovered);
2020-12-29 16:08:21 +00:00
}
2021-02-01 19:37:08 +00:00
2020-12-29 16:08:21 +00:00
if (this.Plugin.Config.KeepHistory) {
// get a list of the previous targeters that aren't currently targeting
var previous = (previousTargeters ?? new List<Targeter>())
2021-08-23 03:33:57 +00:00
.Where(old => targeting.All(actor => actor.ObjectId != old.ObjectId))
.Take(this.Plugin.Config.NumHistory);
2020-12-29 16:08:21 +00:00
// add previous targeters to the list
foreach (var oldTargeter in previous) {
2021-08-23 03:33:57 +00:00
GameObject? obj = null;
objects?.TryGetValue(oldTargeter.ObjectId, out obj);
this.AddEntry(oldTargeter, obj, ref anyHovered, ImGuiSelectableFlags.Disabled);
2020-12-29 16:08:21 +00:00
}
}
2021-02-01 19:37:08 +00:00
2021-04-05 19:13:41 +00:00
ImGui.EndListBox();
2020-12-29 16:08:21 +00:00
}
2021-02-01 19:37:08 +00:00
2021-08-23 03:33:57 +00:00
var previousFocus = this.PreviousFocus;
if (this.Plugin.Config.FocusTargetOnHover && !anyHovered && previousFocus != null) {
if (previousFocus == uint.MaxValue) {
this.Plugin.TargetManager.FocusTarget = null;
2020-12-29 16:08:21 +00:00
} else {
2021-08-23 03:33:57 +00:00
var actor = this.Plugin.ObjectTable.FirstOrDefault(a => a.ObjectId == previousFocus);
2020-12-29 16:08:21 +00:00
// either target the actor if still present or target nothing
2021-08-23 03:33:57 +00:00
this.Plugin.TargetManager.FocusTarget = actor;
2020-12-29 16:08:21 +00:00
}
2021-02-01 19:37:08 +00:00
2021-08-23 03:33:57 +00:00
this.PreviousFocus = null;
2020-12-29 16:08:21 +00:00
}
2021-02-01 19:37:08 +00:00
2020-12-29 16:08:21 +00:00
ImGui.End();
}
}
private static void HelpMarker(string text) {
ImGui.TextDisabled("(?)");
if (!ImGui.IsItemHovered()) {
return;
}
ImGui.BeginTooltip();
ImGui.PushTextWrapPos(ImGui.GetFontSize() * 20f);
ImGui.TextUnformatted(text);
ImGui.PopTextWrapPos();
ImGui.EndTooltip();
}
2021-08-23 03:33:57 +00:00
private void AddEntry(Targeter targeter, GameObject? obj, ref bool anyHovered, ImGuiSelectableFlags flags = ImGuiSelectableFlags.None) {
ImGui.BeginGroup();
2021-08-23 03:33:57 +00:00
ImGui.Selectable(targeter.Name.TextValue, false, flags);
if (this.Plugin.Config.ShowTimestamps) {
var time = DateTime.UtcNow - targeter.When >= TimeSpan.FromDays(1)
? targeter.When.ToLocalTime().ToString("dd/MM")
: targeter.When.ToLocalTime().ToString("t");
2022-08-21 19:30:25 +00:00
var windowWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
ImGui.SameLine(windowWidth - ImGui.CalcTextSize(time).X);
if (flags.HasFlag(ImGuiSelectableFlags.Disabled)) {
ImGui.PushStyleColor(ImGuiCol.Text, ImGui.GetStyle().Colors[(int) ImGuiCol.TextDisabled]);
}
ImGui.TextUnformatted(time);
if (flags.HasFlag(ImGuiSelectableFlags.Disabled)) {
ImGui.PopStyleColor();
}
}
ImGui.EndGroup();
2020-12-29 16:08:21 +00:00
var hover = ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled);
var left = hover && ImGui.IsMouseClicked(ImGuiMouseButton.Left);
var right = hover && ImGui.IsMouseClicked(ImGuiMouseButton.Right);
2020-12-29 16:08:21 +00:00
2021-08-23 03:33:57 +00:00
obj ??= this.Plugin.ObjectTable.FirstOrDefault(a => a.ObjectId == targeter.ObjectId);
2020-12-29 16:08:21 +00:00
// don't count as hovered if the actor isn't here (clears focus target when hovering missing actors)
2021-08-23 03:33:57 +00:00
if (obj != null) {
2020-12-29 16:08:21 +00:00
anyHovered |= hover;
}
2021-08-23 03:33:57 +00:00
if (this.Plugin.Config.FocusTargetOnHover && hover && obj != null) {
this.PreviousFocus ??= this.Plugin.TargetManager.FocusTarget?.ObjectId ?? uint.MaxValue;
this.Plugin.TargetManager.FocusTarget = obj;
2020-12-29 16:08:21 +00:00
}
if (left) {
2021-02-01 19:37:08 +00:00
if (this.Plugin.Config.OpenExamine && ImGui.GetIO().KeyAlt) {
2021-08-23 03:33:57 +00:00
if (obj != null) {
this.Plugin.Common.Functions.Examine.OpenExamineWindow(obj);
2020-12-29 16:08:21 +00:00
} else {
2021-04-28 14:41:34 +00:00
var error = string.Format(Language.ExamineErrorToast, targeter.Name);
2021-08-23 03:33:57 +00:00
this.Plugin.ToastGui.ShowError(error);
2020-12-29 16:08:21 +00:00
}
} else {
2021-08-23 03:33:57 +00:00
var payload = new PlayerPayload(targeter.Name.TextValue, targeter.HomeWorldId);
Payload[] payloads = { payload };
2023-09-28 06:56:38 +00:00
this.Plugin.ChatGui.Print(new XivChatEntry {
2021-08-23 03:33:57 +00:00
Message = new SeString(payloads),
2020-12-29 16:08:21 +00:00
});
}
2021-08-23 03:33:57 +00:00
} else if (right && obj != null) {
this.Plugin.TargetManager.Target = obj;
2020-12-29 16:08:21 +00:00
}
}
2021-08-23 03:33:57 +00:00
private void MarkPlayer(GameObject? player, Vector4 colour, float size) {
2020-12-29 16:08:21 +00:00
if (player == null) {
return;
}
2021-08-23 03:33:57 +00:00
if (!this.Plugin.GameGui.WorldToScreen(player.Position, out var screenPos)) {
2020-12-29 16:08:21 +00:00
return;
}
ImGui.PushClipRect(ImGuiHelpers.MainViewport.Pos, ImGuiHelpers.MainViewport.Pos + ImGuiHelpers.MainViewport.Size, false);
2020-12-29 16:08:21 +00:00
ImGui.GetWindowDrawList().AddCircleFilled(
ImGuiHelpers.MainViewport.Pos + new Vector2(screenPos.X, screenPos.Y),
2020-12-29 16:08:21 +00:00
size,
ImGui.GetColorU32(colour),
100
);
ImGui.PopClipRect();
}
private PlayerCharacter? GetCurrentTarget() {
2021-08-23 03:33:57 +00:00
var player = this.Plugin.ClientState.LocalPlayer;
2020-12-29 16:08:21 +00:00
if (player == null) {
return null;
}
2021-08-23 03:33:57 +00:00
var targetId = player.TargetObjectId;
2020-12-29 16:08:21 +00:00
if (targetId <= 0) {
return null;
}
2021-08-23 03:33:57 +00:00
return this.Plugin.ObjectTable
.Where(actor => actor.ObjectId == targetId && actor is PlayerCharacter)
2020-12-29 16:08:21 +00:00
.Select(actor => actor as PlayerCharacter)
.FirstOrDefault();
}
}
}