Color-code the DTR entry (#76)

This commit is contained in:
N. Lo
2024-08-19 10:23:40 +02:00
committed by Loporrit
parent d39c79a227
commit fec13209d8
3 changed files with 34 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ public class MareConfig : IMareConfiguration
public int DtrStyle { get; set; } = 0; public int DtrStyle { get; set; } = 0;
public bool ShowUidInDtrTooltip { get; set; } = true; public bool ShowUidInDtrTooltip { get; set; } = true;
public bool PreferNoteInDtrTooltip { get; set; } = false; public bool PreferNoteInDtrTooltip { get; set; } = false;
public bool UseColorsInDtr { get; set; } = true;
public bool EnableRightClickMenus { get; set; } = true; public bool EnableRightClickMenus { get; set; } = true;
public NotificationLocation ErrorNotification { get; set; } = NotificationLocation.Both; public NotificationLocation ErrorNotification { get; set; } = NotificationLocation.Both;
public string ExportFolder { get; set; } = string.Empty; public string ExportFolder { get; set; } = string.Empty;

View File

@@ -1,4 +1,5 @@
using Dalamud.Game.Gui.Dtr; using Dalamud.Game.Gui.Dtr;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using MareSynchronos.MareConfiguration; using MareSynchronos.MareConfiguration;
using MareSynchronos.MareConfiguration.Configurations; using MareSynchronos.MareConfiguration.Configurations;
@@ -38,6 +39,8 @@ public sealed class DtrEntry : IDisposable, IHostedService
private readonly PairManager _pairManager; private readonly PairManager _pairManager;
private Task? _runTask; private Task? _runTask;
private string? _text; private string? _text;
private string? _tooltip;
private StatusColorId _color;
public DtrEntry(ILogger<DtrEntry> logger, IDtrBar dtrBar, ConfigurationServiceBase<MareConfig> configService, MareMediator mareMediator, PairManager pairManager, ApiController apiController) public DtrEntry(ILogger<DtrEntry> logger, IDtrBar dtrBar, ConfigurationServiceBase<MareConfig> configService, MareMediator mareMediator, PairManager pairManager, ApiController apiController)
{ {
@@ -90,6 +93,8 @@ public sealed class DtrEntry : IDisposable, IHostedService
if (!_entry.IsValueCreated) return; if (!_entry.IsValueCreated) return;
_logger.LogInformation("Clearing entry"); _logger.LogInformation("Clearing entry");
_text = null; _text = null;
_tooltip = null;
_color = default;
_entry.Value.Shown = false; _entry.Value.Shown = false;
} }
@@ -134,6 +139,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
string text; string text;
string tooltip; string tooltip;
StatusColorId color;
if (_apiController.IsConnected) if (_apiController.IsConnected)
{ {
var pairCount = _pairManager.GetVisibleUserCount(); var pairCount = _pairManager.GetVisibleUserCount();
@@ -156,22 +162,30 @@ public sealed class DtrEntry : IDisposable, IHostedService
} }
tooltip = $"Loporrit: Connected{Environment.NewLine}----------{Environment.NewLine}{string.Join(Environment.NewLine, visiblePairs)}"; tooltip = $"Loporrit: Connected{Environment.NewLine}----------{Environment.NewLine}{string.Join(Environment.NewLine, visiblePairs)}";
color = StatusColorId.PairsInRange;
} }
else else
{ {
tooltip = "Loporrit: Connected"; tooltip = "Loporrit: Connected";
color = default;
} }
} }
else else
{ {
text = RenderDtrStyle(_configService.Current.DtrStyle, "\uE04C"); text = RenderDtrStyle(_configService.Current.DtrStyle, "\uE04C");
tooltip = "Loporrit: Not Connected"; tooltip = "Loporrit: 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; _text = text;
_entry.Value.Text = text; _tooltip = tooltip;
_color = color;
_entry.Value.Text = color != default ? BuildColoredSeString(text, color) : text;
_entry.Value.Tooltip = tooltip; _entry.Value.Tooltip = tooltip;
} }
} }
@@ -193,4 +207,14 @@ public sealed class DtrEntry : IDisposable, IHostedService
_ => $"\uE044 {text}" _ => $"\uE044 {text}"
}; };
} }
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,
}
} }

View File

@@ -979,6 +979,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
var enableDtrEntry = _configService.Current.EnableDtrEntry; var enableDtrEntry = _configService.Current.EnableDtrEntry;
var showUidInDtrTooltip = _configService.Current.ShowUidInDtrTooltip; var showUidInDtrTooltip = _configService.Current.ShowUidInDtrTooltip;
var preferNoteInDtrTooltip = _configService.Current.PreferNoteInDtrTooltip; var preferNoteInDtrTooltip = _configService.Current.PreferNoteInDtrTooltip;
var useColorsInDtr = _configService.Current.UseColorsInDtr;
if (ImGui.Checkbox("Enable Game Right Click Menu Entries", ref enableRightClickMenu)) if (ImGui.Checkbox("Enable Game Right Click Menu Entries", ref enableRightClickMenu))
{ {
@@ -1016,6 +1017,12 @@ public class SettingsUi : WindowMediatorSubscriberBase
_configService.Current.DtrStyle = i; _configService.Current.DtrStyle = i;
_configService.Save(); _configService.Save();
}, _configService.Current.DtrStyle); }, _configService.Current.DtrStyle);
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)) if (ImGui.Checkbox("Show separate Visible group", ref showVisibleSeparate))