(05bb1cedc) Made SerializableEntityEditor string input fields scrollable horizontally. Closes #1158
This commit is contained in:
@@ -27,6 +27,11 @@ namespace Barotrauma
|
|||||||
private bool overflowClipActive;
|
private bool overflowClipActive;
|
||||||
public bool OverflowClip;
|
public bool OverflowClip;
|
||||||
|
|
||||||
|
public bool OverflowClipActive
|
||||||
|
{
|
||||||
|
get { return overflowClipActive; }
|
||||||
|
}
|
||||||
|
|
||||||
private float textDepth;
|
private float textDepth;
|
||||||
|
|
||||||
public Vector2 TextOffset { get; set; }
|
public Vector2 TextOffset { get; set; }
|
||||||
@@ -88,6 +93,7 @@ namespace Barotrauma
|
|||||||
public Vector2 TextPos
|
public Vector2 TextPos
|
||||||
{
|
{
|
||||||
get { return textPos; }
|
get { return textPos; }
|
||||||
|
set { textPos = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public float TextScale
|
public float TextScale
|
||||||
@@ -327,7 +333,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
spriteBatch.GraphicsDevice.ScissorRectangle = prevScissorRect;
|
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);
|
if (OutlineColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, OutlineColor * (currColor.A / 255.0f), false);
|
||||||
|
|||||||
@@ -118,11 +118,17 @@ namespace Barotrauma
|
|||||||
get { return maxTextLength; }
|
get { return maxTextLength; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
textBlock.OverflowClip = true;
|
textBlock.OverflowClip = value != null;
|
||||||
maxTextLength = value;
|
maxTextLength = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool OverflowClip
|
||||||
|
{
|
||||||
|
get { return textBlock.OverflowClip; }
|
||||||
|
set { textBlock.OverflowClip = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Enabled
|
public override bool Enabled
|
||||||
{
|
{
|
||||||
get { return enabled; }
|
get { return enabled; }
|
||||||
@@ -318,7 +324,7 @@ namespace Barotrauma
|
|||||||
for (int i = 0; i <= textBlock.Text.Length; i++)
|
for (int i = 0; i <= textBlock.Text.Length; i++)
|
||||||
{
|
{
|
||||||
Vector2 textSize = Font.MeasureString(textBlock.Text.Substring(0, 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);
|
//DebugConsole.NewMessage($"index: {i}, pos: {indexPos}", Color.WhiteSmoke);
|
||||||
positions.Add(new Tuple<Vector2, int>(textBlock.Rect.Location.ToVector2() + indexPos, i));
|
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);
|
isSelecting = PlayerInput.KeyDown(Keys.LeftShift) || PlayerInput.KeyDown(Keys.RightShift);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CaretEnabled)
|
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;
|
caretTimer += deltaTime;
|
||||||
caretVisible = ((caretTimer * 1000.0f) % 1000) < 500;
|
caretVisible = ((caretTimer * 1000.0f) % 1000) < 500;
|
||||||
if (caretVisible && caretPosDirty)
|
if (caretVisible && caretPosDirty)
|
||||||
@@ -415,7 +434,7 @@ namespace Barotrauma
|
|||||||
CalculateCaretPos();
|
CalculateCaretPos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GUI.KeyboardDispatcher.Subscriber == this)
|
if (GUI.KeyboardDispatcher.Subscriber == this)
|
||||||
{
|
{
|
||||||
state = ComponentState.Selected;
|
state = ComponentState.Selected;
|
||||||
@@ -534,15 +553,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void ReceiveTextInput(char inputChar)
|
public void ReceiveTextInput(char inputChar)
|
||||||
{
|
{
|
||||||
if (selectedCharacters > 0)
|
ReceiveTextInput(inputChar.ToString());
|
||||||
{
|
|
||||||
RemoveSelectedText();
|
|
||||||
}
|
|
||||||
if (SetText(Text.Insert(CaretIndex, inputChar.ToString())))
|
|
||||||
{
|
|
||||||
CaretIndex = Math.Min(Text.Length, CaretIndex + 1);
|
|
||||||
OnTextChanged?.Invoke(this, Text);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReceiveTextInput(string input)
|
public void ReceiveTextInput(string input)
|
||||||
@@ -551,10 +562,16 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
RemoveSelectedText();
|
RemoveSelectedText();
|
||||||
}
|
}
|
||||||
|
Vector2 textPos = textBlock.TextPos;
|
||||||
|
bool wasOverflowClipActive = textBlock.OverflowClipActive;
|
||||||
if (SetText(Text.Insert(CaretIndex, input)))
|
if (SetText(Text.Insert(CaretIndex, input)))
|
||||||
{
|
{
|
||||||
CaretIndex = Math.Min(Text.Length, CaretIndex + input.Length);
|
CaretIndex = Math.Min(Text.Length, CaretIndex + input.Length);
|
||||||
OnTextChanged?.Invoke(this, Text);
|
OnTextChanged?.Invoke(this, Text);
|
||||||
|
if (textBlock.OverflowClipActive && wasOverflowClipActive && !MathUtils.NearlyEqual(textBlock.TextPos, textPos))
|
||||||
|
{
|
||||||
|
textBlock.TextPos = textPos + Vector2.UnitX * Font.MeasureString(input).X;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -510,6 +510,7 @@ namespace Barotrauma
|
|||||||
ToolTip = toolTip,
|
ToolTip = toolTip,
|
||||||
Font = GUI.SmallFont,
|
Font = GUI.SmallFont,
|
||||||
Text = value,
|
Text = value,
|
||||||
|
OverflowClip = true,
|
||||||
OnEnterPressed = (textBox, text) =>
|
OnEnterPressed = (textBox, text) =>
|
||||||
{
|
{
|
||||||
if (property.TrySetValue(entity, text))
|
if (property.TrySetValue(entity, text))
|
||||||
|
|||||||
Reference in New Issue
Block a user