Make the Event Viewer UI a little simpler

This commit is contained in:
Loporrit
2025-02-09 06:50:48 +00:00
parent 6f88ed1ea5
commit 6ab9812f9a
2 changed files with 103 additions and 85 deletions

View File

@@ -1,8 +1,11 @@
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Colors; using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.Utility; using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Utility.Raii;
using Dalamud.Utility;
using ImGuiNET; using ImGuiNET;
using MareSynchronos.MareConfiguration;
using MareSynchronos.Services; using MareSynchronos.Services;
using MareSynchronos.Services.Events; using MareSynchronos.Services.Events;
using MareSynchronos.Services.Mediator; using MareSynchronos.Services.Mediator;
@@ -17,13 +20,11 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
{ {
private readonly EventAggregator _eventAggregator; private readonly EventAggregator _eventAggregator;
private readonly UiSharedService _uiSharedService; private readonly UiSharedService _uiSharedService;
private readonly MareConfigService _configService;
private List<Event> _currentEvents = new(); private List<Event> _currentEvents = new();
private Lazy<List<Event>> _filteredEvents; private Lazy<List<Event>> _filteredEvents;
private string _filterFreeText = string.Empty; private string _filterFreeText = string.Empty;
private string _filterCharacter = string.Empty; private bool _isPaused = false;
private string _filterUid = string.Empty;
private string _filterSource = string.Empty;
private string _filterEvent = string.Empty;
private List<Event> CurrentEvents private List<Event> CurrentEvents
{ {
@@ -39,15 +40,15 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
} }
public EventViewerUI(ILogger<EventViewerUI> logger, MareMediator mediator, public EventViewerUI(ILogger<EventViewerUI> logger, MareMediator mediator,
EventAggregator eventAggregator, UiSharedService uiSharedService, EventAggregator eventAggregator, UiSharedService uiSharedService, MareConfigService configService,
PerformanceCollectorService performanceCollectorService) : base(logger, mediator, "Event Viewer", performanceCollectorService) PerformanceCollectorService performanceCollectorService) : base(logger, mediator, "Event Viewer", performanceCollectorService)
{ {
_eventAggregator = eventAggregator; _eventAggregator = eventAggregator;
_uiSharedService = uiSharedService; _uiSharedService = uiSharedService;
_configService = configService;
SizeConstraints = new() SizeConstraints = new()
{ {
MinimumSize = new(600, 500), MinimumSize = new(700, 400)
MaximumSize = new(1000, 2000)
}; };
_filteredEvents = RecreateFilter(); _filteredEvents = RecreateFilter();
} }
@@ -56,27 +57,11 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
{ {
return new(() => return new(() =>
CurrentEvents.Where(f => CurrentEvents.Where(f =>
(string.IsNullOrEmpty(_filterFreeText) string.IsNullOrEmpty(_filterFreeText)
|| (f.EventSource.Contains(_filterFreeText, StringComparison.OrdinalIgnoreCase) || (f.EventSource.Contains(_filterFreeText, StringComparison.OrdinalIgnoreCase)
|| f.Character.Contains(_filterFreeText, StringComparison.OrdinalIgnoreCase) || f.Character.Contains(_filterFreeText, StringComparison.OrdinalIgnoreCase)
|| f.UID.Contains(_filterFreeText, StringComparison.OrdinalIgnoreCase) || f.UID.Contains(_filterFreeText, StringComparison.OrdinalIgnoreCase)
|| f.Message.Contains(_filterFreeText, StringComparison.OrdinalIgnoreCase) || f.Message.Contains(_filterFreeText, StringComparison.OrdinalIgnoreCase)
))
&&
(string.IsNullOrEmpty(_filterUid)
|| (f.UID.Contains(_filterUid, StringComparison.OrdinalIgnoreCase))
)
&&
(string.IsNullOrEmpty(_filterSource)
|| (f.EventSource.Contains(_filterSource, StringComparison.OrdinalIgnoreCase))
)
&&
(string.IsNullOrEmpty(_filterCharacter)
|| (f.Character.Contains(_filterCharacter, StringComparison.OrdinalIgnoreCase))
)
&&
(string.IsNullOrEmpty(_filterEvent)
|| (f.Message.Contains(_filterEvent, StringComparison.OrdinalIgnoreCase))
) )
).ToList()); ).ToList());
} }
@@ -84,10 +69,6 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
private void ClearFilters() private void ClearFilters()
{ {
_filterFreeText = string.Empty; _filterFreeText = string.Empty;
_filterCharacter = string.Empty;
_filterUid = string.Empty;
_filterSource = string.Empty;
_filterEvent = string.Empty;
_filteredEvents = RecreateFilter(); _filteredEvents = RecreateFilter();
} }
@@ -99,57 +80,61 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
protected override void DrawInternal() protected override void DrawInternal()
{ {
using (ImRaii.Disabled(!_eventAggregator.NewEventsAvailable)) var newEventsAvailable = _eventAggregator.NewEventsAvailable;
var freezeSize = UiSharedService.GetNormalizedIconTextButtonSize(FontAwesomeIcon.PlayCircle, "Unfreeze View").X;
if (_isPaused)
{ {
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.ArrowsToCircle, "Refresh events")) using (ImRaii.PushColor(ImGuiCol.Text, ImGuiColors.DalamudYellow, newEventsAvailable))
{ {
CurrentEvents = _eventAggregator.EventList.Value.OrderByDescending(f => f.EventTime).ToList(); if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.PlayCircle, "Unfreeze View"))
_isPaused = false;
if (newEventsAvailable)
UiSharedService.AttachToolTip("New events are available. Click to resume updating.");
} }
} }
else
{
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.PauseCircle, "Freeze View"))
_isPaused = true;
}
if (_eventAggregator.NewEventsAvailable) if (newEventsAvailable && !_isPaused)
CurrentEvents = _eventAggregator.EventList.Value.OrderByDescending(f => f.EventTime).ToList();
ImGui.SameLine(freezeSize + ImGui.GetStyle().ItemSpacing.X * 2);
bool changedFilter = false;
ImGui.SetNextItemWidth(200);
changedFilter |= ImGui.InputText("Filter lines", ref _filterFreeText, 50);
if (changedFilter) _filteredEvents = RecreateFilter();
using (ImRaii.Disabled(_filterFreeText.IsNullOrEmpty()))
{ {
ImGui.SameLine(); ImGui.SameLine();
ImGui.AlignTextToFramePadding(); if (ImGuiComponents.IconButton(FontAwesomeIcon.Ban))
UiSharedService.ColorTextWrapped("New events are available, press refresh to update", ImGuiColors.DalamudYellow);
}
var buttonSize = UiSharedService.GetNormalizedIconTextButtonSize(FontAwesomeIcon.FolderOpen, "Open EventLog Folder");
var dist = ImGui.GetWindowContentRegionMax().X - buttonSize.X;
ImGui.SameLine(dist);
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.FolderOpen, "Open EventLog folder"))
{
ProcessStartInfo ps = new()
{ {
FileName = _eventAggregator.EventLogFolder, _filterFreeText = string.Empty;
UseShellExecute = true, _filteredEvents = RecreateFilter();
WindowStyle = ProcessWindowStyle.Normal }
}; }
Process.Start(ps);
} if (_configService.Current.LogEvents)
{
UiSharedService.FontText("Last Events", _uiSharedService.UidFont); var buttonSize = UiSharedService.GetNormalizedIconTextButtonSize(FontAwesomeIcon.FolderOpen, "Open EventLog Folder");
var foldOut = ImRaii.TreeNode("Filter"); var dist = ImGui.GetWindowContentRegionMax().X - buttonSize.X;
if (foldOut) ImGui.SameLine(dist);
{ if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.FolderOpen, "Open EventLog folder"))
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.Ban, "Clear Filters")) {
{ ProcessStartInfo ps = new()
ClearFilters(); {
FileName = _eventAggregator.EventLogFolder,
UseShellExecute = true,
WindowStyle = ProcessWindowStyle.Normal
};
Process.Start(ps);
} }
bool changedFilter = false;
ImGui.SetNextItemWidth(200);
changedFilter |= ImGui.InputText("Search all columns", ref _filterFreeText, 50);
ImGui.SetNextItemWidth(200);
changedFilter |= ImGui.InputText("Filter by Source", ref _filterSource, 50);
ImGui.SetNextItemWidth(200);
changedFilter |= ImGui.InputText("Filter by UID", ref _filterUid, 50);
ImGui.SetNextItemWidth(200);
changedFilter |= ImGui.InputText("Filter by Character", ref _filterCharacter, 50);
ImGui.SetNextItemWidth(200);
changedFilter |= ImGui.InputText("Filter by Event", ref _filterEvent, 50);
if (changedFilter) _filteredEvents = RecreateFilter();
} }
foldOut.Dispose();
var cursorPos = ImGui.GetCursorPosY(); var cursorPos = ImGui.GetCursorPosY();
var max = ImGui.GetWindowContentRegionMax(); var max = ImGui.GetWindowContentRegionMax();
@@ -158,18 +143,27 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
var height = max.Y - cursorPos; var height = max.Y - cursorPos;
using var table = ImRaii.Table("eventTable", 6, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.ScrollY | ImGuiTableFlags.RowBg, using var table = ImRaii.Table("eventTable", 6, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.ScrollY | ImGuiTableFlags.RowBg,
new Vector2(width, height)); new Vector2(width, height));
float timeColWidth = ImGui.CalcTextSize("88:88:88 PM").X;
float sourceColWidth = ImGui.CalcTextSize("PairManager").X;
float uidColWidth = ImGui.CalcTextSize("WWWWWWW").X;
float characterColWidth = ImGui.CalcTextSize("Wwwwww Wwwwww").X;
if (table) if (table)
{ {
ImGui.TableSetupScrollFreeze(0, 1); ImGui.TableSetupScrollFreeze(0, 1);
ImGui.TableSetupColumn(string.Empty, ImGuiTableColumnFlags.NoSort); ImGui.TableSetupColumn(string.Empty, ImGuiTableColumnFlags.NoSort);
ImGui.TableSetupColumn("Time"); ImGui.TableSetupColumn("Time", ImGuiTableColumnFlags.None, timeColWidth);
ImGui.TableSetupColumn("Source"); ImGui.TableSetupColumn("Source", ImGuiTableColumnFlags.None, sourceColWidth);
ImGui.TableSetupColumn("UID"); ImGui.TableSetupColumn("UID", ImGuiTableColumnFlags.None, uidColWidth);
ImGui.TableSetupColumn("Character"); ImGui.TableSetupColumn("Character", ImGuiTableColumnFlags.None, characterColWidth);
ImGui.TableSetupColumn("Event"); ImGui.TableSetupColumn("Event", ImGuiTableColumnFlags.None);
ImGui.TableHeadersRow(); ImGui.TableHeadersRow();
int i = 0;
foreach (var ev in _filteredEvents.Value) foreach (var ev in _filteredEvents.Value)
{ {
++i;
var icon = ev.EventSeverity switch var icon = ev.EventSeverity switch
{ {
EventSeverity.Informational => FontAwesomeIcon.InfoCircle, EventSeverity.Informational => FontAwesomeIcon.InfoCircle,
@@ -191,16 +185,38 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
UiSharedService.AttachToolTip(ev.EventSeverity.ToString()); UiSharedService.AttachToolTip(ev.EventSeverity.ToString());
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.AlignTextToFramePadding(); ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(ev.EventTime.ToString("G", CultureInfo.CurrentCulture)); ImGui.TextUnformatted(ev.EventTime.ToString("T", CultureInfo.CurrentCulture));
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.AlignTextToFramePadding(); ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(ev.EventSource); ImGui.TextUnformatted(ev.EventSource);
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.AlignTextToFramePadding(); ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(string.IsNullOrEmpty(ev.UID) ? "--" : ev.UID); if (!string.IsNullOrEmpty(ev.UID))
{
if (ImGui.Selectable(ev.UID + $"##{i}"))
{
_filterFreeText = ev.UID;
_filteredEvents = RecreateFilter();
}
}
else
{
ImGui.TextUnformatted("--");
}
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.AlignTextToFramePadding(); ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(string.IsNullOrEmpty(ev.Character) ? "--" : ev.Character); if (!string.IsNullOrEmpty(ev.Character))
{
if (ImGui.Selectable(ev.Character + $"##{i}"))
{
_filterFreeText = ev.Character;
_filteredEvents = RecreateFilter();
}
}
else
{
ImGui.TextUnformatted("--");
}
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.AlignTextToFramePadding(); ImGui.AlignTextToFramePadding();
var posX = ImGui.GetCursorPosX(); var posX = ImGui.GetCursorPosX();

View File

@@ -651,15 +651,17 @@ public class SettingsUi : WindowMediatorSubscriberBase
} }
UiSharedService.DrawHelpText("Enabling this can incur a (slight) performance impact. Enabling this for extended periods of time is not recommended."); UiSharedService.DrawHelpText("Enabling this can incur a (slight) performance impact. Enabling this for extended periods of time is not recommended.");
using var disabled = ImRaii.Disabled(!logPerformance); using (ImRaii.Disabled(!logPerformance))
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog"))
{ {
_performanceCollector.PrintPerformanceStats(); if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog"))
} {
ImGui.SameLine(); _performanceCollector.PrintPerformanceStats();
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats (last 60s) to /xllog")) }
{ ImGui.SameLine();
_performanceCollector.PrintPerformanceStats(60); if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats (last 60s) to /xllog"))
{
_performanceCollector.PrintPerformanceStats(60);
}
} }
bool logEvents = _configService.Current.LogEvents; bool logEvents = _configService.Current.LogEvents;