diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs
index 08468d81f..5b758ad98 100644
--- a/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs
+++ b/Barotrauma/BarotraumaClient/Source/GUI/GUI.cs
@@ -546,6 +546,9 @@ namespace Barotrauma
}
}
+ ///
+ /// Displays a message at the center of the screen, automatically preventing overlapping with other centered messages
+ ///
public static void AddMessage(string message, Color color, float lifeTime = 3.0f, bool playSound = true)
{
if (messages.Count > 0 && messages[messages.Count - 1].Text == message)
@@ -555,12 +558,15 @@ namespace Barotrauma
}
Vector2 pos = new Vector2(GameMain.GraphicsWidth / 2.0f, GameMain.GraphicsHeight * 0.7f);
- pos.Y += messages.FindAll(m => m.Centered).Count * 30;
+ pos.Y += messages.FindAll(m => m.AutoCenter).Count * 30;
messages.Add(new GUIMessage(message, color, pos, lifeTime, Alignment.Center, true));
if (playSound) PlayUISound(GUISoundType.Message);
}
+ ///
+ /// Display and automatically fade out a piece of text at an arbitrary position on the screen
+ ///
public static void AddMessage(string message, Vector2 position, Alignment alignment, Color color, float lifeTime = 3.0f, bool playSound = true)
{
if (messages.Count > 0 && messages[messages.Count - 1].Text == message)
@@ -599,7 +605,7 @@ namespace Barotrauma
alpha -= 1.0f - msg.LifeTime;
}
- if (msg.Centered)
+ if (msg.AutoCenter)
{
msg.Pos = MathUtils.SmoothStep(msg.Pos, currPos, deltaTime * 20.0f);
currPos.Y += 30.0f;
diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs
index cb1f6b437..de437566d 100644
--- a/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs
+++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIMessage.cs
@@ -46,14 +46,21 @@ namespace Barotrauma
private set;
}
- public bool Centered;
- public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool centered)
+ ///
+ /// Autocentered messages are automatically placed at the center of the screen and prevented from overlapping with each other
+ ///
+ public bool AutoCenter;
+
+ public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool autoCenter)
{
coloredText = new ColoredText(text, color);
pos = position;
this.lifeTime = lifeTime;
this.Alignment = textAlignment;
+ this.AutoCenter = autoCenter;
+
+ size = GUI.Font.MeasureString(text);
if (textAlignment.HasFlag(Alignment.Left))
Origin.X += size.X * 0.5f;
@@ -67,14 +74,10 @@ namespace Barotrauma
if (textAlignment.HasFlag(Alignment.Bottom))
Origin.Y -= size.Y * 0.5f;
- if (centered)
+ if (autoCenter)
{
Origin = new Vector2((int)(0.5f * size.X), (int)(0.5f * size.Y));
}
- else
- {
- size = GUI.Font.MeasureString(text);
- }
}
}
}