From f90d74e90f894dd0551d3eaf0891ca895883df78 Mon Sep 17 00:00:00 2001
From: Jannify <23176718+Jannify@users.noreply.github.com>
Date: Tue, 29 Oct 2024 16:14:48 +0100
Subject: [PATCH] Improve string building for name/ip/port on server list
button
---
.../ServersList/MainMenuServerListPanel.cs | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/NitroxClient/MonoBehaviours/Gui/MainMenu/ServersList/MainMenuServerListPanel.cs b/NitroxClient/MonoBehaviours/Gui/MainMenu/ServersList/MainMenuServerListPanel.cs
index 1ba4af4a4..24c097687 100644
--- a/NitroxClient/MonoBehaviours/Gui/MainMenu/ServersList/MainMenuServerListPanel.cs
+++ b/NitroxClient/MonoBehaviours/Gui/MainMenu/ServersList/MainMenuServerListPanel.cs
@@ -1,4 +1,6 @@
+using System;
using System.Net;
+using System.Text;
using System.Threading.Tasks;
using FMODUnity;
using NitroxClient.Communication;
@@ -242,14 +244,22 @@ void AddButton(IPEndPoint serverEndPoint)
public void CreateServerButton(string serverName, string address, int port, bool isReadOnly = false)
{
- string HideIfNecessary(object text) => NitroxPrefs.HideIp.Value ? "****" : $"{text}";
-
GameObject multiplayerButtonInst = Instantiate(multiplayerButtonRef, serverAreaContent, false);
multiplayerButtonInst.name = $"NitroxServer_{serverAreaContent.childCount - 1}";
- string text = $"{Language.main.Get("Nitrox_ConnectTo")} {serverName}\n{HideIfNecessary(address)}:{HideIfNecessary(port)}";
+ StringBuilder buttonText = new();
+ buttonText.Append(Language.main.Get("Nitrox_ConnectTo")).Append(" ").Append(serverName).AppendLine("");
+ if (NitroxPrefs.HideIp.Value)
+ {
+ buttonText.AppendLine("***.***.***.***").AppendLine("*****");
+ }
+ else
+ {
+ buttonText.Append(address[^Math.Min(address.Length, 25)..]).Append(':').Append(port);
+ }
+
MainMenuServerButton serverButton = multiplayerButtonInst.AddComponent();
- serverButton.Init(text, address, port, isReadOnly);
+ serverButton.Init(buttonText.ToString(), address, port, isReadOnly);
EventTrigger[] eventTriggers = multiplayerButtonInst.GetComponentsInChildren(true); // One from the normal and one from the delete button
ForwardTriggerScrollToScrollRect(eventTriggers[0]);