Cleaned up and made both Text and Icon align.
This commit is contained in:
@@ -6,7 +6,6 @@ using FFXIVClientStructs.FFXIV.Client.System.Framework;
|
|||||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||||
using FFXIVClientStructs.FFXIV.Component.GUI;
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
||||||
using LightlessSync.LightlessConfiguration;
|
using LightlessSync.LightlessConfiguration;
|
||||||
using LightlessSync.LightlessConfiguration.Configurations;
|
|
||||||
using LightlessSync.PlayerData.Pairs;
|
using LightlessSync.PlayerData.Pairs;
|
||||||
using LightlessSync.Services.Mediator;
|
using LightlessSync.Services.Mediator;
|
||||||
using LightlessSync.UI;
|
using LightlessSync.UI;
|
||||||
@@ -43,8 +42,9 @@ public unsafe class NameplateHandler : IMediatorSubscriber
|
|||||||
private readonly int[] _cachedNameplateTextOffsets = new int[AddonNamePlate.NumNamePlateObjects];
|
private readonly int[] _cachedNameplateTextOffsets = new int[AddonNamePlate.NumNamePlateObjects];
|
||||||
|
|
||||||
internal const uint mNameplateNodeIDBase = 0x7D99D500;
|
internal const uint mNameplateNodeIDBase = 0x7D99D500;
|
||||||
private const string DefaultLabelText = "Lightfinder";
|
private const string DefaultLabelText = "LightFinder";
|
||||||
private const SeIconChar DefaultIcon = SeIconChar.LinkMarker;
|
private const SeIconChar DefaultIcon = SeIconChar.LinkMarker;
|
||||||
|
private const int ContainerOffsetX = 50;
|
||||||
private static readonly string DefaultIconGlyph = SeIconCharExtensions.ToIconString(DefaultIcon);
|
private static readonly string DefaultIconGlyph = SeIconCharExtensions.ToIconString(DefaultIcon);
|
||||||
|
|
||||||
private volatile HashSet<string> _activeBroadcastingCids = [];
|
private volatile HashSet<string> _activeBroadcastingCids = [];
|
||||||
@@ -266,11 +266,21 @@ public unsafe class NameplateHandler : IMediatorSubscriber
|
|||||||
var scaleMultiplier = System.Math.Clamp(config.LightfinderLabelScale, 0.5f, 2.0f);
|
var scaleMultiplier = System.Math.Clamp(config.LightfinderLabelScale, 0.5f, 2.0f);
|
||||||
var baseScale = config.LightfinderLabelUseIcon ? 1.0f : 0.5f;
|
var baseScale = config.LightfinderLabelUseIcon ? 1.0f : 0.5f;
|
||||||
var effectiveScale = baseScale * scaleMultiplier;
|
var effectiveScale = baseScale * scaleMultiplier;
|
||||||
var nodeWidth = (int)System.Math.Round(AtkNodeHelpers.DefaultTextNodeWidth * effectiveScale);
|
var labelContent = config.LightfinderLabelUseIcon
|
||||||
var nodeHeight = (int)System.Math.Round(AtkNodeHelpers.DefaultTextNodeHeight * effectiveScale);
|
? NormalizeIconGlyph(config.LightfinderLabelIconGlyph)
|
||||||
|
: DefaultLabelText;
|
||||||
|
|
||||||
int positionX = 58;
|
pNode->FontType = config.LightfinderLabelUseIcon ? FontType.Axis : FontType.MiedingerMed;
|
||||||
AlignmentType alignment = AlignmentType.Bottom;
|
pNode->AtkResNode.SetScale(effectiveScale, effectiveScale);
|
||||||
|
pNode->SetText(labelContent);
|
||||||
|
var nodeWidth = (int)pNode->AtkResNode.GetWidth();
|
||||||
|
if (nodeWidth <= 0)
|
||||||
|
nodeWidth = (int)System.Math.Round(AtkNodeHelpers.DefaultTextNodeWidth * effectiveScale);
|
||||||
|
var nodeHeight = (int)System.Math.Round(AtkNodeHelpers.DefaultTextNodeHeight * effectiveScale);
|
||||||
|
var baseFontSize = config.LightfinderLabelUseIcon ? 36f : 24f;
|
||||||
|
var computedFontSize = (int)System.Math.Round(baseFontSize * scaleMultiplier);
|
||||||
|
pNode->FontSize = (byte)System.Math.Clamp(computedFontSize, 1, 255);
|
||||||
|
AlignmentType alignment;
|
||||||
|
|
||||||
var textScaleY = nameText->AtkResNode.ScaleY;
|
var textScaleY = nameText->AtkResNode.ScaleY;
|
||||||
if (textScaleY <= 0f)
|
if (textScaleY <= 0f)
|
||||||
@@ -349,49 +359,50 @@ public unsafe class NameplateHandler : IMediatorSubscriber
|
|||||||
{
|
{
|
||||||
hasValidOffset = false;
|
hasValidOffset = false;
|
||||||
}
|
}
|
||||||
|
int positionX;
|
||||||
|
|
||||||
if (config.LightfinderAutoAlign && nameContainer != null && hasValidOffset)
|
if (config.LightfinderAutoAlign && nameContainer != null && hasValidOffset)
|
||||||
{
|
{
|
||||||
var nameplateWidth = (int)nameContainer->Width;
|
var nameplateWidth = (int)nameContainer->Width;
|
||||||
|
|
||||||
int labelWidth;
|
if (!config.LightfinderLabelUseIcon && nodeWidth > nameplateWidth)
|
||||||
if (config.LightfinderLabelUseIcon)
|
nodeWidth = nameplateWidth;
|
||||||
{
|
|
||||||
var iconSize = (int)System.Math.Round(config.LightfinderLabelUseIcon ? 36f : 24f * scaleMultiplier);
|
if (!config.LightfinderLabelUseIcon)
|
||||||
labelWidth = iconSize;
|
pNode->AtkResNode.Width = (ushort)nodeWidth;
|
||||||
}
|
|
||||||
else
|
int leftPos = nameplateWidth / 8;
|
||||||
{
|
int rightPos = nameplateWidth - nodeWidth - (nameplateWidth / 8);
|
||||||
labelWidth = (int)System.Math.Round(AtkNodeHelpers.DefaultTextNodeWidth * effectiveScale);
|
int centrePos = (nameplateWidth - nodeWidth) / 2;
|
||||||
}
|
int staticMargin = 24;
|
||||||
|
int calcMargin = (int)(nameplateWidth * 0.15f);
|
||||||
|
|
||||||
switch (config.LabelAlignment)
|
switch (config.LabelAlignment)
|
||||||
{
|
{
|
||||||
case LabelAlignment.Left:
|
case LabelAlignment.Left:
|
||||||
positionX = nameplateWidth / 2 - textWidth / 2;
|
positionX = config.LightfinderLabelUseIcon ? leftPos + staticMargin : calcMargin;
|
||||||
break;
|
alignment = AlignmentType.BottomLeft;
|
||||||
case LabelAlignment.Center:
|
|
||||||
positionX = nameplateWidth / 2 - labelWidth / 2;
|
|
||||||
break;
|
break;
|
||||||
case LabelAlignment.Right:
|
case LabelAlignment.Right:
|
||||||
positionX = nameplateWidth / 2 + textWidth / 2 - labelWidth;
|
positionX = config.LightfinderLabelUseIcon ? rightPos - staticMargin : nameplateWidth - nodeWidth + calcMargin;
|
||||||
|
alignment = AlignmentType.BottomRight;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
positionX = config.LightfinderLabelUseIcon ? centrePos : centrePos + calcMargin;
|
||||||
|
alignment = AlignmentType.Bottom;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
alignment = AlignmentType.BottomLeft;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
positionX = 58 + config.LightfinderLabelOffsetX;
|
||||||
alignment = AlignmentType.Bottom;
|
alignment = AlignmentType.Bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
positionX += config.LightfinderLabelOffsetX;
|
|
||||||
positionY += config.LightfinderLabelOffsetY;
|
positionY += config.LightfinderLabelOffsetY;
|
||||||
|
|
||||||
alignment = (AlignmentType)System.Math.Clamp((int)alignment, 0, 8);
|
alignment = (AlignmentType)System.Math.Clamp((int)alignment, 0, 8);
|
||||||
pNode->AtkResNode.SetPositionShort((short)System.Math.Clamp(positionX, short.MinValue, short.MaxValue), (short)System.Math.Clamp(positionY, short.MinValue, short.MaxValue));
|
|
||||||
pNode->AtkResNode.SetUseDepthBasedPriority(true);
|
pNode->AtkResNode.SetUseDepthBasedPriority(true);
|
||||||
pNode->AtkResNode.SetScale(effectiveScale, effectiveScale);
|
|
||||||
|
|
||||||
pNode->AtkResNode.Color.A = 255;
|
pNode->AtkResNode.Color.A = 255;
|
||||||
|
|
||||||
@@ -405,24 +416,25 @@ public unsafe class NameplateHandler : IMediatorSubscriber
|
|||||||
pNode->EdgeColor.B = (byte)(edgeColor.Z * 255);
|
pNode->EdgeColor.B = (byte)(edgeColor.Z * 255);
|
||||||
pNode->EdgeColor.A = (byte)(edgeColor.W * 255);
|
pNode->EdgeColor.A = (byte)(edgeColor.W * 255);
|
||||||
|
|
||||||
var baseFontSize = config.LightfinderLabelUseIcon ? 36f : 24f;
|
|
||||||
var computedFontSize = (int)System.Math.Round(baseFontSize * scaleMultiplier);
|
if(!config.LightfinderLabelUseIcon)
|
||||||
pNode->FontSize = (byte)System.Math.Clamp(computedFontSize, 1, 255);
|
{
|
||||||
pNode->AlignmentType = alignment;
|
pNode->AlignmentType = AlignmentType.Bottom;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pNode->AlignmentType = alignment;
|
||||||
|
}
|
||||||
|
pNode->AtkResNode.SetPositionShort(
|
||||||
|
(short)System.Math.Clamp(positionX, short.MinValue, short.MaxValue),
|
||||||
|
(short)System.Math.Clamp(positionY, short.MinValue, short.MaxValue)
|
||||||
|
);
|
||||||
var computedLineSpacing = (int)System.Math.Round(24 * scaleMultiplier);
|
var computedLineSpacing = (int)System.Math.Round(24 * scaleMultiplier);
|
||||||
pNode->LineSpacing = (byte)System.Math.Clamp(computedLineSpacing, 0, byte.MaxValue);
|
pNode->LineSpacing = (byte)System.Math.Clamp(computedLineSpacing, 0, byte.MaxValue);
|
||||||
pNode->CharSpacing = 1;
|
pNode->CharSpacing = 1;
|
||||||
|
|
||||||
pNode->TextFlags = config.LightfinderLabelUseIcon
|
pNode->TextFlags = config.LightfinderLabelUseIcon
|
||||||
? TextFlags.Edge | TextFlags.Glare | TextFlags.AutoAdjustNodeSize
|
? TextFlags.Edge | TextFlags.Glare | TextFlags.AutoAdjustNodeSize
|
||||||
: TextFlags.Edge | TextFlags.Glare;
|
: TextFlags.Edge | TextFlags.Glare;
|
||||||
|
|
||||||
var labelContent = config.LightfinderLabelUseIcon
|
|
||||||
? NormalizeIconGlyph(config.LightfinderLabelIconGlyph)
|
|
||||||
: DefaultLabelText;
|
|
||||||
|
|
||||||
pNode->FontType = config.LightfinderLabelUseIcon ? FontType.Axis : FontType.MiedingerMed;
|
|
||||||
pNode->SetText(labelContent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,4 +570,12 @@ public unsafe class NameplateHandler : IMediatorSubscriber
|
|||||||
|
|
||||||
FlagRefresh();
|
FlagRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearNameplateCaches()
|
||||||
|
{
|
||||||
|
System.Array.Clear(_cachedNameplateTextWidths, 0, _cachedNameplateTextWidths.Length);
|
||||||
|
System.Array.Clear(_cachedNameplateTextHeights, 0, _cachedNameplateTextHeights.Length);
|
||||||
|
System.Array.Clear(_cachedNameplateContainerHeights, 0, _cachedNameplateContainerHeights.Length);
|
||||||
|
System.Array.Fill(_cachedNameplateTextOffsets, int.MinValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1071,6 +1071,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
_configService.Current.LightfinderLabelOffsetX = (short)offsetX;
|
_configService.Current.LightfinderLabelOffsetX = (short)offsetX;
|
||||||
_configService.Save();
|
_configService.Save();
|
||||||
|
_nameplateHandler.ClearNameplateCaches();
|
||||||
_nameplateHandler.FlagRefresh();
|
_nameplateHandler.FlagRefresh();
|
||||||
_nameplateService.RequestRedraw();
|
_nameplateService.RequestRedraw();
|
||||||
}
|
}
|
||||||
@@ -1081,6 +1082,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
_configService.Current.LightfinderLabelOffsetY = (short)offsetY;
|
_configService.Current.LightfinderLabelOffsetY = (short)offsetY;
|
||||||
_configService.Save();
|
_configService.Save();
|
||||||
|
_nameplateHandler.ClearNameplateCaches();
|
||||||
_nameplateHandler.FlagRefresh();
|
_nameplateHandler.FlagRefresh();
|
||||||
_nameplateService.RequestRedraw();
|
_nameplateService.RequestRedraw();
|
||||||
}
|
}
|
||||||
@@ -1091,6 +1093,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
_configService.Current.LightfinderLabelScale = labelScale;
|
_configService.Current.LightfinderLabelScale = labelScale;
|
||||||
_configService.Save();
|
_configService.Save();
|
||||||
|
_nameplateHandler.ClearNameplateCaches();
|
||||||
_nameplateHandler.FlagRefresh();
|
_nameplateHandler.FlagRefresh();
|
||||||
_nameplateService.RequestRedraw();
|
_nameplateService.RequestRedraw();
|
||||||
}
|
}
|
||||||
@@ -1101,6 +1104,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
_configService.Current.LightfinderAutoAlign = autoAlign;
|
_configService.Current.LightfinderAutoAlign = autoAlign;
|
||||||
_configService.Save();
|
_configService.Save();
|
||||||
|
_nameplateHandler.ClearNameplateCaches();
|
||||||
_nameplateHandler.FlagRefresh();
|
_nameplateHandler.FlagRefresh();
|
||||||
_nameplateService.RequestRedraw();
|
_nameplateService.RequestRedraw();
|
||||||
}
|
}
|
||||||
@@ -1149,6 +1153,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
_configService.Current.LightfinderLabelShowOwn = showOwn;
|
_configService.Current.LightfinderLabelShowOwn = showOwn;
|
||||||
_configService.Save();
|
_configService.Save();
|
||||||
|
_nameplateHandler.ClearNameplateCaches();
|
||||||
_nameplateHandler.FlagRefresh();
|
_nameplateHandler.FlagRefresh();
|
||||||
_nameplateService.RequestRedraw();
|
_nameplateService.RequestRedraw();
|
||||||
}
|
}
|
||||||
@@ -1159,6 +1164,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
_configService.Current.LightfinderLabelShowPaired = showPaired;
|
_configService.Current.LightfinderLabelShowPaired = showPaired;
|
||||||
_configService.Save();
|
_configService.Save();
|
||||||
|
_nameplateHandler.ClearNameplateCaches();
|
||||||
_nameplateHandler.FlagRefresh();
|
_nameplateHandler.FlagRefresh();
|
||||||
_nameplateService.RequestRedraw();
|
_nameplateService.RequestRedraw();
|
||||||
}
|
}
|
||||||
@@ -1169,6 +1175,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
_configService.Current.LightfinderLabelUseIcon = useIcon;
|
_configService.Current.LightfinderLabelUseIcon = useIcon;
|
||||||
_configService.Save();
|
_configService.Save();
|
||||||
|
_nameplateHandler.ClearNameplateCaches();
|
||||||
_nameplateHandler.FlagRefresh();
|
_nameplateHandler.FlagRefresh();
|
||||||
_nameplateService.RequestRedraw();
|
_nameplateService.RequestRedraw();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user