Added smoothing on the download bar, reducing jitter.
This commit is contained in:
@@ -17,6 +17,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
private readonly LightlessConfigService _configService;
|
private readonly LightlessConfigService _configService;
|
||||||
private readonly ConcurrentDictionary<GameObjectHandler, Dictionary<string, FileDownloadStatus>> _currentDownloads = new();
|
private readonly ConcurrentDictionary<GameObjectHandler, Dictionary<string, FileDownloadStatus>> _currentDownloads = new();
|
||||||
|
private readonly Dictionary<GameObjectHandler, Vector2> _smoothed = [];
|
||||||
private readonly DalamudUtilService _dalamudUtilService;
|
private readonly DalamudUtilService _dalamudUtilService;
|
||||||
private readonly FileUploadManager _fileTransferManager;
|
private readonly FileUploadManager _fileTransferManager;
|
||||||
private readonly UiSharedService _uiShared;
|
private readonly UiSharedService _uiShared;
|
||||||
@@ -195,8 +196,19 @@ public class DownloadUi : WindowMediatorSubscriberBase
|
|||||||
|
|
||||||
foreach (var transfer in _currentDownloads.ToList())
|
foreach (var transfer in _currentDownloads.ToList())
|
||||||
{
|
{
|
||||||
var screenPos = _dalamudUtilService.WorldToScreen(transfer.Key.GetGameObject());
|
var transferKey = transfer.Key;
|
||||||
if (screenPos == Vector2.Zero) continue;
|
var rawPos = _dalamudUtilService.WorldToScreen(transferKey.GetGameObject());
|
||||||
|
|
||||||
|
//If RawPos is zero, remove it from smoothed dictionary
|
||||||
|
if (rawPos == Vector2.Zero)
|
||||||
|
{
|
||||||
|
_smoothed.Remove(transferKey);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Smoothing out the movement and fix jitter around the position.
|
||||||
|
Vector2 screenPos = _smoothed.TryGetValue(transferKey, out var lastPos) ? (rawPos - lastPos).Length() < 4f ? lastPos : rawPos : rawPos;
|
||||||
|
_smoothed[transferKey] = screenPos;
|
||||||
|
|
||||||
var totalBytes = transfer.Value.Sum(c => c.Value.TotalBytes);
|
var totalBytes = transfer.Value.Sum(c => c.Value.TotalBytes);
|
||||||
var transferredBytes = transfer.Value.Sum(c => c.Value.TransferredBytes);
|
var transferredBytes = transfer.Value.Sum(c => c.Value.TransferredBytes);
|
||||||
|
|||||||
Reference in New Issue
Block a user