Unstable 0.15.15.0 (and the one before it I forgor)
This commit is contained in:
@@ -434,130 +434,8 @@ namespace Barotrauma
|
||||
return Color.Lerp(gradient[(int)scaledT], gradient[(int)Math.Min(scaledT + 1, gradient.Length - 1)], (scaledT - (int)scaledT));
|
||||
}
|
||||
|
||||
public static string WrapText(string text, float lineLength, ScalableFont font, float textScale = 1.0f, bool playerInput = false) //TODO: could integrate this into the ScalableFont class directly
|
||||
{
|
||||
Vector2 textSize = font.MeasureString(text);
|
||||
if (textSize.X <= lineLength) { return text; }
|
||||
|
||||
if (!playerInput)
|
||||
{
|
||||
text = text.Replace("\n", " \n ");
|
||||
}
|
||||
|
||||
List<string> words = new List<string>();
|
||||
string currWord = "";
|
||||
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
if (TextManager.IsCJK(text[i].ToString()))
|
||||
{
|
||||
if (currWord.Length > 0)
|
||||
{
|
||||
words.Add(currWord);
|
||||
currWord = "";
|
||||
}
|
||||
words.Add(text[i].ToString());
|
||||
}
|
||||
else if (text[i] == ' ')
|
||||
{
|
||||
if (currWord.Length > 0)
|
||||
{
|
||||
words.Add(currWord);
|
||||
currWord = "";
|
||||
}
|
||||
words.Add(string.Empty);
|
||||
}
|
||||
else
|
||||
{
|
||||
currWord += text[i];
|
||||
}
|
||||
}
|
||||
if (currWord.Length > 0)
|
||||
{
|
||||
words.Add(currWord);
|
||||
currWord = "";
|
||||
}
|
||||
|
||||
StringBuilder wrappedText = new StringBuilder();
|
||||
float linePos = 0f;
|
||||
Vector2 spaceSize = font.MeasureString(" ") * textScale;
|
||||
for (int i = 0; i < words.Count; ++i)
|
||||
{
|
||||
string currentWord = words[i];
|
||||
if (currentWord.Length == 0)
|
||||
{
|
||||
// space
|
||||
currentWord = " ";
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(currentWord) && currentWord != "\n")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector2 size = words[i].Length == 0 ? spaceSize : font.MeasureString(currentWord) * textScale;
|
||||
|
||||
if (size.X > lineLength)
|
||||
{
|
||||
float splitSize = 0.0f;
|
||||
List<string> splitWord = new List<string>() { string.Empty };
|
||||
int k = 0;
|
||||
|
||||
for (int j = 0; j < currentWord.Length; j++)
|
||||
{
|
||||
splitWord[k] += currentWord[j];
|
||||
splitSize += (font.MeasureString(currentWord[j].ToString()) * textScale).X;
|
||||
|
||||
if (splitSize + linePos > lineLength)
|
||||
{
|
||||
linePos = splitSize = 0.0f;
|
||||
splitWord[k] = splitWord[k].Remove(splitWord[k].Length - 1) + "\n";
|
||||
if (splitWord[k].Length <= 1) { break; }
|
||||
j--;
|
||||
splitWord.Add(string.Empty);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < splitWord.Count; j++)
|
||||
{
|
||||
wrappedText.Append(splitWord[j]);
|
||||
}
|
||||
|
||||
linePos = splitSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (linePos + size.X < lineLength)
|
||||
{
|
||||
wrappedText.Append(currentWord);
|
||||
if (currentWord == "\n")
|
||||
{
|
||||
linePos = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
linePos += size.X;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wrappedText.Append("\n");
|
||||
wrappedText.Append(currentWord);
|
||||
|
||||
linePos = size.X;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!playerInput)
|
||||
{
|
||||
return wrappedText.ToString().Replace(" \n ", "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
return wrappedText.ToString();
|
||||
}
|
||||
}
|
||||
public static string WrapText(string text, float lineLength, ScalableFont font, float textScale = 1.0f)
|
||||
=> font.WrapText(text, lineLength / textScale);
|
||||
|
||||
public static void ParseConnectCommand(string[] args, out string name, out string endpoint, out UInt64 lobbyId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user