From cb9f33dc689c2a0291a187bbd34c75b67ad24839 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Fri, 26 Apr 2019 11:17:27 +0300 Subject: [PATCH] (4e4b8532a) Fixed buttons overlapping with the text in some GUIMessageBoxes on large resolutions (I think, needs to be tested on resolutions higher than 1080p). Using relative scale on the texts and the button container caused them to upscale when scaling the message box (for example when making room for the link buttons in the editor disclaimer). --- .../Source/GUI/GUIMessageBox.cs | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUIMessageBox.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUIMessageBox.cs index 5d1c333c4..55114def0 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUIMessageBox.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUIMessageBox.cs @@ -38,34 +38,22 @@ namespace Barotrauma public GUIMessageBox(string headerText, string text, string[] buttons, int width = DefaultWidth, int height = 0, Alignment textAlignment = Alignment.TopLeft, string tag = "") : base(new RectTransform(Vector2.One, GUI.Canvas, Anchor.Center), style: "") { - int headerHeight = 30; - InnerFrame = new GUIFrame(new RectTransform(new Point(width, height), RectTransform, Anchor.Center) { IsFixedSize = false }, style: null); GUI.Style.Apply(InnerFrame, "", this); Content = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.85f), InnerFrame.RectTransform, Anchor.Center)) { AbsoluteSpacing = 5 }; Tag = tag; - - if (height == 0) - { - string wrappedText = ToolBox.WrapText(text, Content.Rect.Width, GUI.Font); - string[] lines = wrappedText.Split('\n'); - foreach (string line in lines) - { - height += (int)GUI.Font.MeasureString(line).Y; - } - height += string.IsNullOrWhiteSpace(headerText) ? 220 : 220 - headerHeight; - } - InnerFrame.RectTransform.NonScaledSize = new Point(InnerFrame.Rect.Width, height); - + Header = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), Content.RectTransform), headerText, textAlignment: Alignment.Center, wrap: true); + Header.RectTransform.MinSize = new Point(0, Header.Rect.Height); GUI.Style.Apply(Header, "", this); if (!string.IsNullOrWhiteSpace(text)) { Text = new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.0f), Content.RectTransform), text, textAlignment: textAlignment, wrap: true); + Text.RectTransform.MinSize = new Point(0, Text.Rect.Height); GUI.Style.Apply(Text, "", this); } @@ -75,7 +63,18 @@ namespace Barotrauma AbsoluteSpacing = 5, IgnoreLayoutGroups = true }; - + buttonContainer.RectTransform.NonScaledSize = buttonContainer.RectTransform.MinSize = buttonContainer.RectTransform.MaxSize = + new Point(buttonContainer.Rect.Width, (int)(30 * GUI.Scale)); + + if (height == 0) + { + height += Header.Rect.Height + Content.AbsoluteSpacing; + height += (Text == null ? 0 : Text.Rect.Height) + Content.AbsoluteSpacing; + height += buttonContainer.Rect.Height; + + InnerFrame.RectTransform.NonScaledSize = new Point(InnerFrame.Rect.Width, (int)(height / Content.RectTransform.RelativeSize.Y)); + } + Buttons = new List(buttons.Length); for (int i = 0; i < buttons.Length; i++) {