Make the DTR colors configurable (#77)
* Make the DTR colors configurable * Allow using (most of) the full RGB space (thanks @Caraxi)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Dalamud.Game.Gui.Dtr;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Game.Text.SeStringHandling.Payloads;
|
||||
using Dalamud.Plugin.Services;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.MareConfiguration.Configurations;
|
||||
@@ -8,6 +9,7 @@ using MareSynchronos.Services.Mediator;
|
||||
using MareSynchronos.WebAPI;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MareSynchronos.UI;
|
||||
|
||||
@@ -40,7 +42,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
||||
private Task? _runTask;
|
||||
private string? _text;
|
||||
private string? _tooltip;
|
||||
private StatusColorId _color;
|
||||
private Colors _colors;
|
||||
|
||||
public DtrEntry(ILogger<DtrEntry> logger, IDtrBar dtrBar, ConfigurationServiceBase<MareConfig> configService, MareMediator mareMediator, PairManager pairManager, ApiController apiController)
|
||||
{
|
||||
@@ -94,7 +96,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
||||
_logger.LogInformation("Clearing entry");
|
||||
_text = null;
|
||||
_tooltip = null;
|
||||
_color = default;
|
||||
_colors = default;
|
||||
|
||||
_entry.Value.Shown = false;
|
||||
}
|
||||
@@ -139,7 +141,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
||||
|
||||
string text;
|
||||
string tooltip;
|
||||
StatusColorId color;
|
||||
Colors colors;
|
||||
if (_apiController.IsConnected)
|
||||
{
|
||||
var pairCount = _pairManager.GetVisibleUserCount();
|
||||
@@ -162,30 +164,30 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
||||
}
|
||||
|
||||
tooltip = $"Loporrit: Connected{Environment.NewLine}----------{Environment.NewLine}{string.Join(Environment.NewLine, visiblePairs)}";
|
||||
color = StatusColorId.PairsInRange;
|
||||
colors = _configService.Current.DtrColorsPairsInRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltip = "Loporrit: Connected";
|
||||
color = default;
|
||||
colors = _configService.Current.DtrColorsDefault;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
text = RenderDtrStyle(_configService.Current.DtrStyle, "\uE04C");
|
||||
tooltip = "Loporrit: Not Connected";
|
||||
color = StatusColorId.NotConnected;
|
||||
colors = _configService.Current.DtrColorsNotConnected;
|
||||
}
|
||||
|
||||
if (!_configService.Current.UseColorsInDtr)
|
||||
color = default;
|
||||
colors = default;
|
||||
|
||||
if (!string.Equals(text, _text, StringComparison.Ordinal) || !string.Equals(tooltip, _tooltip, StringComparison.Ordinal) || color != _color)
|
||||
if (!string.Equals(text, _text, StringComparison.Ordinal) || !string.Equals(tooltip, _tooltip, StringComparison.Ordinal) || colors != _colors)
|
||||
{
|
||||
_text = text;
|
||||
_tooltip = tooltip;
|
||||
_color = color;
|
||||
_entry.Value.Text = color != default ? BuildColoredSeString(text, color) : text;
|
||||
_colors = colors;
|
||||
_entry.Value.Text = BuildColoredSeString(text, colors);
|
||||
_entry.Value.Tooltip = tooltip;
|
||||
}
|
||||
}
|
||||
@@ -208,13 +210,32 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
||||
};
|
||||
}
|
||||
|
||||
private static SeString BuildColoredSeString(string text, StatusColorId color)
|
||||
=> new SeStringBuilder().AddUiGlow(text, (ushort)color).Build();
|
||||
#region Colored SeString
|
||||
private const byte _colorTypeForeground = 0x13;
|
||||
private const byte _colorTypeGlow = 0x14;
|
||||
|
||||
private enum StatusColorId : ushort
|
||||
private static SeString BuildColoredSeString(string text, Colors colors)
|
||||
{
|
||||
None = default,
|
||||
NotConnected = 518,
|
||||
PairsInRange = 526,
|
||||
var ssb = new SeStringBuilder();
|
||||
if (colors.Foreground != default)
|
||||
ssb.Add(BuildColorStartPayload(_colorTypeForeground, colors.Foreground));
|
||||
if (colors.Glow != default)
|
||||
ssb.Add(BuildColorStartPayload(_colorTypeGlow, colors.Glow));
|
||||
ssb.AddText(text);
|
||||
if (colors.Glow != default)
|
||||
ssb.Add(BuildColorEndPayload(_colorTypeGlow));
|
||||
if (colors.Foreground != default)
|
||||
ssb.Add(BuildColorEndPayload(_colorTypeForeground));
|
||||
return ssb.Build();
|
||||
}
|
||||
|
||||
private static RawPayload BuildColorStartPayload(byte colorType, uint color)
|
||||
=> new(unchecked([0x02, colorType, 0x05, 0xF6, byte.Max((byte)color, 0x01), byte.Max((byte)(color >> 8), 0x01), byte.Max((byte)(color >> 16), 0x01), 0x03]));
|
||||
|
||||
private static RawPayload BuildColorEndPayload(byte colorType)
|
||||
=> new([0x02, colorType, 0x02, 0xEC, 0x03]);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public readonly record struct Colors(uint Foreground = default, uint Glow = default);
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user