Compactor multi-threaded, fixed many of IDE warnings

This commit is contained in:
cake
2025-11-14 23:56:39 +01:00
parent 3f1037dade
commit c3597b5789
14 changed files with 361 additions and 321 deletions

View File

@@ -22,7 +22,7 @@ namespace LightlessSync.UI
private readonly UiSharedService _uiSharedService;
private readonly BroadcastScannerService _broadcastScannerService;
private IReadOnlyList<GroupFullInfoDto> _allSyncshells;
private IReadOnlyList<GroupFullInfoDto> _allSyncshells = Array.Empty<GroupFullInfoDto>();
private string _userUid = string.Empty;
private readonly List<(string Label, string? GID, bool IsAvailable)> _syncshellOptions = new();

View File

@@ -13,13 +13,15 @@ internal sealed partial class CharaDataHubUi
AccessTypeDto.AllPairs => "All Pairs",
AccessTypeDto.ClosePairs => "Direct Pairs",
AccessTypeDto.Individuals => "Specified",
AccessTypeDto.Public => "Everyone"
AccessTypeDto.Public => "Everyone",
_ => throw new NotSupportedException()
};
private static string GetShareTypeString(ShareTypeDto dto) => dto switch
{
ShareTypeDto.Private => "Code Only",
ShareTypeDto.Shared => "Shared"
ShareTypeDto.Shared => "Shared",
_ => throw new NotSupportedException()
};
private static string GetWorldDataTooltipText(PoseEntryExtended poseEntry)
@@ -31,7 +33,7 @@ internal sealed partial class CharaDataHubUi
private void GposeMetaInfoAction(Action<CharaDataMetaInfoExtendedDto?> gposeActionDraw, string actionDescription, CharaDataMetaInfoExtendedDto? dto, bool hasValidGposeTarget, bool isSpawning)
{
StringBuilder sb = new StringBuilder();
StringBuilder sb = new();
sb.AppendLine(actionDescription);
bool isDisabled = false;

View File

@@ -29,6 +29,7 @@ using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.InteropServices;
namespace LightlessSync.UI;
@@ -105,7 +106,7 @@ public class CompactUi : WindowMediatorSubscriberBase
_renamePairTagUi = renameTagUi;
_ipcManager = ipcManager;
_broadcastService = broadcastService;
_tabMenu = new TopTabMenu(Mediator, _apiController, _pairManager, _uiSharedService, pairRequestService, dalamudUtilService, lightlessNotificationService);
_tabMenu = new TopTabMenu(Mediator, _apiController, _pairManager, _uiSharedService, pairRequestService);
AllowPinning = true;
AllowClickthrough = false;
@@ -285,11 +286,10 @@ public class CompactUi : WindowMediatorSubscriberBase
private void DrawPairs()
{
var ySize = _transferPartHeight == 0
float ySize = Math.Abs(_transferPartHeight) < 0.0001f
? 1
: (ImGui.GetWindowContentRegionMax().Y - ImGui.GetWindowContentRegionMin().Y
+ ImGui.GetTextLineHeight() - ImGui.GetStyle().WindowPadding.Y - ImGui.GetStyle().WindowBorderSize) - _transferPartHeight - ImGui.GetCursorPosY();
: ((ImGui.GetWindowContentRegionMax().Y - ImGui.GetWindowContentRegionMin().Y
+ ImGui.GetTextLineHeight() - ImGui.GetStyle().WindowPadding.Y - ImGui.GetStyle().WindowBorderSize) - _transferPartHeight - ImGui.GetCursorPosY());
ImGui.BeginChild("list", new Vector2(_windowContentWidth, ySize), border: false);
foreach (var item in _drawFolders)
@@ -470,6 +470,7 @@ public class CompactUi : WindowMediatorSubscriberBase
return new DownloadSummary(totalFiles, transferredFiles, transferredBytes, totalBytes);
}
[StructLayout(LayoutKind.Auto)]
private readonly record struct DownloadSummary(int TotalFiles, int TransferredFiles, long TransferredBytes, long TotalBytes)
{
public bool HasDownloads => TotalFiles > 0 || TotalBytes > 0;

View File

@@ -297,7 +297,6 @@ public class EditProfileUi : WindowMediatorSubscriberBase
ImGui.Dummy(new Vector2(5));
var font = UiBuilder.MonoFont;
var playerUID = _apiController.UID;
var playerDisplay = _apiController.DisplayName;
var previewTextColor = textEnabled ? textColor : Vector4.One;

View File

@@ -154,13 +154,11 @@ public class IdDisplayHandler
Vector2 itemMin;
Vector2 itemMax;
Vector2 textSize;
using (ImRaii.PushFont(font, textIsUid))
{
SeStringUtils.RenderSeStringWithHitbox(seString, rowStart, font, pair.UserData.UID);
itemMin = ImGui.GetItemRectMin();
itemMax = ImGui.GetItemRectMax();
//textSize = itemMax - itemMin;
}
if (useHighlight)
@@ -202,7 +200,7 @@ public class IdDisplayHandler
if (ImGui.IsItemHovered())
{
if (!string.Equals(_lastMouseOverUid, id))
if (!string.Equals(_lastMouseOverUid, id, StringComparison.Ordinal))
{
_popupTime = DateTime.UtcNow.AddSeconds(_lightlessConfigService.Current.ProfileDelay);
}
@@ -223,7 +221,7 @@ public class IdDisplayHandler
}
else
{
if (string.Equals(_lastMouseOverUid, id))
if (string.Equals(_lastMouseOverUid, id, StringComparison.Ordinal))
{
_mediator.Publish(new ProfilePopoutToggle(Pair: null));
_lastMouseOverUid = string.Empty;

View File

@@ -139,7 +139,7 @@ public class StandaloneProfileUi : WindowMediatorSubscriberBase
}
}
if (Pair.UserPair.Groups.Any())
if (Pair.UserPair?.Groups?.Count > 0)
{
ImGui.TextUnformatted("Paired through Syncshells:");
foreach (var group in Pair.UserPair.Groups)

View File

@@ -222,6 +222,13 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
{
ImGui.Dummy(new Vector2(5));
if (_profileData == null)
{
UiSharedService.ColorTextWrapped("Failed to load profile data.", ImGuiColors.DalamudRed);
ImGui.TreePop();
return;
}
if (!_profileImage.SequenceEqual(_profileData.ImageData.Value))
{
_profileImage = _profileData.ImageData.Value;
@@ -379,7 +386,7 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
UiSharedService.AttachToolTip("Clears your profile description text");
ImGui.Separator();
ImGui.TextUnformatted($"Profile Options:");
var isNsfw = _profileData.IsNsfw;
var isNsfw = _profileData?.IsNsfw ?? false;
if (ImGui.Checkbox("Profile is NSFW", ref isNsfw))
{
_ = _apiController.GroupSetProfile(new GroupProfileDto(new GroupData(GroupFullInfo.Group.AliasOrGID), Description: null, Tags: null, PictureBase64: null, BannerBase64: null, IsNsfw: isNsfw, IsDisabled: null));

View File

@@ -9,7 +9,6 @@ using LightlessSync.LightlessConfiguration.Models;
using LightlessSync.PlayerData.Pairs;
using LightlessSync.Services;
using LightlessSync.Services.Mediator;
using LightlessSync.Utils;
using LightlessSync.WebAPI;
using System.Numerics;
@@ -24,27 +23,21 @@ public class TopTabMenu
private readonly PairManager _pairManager;
private readonly PairRequestService _pairRequestService;
private readonly DalamudUtilService _dalamudUtilService;
private readonly HashSet<string> _pendingPairRequestActions = new(StringComparer.Ordinal);
private bool _pairRequestsExpanded; // useless for now
private int _lastRequestCount;
private readonly UiSharedService _uiSharedService;
private readonly NotificationService _lightlessNotificationService;
private string _filter = string.Empty;
private int _globalControlCountdown = 0;
private float _pairRequestsHeight = 150f;
private string _pairToAdd = string.Empty;
private SelectedTab _selectedTab = SelectedTab.None;
public TopTabMenu(LightlessMediator lightlessMediator, ApiController apiController, PairManager pairManager, UiSharedService uiSharedService, PairRequestService pairRequestService, DalamudUtilService dalamudUtilService, NotificationService lightlessNotificationService)
public TopTabMenu(LightlessMediator lightlessMediator, ApiController apiController, PairManager pairManager, UiSharedService uiSharedService, PairRequestService pairRequestService)
{
_lightlessMediator = lightlessMediator;
_apiController = apiController;
_pairManager = pairManager;
_pairRequestService = pairRequestService;
_dalamudUtilService = dalamudUtilService;
_uiSharedService = uiSharedService;
_lightlessNotificationService = lightlessNotificationService;
}
private enum SelectedTab
@@ -70,13 +63,17 @@ public class TopTabMenu
_filter = value;
}
}
private SelectedTab TabSelection
private SelectedTab GetTabSelection()
{
get => _selectedTab; set
{
_selectedTab = value;
}
return _selectedTab;
}
private void SetTabSelection(SelectedTab value)
{
_selectedTab = value;
}
public void Draw()
{
var availableWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
@@ -85,7 +82,7 @@ public class TopTabMenu
var buttonY = _uiSharedService.GetIconButtonSize(FontAwesomeIcon.Pause).Y;
var buttonSize = new Vector2(buttonX, buttonY);
var drawList = ImGui.GetWindowDrawList();
var underlineColor = ImGui.GetColorU32(UIColors.Get("LightlessPurpleActive")); // ImGui.GetColorU32(ImGuiCol.Separator);
var underlineColor = ImGui.GetColorU32(UIColors.Get("LightlessPurpleActive"));
var btncolor = ImRaii.PushColor(ImGuiCol.Button, ImGui.ColorConvertFloat4ToU32(new(0, 0, 0, 0)));
ImGuiHelpers.ScaledDummy(spacing.Y / 2f);
@@ -95,11 +92,11 @@ public class TopTabMenu
var x = ImGui.GetCursorScreenPos();
if (ImGui.Button(FontAwesomeIcon.User.ToIconString(), buttonSize))
{
TabSelection = TabSelection == SelectedTab.Individual ? SelectedTab.None : SelectedTab.Individual;
SetTabSelection(GetTabSelection() == SelectedTab.Individual ? SelectedTab.None : SelectedTab.Individual);
}
ImGui.SameLine();
var xAfter = ImGui.GetCursorScreenPos();
if (TabSelection == SelectedTab.Individual)
if (GetTabSelection() == SelectedTab.Individual)
drawList.AddLine(x with { Y = x.Y + buttonSize.Y + spacing.Y },
xAfter with { Y = xAfter.Y + buttonSize.Y + spacing.Y, X = xAfter.X - spacing.X },
underlineColor, 2);
@@ -111,11 +108,11 @@ public class TopTabMenu
var x = ImGui.GetCursorScreenPos();
if (ImGui.Button(FontAwesomeIcon.Users.ToIconString(), buttonSize))
{
TabSelection = TabSelection == SelectedTab.Syncshell ? SelectedTab.None : SelectedTab.Syncshell;
SetTabSelection(GetTabSelection() == SelectedTab.Syncshell ? SelectedTab.None : SelectedTab.Syncshell);
}
ImGui.SameLine();
var xAfter = ImGui.GetCursorScreenPos();
if (TabSelection == SelectedTab.Syncshell)
if (GetTabSelection() == SelectedTab.Syncshell)
drawList.AddLine(x with { Y = x.Y + buttonSize.Y + spacing.Y },
xAfter with { Y = xAfter.Y + buttonSize.Y + spacing.Y, X = xAfter.X - spacing.X },
underlineColor, 2);
@@ -128,12 +125,12 @@ public class TopTabMenu
var x = ImGui.GetCursorScreenPos();
if (ImGui.Button(FontAwesomeIcon.Compass.ToIconString(), buttonSize))
{
TabSelection = TabSelection == SelectedTab.Lightfinder ? SelectedTab.None : SelectedTab.Lightfinder;
SetTabSelection(GetTabSelection() == SelectedTab.Lightfinder ? SelectedTab.None : SelectedTab.Lightfinder);
}
ImGui.SameLine();
var xAfter = ImGui.GetCursorScreenPos();
if (TabSelection == SelectedTab.Lightfinder)
if (GetTabSelection() == SelectedTab.Lightfinder)
drawList.AddLine(x with { Y = x.Y + buttonSize.Y + spacing.Y },
xAfter with { Y = xAfter.Y + buttonSize.Y + spacing.Y, X = xAfter.X - spacing.X },
underlineColor, 2);
@@ -146,12 +143,12 @@ public class TopTabMenu
var x = ImGui.GetCursorScreenPos();
if (ImGui.Button(FontAwesomeIcon.UserCog.ToIconString(), buttonSize))
{
TabSelection = TabSelection == SelectedTab.UserConfig ? SelectedTab.None : SelectedTab.UserConfig;
SetTabSelection(GetTabSelection() == SelectedTab.UserConfig ? SelectedTab.None : SelectedTab.UserConfig);
}
ImGui.SameLine();
var xAfter = ImGui.GetCursorScreenPos();
if (TabSelection == SelectedTab.UserConfig)
if (GetTabSelection() == SelectedTab.UserConfig)
drawList.AddLine(x with { Y = x.Y + buttonSize.Y + spacing.Y },
xAfter with { Y = xAfter.Y + buttonSize.Y + spacing.Y, X = xAfter.X - spacing.X },
underlineColor, 2);
@@ -161,7 +158,7 @@ public class TopTabMenu
ImGui.SameLine();
using (ImRaii.PushFont(UiBuilder.IconFont))
{
var x = ImGui.GetCursorScreenPos();
ImGui.GetCursorScreenPos();
if (ImGui.Button(FontAwesomeIcon.Cog.ToIconString(), buttonSize))
{
_lightlessMediator.Publish(new UiToggleMessage(typeof(SettingsUi)));
@@ -175,26 +172,26 @@ public class TopTabMenu
ImGuiHelpers.ScaledDummy(spacing);
if (TabSelection == SelectedTab.Individual)
if (GetTabSelection() == SelectedTab.Individual)
{
DrawAddPair(availableWidth, spacing.X);
DrawGlobalIndividualButtons(availableWidth, spacing.X);
}
else if (TabSelection == SelectedTab.Syncshell)
else if (GetTabSelection() == SelectedTab.Syncshell)
{
DrawSyncshellMenu(availableWidth, spacing.X);
DrawGlobalSyncshellButtons(availableWidth, spacing.X);
}
else if (TabSelection == SelectedTab.Lightfinder)
else if (GetTabSelection() == SelectedTab.Lightfinder)
{
DrawLightfinderMenu(availableWidth, spacing.X);
}
else if (TabSelection == SelectedTab.UserConfig)
else if (GetTabSelection() == SelectedTab.UserConfig)
{
DrawUserConfig(availableWidth, spacing.X);
}
if (TabSelection != SelectedTab.None) ImGuiHelpers.ScaledDummy(3f);
if (GetTabSelection() != SelectedTab.None) ImGuiHelpers.ScaledDummy(3f);
DrawIncomingPairRequests(availableWidth);
@@ -227,17 +224,9 @@ public class TopTabMenu
var count = requests.Count;
if (count == 0)
{
_pairRequestsExpanded = false;
_lastRequestCount = 0;
return;
}
if (count > _lastRequestCount)
{
_pairRequestsExpanded = true;
}
_lastRequestCount = count;
var label = $"Incoming Pair Requests - {count}##IncomingPairRequestsHeader";
using (ImRaii.PushColor(ImGuiCol.Header, UIColors.Get("LightlessPurple")))
@@ -245,16 +234,12 @@ public class TopTabMenu
using (ImRaii.PushColor(ImGuiCol.HeaderActive, UIColors.Get("LightlessPurple")))
{
bool open = ImGui.CollapsingHeader(label, ImGuiTreeNodeFlags.DefaultOpen);
_pairRequestsExpanded = open;
if (ImGui.IsItemHovered())
UiSharedService.AttachToolTip("Expand to view incoming pair requests.");
if (open)
{
var lineHeight = ImGui.GetTextLineHeightWithSpacing();
//var desiredHeight = Math.Clamp(count * lineHeight * 2f, 130f * ImGuiHelpers.GlobalScale, 185f * ImGuiHelpers.GlobalScale); we use resize bar instead
ImGui.SetCursorPosX(ImGui.GetCursorPosX() - 2f);
using (ImRaii.PushColor(ImGuiCol.ChildBg, UIColors.Get("LightlessPurple")))
@@ -300,7 +285,6 @@ public class TopTabMenu
{
float playerColWidth = 207f * ImGuiHelpers.GlobalScale;
float receivedColWidth = 73f * ImGuiHelpers.GlobalScale;
float actionsColWidth = 50f * ImGuiHelpers.GlobalScale;
ImGui.Separator();
ImGui.TextUnformatted("Player");
@@ -385,7 +369,6 @@ public class TopTabMenu
try
{
var myCidHash = (await _dalamudUtilService.GetCIDAsync().ConfigureAwait(false)).ToString().GetHash256();
await _apiController.TryPairWithContentId(request.HashedCid).ConfigureAwait(false);
_pairRequestService.RemoveRequest(request.HashedCid);

View File

@@ -25,7 +25,6 @@ public class UpdateNotesUi : WindowMediatorSubscriberBase
private ChangelogFile _changelog = new();
private CreditsFile _credits = new();
private bool _scrollToTop;
private int _selectedTab;
private bool _hasInitializedCollapsingHeaders;
private struct Particle
@@ -160,7 +159,7 @@ public class UpdateNotesUi : WindowMediatorSubscriberBase
DrawParticleEffects(headerStart, extendedParticleSize);
}
private void DrawGradientBackground(Vector2 headerStart, Vector2 headerEnd)
private static void DrawGradientBackground(Vector2 headerStart, Vector2 headerEnd)
{
var drawList = ImGui.GetWindowDrawList();
@@ -188,7 +187,7 @@ public class UpdateNotesUi : WindowMediatorSubscriberBase
}
}
private void DrawBottomGradient(Vector2 headerStart, Vector2 headerEnd, float width)
private static void DrawBottomGradient(Vector2 headerStart, Vector2 headerEnd, float width)
{
var drawList = ImGui.GetWindowDrawList();
var gradientHeight = 60f;
@@ -513,7 +512,6 @@ public class UpdateNotesUi : WindowMediatorSubscriberBase
{
if (changelogTab)
{
_selectedTab = 0;
DrawChangelog();
}
}
@@ -524,7 +522,6 @@ public class UpdateNotesUi : WindowMediatorSubscriberBase
{
if (creditsTab)
{
_selectedTab = 1;
DrawCredits();
}
}
@@ -558,7 +555,7 @@ public class UpdateNotesUi : WindowMediatorSubscriberBase
}
}
private void DrawCreditCategory(CreditCategory category)
private static void DrawCreditCategory(CreditCategory category)
{
DrawFeatureSection(category.Category, UIColors.Get("LightlessBlue"));