Added the old system of WQPD back. added more options of it.

This commit is contained in:
cake
2025-12-05 04:43:30 +01:00
parent 1c36db97dc
commit 69b504c42f
3 changed files with 390 additions and 252 deletions

View File

@@ -1,4 +1,4 @@
using Dalamud.Bindings.ImGui;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Colors;
using LightlessSync.LightlessConfiguration;
using LightlessSync.LightlessConfiguration.Models;
@@ -154,102 +154,228 @@ public class DownloadUi : WindowMediatorSubscriberBase
if (_configService.Current.ShowTransferBars)
{
const int dlBarBorder = 3;
const float rounding = 6f;
var shadowOffset = new Vector2(2, 2);
DrawTransferBar();
}
}
foreach (var transfer in _currentDownloads.ToList())
private void DrawTransferBar()
{
const int dlBarBorder = 3;
const float rounding = 6f;
var shadowOffset = new Vector2(2, 2);
foreach (var transfer in _currentDownloads.ToList())
{
var transferKey = transfer.Key;
var rawPos = _dalamudUtilService.WorldToScreen(transferKey.GetGameObject());
// If RawPos is zero, remove it from smoothed dictionary
if (rawPos == Vector2.Zero)
{
var transferKey = transfer.Key;
var rawPos = _dalamudUtilService.WorldToScreen(transferKey.GetGameObject());
_smoothed.Remove(transferKey);
continue;
}
//If RawPos is zero, remove it from smoothed dictionary
if (rawPos == Vector2.Zero)
// 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 transferredBytes = transfer.Value.Sum(c => c.Value.TransferredBytes);
// Per-player state counts
var dlSlot = 0;
var dlQueue = 0;
var dlProg = 0;
var dlDecomp = 0;
foreach (var entry in transfer.Value)
{
var fileStatus = entry.Value;
switch (fileStatus.DownloadStatus)
{
_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 transferredBytes = transfer.Value.Sum(c => c.Value.TransferredBytes);
var maxDlText = $"{UiSharedService.ByteToString(totalBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
var textSize = _configService.Current.TransferBarsShowText
? ImGui.CalcTextSize(maxDlText)
: new Vector2(10, 10);
int dlBarHeight = _configService.Current.TransferBarsHeight > ((int)textSize.Y + 5)
? _configService.Current.TransferBarsHeight
: (int)textSize.Y + 5;
int dlBarWidth = _configService.Current.TransferBarsWidth > ((int)textSize.X + 10)
? _configService.Current.TransferBarsWidth
: (int)textSize.X + 10;
var dlBarStart = new Vector2(screenPos.X - dlBarWidth / 2f, screenPos.Y - dlBarHeight / 2f);
var dlBarEnd = new Vector2(screenPos.X + dlBarWidth / 2f, screenPos.Y + dlBarHeight / 2f);
// Precompute rects
var outerStart = new Vector2(dlBarStart.X - dlBarBorder - 1, dlBarStart.Y - dlBarBorder - 1);
var outerEnd = new Vector2(dlBarEnd.X + dlBarBorder + 1, dlBarEnd.Y + dlBarBorder + 1);
var borderStart = new Vector2(dlBarStart.X - dlBarBorder, dlBarStart.Y - dlBarBorder);
var borderEnd = new Vector2(dlBarEnd.X + dlBarBorder, dlBarEnd.Y + dlBarBorder);
var drawList = ImGui.GetBackgroundDrawList();
//Shadow, background, border, bar background
drawList.AddRectFilled(outerStart + shadowOffset, outerEnd + shadowOffset, UiSharedService.Color(0, 0, 0, 100 / 2), rounding + 2);
drawList.AddRectFilled(outerStart, outerEnd, UiSharedService.Color(0, 0, 0, 100), rounding + 2);
drawList.AddRectFilled(borderStart, borderEnd, UiSharedService.Color(ImGuiColors.DalamudGrey), rounding);
drawList.AddRectFilled(dlBarStart, dlBarEnd, UiSharedService.Color(0, 0, 0, 100), rounding);
var dlProgressPercent = transferredBytes / (double)totalBytes;
var progressEndX = dlBarStart.X + (float)(dlProgressPercent * dlBarWidth);
var progressEnd = new Vector2(progressEndX, dlBarEnd.Y);
drawList.AddRectFilled(dlBarStart, progressEnd, UiSharedService.Color(UIColors.Get("LightlessPurple")), rounding);
if (_configService.Current.TransferBarsShowText)
{
var downloadText = $"{UiSharedService.ByteToString(transferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
UiSharedService.DrawOutlinedFont(drawList, downloadText, screenPos with { X = screenPos.X - textSize.X / 2f - 1, Y = screenPos.Y - textSize.Y / 2f - 1 },
UiSharedService.Color(ImGuiColors.DalamudGrey),
UiSharedService.Color(0, 0, 0, 100),
1
);
case DownloadStatus.WaitingForSlot:
dlSlot++;
break;
case DownloadStatus.WaitingForQueue:
dlQueue++;
break;
case DownloadStatus.Downloading:
dlProg++;
break;
case DownloadStatus.Decompressing:
dlDecomp++;
break;
}
}
if (_configService.Current.ShowUploading)
string statusText;
if (dlProg > 0)
{
foreach (var player in _uploadingPlayers.Select(p => p.Key).ToList())
statusText = "Downloading";
}
else if (dlDecomp > 0 || (totalBytes > 0 && transferredBytes >= totalBytes))
{
statusText = "Decompressing";
}
else if (dlQueue > 0)
{
statusText = "Waiting for queue";
}
else if (dlSlot > 0)
{
statusText = "Waiting for slot";
}
else
{
statusText = "Waiting";
}
var hasValidSize = totalBytes > 0;
var maxDlText = $"{UiSharedService.ByteToString(totalBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
var textSize = _configService.Current.TransferBarsShowText
? ImGui.CalcTextSize(maxDlText)
: new Vector2(10, 10);
int dlBarHeight = _configService.Current.TransferBarsHeight > ((int)textSize.Y + 5)
? _configService.Current.TransferBarsHeight
: (int)textSize.Y + 5;
int dlBarWidth = _configService.Current.TransferBarsWidth > ((int)textSize.X + 10)
? _configService.Current.TransferBarsWidth
: (int)textSize.X + 10;
var dlBarStart = new Vector2(screenPos.X - dlBarWidth / 2f, screenPos.Y - dlBarHeight / 2f);
var dlBarEnd = new Vector2(screenPos.X + dlBarWidth / 2f, screenPos.Y + dlBarHeight / 2f);
// Precompute rects
var outerStart = new Vector2(dlBarStart.X - dlBarBorder - 1, dlBarStart.Y - dlBarBorder - 1);
var outerEnd = new Vector2(dlBarEnd.X + dlBarBorder + 1, dlBarEnd.Y + dlBarBorder + 1);
var borderStart = new Vector2(dlBarStart.X - dlBarBorder, dlBarStart.Y - dlBarBorder);
var borderEnd = new Vector2(dlBarEnd.X + dlBarBorder, dlBarEnd.Y + dlBarBorder);
var drawList = ImGui.GetBackgroundDrawList();
drawList.AddRectFilled(
outerStart + shadowOffset,
outerEnd + shadowOffset,
UiSharedService.Color(0, 0, 0, 100 / 2),
rounding + 2
);
drawList.AddRectFilled(
outerStart,
outerEnd,
UiSharedService.Color(0, 0, 0, 100),
rounding + 2
);
drawList.AddRectFilled(
borderStart,
borderEnd,
UiSharedService.Color(ImGuiColors.DalamudGrey),
rounding
);
drawList.AddRectFilled(
dlBarStart,
dlBarEnd,
UiSharedService.Color(0, 0, 0, 100),
rounding
);
bool showFill = false;
double fillPercent = 0.0;
if (hasValidSize)
{
if (dlProg > 0)
{
var screenPos = _dalamudUtilService.WorldToScreen(player.GetGameObject());
if (screenPos == Vector2.Zero) continue;
fillPercent = transferredBytes / (double)totalBytes;
showFill = true;
}
else if (dlDecomp > 0 || transferredBytes >= totalBytes)
{
fillPercent = 1.0;
showFill = true;
}
}
try
if (showFill)
{
if (fillPercent < 0) fillPercent = 0;
if (fillPercent > 1) fillPercent = 1;
var progressEndX = dlBarStart.X + (float)(fillPercent * dlBarWidth);
var progressEnd = new Vector2(progressEndX, dlBarEnd.Y);
drawList.AddRectFilled(
dlBarStart,
progressEnd,
UiSharedService.Color(UIColors.Get("LightlessPurple")),
rounding
);
}
if (_configService.Current.TransferBarsShowText)
{
string downloadText;
if (dlProg > 0 && hasValidSize)
{
downloadText =
$"{statusText} {UiSharedService.ByteToString(transferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
}
else if ((dlDecomp > 0 || transferredBytes >= totalBytes) && hasValidSize)
{
downloadText = "Decompressing";
}
else
{
// Waiting states
downloadText = statusText;
}
var actualTextSize = ImGui.CalcTextSize(downloadText);
UiSharedService.DrawOutlinedFont(
drawList,
downloadText,
screenPos with
{
using var _ = _uiShared.UidFont.Push();
var uploadText = "Uploading";
X = screenPos.X - actualTextSize.X / 2f - 1,
Y = screenPos.Y - actualTextSize.Y / 2f - 1
},
UiSharedService.Color(ImGuiColors.DalamudGrey),
UiSharedService.Color(0, 0, 0, 100),
1
);
}
}
var textSize = ImGui.CalcTextSize(uploadText);
if (_configService.Current.ShowUploading)
{
foreach (var player in _uploadingPlayers.Select(p => p.Key).ToList())
{
var screenPos = _dalamudUtilService.WorldToScreen(player.GetGameObject());
if (screenPos == Vector2.Zero) continue;
var drawList = ImGui.GetBackgroundDrawList();
UiSharedService.DrawOutlinedFont(drawList, uploadText, screenPos with { X = screenPos.X - textSize.X / 2f - 1, Y = screenPos.Y - textSize.Y / 2f - 1 },
UiSharedService.Color(ImGuiColors.DalamudYellow),
UiSharedService.Color(0, 0, 0, 100),
2
);
}
catch
{
_logger.LogDebug("Error drawing upload progress");
}
try
{
using var _ = _uiShared.UidFont.Push();
var uploadText = "Uploading";
var textSize = ImGui.CalcTextSize(uploadText);
var drawList = ImGui.GetBackgroundDrawList();
UiSharedService.DrawOutlinedFont(drawList, uploadText, screenPos with { X = screenPos.X - textSize.X / 2f - 1, Y = screenPos.Y - textSize.Y / 2f - 1 },
UiSharedService.Color(ImGuiColors.DalamudYellow),
UiSharedService.Color(0, 0, 0, 100),
2
);
}
catch
{
_logger.LogDebug("Error drawing upload progress");
}
}
}
@@ -257,7 +383,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
private void DrawDownloadSummaryBox()
{
if (!_currentDownloads.Any())
if (_currentDownloads.IsEmpty)
return;
const float padding = 6f;
@@ -271,10 +397,24 @@ public class DownloadUi : WindowMediatorSubscriberBase
long totalBytes = 0;
long transferredBytes = 0;
// (Name, files done, files total, bytes done, bytes total, speed)
var perPlayer = new List<(string Name, int TransferredFiles, int TotalFiles, long TransferredBytes, long TotalBytes, double SpeedBytesPerSecond)>();
var totalDlSlot = 0;
var totalDlQueue = 0;
var totalDlProg = 0;
var totalDlDecomp = 0;
foreach (var transfer in _currentDownloads.ToList())
var perPlayer = new List<(
string Name,
int TransferredFiles,
int TotalFiles,
long TransferredBytes,
long TotalBytes,
double SpeedBytesPerSecond,
int DlSlot,
int DlQueue,
int DlProg,
int DlDecomp)>();
foreach (var transfer in _currentDownloads)
{
var handler = transfer.Key;
var statuses = transfer.Value.Values;
@@ -289,6 +429,36 @@ public class DownloadUi : WindowMediatorSubscriberBase
totalBytes += playerTotalBytes;
transferredBytes += playerTransferredBytes;
// per-player W/Q/P/D
var playerDlSlot = 0;
var playerDlQueue = 0;
var playerDlProg = 0;
var playerDlDecomp = 0;
foreach (var entry in transfer.Value)
{
var fileStatus = entry.Value;
switch (fileStatus.DownloadStatus)
{
case DownloadStatus.WaitingForSlot:
playerDlSlot++;
totalDlSlot++;
break;
case DownloadStatus.WaitingForQueue:
playerDlQueue++;
totalDlQueue++;
break;
case DownloadStatus.Downloading:
playerDlProg++;
totalDlProg++;
break;
case DownloadStatus.Decompressing:
playerDlDecomp++;
totalDlDecomp++;
break;
}
}
double speed = 0;
if (playerTotalBytes > 0)
{
@@ -307,7 +477,11 @@ public class DownloadUi : WindowMediatorSubscriberBase
playerTotalFiles,
playerTransferredBytes,
playerTotalBytes,
speed
speed,
playerDlSlot,
playerDlQueue,
playerDlProg,
playerDlDecomp
));
}
@@ -321,7 +495,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
if (totalFiles == 0 || totalBytes == 0)
return;
// max speed for scale (clamped)
// max speed for per-player bar scale (clamped)
double maxSpeed = perPlayer.Count > 0 ? perPlayer.Max(p => p.SpeedBytesPerSecond) : 0;
if (maxSpeed <= 0)
maxSpeed = 1;
@@ -330,8 +504,11 @@ public class DownloadUi : WindowMediatorSubscriberBase
var windowPos = ImGui.GetWindowPos();
// Overall texts
var headerText = $"Downloading {transferredFiles}/{totalFiles} files";
var bytesText = $"{UiSharedService.ByteToString(transferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
var headerText =
$"Downloading {transferredFiles}/{totalFiles} files [W:{totalDlSlot}/Q:{totalDlQueue}/P:{totalDlProg}/D:{totalDlDecomp}]";
var bytesText =
$"{UiSharedService.ByteToString(transferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
var totalSpeed = perPlayer.Sum(p => p.SpeedBytesPerSecond);
var speedText = totalSpeed > 0
@@ -346,19 +523,17 @@ public class DownloadUi : WindowMediatorSubscriberBase
if (bytesSize.X > contentWidth) contentWidth = bytesSize.X;
if (totalSpeedSize.X > contentWidth) contentWidth = totalSpeedSize.X;
foreach (var p in perPlayer)
if (_configService.Current.ShowPlayerLinesTransferWindow)
{
var playerSpeedText = p.SpeedBytesPerSecond > 0
? $"{UiSharedService.ByteToString((long)p.SpeedBytesPerSecond)}/s"
: "-";
foreach (var p in perPlayer)
{
var line =
$"{p.Name} [W:{p.DlSlot}/Q:{p.DlQueue}/P:{p.DlProg}/D:{p.DlDecomp}] {p.TransferredFiles}/{p.TotalFiles}";
var line = $"{p.Name}: {p.TransferredFiles}/{p.TotalFiles} " +
$"({UiSharedService.ByteToString(p.TransferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(p.TotalBytes)}) " +
$"@ {playerSpeedText}";
var lineSize = ImGui.CalcTextSize(line);
if (lineSize.X > contentWidth)
contentWidth = lineSize.X;
var lineSize = ImGui.CalcTextSize(line);
if (lineSize.X > contentWidth)
contentWidth = lineSize.X;
}
}
var lineHeight = ImGui.GetTextLineHeight();
@@ -370,16 +545,29 @@ public class DownloadUi : WindowMediatorSubscriberBase
if (boxWidth < minBoxWidth)
boxWidth = minBoxWidth;
// Box height
float boxHeight = 0;
boxHeight += padding;
boxHeight += globalBarHeight;
boxHeight += padding;
boxHeight += globalBarHeight;
boxHeight += padding;
boxHeight += lineHeight + spacingY;
boxHeight += lineHeight + spacingY;
boxHeight += lineHeight * 1.4f + spacingY;
boxHeight += lineHeight * 1.4f + spacingY;
if (_configService.Current.ShowPlayerLinesTransferWindow)
{
foreach (var p in perPlayer)
{
boxHeight += lineHeight + spacingY;
if (_configService.Current.ShowPlayerSpeedBarsTransferWindow && p.DlProg > 0)
{
boxHeight += perPlayerBarHeight + spacingY;
}
}
}
boxHeight += perPlayer.Count * (lineHeight + perPlayerBarHeight + spacingY * 2);
boxHeight += padding;
var boxMin = windowPos;
@@ -399,25 +587,50 @@ public class DownloadUi : WindowMediatorSubscriberBase
if (progress > 1f) progress = 1f;
drawList.AddRectFilled(barMin, barMax, UiSharedService.Color(40, 40, 40, _transferBoxTransparency), 3f);
drawList.AddRectFilled(barMin, new Vector2(barMin.X + (barMax.X - barMin.X) * progress, barMax.Y), UiSharedService.Color(UIColors.Get("LightlessPurple")), 3f);
drawList.AddRectFilled(
barMin,
new Vector2(barMin.X + (barMax.X - barMin.X) * progress, barMax.Y),
UiSharedService.Color(UIColors.Get("LightlessPurple")),
3f
);
cursor.Y = barMax.Y + padding;
// Header
UiSharedService.DrawOutlinedFont(drawList, headerText, cursor, UiSharedService.Color(ImGuiColors.DalamudWhite), UiSharedService.Color(0, 0, 0, _transferBoxTransparency), 1);
UiSharedService.DrawOutlinedFont(
drawList,
headerText,
cursor,
UiSharedService.Color(ImGuiColors.DalamudWhite),
UiSharedService.Color(0, 0, 0, _transferBoxTransparency),
1
);
cursor.Y += lineHeight + spacingY;
// Bytes
UiSharedService.DrawOutlinedFont(drawList, bytesText, cursor, UiSharedService.Color(ImGuiColors.DalamudWhite), UiSharedService.Color(0, 0, 0, _transferBoxTransparency), 1);
UiSharedService.DrawOutlinedFont(
drawList,
bytesText,
cursor,
UiSharedService.Color(ImGuiColors.DalamudWhite),
UiSharedService.Color(0, 0, 0, _transferBoxTransparency),
1
);
cursor.Y += lineHeight + spacingY;
// Total speed WIP
UiSharedService.DrawOutlinedFont(drawList, speedText, cursor, UiSharedService.Color(UIColors.Get("LightlessPurple")), UiSharedService.Color(0, 0, 0, _transferBoxTransparency), 1);
// Total speed
UiSharedService.DrawOutlinedFont(
drawList,
speedText,
cursor,
UiSharedService.Color(UIColors.Get("LightlessPurple")),
UiSharedService.Color(0, 0, 0, _transferBoxTransparency),
1
);
cursor.Y += lineHeight * 1.4f + spacingY;
if (_configService.Current.ShowPlayerLinesTransferWindow)
{
// Per-player lines
var orderedPlayers = perPlayer.OrderByDescending(p => p.TotalBytes).ToList();
foreach (var p in orderedPlayers)
@@ -426,13 +639,31 @@ public class DownloadUi : WindowMediatorSubscriberBase
? $"{UiSharedService.ByteToString((long)p.SpeedBytesPerSecond)}/s"
: "-";
var line = $"{p.Name}: {p.TransferredFiles}/{p.TotalFiles} " +
$"({UiSharedService.ByteToString(p.TransferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(p.TotalBytes)}) " +
$"@ {playerSpeedText}";
var labelLine =
$"{p.Name} [W:{p.DlSlot}/Q:{p.DlQueue}/P:{p.DlProg}/D:{p.DlDecomp}] {p.TransferredFiles}/{p.TotalFiles}";
if (!_configService.Current.ShowPlayerSpeedBarsTransferWindow || p.DlProg <= 0)
{
var fullLine =
$"{labelLine} " +
$"({UiSharedService.ByteToString(p.TransferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(p.TotalBytes)}) " +
$"@ {playerSpeedText}";
UiSharedService.DrawOutlinedFont(
drawList,
fullLine,
cursor,
UiSharedService.Color(255, 255, 255, _transferBoxTransparency),
UiSharedService.Color(0, 0, 0, _transferBoxTransparency),
1
);
cursor.Y += lineHeight + spacingY;
continue;
}
UiSharedService.DrawOutlinedFont(
drawList,
line,
labelLine,
cursor,
UiSharedService.Color(255, 255, 255, _transferBoxTransparency),
UiSharedService.Color(0, 0, 0, _transferBoxTransparency),
@@ -467,7 +698,26 @@ public class DownloadUi : WindowMediatorSubscriberBase
3f
);
cursor.Y += perPlayerBarHeight + spacingY * 2;
var barText =
$"{UiSharedService.ByteToString(p.TransferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(p.TotalBytes)} @ {playerSpeedText}";
var barTextSize = ImGui.CalcTextSize(barText);
var barTextPos = new Vector2(
barBgMin.X + ((barBgMax.X - barBgMin.X) - barTextSize.X) / 2f - 1,
barBgMin.Y + ((perPlayerBarHeight - barTextSize.Y) / 2f) - 1
);
UiSharedService.DrawOutlinedFont(
drawList,
barText,
barTextPos,
UiSharedService.Color(255, 255, 255, _transferBoxTransparency),
UiSharedService.Color(0, 0, 0, _transferBoxTransparency),
1
);
cursor.Y += perPlayerBarHeight + spacingY;
}
}
}