v1.4.4.1 (Blood in the Water Update)

This commit is contained in:
Regalis11
2024-04-24 18:09:05 +03:00
parent 89b91d1c3e
commit ff1b8951a7
397 changed files with 15250 additions and 6479 deletions
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Barotrauma.Networking;
using Color = Microsoft.Xna.Framework.Color;
@@ -422,6 +423,38 @@ namespace Barotrauma
return str;
}
/// <summary>
/// Removes lines on a multi-line string until it fits within the specified height and adds "..." to the end if the string is too long.
/// Doesn't really do anything if the string is only one line, should mostly be used with <see cref="GUITextBlock.WrappedText"/>.
/// </summary>
public static string LimitStringHeight(string str, ScalableFont font, int maxHeight)
{
if (maxHeight <= 0 || string.IsNullOrWhiteSpace(str)) { return string.Empty; }
float currHeight = font.MeasureString("...").Y;
var lines = str.Split('\n');
var sb = new StringBuilder();
foreach (string line in lines)
{
var (lineX, lineY) = font.MeasureString(line);
currHeight += lineY;
if (currHeight > maxHeight)
{
var modifiedLine = line;
while (font.MeasureString($"{modifiedLine}...").X > lineX)
{
modifiedLine = modifiedLine[..^1];
}
sb.AppendLine($"{modifiedLine}...");
return sb.ToString();
}
sb.AppendLine(line);
}
return str;
}
public static Color GradientLerp(float t, params Color[] gradient)
{
if (!MathUtils.IsValid(t)) { return Color.Purple; }