Skip to content

Commit

Permalink
Improve string building for name/ip/port on server list button
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannify committed Oct 30, 2024
1 parent 7c2448c commit f90d74e
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using FMODUnity;
using NitroxClient.Communication;
Expand Down Expand Up @@ -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")} <b>{serverName}</b>\n{HideIfNecessary(address)}:{HideIfNecessary(port)}";
StringBuilder buttonText = new();
buttonText.Append(Language.main.Get("Nitrox_ConnectTo")).Append(" <b>").Append(serverName).AppendLine("</b>");
if (NitroxPrefs.HideIp.Value)
{
buttonText.AppendLine("***.***.***.***").AppendLine("*****");
}
else
{
buttonText.Append(address[^Math.Min(address.Length, 25)..]).Append(':').Append(port);
}

MainMenuServerButton serverButton = multiplayerButtonInst.AddComponent<MainMenuServerButton>();
serverButton.Init(text, address, port, isReadOnly);
serverButton.Init(buttonText.ToString(), address, port, isReadOnly);

EventTrigger[] eventTriggers = multiplayerButtonInst.GetComponentsInChildren<EventTrigger>(true); // One from the normal and one from the delete button
ForwardTriggerScrollToScrollRect(eventTriggers[0]);
Expand Down

0 comments on commit f90d74e

Please sign in to comment.