init 2
This commit is contained in:
@@ -10,13 +10,16 @@ using LightlessSync.Services.ServerConfiguration;
|
||||
using LightlessSync.UI.Style;
|
||||
using LightlessSync.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
|
||||
namespace LightlessSync.UI.Handlers;
|
||||
|
||||
public class IdDisplayHandler
|
||||
{
|
||||
private readonly LightlessConfigService _lightlessConfigService;
|
||||
private readonly PlayerPerformanceConfigService _playerPerformanceConfigService;
|
||||
private readonly LightlessMediator _mediator;
|
||||
private readonly ServerConfigurationManager _serverManager;
|
||||
private readonly Dictionary<string, bool> _showIdForEntry = new(StringComparer.Ordinal);
|
||||
@@ -30,11 +33,16 @@ public class IdDisplayHandler
|
||||
private Vector4 _currentBg = new(0.15f, 0.15f, 0.15f, 1f);
|
||||
private float _highlightBoost;
|
||||
|
||||
public IdDisplayHandler(LightlessMediator mediator, ServerConfigurationManager serverManager, LightlessConfigService lightlessConfigService)
|
||||
public IdDisplayHandler(
|
||||
LightlessMediator mediator,
|
||||
ServerConfigurationManager serverManager,
|
||||
LightlessConfigService lightlessConfigService,
|
||||
PlayerPerformanceConfigService playerPerformanceConfigService)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_serverManager = serverManager;
|
||||
_lightlessConfigService = lightlessConfigService;
|
||||
_playerPerformanceConfigService = playerPerformanceConfigService;
|
||||
}
|
||||
|
||||
public void DrawGroupText(string id, GroupFullInfoDto group, float textPosX, Func<float> editBoxWidth)
|
||||
@@ -48,6 +56,13 @@ public class IdDisplayHandler
|
||||
using (ImRaii.PushFont(UiBuilder.MonoFont, textIsUid))
|
||||
ImGui.TextUnformatted(playerText);
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.SetTooltip("Left click to switch between ID display and alias"
|
||||
+ Environment.NewLine + "Right click to edit notes for this syncshell"
|
||||
+ Environment.NewLine + "Middle Mouse Button to open syncshell profile in a separate window");
|
||||
}
|
||||
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Left))
|
||||
{
|
||||
var prevState = textIsUid;
|
||||
@@ -73,6 +88,11 @@ public class IdDisplayHandler
|
||||
_editEntry = group.GID;
|
||||
_editIsUid = false;
|
||||
}
|
||||
|
||||
if (ImGui.IsItemClicked(ImGuiMouseButton.Middle))
|
||||
{
|
||||
_mediator.Publish(new GroupProfileOpenStandaloneMessage(group));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -97,10 +117,14 @@ public class IdDisplayHandler
|
||||
{
|
||||
ImGui.SameLine(textPosX);
|
||||
(bool textIsUid, string playerText) = GetPlayerText(pair);
|
||||
var compactPerformanceText = BuildCompactPerformanceUsageText(pair);
|
||||
|
||||
if (!string.Equals(_editEntry, pair.UserData.UID, StringComparison.Ordinal))
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
var rowStart = ImGui.GetCursorScreenPos();
|
||||
var rowWidth = MathF.Max(editBoxWidth.Invoke(), 0f);
|
||||
var rowRightLimit = rowStart.X + rowWidth;
|
||||
|
||||
var font = textIsUid ? UiBuilder.MonoFont : ImGui.GetFont();
|
||||
|
||||
@@ -125,7 +149,6 @@ public class IdDisplayHandler
|
||||
? SeStringUtils.BuildFormattedPlayerName(playerText, textColor, glowColor)
|
||||
: SeStringUtils.BuildPlain(playerText);
|
||||
|
||||
var rowStart = ImGui.GetCursorScreenPos();
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
bool useHighlight = false;
|
||||
float highlightPadX = 0f;
|
||||
@@ -200,6 +223,8 @@ public class IdDisplayHandler
|
||||
drawList.ChannelsMerge();
|
||||
}
|
||||
|
||||
var nameRectMin = ImGui.GetItemRectMin();
|
||||
var nameRectMax = ImGui.GetItemRectMax();
|
||||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
if (!string.Equals(_lastMouseOverUid, id))
|
||||
@@ -261,12 +286,43 @@ public class IdDisplayHandler
|
||||
{
|
||||
_mediator.Publish(new ProfileOpenStandaloneMessage(pair));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(compactPerformanceText))
|
||||
{
|
||||
ImGui.SameLine();
|
||||
|
||||
const float compactFontScale = 0.85f;
|
||||
ImGui.SetWindowFontScale(compactFontScale);
|
||||
var compactHeight = ImGui.GetTextLineHeight();
|
||||
var nameHeight = nameRectMax.Y - nameRectMin.Y;
|
||||
var targetPos = ImGui.GetCursorScreenPos();
|
||||
var availableWidth = MathF.Max(rowRightLimit - targetPos.X, 0f);
|
||||
var centeredY = nameRectMin.Y + MathF.Max((nameHeight - compactHeight) * 0.5f, 0f);
|
||||
float verticalOffset = 1f * ImGuiHelpers.GlobalScale;
|
||||
centeredY += verticalOffset;
|
||||
ImGui.SetCursorScreenPos(new Vector2(targetPos.X, centeredY));
|
||||
|
||||
var performanceText = string.Empty;
|
||||
var wasTruncated = false;
|
||||
if (availableWidth > 0f)
|
||||
{
|
||||
performanceText = TruncateTextToWidth(compactPerformanceText, availableWidth, out wasTruncated);
|
||||
}
|
||||
|
||||
ImGui.TextDisabled(performanceText);
|
||||
ImGui.SetWindowFontScale(1f);
|
||||
|
||||
if (wasTruncated && ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.SetTooltip(compactPerformanceText);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.AlignTextToFramePadding();
|
||||
|
||||
ImGui.SetNextItemWidth(editBoxWidth.Invoke());
|
||||
ImGui.SetNextItemWidth(MathF.Max(editBoxWidth.Invoke(), 0f));
|
||||
if (ImGui.InputTextWithHint("##" + pair.UserData.UID, "Nick/Notes", ref _editComment, 255, ImGuiInputTextFlags.EnterReturnsTrue))
|
||||
{
|
||||
_serverManager.SetNoteForUid(pair.UserData.UID, _editComment);
|
||||
@@ -346,6 +402,57 @@ public class IdDisplayHandler
|
||||
return (textIsUid, playerText!);
|
||||
}
|
||||
|
||||
private string? BuildCompactPerformanceUsageText(Pair pair)
|
||||
{
|
||||
var config = _playerPerformanceConfigService.Current;
|
||||
if (!config.ShowPerformanceIndicator || !config.ShowPerformanceUsageNextToName)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var vramBytes = pair.LastAppliedApproximateEffectiveVRAMBytes >= 0
|
||||
? pair.LastAppliedApproximateEffectiveVRAMBytes
|
||||
: pair.LastAppliedApproximateVRAMBytes;
|
||||
var triangleCount = pair.LastAppliedDataTris;
|
||||
if (vramBytes < 0 && triangleCount < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var segments = new List<string>(2);
|
||||
if (vramBytes >= 0)
|
||||
{
|
||||
segments.Add(UiSharedService.ByteToString(vramBytes));
|
||||
}
|
||||
|
||||
if (triangleCount >= 0)
|
||||
{
|
||||
segments.Add(FormatTriangleCount(triangleCount));
|
||||
}
|
||||
|
||||
return segments.Count == 0 ? null : string.Join(" / ", segments);
|
||||
}
|
||||
|
||||
private static string FormatTriangleCount(long triangleCount)
|
||||
{
|
||||
if (triangleCount < 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
if (triangleCount >= 1_000_000)
|
||||
{
|
||||
return FormattableString.Invariant($"{triangleCount / 1_000_000d:0.#}m tris");
|
||||
}
|
||||
|
||||
if (triangleCount >= 1_000)
|
||||
{
|
||||
return FormattableString.Invariant($"{triangleCount / 1_000d:0.#}k tris");
|
||||
}
|
||||
|
||||
return $"{triangleCount} tris";
|
||||
}
|
||||
|
||||
internal void Clear()
|
||||
{
|
||||
_editEntry = string.Empty;
|
||||
@@ -370,4 +477,52 @@ public class IdDisplayHandler
|
||||
|
||||
return showidInsteadOfName;
|
||||
}
|
||||
}
|
||||
|
||||
private static string TruncateTextToWidth(string text, float maxWidth, out bool wasTruncated)
|
||||
{
|
||||
wasTruncated = false;
|
||||
if (string.IsNullOrEmpty(text) || maxWidth <= 0f)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var fullWidth = ImGui.CalcTextSize(text).X;
|
||||
if (fullWidth <= maxWidth)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
wasTruncated = true;
|
||||
|
||||
const string Ellipsis = "...";
|
||||
var ellipsisWidth = ImGui.CalcTextSize(Ellipsis).X;
|
||||
if (ellipsisWidth >= maxWidth)
|
||||
{
|
||||
return Ellipsis;
|
||||
}
|
||||
|
||||
var builder = new StringBuilder(text.Length);
|
||||
var remainingWidth = maxWidth - ellipsisWidth;
|
||||
|
||||
foreach (var rune in text.EnumerateRunes())
|
||||
{
|
||||
var runeText = rune.ToString();
|
||||
var runeWidth = ImGui.CalcTextSize(runeText).X;
|
||||
if (runeWidth > remainingWidth)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
builder.Append(runeText);
|
||||
remainingWidth -= runeWidth;
|
||||
}
|
||||
|
||||
if (builder.Length == 0)
|
||||
{
|
||||
return Ellipsis;
|
||||
}
|
||||
|
||||
builder.Append(Ellipsis);
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user