(05bb1cedc) Made SerializableEntityEditor string input fields scrollable horizontally. Closes #1158

This commit is contained in:
Joonas Rikkonen
2019-04-23 17:23:44 +03:00
parent 77d0b2aaab
commit 63f7449b6f
3 changed files with 38 additions and 14 deletions

View File

@@ -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);

View File

@@ -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<Vector2, int>(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;
}
}
}

View File

@@ -510,6 +510,7 @@ namespace Barotrauma
ToolTip = toolTip,
Font = GUI.SmallFont,
Text = value,
OverflowClip = true,
OnEnterPressed = (textBox, text) =>
{
if (property.TrySetValue(entity, text))