This commit is contained in:
2025-10-06 03:47:24 +09:00
parent 39784a1fea
commit c35650438c
22 changed files with 1480 additions and 184 deletions

View File

@@ -1,4 +1,5 @@
using Dalamud.Bindings.ImGui;
using System;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
@@ -376,7 +377,7 @@ public class CompactUi : WindowMediatorSubscriberBase
private void DrawTransfers()
{
var currentUploads = _fileTransferManager.CurrentUploads.ToList();
var currentUploads = _fileTransferManager.GetCurrentUploadsSnapshot();
ImGui.AlignTextToFramePadding();
_uiSharedService.IconText(FontAwesomeIcon.Upload);
ImGui.SameLine(35 * ImGuiHelpers.GlobalScale);
@@ -386,10 +387,12 @@ public class CompactUi : WindowMediatorSubscriberBase
var totalUploads = currentUploads.Count;
var doneUploads = currentUploads.Count(c => c.IsTransferred);
var activeUploads = currentUploads.Count(c => !c.IsTransferred);
var uploadSlotLimit = Math.Clamp(_configService.Current.ParallelUploads, 1, 8);
var totalUploaded = currentUploads.Sum(c => c.Transferred);
var totalToUpload = currentUploads.Sum(c => c.Total);
ImGui.TextUnformatted($"{doneUploads}/{totalUploads}");
ImGui.TextUnformatted($"{doneUploads}/{totalUploads} (slots {activeUploads}/{uploadSlotLimit})");
var uploadText = $"({UiSharedService.ByteToString(totalUploaded)}/{UiSharedService.ByteToString(totalToUpload)})";
var textSize = ImGui.CalcTextSize(uploadText);
ImGui.SameLine(_windowContentWidth - textSize.X);
@@ -488,7 +491,7 @@ public class CompactUi : WindowMediatorSubscriberBase
float contentWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
float uidStartX = (contentWidth - uidTextSize.X) / 2f;
float cursorY = ImGui.GetCursorPosY();
float cursorY = ImGui.GetCursorPosY();
if (_configService.Current.BroadcastEnabled && _apiController.IsConnected)
{
@@ -619,7 +622,7 @@ public class CompactUi : WindowMediatorSubscriberBase
ImGui.SameLine();
ImGui.SetCursorPosY(cursorY + 15f);
_uiSharedService.IconText(FontAwesomeIcon.ExclamationTriangle, UIColors.Get("LightlessYellow"));
string warningMessage = "";
if (isOverTriHold)
{
@@ -825,7 +828,7 @@ public class CompactUi : WindowMediatorSubscriberBase
.Where(u => FilterGroupUsers(u.Value, group)));
filteredGroupPairs = filteredPairs
.Where(u => FilterGroupUsers( u.Value, group) && FilterOnlineOrPausedSelf(u.Key))
.Where(u => FilterGroupUsers(u.Value, group) && FilterOnlineOrPausedSelf(u.Key))
.OrderByDescending(u => u.Key.IsOnline)
.ThenBy(u =>
{

View File

@@ -1,4 +1,5 @@
using Dalamud.Bindings.ImGui;
using System;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Colors;
using LightlessSync.LightlessConfiguration;
using LightlessSync.PlayerData.Handlers;
@@ -19,14 +20,16 @@ public class DownloadUi : WindowMediatorSubscriberBase
private readonly DalamudUtilService _dalamudUtilService;
private readonly FileUploadManager _fileTransferManager;
private readonly UiSharedService _uiShared;
private readonly PairProcessingLimiter _pairProcessingLimiter;
private readonly ConcurrentDictionary<GameObjectHandler, bool> _uploadingPlayers = new();
public DownloadUi(ILogger<DownloadUi> logger, DalamudUtilService dalamudUtilService, LightlessConfigService configService,
FileUploadManager fileTransferManager, LightlessMediator mediator, UiSharedService uiShared, PerformanceCollectorService performanceCollectorService)
PairProcessingLimiter pairProcessingLimiter, FileUploadManager fileTransferManager, LightlessMediator mediator, UiSharedService uiShared, PerformanceCollectorService performanceCollectorService)
: base(logger, mediator, "Lightless Sync Downloads", performanceCollectorService)
{
_dalamudUtilService = dalamudUtilService;
_configService = configService;
_pairProcessingLimiter = pairProcessingLimiter;
_fileTransferManager = fileTransferManager;
_uiShared = uiShared;
@@ -73,11 +76,25 @@ public class DownloadUi : WindowMediatorSubscriberBase
{
if (_configService.Current.ShowTransferWindow)
{
var limiterSnapshot = _pairProcessingLimiter.GetSnapshot();
if (limiterSnapshot.IsEnabled)
{
var queueColor = limiterSnapshot.Waiting > 0 ? ImGuiColors.DalamudYellow : ImGuiColors.DalamudGrey;
var queueText = $"Pair queue {limiterSnapshot.InFlight}/{limiterSnapshot.Limit}";
queueText += limiterSnapshot.Waiting > 0 ? $" ({limiterSnapshot.Waiting} waiting, {limiterSnapshot.Remaining} free)" : $" ({limiterSnapshot.Remaining} free)";
UiSharedService.DrawOutlinedFont(queueText, queueColor, new Vector4(0, 0, 0, 255), 1);
ImGui.NewLine();
}
else
{
UiSharedService.DrawOutlinedFont("Pair apply limiter disabled", ImGuiColors.DalamudGrey, new Vector4(0, 0, 0, 255), 1);
ImGui.NewLine();
}
try
{
if (_fileTransferManager.CurrentUploads.Any())
if (_fileTransferManager.IsUploading)
{
var currentUploads = _fileTransferManager.CurrentUploads.ToList();
var currentUploads = _fileTransferManager.GetCurrentUploadsSnapshot();
var totalUploads = currentUploads.Count;
var doneUploads = currentUploads.Count(c => c.IsTransferred);
@@ -214,7 +231,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
{
if (_uiShared.EditTrackerPosition) return true;
if (!_configService.Current.ShowTransferWindow && !_configService.Current.ShowTransferBars) return false;
if (!_currentDownloads.Any() && !_fileTransferManager.CurrentUploads.Any() && !_uploadingPlayers.Any()) return false;
if (!_currentDownloads.Any() && !_fileTransferManager.IsUploading && !_uploadingPlayers.Any()) return false;
if (!IsOpen) return false;
return true;
}

View File

@@ -1,4 +1,5 @@
using Dalamud.Bindings.ImGui;
using Dalamud.Game.Text;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Utility;
@@ -10,6 +11,7 @@ using LightlessSync.API.Routes;
using LightlessSync.FileCache;
using LightlessSync.Interop.Ipc;
using LightlessSync.LightlessConfiguration;
using LightlessSync.LightlessConfiguration.Configurations;
using LightlessSync.LightlessConfiguration.Models;
using LightlessSync.PlayerData.Handlers;
using LightlessSync.PlayerData.Pairs;
@@ -17,15 +19,18 @@ using LightlessSync.Services;
using LightlessSync.Services.Mediator;
using LightlessSync.Services.ServerConfiguration;
using LightlessSync.Utils;
using LightlessSync.UtilsEnum.Enum;
using LightlessSync.WebAPI;
using LightlessSync.WebAPI.Files;
using LightlessSync.WebAPI.Files.Models;
using LightlessSync.WebAPI.SignalR.Utils;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Numerics;
@@ -50,10 +55,12 @@ public class SettingsUi : WindowMediatorSubscriberBase
private readonly PairManager _pairManager;
private readonly PerformanceCollectorService _performanceCollector;
private readonly PlayerPerformanceConfigService _playerPerformanceConfigService;
private readonly PairProcessingLimiter _pairProcessingLimiter;
private readonly ServerConfigurationManager _serverConfigurationManager;
private readonly UiSharedService _uiShared;
private readonly IProgress<(int, int, FileCacheEntity)> _validationProgress;
private readonly NameplateService _nameplateService;
private readonly NameplateHandler _nameplateHandler;
private (int, int, FileCacheEntity) _currentProgress;
private bool _deleteAccountPopupModalShown = false;
private bool _deleteFilesPopupModalShown = false;
@@ -63,6 +70,23 @@ public class SettingsUi : WindowMediatorSubscriberBase
private bool _readClearCache = false;
private int _selectedEntry = -1;
private string _uidToAddForIgnore = string.Empty;
private string _lightfinderIconInput = string.Empty;
private bool _lightfinderIconInputInitialized = false;
private int _lightfinderIconPresetIndex = -1;
private static readonly (string Label, SeIconChar Icon)[] LightfinderIconPresets = new[]
{
("Link Marker", SeIconChar.LinkMarker),
("Hyadelyn", SeIconChar.Hyadelyn),
("Gil", SeIconChar.Gil),
("Quest Sync", SeIconChar.QuestSync),
("Glamoured", SeIconChar.Glamoured),
("Glamoured (Dyed)", SeIconChar.GlamouredDyed),
("Auto-Translate Open", SeIconChar.AutoTranslateOpen),
("Auto-Translate Close", SeIconChar.AutoTranslateClose),
("Boxed Star", SeIconChar.BoxedStar),
("Boxed Plus", SeIconChar.BoxedPlus)
};
private CancellationTokenSource? _validationCts;
private Task<List<FileCacheEntity>>? _validationTask;
private bool _wasOpen = false;
@@ -72,6 +96,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
PairManager pairManager,
ServerConfigurationManager serverConfigurationManager,
PlayerPerformanceConfigService playerPerformanceConfigService,
PairProcessingLimiter pairProcessingLimiter,
LightlessMediator mediator, PerformanceCollectorService performanceCollector,
FileUploadManager fileTransferManager,
FileTransferOrchestrator fileTransferOrchestrator,
@@ -79,12 +104,14 @@ public class SettingsUi : WindowMediatorSubscriberBase
FileCompactor fileCompactor, ApiController apiController,
IpcManager ipcManager, CacheMonitor cacheMonitor,
DalamudUtilService dalamudUtilService, HttpClient httpClient,
NameplateService nameplateService) : base(logger, mediator, "Lightless Sync Settings", performanceCollector)
NameplateService nameplateService,
NameplateHandler nameplateHandler) : base(logger, mediator, "Lightless Sync Settings", performanceCollector)
{
_configService = configService;
_pairManager = pairManager;
_serverConfigurationManager = serverConfigurationManager;
_playerPerformanceConfigService = playerPerformanceConfigService;
_pairProcessingLimiter = pairProcessingLimiter;
_performanceCollector = performanceCollector;
_fileTransferManager = fileTransferManager;
_fileTransferOrchestrator = fileTransferOrchestrator;
@@ -97,6 +124,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
_fileCompactor = fileCompactor;
_uiShared = uiShared;
_nameplateService = nameplateService;
_nameplateHandler = nameplateHandler;
AllowClickthrough = false;
AllowPinning = true;
_validationProgress = new Progress<(int, int, FileCacheEntity)>(v => _currentProgress = v);
@@ -218,6 +246,9 @@ public class SettingsUi : WindowMediatorSubscriberBase
ImGuiHelpers.ScaledDummy(5);
int maxParallelDownloads = _configService.Current.ParallelDownloads;
int maxParallelUploads = _configService.Current.ParallelUploads;
int maxPairApplications = _configService.Current.MaxConcurrentPairApplications;
bool limitPairApplications = _configService.Current.EnablePairProcessingLimiter;
bool useAlternativeUpload = _configService.Current.UseAlternativeFileUpload;
int downloadSpeedLimit = _configService.Current.DownloadSpeedLimitInBytes;
@@ -254,7 +285,60 @@ public class SettingsUi : WindowMediatorSubscriberBase
{
_configService.Current.ParallelDownloads = maxParallelDownloads;
_configService.Save();
Mediator.Publish(new DownloadLimitChangedMessage());
}
_uiShared.DrawHelpText("Controls how many download slots can be active at once.");
if (ImGui.SliderInt("Maximum Parallel Uploads", ref maxParallelUploads, 1, 8))
{
_configService.Current.ParallelUploads = maxParallelUploads;
_configService.Save();
}
_uiShared.DrawHelpText("Controls how many uploads can run at once.");
_uiShared.ColoredSeparator(UIColors.Get("LightlessPurple"), 2f);
if (ImGui.Checkbox("Enable Pair Download Limiter", ref limitPairApplications))
{
_configService.Current.EnablePairProcessingLimiter = limitPairApplications;
_configService.Save();
Mediator.Publish(new PairProcessingLimitChangedMessage());
}
_uiShared.DrawHelpText("When enabled we stagger pair downloads to avoid large network and game lag caused by attempting to download everyone at once.");
var limiterDisabledScope = !limitPairApplications;
if (limiterDisabledScope)
{
ImGui.BeginDisabled();
}
if (ImGui.SliderInt("Maximum Concurrent Pair Downloads", ref maxPairApplications, 1, 6))
{
_configService.Current.MaxConcurrentPairApplications = maxPairApplications;
_configService.Save();
Mediator.Publish(new PairProcessingLimitChangedMessage());
}
_uiShared.DrawHelpText("How many pair downloads/applications can run simultaneously when the limit is on.");
if (limiterDisabledScope)
{
ImGui.EndDisabled();
}
var limiterSnapshot = _pairProcessingLimiter.GetSnapshot();
if (limiterSnapshot.IsEnabled)
{
var queueColor = limiterSnapshot.Waiting > 0 ? ImGuiColors.DalamudYellow : ImGuiColors.DalamudGrey;
var queueText = $"Pair queue {limiterSnapshot.InFlight}/{limiterSnapshot.Limit}";
queueText += limiterSnapshot.Waiting > 0 ? $" ({limiterSnapshot.Waiting} waiting, {limiterSnapshot.Remaining} free)" : $" ({limiterSnapshot.Remaining} free)";
ImGui.TextColored(queueColor, queueText);
}
else
{
ImGui.TextColored(ImGuiColors.DalamudGrey, "Pair apply limiter is disabled.");
}
_uiShared.ColoredSeparator(UIColors.Get("LightlessPurple"), 2f);
if (ImGui.Checkbox("Use Alternative Upload Method", ref useAlternativeUpload))
{
@@ -409,25 +493,33 @@ public class SettingsUi : WindowMediatorSubscriberBase
{
if (ApiController.ServerState is ServerState.Connected && ImGui.BeginTabItem("Transfers"))
{
ImGui.TextUnformatted("Uploads");
var uploadsSnapshot = _fileTransferManager.GetCurrentUploadsSnapshot();
var activeUploads = uploadsSnapshot.Count(c => !c.IsTransferred);
var uploadSlotLimit = Math.Clamp(_configService.Current.ParallelUploads, 1, 8);
ImGui.TextUnformatted($"Uploads (slots {activeUploads}/{uploadSlotLimit})");
if (ImGui.BeginTable("UploadsTable", 3))
{
ImGui.TableSetupColumn("File");
ImGui.TableSetupColumn("Uploaded");
ImGui.TableSetupColumn("Size");
ImGui.TableHeadersRow();
foreach (var transfer in _fileTransferManager.CurrentUploads.ToArray())
foreach (var transfer in uploadsSnapshot)
{
var color = UiSharedService.UploadColor((transfer.Transferred, transfer.Total));
var col = ImRaii.PushColor(ImGuiCol.Text, color);
using var col = ImRaii.PushColor(ImGuiCol.Text, color);
ImGui.TableNextColumn();
ImGui.TextUnformatted(transfer.Hash);
if (transfer is UploadFileTransfer uploadTransfer)
{
ImGui.TextUnformatted(uploadTransfer.LocalFile);
}
else
{
ImGui.TextUnformatted(transfer.Hash);
}
ImGui.TableNextColumn();
ImGui.TextUnformatted(UiSharedService.ByteToString(transfer.Transferred));
ImGui.TableNextColumn();
ImGui.TextUnformatted(UiSharedService.ByteToString(transfer.Total));
col.Dispose();
ImGui.TableNextRow();
}
ImGui.EndTable();
@@ -972,6 +1064,191 @@ public class SettingsUi : WindowMediatorSubscriberBase
ImGui.Separator();
if (_uiShared.MediumTreeNode("Lightfinder", UIColors.Get("LightlessPurple")))
{
var offsetX = (int)_configService.Current.LightfinderLabelOffsetX;
if (ImGui.SliderInt("Label Offset X", ref offsetX, -200, 200))
{
_configService.Current.LightfinderLabelOffsetX = (short)offsetX;
_configService.Save();
_nameplateHandler.FlagRefresh();
_nameplateService.RequestRedraw();
}
_uiShared.DrawHelpText("Moves the Lightfinder label horizontally on player nameplates.");
var offsetY = (int)_configService.Current.LightfinderLabelOffsetY;
if (ImGui.SliderInt("Label Offset Y", ref offsetY, -200, 200))
{
_configService.Current.LightfinderLabelOffsetY = (short)offsetY;
_configService.Save();
_nameplateHandler.FlagRefresh();
_nameplateService.RequestRedraw();
}
_uiShared.DrawHelpText("Moves the Lightfinder label vertically on player nameplates.");
var labelScale = _configService.Current.LightfinderLabelScale;
if (ImGui.SliderFloat("Label Size", ref labelScale, 0.5f, 2.0f, "%.2fx"))
{
_configService.Current.LightfinderLabelScale = labelScale;
_configService.Save();
_nameplateHandler.FlagRefresh();
_nameplateService.RequestRedraw();
}
_uiShared.DrawHelpText("Adjusts the Lightfinder label size for both text and icon modes.");
var autoAlign = _configService.Current.LightfinderAutoAlign;
if (ImGui.Checkbox("Automatically align with nameplate", ref autoAlign))
{
_configService.Current.LightfinderAutoAlign = autoAlign;
_configService.Save();
_nameplateHandler.FlagRefresh();
_nameplateService.RequestRedraw();
}
_uiShared.DrawHelpText("Automatically position the label relative to the in-game nameplate. Turn off to rely entirely on manual offsets.");
if (autoAlign)
{
var alignmentOption = _configService.Current.LabelAlignment;
var alignmentLabel = alignmentOption switch
{
LabelAlignment.Left => "Left",
LabelAlignment.Right => "Right",
_ => "Center",
};
if (ImGui.BeginCombo("Horizontal Alignment", alignmentLabel))
{
foreach (LabelAlignment option in Enum.GetValues<LabelAlignment>())
{
var optionLabel = option switch
{
LabelAlignment.Left => "Left",
LabelAlignment.Right => "Right",
_ => "Center",
};
var selected = option == alignmentOption;
if (ImGui.Selectable(optionLabel, selected))
{
_configService.Current.LabelAlignment = option;
_configService.Save();
_nameplateHandler.FlagRefresh();
_nameplateService.RequestRedraw();
}
if (selected)
ImGui.SetItemDefaultFocus();
}
ImGui.EndCombo();
}
}
var useIcon = _configService.Current.LightfinderLabelUseIcon;
if (ImGui.Checkbox("Show icon instead of text", ref useIcon))
{
_configService.Current.LightfinderLabelUseIcon = useIcon;
_configService.Save();
_nameplateHandler.FlagRefresh();
_nameplateService.RequestRedraw();
if (useIcon)
{
RefreshLightfinderIconState();
}
else
{
_lightfinderIconInputInitialized = false;
_lightfinderIconPresetIndex = -1;
}
}
_uiShared.DrawHelpText("Switch between the Lightfinder text label and an icon on nameplates.");
if (useIcon)
{
if (!_lightfinderIconInputInitialized)
{
RefreshLightfinderIconState();
}
var currentPresetLabel = _lightfinderIconPresetIndex >= 0
? $"{GetLightfinderPresetGlyph(_lightfinderIconPresetIndex)} {LightfinderIconPresets[_lightfinderIconPresetIndex].Label}"
: "Custom";
if (ImGui.BeginCombo("Preset Icon", currentPresetLabel))
{
for (int i = 0; i < LightfinderIconPresets.Length; i++)
{
var optionGlyph = GetLightfinderPresetGlyph(i);
var preview = $"{optionGlyph} {LightfinderIconPresets[i].Label}";
var selected = i == _lightfinderIconPresetIndex;
if (ImGui.Selectable(preview, selected))
{
ApplyLightfinderIcon(optionGlyph, i);
}
}
if (ImGui.Selectable("Custom", _lightfinderIconPresetIndex == -1))
{
_lightfinderIconPresetIndex = -1;
}
ImGui.EndCombo();
}
var editorBuffer = _lightfinderIconInput;
if (ImGui.InputText("Icon Glyph", ref editorBuffer, 16))
{
_lightfinderIconInput = editorBuffer;
_lightfinderIconPresetIndex = -1;
}
if (ImGui.Button("Apply Icon"))
{
var normalized = NameplateHandler.NormalizeIconGlyph(_lightfinderIconInput);
ApplyLightfinderIcon(normalized, _lightfinderIconPresetIndex);
}
ImGui.SameLine();
if (ImGui.Button("Reset Icon"))
{
var defaultGlyph = NameplateHandler.NormalizeIconGlyph(null);
var defaultIndex = -1;
for (int i = 0; i < LightfinderIconPresets.Length; i++)
{
if (string.Equals(GetLightfinderPresetGlyph(i), defaultGlyph, StringComparison.Ordinal))
{
defaultIndex = i;
break;
}
}
if (defaultIndex < 0)
{
defaultIndex = 0;
}
ApplyLightfinderIcon(GetLightfinderPresetGlyph(defaultIndex), defaultIndex);
}
var previewGlyph = NameplateHandler.NormalizeIconGlyph(_lightfinderIconInput);
ImGui.SameLine();
ImGui.AlignTextToFramePadding();
ImGui.Text($"Preview: {previewGlyph}");
_uiShared.DrawHelpText("Enter a hex code (e.g. E0BB), pick a preset, or paste an icon character directly.");
}
else
{
_lightfinderIconInputInitialized = false;
_lightfinderIconPresetIndex = -1;
}
_uiShared.ColoredSeparator(UIColors.Get("LightlessPurple"), 1.5f);
ImGui.TreePop();
}
ImGui.Separator();
if (_uiShared.MediumTreeNode("Colors", UIColors.Get("LightlessPurple")))
{
ImGui.TextUnformatted("UI Theme Colors");
@@ -2216,6 +2493,39 @@ public class SettingsUi : WindowMediatorSubscriberBase
return (true, failedConversions.Count != 0, sb.ToString());
}
private static string GetLightfinderPresetGlyph(int index)
{
return NameplateHandler.NormalizeIconGlyph(SeIconCharExtensions.ToIconString(LightfinderIconPresets[index].Icon));
}
private void RefreshLightfinderIconState()
{
var normalized = NameplateHandler.NormalizeIconGlyph(_configService.Current.LightfinderLabelIconGlyph);
_lightfinderIconInput = NameplateHandler.ToIconEditorString(normalized);
_lightfinderIconInputInitialized = true;
_lightfinderIconPresetIndex = -1;
for (int i = 0; i < LightfinderIconPresets.Length; i++)
{
if (string.Equals(GetLightfinderPresetGlyph(i), normalized, StringComparison.Ordinal))
{
_lightfinderIconPresetIndex = i;
break;
}
}
}
private void ApplyLightfinderIcon(string normalizedGlyph, int presetIndex)
{
_configService.Current.LightfinderLabelIconGlyph = normalizedGlyph;
_configService.Save();
_nameplateHandler.FlagRefresh();
_nameplateService.RequestRedraw();
_lightfinderIconInput = NameplateHandler.ToIconEditorString(normalizedGlyph);
_lightfinderIconPresetIndex = presetIndex;
_lightfinderIconInputInitialized = true;
}
private void DrawSettingsContent()
{
if (_apiController.ServerState is ServerState.Connected)