diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUITextBlock.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUITextBlock.cs index e90fed400..07d09a5dd 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUITextBlock.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUITextBlock.cs @@ -27,6 +27,11 @@ namespace Barotrauma private bool overflowClipActive; public bool OverflowClip; + public bool OverflowClipActive + { + get { return overflowClipActive; } + } + private float textDepth; public Vector2 TextOffset { get; set; } @@ -88,6 +93,7 @@ namespace Barotrauma public Vector2 TextPos { get { return textPos; } + set { textPos = value; } } public float TextScale @@ -327,7 +333,7 @@ namespace Barotrauma { spriteBatch.End(); spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect; - spriteBatch.Begin(SpriteSortMode.Deferred); + spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: GameMain.ScissorTestEnable); } if (OutlineColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, OutlineColor * (currColor.A / 255.0f), false); diff --git a/Barotrauma/BarotraumaClient/Source/GUI/GUITextBox.cs b/Barotrauma/BarotraumaClient/Source/GUI/GUITextBox.cs index 5e24b6e9e..73fcd1b3a 100644 --- a/Barotrauma/BarotraumaClient/Source/GUI/GUITextBox.cs +++ b/Barotrauma/BarotraumaClient/Source/GUI/GUITextBox.cs @@ -118,11 +118,17 @@ namespace Barotrauma get { return maxTextLength; } set { - textBlock.OverflowClip = true; + textBlock.OverflowClip = value != null; maxTextLength = value; } } + public bool OverflowClip + { + get { return textBlock.OverflowClip; } + set { textBlock.OverflowClip = value; } + } + public override bool Enabled { get { return enabled; } @@ -318,7 +324,7 @@ namespace Barotrauma for (int i = 0; i <= textBlock.Text.Length; i++) { Vector2 textSize = Font.MeasureString(textBlock.Text.Substring(0, i)); - Vector2 indexPos = new Vector2(textSize.X + textBlock.Padding.X, textSize.Y + textBlock.Padding.Y); + Vector2 indexPos = new Vector2(textSize.X + textBlock.Padding.X, textSize.Y + textBlock.Padding.Y) + textBlock.TextPos - textBlock.Origin; //DebugConsole.NewMessage($"index: {i}, pos: {indexPos}", Color.WhiteSmoke); positions.Add(new Tuple(textBlock.Rect.Location.ToVector2() + indexPos, i)); } @@ -405,9 +411,22 @@ namespace Barotrauma { isSelecting = PlayerInput.KeyDown(Keys.LeftShift) || PlayerInput.KeyDown(Keys.RightShift); } - + if (CaretEnabled) { + if (textBlock.OverflowClipActive) + { + if (CaretScreenPos.X < Rect.X + textBlock.Padding.X) + { + textBlock.TextPos = new Vector2(textBlock.TextPos.X + ((Rect.X + textBlock.Padding.X) - CaretScreenPos.X), textBlock.TextPos.Y); + CalculateCaretPos(); + } + else if (CaretScreenPos.X > Rect.Right - textBlock.Padding.Z) + { + textBlock.TextPos = new Vector2(textBlock.TextPos.X - (CaretScreenPos.X - (Rect.Right - textBlock.Padding.Z)), textBlock.TextPos.Y); + CalculateCaretPos(); + } + } caretTimer += deltaTime; caretVisible = ((caretTimer * 1000.0f) % 1000) < 500; if (caretVisible && caretPosDirty) @@ -415,7 +434,7 @@ namespace Barotrauma CalculateCaretPos(); } } - + if (GUI.KeyboardDispatcher.Subscriber == this) { state = ComponentState.Selected; @@ -534,15 +553,7 @@ namespace Barotrauma public void ReceiveTextInput(char inputChar) { - if (selectedCharacters > 0) - { - RemoveSelectedText(); - } - if (SetText(Text.Insert(CaretIndex, inputChar.ToString()))) - { - CaretIndex = Math.Min(Text.Length, CaretIndex + 1); - OnTextChanged?.Invoke(this, Text); - } + ReceiveTextInput(inputChar.ToString()); } public void ReceiveTextInput(string input) @@ -551,10 +562,16 @@ namespace Barotrauma { RemoveSelectedText(); } + Vector2 textPos = textBlock.TextPos; + bool wasOverflowClipActive = textBlock.OverflowClipActive; if (SetText(Text.Insert(CaretIndex, input))) { CaretIndex = Math.Min(Text.Length, CaretIndex + input.Length); OnTextChanged?.Invoke(this, Text); + if (textBlock.OverflowClipActive && wasOverflowClipActive && !MathUtils.NearlyEqual(textBlock.TextPos, textPos)) + { + textBlock.TextPos = textPos + Vector2.UnitX * Font.MeasureString(input).X; + } } } diff --git a/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs b/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs index cb0e9cd57..6d244e815 100644 --- a/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs +++ b/Barotrauma/BarotraumaClient/Source/Serialization/SerializableEntityEditor.cs @@ -510,6 +510,7 @@ namespace Barotrauma ToolTip = toolTip, Font = GUI.SmallFont, Text = value, + OverflowClip = true, OnEnterPressed = (textBox, text) => { if (property.TrySetValue(entity, text))