diff --git a/MareSynchronos/UI/EventViewerUI.cs b/MareSynchronos/UI/EventViewerUI.cs index 023be7b..5ce53f2 100644 --- a/MareSynchronos/UI/EventViewerUI.cs +++ b/MareSynchronos/UI/EventViewerUI.cs @@ -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 _currentEvents = new(); private Lazy> _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 CurrentEvents { @@ -39,15 +40,15 @@ internal class EventViewerUI : WindowMediatorSubscriberBase } public EventViewerUI(ILogger 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,57 +80,61 @@ 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); - } - - 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() + if (ImGuiComponents.IconButton(FontAwesomeIcon.Ban)) { - FileName = _eventAggregator.EventLogFolder, - UseShellExecute = true, - WindowStyle = ProcessWindowStyle.Normal - }; - Process.Start(ps); - } - - UiSharedService.FontText("Last Events", _uiSharedService.UidFont); - var foldOut = ImRaii.TreeNode("Filter"); - if (foldOut) - { - if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.Ban, "Clear Filters")) - { - ClearFilters(); + _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); + if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.FolderOpen, "Open EventLog folder")) + { + ProcessStartInfo ps = new() + { + 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 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(); diff --git a/MareSynchronos/UI/SettingsUi.cs b/MareSynchronos/UI/SettingsUi.cs index e855c50..9f38f42 100644 --- a/MareSynchronos/UI/SettingsUi.cs +++ b/MareSynchronos/UI/SettingsUi.cs @@ -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."); - using var disabled = ImRaii.Disabled(!logPerformance); - if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog")) + using (ImRaii.Disabled(!logPerformance)) { - _performanceCollector.PrintPerformanceStats(); - } - ImGui.SameLine(); - if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats (last 60s) to /xllog")) - { - _performanceCollector.PrintPerformanceStats(60); + if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats to /xllog")) + { + _performanceCollector.PrintPerformanceStats(); + } + ImGui.SameLine(); + if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.StickyNote, "Print Performance Stats (last 60s) to /xllog")) + { + _performanceCollector.PrintPerformanceStats(60); + } } bool logEvents = _configService.Current.LogEvents;