From 7d2b701784916139fae6311ab57b88ee8bea7860 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sat, 30 Dec 2017 18:32:27 +0200 Subject: [PATCH] GUIMessageBox text overflow fix: the padding of the GUIFrame is taken into account when determining the height of the text, and the messagebox is always automatically resized if the height parameter is not given. --- .../BarotraumaClient/Source/GUI/GUIMessageBox.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIMessageBox.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIMessageBox.cs index c61fae4a4..2d48813eb 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIMessageBox.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIMessageBox.cs @@ -39,15 +39,18 @@ namespace Barotrauma this.Buttons[0].OnClicked = Close; } - public GUIMessageBox(string headerText, string text, string[] buttons, int width = DefaultWidth, int height = DefaultHeight, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null) + public GUIMessageBox(string headerText, string text, string[] buttons, int width = DefaultWidth, int height = 0, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null) : base(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f, Alignment.TopLeft, null, parent) { int headerHeight = 30; + var frame = new GUIFrame(new Rectangle(0, 0, width, height), null, Alignment.Center, "", this); + GUI.Style.Apply(frame, "", this); + if (height == 0) { - string wrappedText = ToolBox.WrapText(text, width, GUI.Font); + string wrappedText = ToolBox.WrapText(text, frame.Rect.Width - frame.Padding.X - frame.Padding.Z, GUI.Font); string[] lines = wrappedText.Split('\n'); foreach (string line in lines) { @@ -55,10 +58,8 @@ namespace Barotrauma } height += string.IsNullOrWhiteSpace(headerText) ? 220 : 220 - headerHeight; } + frame.Rect = new Rectangle(frame.Rect.X, GameMain.GraphicsHeight / 2 - height/2, frame.Rect.Width, height); - var frame = new GUIFrame(new Rectangle(0, 0, width, height), null, Alignment.Center, "", this); - GUI.Style.Apply(frame, "", this); - var header = new GUITextBlock(new Rectangle(0, 0, 0, headerHeight), headerText, null, null, textAlignment, "", frame, true); GUI.Style.Apply(header, "", this);