From bff23d12321fbc7b0c50bada6a776b4bd9aee009 Mon Sep 17 00:00:00 2001 From: "N. Lo." Date: Mon, 19 Aug 2024 10:23:40 +0200 Subject: [PATCH] Color-code the DTR entry (#76) --- .../Configurations/MareConfig.cs | 1 + MareSynchronos/UI/DtrEntry.cs | 28 +++++++++++++++++-- MareSynchronos/UI/SettingsUi.cs | 7 +++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs b/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs index 81f7923..9594e3f 100644 --- a/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs +++ b/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs @@ -12,6 +12,7 @@ public class MareConfig : IMareConfiguration public bool EnableDtrEntry { get; set; } = false; public bool ShowUidInDtrTooltip { get; set; } = true; public bool PreferNoteInDtrTooltip { get; set; } = false; + public bool UseColorsInDtr { get; set; } = true; public bool EnableRightClickMenus { get; set; } = true; public NotificationLocation ErrorNotification { get; set; } = NotificationLocation.Both; public string ExportFolder { get; set; } = string.Empty; diff --git a/MareSynchronos/UI/DtrEntry.cs b/MareSynchronos/UI/DtrEntry.cs index a53c398..359c2f7 100644 --- a/MareSynchronos/UI/DtrEntry.cs +++ b/MareSynchronos/UI/DtrEntry.cs @@ -1,4 +1,5 @@ using Dalamud.Game.Gui.Dtr; +using Dalamud.Game.Text.SeStringHandling; using Dalamud.Plugin.Services; using MareSynchronos.MareConfiguration; using MareSynchronos.MareConfiguration.Configurations; @@ -22,6 +23,8 @@ public sealed class DtrEntry : IDisposable, IHostedService private readonly PairManager _pairManager; private Task? _runTask; private string? _text; + private string? _tooltip; + private StatusColorId _color; public DtrEntry(ILogger logger, IDtrBar dtrBar, ConfigurationServiceBase configService, MareMediator mareMediator, PairManager pairManager, ApiController apiController) { @@ -74,6 +77,8 @@ public sealed class DtrEntry : IDisposable, IHostedService if (!_entry.IsValueCreated) return; _logger.LogInformation("Clearing entry"); _text = null; + _tooltip = null; + _color = default; _entry.Value.Shown = false; } @@ -118,6 +123,7 @@ public sealed class DtrEntry : IDisposable, IHostedService string text; string tooltip; + StatusColorId color; if (_apiController.IsConnected) { var pairCount = _pairManager.GetVisibleUserCount(); @@ -139,23 +145,41 @@ public sealed class DtrEntry : IDisposable, IHostedService } tooltip = $"Mare Synchronos: Connected{Environment.NewLine}----------{Environment.NewLine}{string.Join(Environment.NewLine, visiblePairs)}"; + color = StatusColorId.PairsInRange; } else { tooltip = "Mare Synchronos: Connected"; + color = default; } } else { text = "\uE044 \uE04C"; tooltip = "Mare Synchronos: Not Connected"; + color = StatusColorId.NotConnected; } - if (!string.Equals(text, _text, StringComparison.Ordinal)) + if (!_configService.Current.UseColorsInDtr) + color = default; + + if (!string.Equals(text, _text, StringComparison.Ordinal) || !string.Equals(tooltip, _tooltip, StringComparison.Ordinal) || color != _color) { _text = text; - _entry.Value.Text = text; + _tooltip = tooltip; + _color = color; + _entry.Value.Text = color != default ? BuildColoredSeString(text, color) : text; _entry.Value.Tooltip = tooltip; } } + + private static SeString BuildColoredSeString(string text, StatusColorId color) + => new SeStringBuilder().AddUiGlow(text, (ushort)color).Build(); + + private enum StatusColorId : ushort + { + None = default, + NotConnected = 518, + PairsInRange = 526, + } } \ No newline at end of file diff --git a/MareSynchronos/UI/SettingsUi.cs b/MareSynchronos/UI/SettingsUi.cs index 28e0c5d..b681955 100644 --- a/MareSynchronos/UI/SettingsUi.cs +++ b/MareSynchronos/UI/SettingsUi.cs @@ -731,6 +731,7 @@ public class SettingsUi : WindowMediatorSubscriberBase var enableDtrEntry = _configService.Current.EnableDtrEntry; var showUidInDtrTooltip = _configService.Current.ShowUidInDtrTooltip; var preferNoteInDtrTooltip = _configService.Current.PreferNoteInDtrTooltip; + var useColorsInDtr = _configService.Current.UseColorsInDtr; var preferNotesInsteadOfName = _configService.Current.PreferNotesOverNamesForVisible; var groupUpSyncshells = _configService.Current.GroupUpSyncshells; var groupInVisible = _configService.Current.ShowSyncshellUsersInVisible; @@ -764,6 +765,12 @@ public class SettingsUi : WindowMediatorSubscriberBase _configService.Current.PreferNoteInDtrTooltip = preferNoteInDtrTooltip; _configService.Save(); } + + if (ImGui.Checkbox("Color-code the Server Info Bar entry according to status", ref useColorsInDtr)) + { + _configService.Current.UseColorsInDtr = useColorsInDtr; + _configService.Save(); + } } if (ImGui.Checkbox("Show separate Visible group", ref showVisibleSeparate))