stairs fix, wraptext fix, moved drawing sprites from GUIFrame to GUIComponent, server name and "welcome text" in netlobby
This commit is contained in:
@@ -256,27 +256,56 @@ namespace Subsurface
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
public static string WrapText(string text, float lineWidth, SpriteFont font)
|
||||
public static string WrapText(string text, float lineLength, SpriteFont font)
|
||||
{
|
||||
if (GUI.Font.MeasureString(text).X < lineWidth) return text;
|
||||
if (font.MeasureString(text).X < lineLength) return text;
|
||||
|
||||
string[] words = text.Split(' ', '\n');
|
||||
|
||||
string[] words = text.Split(' ');
|
||||
StringBuilder wrappedText = new StringBuilder();
|
||||
float linewidth = 0f;
|
||||
float linePos = 0f;
|
||||
float spaceWidth = font.MeasureString(" ").X;
|
||||
for (int i = 0; i < words.Length; ++i)
|
||||
{
|
||||
Vector2 size = font.MeasureString(words[i]);
|
||||
if (linewidth + size.X < lineWidth)
|
||||
if (string.IsNullOrWhiteSpace(words[i])) continue;
|
||||
|
||||
Vector2 size;
|
||||
string tempWord = words[i];
|
||||
string prevWord = words[i];
|
||||
while ((size = font.MeasureString(tempWord)).X > lineLength)
|
||||
{
|
||||
linewidth += size.X + spaceWidth;
|
||||
tempWord = tempWord.Remove(tempWord.Length - 1, 1);
|
||||
|
||||
|
||||
}
|
||||
words[i] = tempWord;
|
||||
if (prevWord.Length> tempWord.Length)
|
||||
{
|
||||
wrappedText.Append(words[i]);
|
||||
wrappedText.Append(" \n");
|
||||
wrappedText.Append(prevWord.Remove(0, tempWord.Length));
|
||||
linePos = lineLength*2.0f;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (linePos + size.X < lineLength)
|
||||
{
|
||||
wrappedText.Append(words[i]);
|
||||
linePos += size.X + spaceWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (i>0)wrappedText.Remove(wrappedText.Length - 1, 1);
|
||||
wrappedText.Append("\n");
|
||||
linewidth = size.X + spaceWidth;
|
||||
wrappedText.Append(words[i]);
|
||||
|
||||
|
||||
|
||||
|
||||
linePos = size.X + spaceWidth;
|
||||
}
|
||||
wrappedText.Append(words[i]);
|
||||
|
||||
if (i<words.Length-1) wrappedText.Append(" ");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user