migrate server config from v0 to v1, add more transfer bar settings

This commit is contained in:
rootdarkarchon
2023-03-17 13:01:04 +01:00
parent 82991a1172
commit 549bef1afb
13 changed files with 144 additions and 50 deletions

View File

@@ -148,13 +148,11 @@ public class DownloadUi : WindowMediatorSubscriberBase
var totalBytes = transfer.Value.Sum(c => c.Value.TotalBytes);
var transferredBytes = transfer.Value.Sum(c => c.Value.TransferredBytes);
var downloadText =
$"{UiSharedService.ByteToString(transferredBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
var maxDlText = $"{UiSharedService.ByteToString(totalBytes, addSuffix: false)}/{UiSharedService.ByteToString(totalBytes)}";
var textSize = ImGui.CalcTextSize(maxDlText);
var textSize = _configService.Current.TransferBarsShowText ? ImGui.CalcTextSize(maxDlText) : new Vector2(10, 10);
int dlBarHeight = (int)textSize.Y + 8;
int dlBarWidth = (int)textSize.X + 150;
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);
@@ -172,10 +170,15 @@ public class DownloadUi : WindowMediatorSubscriberBase
drawList.AddRectFilled(dlBarStart,
dlBarEnd with { X = dlBarStart.X + (float)(dlProgressPercent * dlBarWidth) },
UiSharedService.Color(50, 205, 50, transparency), 1);
UiSharedService.DrawOutlinedFont(drawList, downloadText,
screenPos with { X = screenPos.X - textSize.X / 2f - 1, Y = screenPos.Y - textSize.Y / 2f - 1 },
UiSharedService.Color(255, 255, 255, transparency),
UiSharedService.Color(0, 0, 0, transparency), 1);
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(255, 255, 255, transparency),
UiSharedService.Color(0, 0, 0, transparency), 1);
}
}
if (_configService.Current.ShowUploading)

View File

@@ -172,6 +172,27 @@ public class SettingsUi : WindowMediatorSubscriberBase
if (!showTransferBars) ImGui.BeginDisabled();
ImGui.Indent();
bool transferBarShowText = _configService.Current.TransferBarsShowText;
if (ImGui.Checkbox("Show Download Text", ref transferBarShowText))
{
_configService.Current.TransferBarsShowText = transferBarShowText;
_configService.Save();
}
UiSharedService.DrawHelpText("Shows download text (amount of MiB downloaded) in the transfer bars");
int transferBarWidth = _configService.Current.TransferBarsWidth;
if (ImGui.SliderInt("Transfer Bar Width", ref transferBarWidth, 10, 500))
{
_configService.Current.TransferBarsWidth = transferBarWidth;
_configService.Save();
}
UiSharedService.DrawHelpText("Width of the displayed transfer bars (will never be less wide than the displayed text)");
int transferBarHeight = _configService.Current.TransferBarsHeight;
if (ImGui.SliderInt("Transfer Bar Height", ref transferBarHeight, 2, 50))
{
_configService.Current.TransferBarsHeight = transferBarHeight;
_configService.Save();
}
UiSharedService.DrawHelpText("Height of the displayed transfer bars (will never be less tall than the displayed text)");
bool showUploading = _configService.Current.ShowUploading;
if (ImGui.Checkbox("Show 'Uploading' text below players that are currently uploading", ref showUploading))
{
@@ -793,12 +814,20 @@ public class SettingsUi : WindowMediatorSubscriberBase
if (ImGui.BeginTabItem("Service Settings"))
{
var serverUri = selectedServer.ServerUri;
ImGui.InputText("Service URI", ref serverUri, 255, ImGuiInputTextFlags.ReadOnly);
UiSharedService.DrawHelpText("You cannot edit the service URI. Add a new service if you need to edit the URI.");
var serverName = selectedServer.ServerName;
var serverUri = selectedServer.ServerUri;
var isMain = string.Equals(serverName, ApiController.MainServer, StringComparison.OrdinalIgnoreCase);
var flags = isMain ? ImGuiInputTextFlags.ReadOnly : ImGuiInputTextFlags.None;
if (ImGui.InputText("Service URI", ref serverUri, 255, flags))
{
selectedServer.ServerUri = serverUri;
}
if (isMain)
{
UiSharedService.DrawHelpText("You cannot edit the URI of the main service.");
}
if (ImGui.InputText("Service Name", ref serverName, 255, flags))
{
selectedServer.ServerName = serverName;
@@ -808,6 +837,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
{
UiSharedService.DrawHelpText("You cannot edit the name of the main service.");
}
if (!isMain && selectedServer != _serverConfigurationManager.CurrentServer)
{
if (UiSharedService.IconTextButton(FontAwesomeIcon.Trash, "Delete Service") && UiSharedService.CtrlPressed())

View File

@@ -632,8 +632,10 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
string[] comboEntries = _serverConfigurationManager.GetServerNames();
if (_serverSelectionIndex == -1)
{
_serverSelectionIndex = Array.IndexOf(_serverConfigurationManager.GetServerApiUrls(), _serverConfigurationManager.CurrentApiUrl);
if (_serverSelectionIndex == -1)
}
if (_serverSelectionIndex == -1 || _serverSelectionIndex >= comboEntries.Length)
{
_serverSelectionIndex = 0;
}
@@ -669,7 +671,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
{
ImGui.SameLine();
var text = "Connect";
if (_serverSelectionIndex == _serverConfigurationManager.GetCurrentServerIndex()) text = "Reconnect";
if (_serverSelectionIndex == _serverConfigurationManager.CurrentServerIndex) text = "Reconnect";
if (IconTextButton(FontAwesomeIcon.Link, text))
{
_serverConfigurationManager.SelectServer(_serverSelectionIndex);