mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-12 19:47:21 +01:00
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:
parent
6b3d79869b
commit
78f9eccb40
3 changed files with 99 additions and 16 deletions
|
|
@ -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;
|
||||
|
||||
|
|
@ -24,7 +26,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)
|
||||
{
|
||||
|
|
@ -78,7 +80,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
|||
_logger.LogInformation("Clearing entry");
|
||||
_text = null;
|
||||
_tooltip = null;
|
||||
_color = default;
|
||||
_colors = default;
|
||||
|
||||
_entry.Value.Shown = false;
|
||||
}
|
||||
|
|
@ -123,7 +125,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
|||
|
||||
string text;
|
||||
string tooltip;
|
||||
StatusColorId color;
|
||||
Colors colors;
|
||||
if (_apiController.IsConnected)
|
||||
{
|
||||
var pairCount = _pairManager.GetVisibleUserCount();
|
||||
|
|
@ -145,41 +147,60 @@ public sealed class DtrEntry : IDisposable, IHostedService
|
|||
}
|
||||
|
||||
tooltip = $"Mare Synchronos: Connected{Environment.NewLine}----------{Environment.NewLine}{string.Join(Environment.NewLine, visiblePairs)}";
|
||||
color = StatusColorId.PairsInRange;
|
||||
colors = _configService.Current.DtrColorsPairsInRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltip = "Mare Synchronos: Connected";
|
||||
color = default;
|
||||
colors = _configService.Current.DtrColorsDefault;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
text = "\uE044 \uE04C";
|
||||
tooltip = "Mare Synchronos: 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;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue