Make the Event Viewer UI a little simpler
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
using Dalamud.Interface;
|
||||
using Dalamud.Interface.Colors;
|
||||
using Dalamud.Interface.Components;
|
||||
using Dalamud.Interface.Utility;
|
||||
using Dalamud.Interface.Utility.Raii;
|
||||
using Dalamud.Utility;
|
||||
using ImGuiNET;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.Services;
|
||||
using MareSynchronos.Services.Events;
|
||||
using MareSynchronos.Services.Mediator;
|
||||
@@ -17,13 +20,11 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
private readonly EventAggregator _eventAggregator;
|
||||
private readonly UiSharedService _uiSharedService;
|
||||
private readonly MareConfigService _configService;
|
||||
private List<Event> _currentEvents = new();
|
||||
private Lazy<List<Event>> _filteredEvents;
|
||||
private string _filterFreeText = string.Empty;
|
||||
private string _filterCharacter = string.Empty;
|
||||
private string _filterUid = string.Empty;
|
||||
private string _filterSource = string.Empty;
|
||||
private string _filterEvent = string.Empty;
|
||||
private bool _isPaused = false;
|
||||
|
||||
private List<Event> CurrentEvents
|
||||
{
|
||||
@@ -39,15 +40,15 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
_eventAggregator = eventAggregator;
|
||||
_uiSharedService = uiSharedService;
|
||||
_configService = configService;
|
||||
SizeConstraints = new()
|
||||
{
|
||||
MinimumSize = new(600, 500),
|
||||
MaximumSize = new(1000, 2000)
|
||||
MinimumSize = new(700, 400)
|
||||
};
|
||||
_filteredEvents = RecreateFilter();
|
||||
}
|
||||
@@ -56,27 +57,11 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
|
||||
{
|
||||
return new(() =>
|
||||
CurrentEvents.Where(f =>
|
||||
(string.IsNullOrEmpty(_filterFreeText)
|
||||
string.IsNullOrEmpty(_filterFreeText)
|
||||
|| (f.EventSource.Contains(_filterFreeText, StringComparison.OrdinalIgnoreCase)
|
||||
|| f.Character.Contains(_filterFreeText, StringComparison.OrdinalIgnoreCase)
|
||||
|| f.UID.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());
|
||||
}
|
||||
@@ -84,10 +69,6 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
|
||||
private void ClearFilters()
|
||||
{
|
||||
_filterFreeText = string.Empty;
|
||||
_filterCharacter = string.Empty;
|
||||
_filterUid = string.Empty;
|
||||
_filterSource = string.Empty;
|
||||
_filterEvent = string.Empty;
|
||||
_filteredEvents = RecreateFilter();
|
||||
}
|
||||
|
||||
@@ -99,21 +80,47 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
|
||||
|
||||
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.AlignTextToFramePadding();
|
||||
UiSharedService.ColorTextWrapped("New events are available, press refresh to update", ImGuiColors.DalamudYellow);
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Ban))
|
||||
{
|
||||
_filterFreeText = string.Empty;
|
||||
_filteredEvents = RecreateFilter();
|
||||
}
|
||||
}
|
||||
|
||||
if (_configService.Current.LogEvents)
|
||||
{
|
||||
var buttonSize = UiSharedService.GetNormalizedIconTextButtonSize(FontAwesomeIcon.FolderOpen, "Open EventLog Folder");
|
||||
var dist = ImGui.GetWindowContentRegionMax().X - buttonSize.X;
|
||||
ImGui.SameLine(dist);
|
||||
@@ -127,29 +134,7 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
|
||||
};
|
||||
Process.Start(ps);
|
||||
}
|
||||
|
||||
UiSharedService.FontText("Last Events", _uiSharedService.UidFont);
|
||||
var foldOut = ImRaii.TreeNode("Filter");
|
||||
if (foldOut)
|
||||
{
|
||||
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.Ban, "Clear Filters"))
|
||||
{
|
||||
ClearFilters();
|
||||
}
|
||||
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 max = ImGui.GetWindowContentRegionMax();
|
||||
@@ -158,18 +143,27 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
|
||||
var height = max.Y - cursorPos;
|
||||
using var table = ImRaii.Table("eventTable", 6, ImGuiTableFlags.SizingFixedFit | ImGuiTableFlags.ScrollY | ImGuiTableFlags.RowBg,
|
||||
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)
|
||||
{
|
||||
ImGui.TableSetupScrollFreeze(0, 1);
|
||||
ImGui.TableSetupColumn(string.Empty, ImGuiTableColumnFlags.NoSort);
|
||||
ImGui.TableSetupColumn("Time");
|
||||
ImGui.TableSetupColumn("Source");
|
||||
ImGui.TableSetupColumn("UID");
|
||||
ImGui.TableSetupColumn("Character");
|
||||
ImGui.TableSetupColumn("Event");
|
||||
ImGui.TableSetupColumn("Time", ImGuiTableColumnFlags.None, timeColWidth);
|
||||
ImGui.TableSetupColumn("Source", ImGuiTableColumnFlags.None, sourceColWidth);
|
||||
ImGui.TableSetupColumn("UID", ImGuiTableColumnFlags.None, uidColWidth);
|
||||
ImGui.TableSetupColumn("Character", ImGuiTableColumnFlags.None, characterColWidth);
|
||||
ImGui.TableSetupColumn("Event", ImGuiTableColumnFlags.None);
|
||||
ImGui.TableHeadersRow();
|
||||
int i = 0;
|
||||
foreach (var ev in _filteredEvents.Value)
|
||||
{
|
||||
++i;
|
||||
|
||||
var icon = ev.EventSeverity switch
|
||||
{
|
||||
EventSeverity.Informational => FontAwesomeIcon.InfoCircle,
|
||||
@@ -191,16 +185,38 @@ internal class EventViewerUI : WindowMediatorSubscriberBase
|
||||
UiSharedService.AttachToolTip(ev.EventSeverity.ToString());
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted(ev.EventTime.ToString("G", CultureInfo.CurrentCulture));
|
||||
ImGui.TextUnformatted(ev.EventTime.ToString("T", CultureInfo.CurrentCulture));
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted(ev.EventSource);
|
||||
ImGui.TableNextColumn();
|
||||
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.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.AlignTextToFramePadding();
|
||||
var posX = ImGui.GetCursorPosX();
|
||||
|
||||
@@ -651,7 +651,8 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
||||
}
|
||||
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();
|
||||
@@ -661,6 +662,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
||||
{
|
||||
_performanceCollector.PrintPerformanceStats(60);
|
||||
}
|
||||
}
|
||||
|
||||
bool logEvents = _configService.Current.LogEvents;
|
||||
if (ImGui.Checkbox("Log Event Viewer Data", ref logEvents))
|
||||
|
||||
Reference in New Issue
Block a user