mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-06-27 19:56:23 +02:00
ControllerOverlay: truncate names from middle instead of end, (due to index identifier usually being on end)
This commit is contained in:
parent
58c2dc4ac4
commit
154f056422
1 changed files with 38 additions and 4 deletions
|
@ -16,7 +16,6 @@ namespace Ryujinx.UI.Overlay
|
|||
{
|
||||
private const float OverlayWidth = 400;
|
||||
private const float Padding = 24;
|
||||
private const float Spacing = 16;
|
||||
private const float PlayerSpacing = 12;
|
||||
private const float PlayerRowHeight = 32;
|
||||
|
||||
|
@ -120,7 +119,7 @@ namespace Ryujinx.UI.Overlay
|
|||
if (playerBindings.ContainsKey(playerIndex))
|
||||
{
|
||||
var controllers = playerBindings[playerIndex];
|
||||
var controllerNames = controllers.Select(c => GetControllerDisplayName(c)).ToList();
|
||||
var controllerNames = GetUniqueControllerDisplayNames(controllers);
|
||||
|
||||
var controllerTextElement = new TextElement(Padding + 56, rowY + 2, string.Join(", ", controllerNames), PlayerTextSize, new SKColor(144, 238, 144)) // LightGreen
|
||||
{
|
||||
|
@ -169,6 +168,37 @@ namespace Ryujinx.UI.Overlay
|
|||
};
|
||||
}
|
||||
|
||||
private List<string> GetUniqueControllerDisplayNames(List<OriginalInputConfig> controllers)
|
||||
{
|
||||
var nameGroups = new Dictionary<string, List<int>>();
|
||||
var displayNames = new List<string>();
|
||||
|
||||
// First pass: get base names and group them
|
||||
for (int i = 0; i < controllers.Count; i++)
|
||||
{
|
||||
string baseName = GetControllerDisplayName(controllers[i]);
|
||||
|
||||
if (!nameGroups.ContainsKey(baseName))
|
||||
{
|
||||
nameGroups[baseName] = new List<int>();
|
||||
}
|
||||
nameGroups[baseName].Add(i);
|
||||
displayNames.Add(baseName);
|
||||
}
|
||||
|
||||
// Second pass: add numbering for duplicates
|
||||
foreach (var group in nameGroups.Where(g => g.Value.Count > 1))
|
||||
{
|
||||
for (int i = 0; i < group.Value.Count; i++)
|
||||
{
|
||||
int index = group.Value[i];
|
||||
displayNames[index] = $"{group.Key} #{i + 1}";
|
||||
}
|
||||
}
|
||||
|
||||
return displayNames;
|
||||
}
|
||||
|
||||
private string GetControllerDisplayName(OriginalInputConfig config)
|
||||
{
|
||||
if (string.IsNullOrEmpty(config.Name))
|
||||
|
@ -181,11 +211,15 @@ namespace Ryujinx.UI.Overlay
|
|||
};
|
||||
}
|
||||
|
||||
// Truncate long controller names
|
||||
// Truncate long controller names from the middle
|
||||
string name = config.Name;
|
||||
if (name.Length > 25)
|
||||
{
|
||||
name = name.Substring(0, 22) + "...";
|
||||
int keepLength = 22; // Total characters to keep (excluding "...")
|
||||
int leftLength = (keepLength + 1) / 2; // Round up for left side
|
||||
int rightLength = keepLength / 2; // Round down for right side
|
||||
|
||||
name = name.Substring(0, leftLength) + "..." + name.Substring(name.Length - rightLength);
|
||||
}
|
||||
|
||||
return name;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue