From 523dfc7295ae2bbc378fb2b08efb24994de58b95 Mon Sep 17 00:00:00 2001 From: CakeAndBanana Date: Wed, 10 Sep 2025 06:08:02 +0200 Subject: [PATCH] Added the treshhold information in compactUI to show in the UID header. --- LightlessSync/UI/CompactUI.cs | 48 ++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/LightlessSync/UI/CompactUI.cs b/LightlessSync/UI/CompactUI.cs index 6c81f9a..82e0a02 100644 --- a/LightlessSync/UI/CompactUI.cs +++ b/LightlessSync/UI/CompactUI.cs @@ -3,6 +3,7 @@ using Dalamud.Interface; using Dalamud.Interface.Utility; using Dalamud.Interface.Utility.Raii; using Dalamud.Utility; +using LightlessSync.API.Data.Enum; using LightlessSync.API.Data.Extensions; using LightlessSync.API.Dto.Group; using LightlessSync.Interop.Ipc; @@ -15,6 +16,7 @@ using LightlessSync.Services.Mediator; using LightlessSync.Services.ServerConfiguration; using LightlessSync.UI.Components; using LightlessSync.UI.Handlers; +using LightlessSync.Utils; using LightlessSync.WebAPI; using LightlessSync.WebAPI.Files; using LightlessSync.WebAPI.Files.Models; @@ -30,11 +32,13 @@ namespace LightlessSync.UI; public class CompactUi : WindowMediatorSubscriberBase { + private readonly CharacterAnalyzer _characterAnalyzer; private readonly ApiController _apiController; private readonly LightlessConfigService _configService; private readonly ConcurrentDictionary> _currentDownloads = new(); private readonly DrawEntityFactory _drawEntityFactory; private readonly FileUploadManager _fileTransferManager; + private readonly PlayerPerformanceConfigService _playerPerformanceConfig; private readonly PairManager _pairManager; private readonly SelectTagForPairUi _selectTagForPairUi; private readonly SelectTagForSyncshellUi _selectTagForSyncshellUi; @@ -48,6 +52,7 @@ public class CompactUi : WindowMediatorSubscriberBase private readonly TagHandler _tagHandler; private readonly UiSharedService _uiSharedService; private List _drawFolders; + private Dictionary>? _cachedAnalysis; private Pair? _lastAddedUser; private string _lastAddedUserComment = string.Empty; private Vector2 _lastPosition = Vector2.One; @@ -60,10 +65,10 @@ public class CompactUi : WindowMediatorSubscriberBase public CompactUi(ILogger logger, UiSharedService uiShared, LightlessConfigService configService, ApiController apiController, PairManager pairManager, ServerConfigurationManager serverManager, LightlessMediator mediator, FileUploadManager fileTransferManager, - TagHandler tagHandler, DrawEntityFactory drawEntityFactory, + TagHandler tagHandler, DrawEntityFactory drawEntityFactory, SelectTagForPairUi selectTagForPairUi, SelectPairForTagUi selectPairForTagUi, RenamePairTagUi renameTagUi, SelectTagForSyncshellUi selectTagForSyncshellUi, SelectSyncshellForTagUi selectSyncshellForTagUi, RenameSyncshellTagUi renameSyncshellTagUi, - PerformanceCollectorService performanceCollectorService, IpcManager ipcManager) + PerformanceCollectorService performanceCollectorService, IpcManager ipcManager, CharacterAnalyzer characterAnalyzer, PlayerPerformanceConfigService playerPerformanceConfig) : base(logger, mediator, "###LightlessSyncMainUI", performanceCollectorService) { _uiSharedService = uiShared; @@ -145,6 +150,8 @@ public class CompactUi : WindowMediatorSubscriberBase MinimumSize = new Vector2(375, 400), MaximumSize = new Vector2(375, 2000), }; + _characterAnalyzer = characterAnalyzer; + _playerPerformanceConfig = playerPerformanceConfig; } protected override void DrawInternal() @@ -407,11 +414,45 @@ public class CompactUi : WindowMediatorSubscriberBase { var uidText = GetUidText(); + //Getting information of character and triangles threshold to show overlimit status in UID bar. + _cachedAnalysis = _characterAnalyzer.LastAnalysis.DeepClone(); + var groupedfiles = _cachedAnalysis.First().Value.Select(v => v.Value).GroupBy(f => f.FileType, StringComparer.Ordinal) + .OrderBy(k => k.Key, StringComparer.Ordinal).ToList(); + var actualTriCount = _cachedAnalysis.First().Value.Sum(f => f.Value.Triangles); + var isOverTriHold = actualTriCount > (_playerPerformanceConfig.Current.TrisWarningThresholdThousands * 1000); + using (_uiSharedService.UidFont.Push()) { var uidTextSize = ImGui.CalcTextSize(uidText); ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X) / 2 - (uidTextSize.X / 2)); ImGui.TextColored(GetUidColor(), uidText); + + if (groupedfiles != null) + { + //Checking of VRAM threshhold + var actualVramUsage = groupedfiles.SingleOrDefault(v => string.Equals(v.Key, "tex", StringComparison.Ordinal)).Sum(f => f.OriginalSize); + var isOverVRAMUsage = _playerPerformanceConfig.Current.VRAMSizeWarningThresholdMiB * 1024 * 1024 < actualVramUsage; + + if (isOverTriHold || isOverVRAMUsage) + { + ImGui.SameLine(); + _uiSharedService.IconText(FontAwesomeIcon.ExclamationTriangle, UIColors.Get("LightlessYellow")); + string warningMessage = ""; + if (isOverTriHold) + { + warningMessage += $"You exceed your own triangles threshold by " + + $"{actualTriCount - _playerPerformanceConfig.Current.TrisWarningThresholdThousands * 1000} triangles."; + warningMessage += Environment.NewLine; + + } + if (isOverVRAMUsage) + { + warningMessage += $"You exceed your own VRAM threshold by " + + $"{UiSharedService.ByteToString(actualVramUsage - (_playerPerformanceConfig.Current.VRAMSizeWarningThresholdMiB * 1024 * 1024))}."; + } + UiSharedService.AttachToolTip(warningMessage); + } + } } if (_apiController.ServerState is ServerState.Connected) @@ -420,18 +461,17 @@ public class CompactUi : WindowMediatorSubscriberBase { ImGui.SetClipboardText(_apiController.DisplayName); } - UiSharedService.AttachToolTip("Click to copy"); if (!string.Equals(_apiController.DisplayName, _apiController.UID, StringComparison.Ordinal)) { var origTextSize = ImGui.CalcTextSize(_apiController.UID); ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X) / 2 - (origTextSize.X / 2)); ImGui.TextColored(GetUidColor(), _apiController.UID); + UiSharedService.AttachToolTip("Click to copy"); if (ImGui.IsItemClicked()) { ImGui.SetClipboardText(_apiController.UID); } - UiSharedService.AttachToolTip("Click to copy"); } } else