(a410fd46c) Trying to help the merge script through a jungle of merges
This commit is contained in:
@@ -230,11 +230,18 @@ namespace Barotrauma
|
||||
if (GameMain.ShowPerf)
|
||||
{
|
||||
int y = 10;
|
||||
DrawString(spriteBatch, new Vector2(300, y), "Draw - Max val: " + GameMain.PerformanceCounter.DrawTimeGraph.LargestValue()+" ms", Color.Green, Color.Black * 0.8f, font: GUI.SmallFont);
|
||||
DrawString(spriteBatch, new Vector2(300, y),
|
||||
"Draw - Avg: " + GameMain.PerformanceCounter.DrawTimeGraph.Average().ToString("0.00") + " ms" +
|
||||
" Max: " + GameMain.PerformanceCounter.DrawTimeGraph.LargestValue().ToString("0.00") + " ms",
|
||||
Color.Green, Color.Black * 0.8f, font: SmallFont);
|
||||
y += 15;
|
||||
GameMain.PerformanceCounter.DrawTimeGraph.Draw(spriteBatch, new Rectangle(300, y, 170, 50), null, 0, Color.Green);
|
||||
y += 50;
|
||||
DrawString(spriteBatch, new Vector2(300, y), "Update - Max val: " + GameMain.PerformanceCounter.UpdateTimeGraph.LargestValue() + " ms", Color.LightBlue, Color.Black * 0.8f, font: GUI.SmallFont);
|
||||
|
||||
DrawString(spriteBatch, new Vector2(300, y),
|
||||
"Update - Avg: " + GameMain.PerformanceCounter.UpdateTimeGraph.Average().ToString("0.00") + " ms" +
|
||||
" Max: " + GameMain.PerformanceCounter.UpdateTimeGraph.LargestValue().ToString("0.00") + " ms",
|
||||
Color.LightBlue, Color.Black * 0.8f, font: SmallFont);
|
||||
y += 15;
|
||||
GameMain.PerformanceCounter.UpdateTimeGraph.Draw(spriteBatch, new Rectangle(300, y, 170, 50), null, 0, Color.LightBlue);
|
||||
GameMain.PerformanceCounter.UpdateIterationsGraph.Draw(spriteBatch, new Rectangle(300, y, 170, 50), 20, 0, Color.Red);
|
||||
@@ -243,7 +250,7 @@ namespace Barotrauma
|
||||
{
|
||||
float elapsedMillisecs = GameMain.PerformanceCounter.GetAverageElapsedMillisecs(key);
|
||||
DrawString(spriteBatch, new Vector2(300, y),
|
||||
key + ": " + elapsedMillisecs,
|
||||
key + ": " + elapsedMillisecs.ToString("0.00"),
|
||||
Color.Lerp(Color.LightGreen, Color.Red, elapsedMillisecs / 10.0f), Color.Black * 0.5f, 0, SmallFont);
|
||||
|
||||
y += 15;
|
||||
|
||||
@@ -85,7 +85,9 @@ namespace Barotrauma
|
||||
{
|
||||
float totalSize = RectTransform.Children
|
||||
.Where(c => !c.GUIComponent.IgnoreLayoutGroups)
|
||||
.Sum(c => isHorizontal ? c.Rect.Width : c.Rect.Height);
|
||||
.Sum(c => isHorizontal ?
|
||||
MathHelper.Clamp(c.Rect.Width, c.MinSize.X, c.MaxSize.X) :
|
||||
MathHelper.Clamp(c.Rect.Height, c.MinSize.Y, c.MaxSize.Y));
|
||||
|
||||
totalSize +=
|
||||
(RectTransform.Children.Count() - 1) *
|
||||
|
||||
@@ -117,7 +117,9 @@ namespace Barotrauma
|
||||
{
|
||||
LayoutGroup = new GUILayoutGroup(new RectTransform(Vector2.One, rectT), isHorizontal: true) { Stretch = true };
|
||||
|
||||
TextBox = new GUITextBox(new RectTransform(Vector2.One, LayoutGroup.RectTransform), textAlignment: textAlignment, style: style)
|
||||
float relativeButtonAreaWidth = MathHelper.Clamp(Rect.Height / (float)Rect.Width, 0.1f, 0.5f);
|
||||
|
||||
TextBox = new GUITextBox(new RectTransform(new Vector2(1.0f - relativeButtonAreaWidth, 1.0f), LayoutGroup.RectTransform), textAlignment: textAlignment, style: style)
|
||||
{
|
||||
ClampText = false,
|
||||
// For some reason the caret in the number inputs is dimmer than it should.
|
||||
@@ -126,7 +128,7 @@ namespace Barotrauma
|
||||
CaretColor = Color.White
|
||||
};
|
||||
TextBox.OnTextChanged += TextChanged;
|
||||
var buttonArea = new GUIFrame(new RectTransform(new Vector2(0.02f, 1.0f), LayoutGroup.RectTransform, Anchor.CenterRight) { MinSize = new Point(Rect.Height, 0) }, style: null);
|
||||
var buttonArea = new GUIFrame(new RectTransform(new Vector2(relativeButtonAreaWidth, 1.0f), LayoutGroup.RectTransform, Anchor.CenterRight) { MinSize = new Point(Rect.Height, 0) }, style: null);
|
||||
PlusButton = new GUIButton(new RectTransform(new Vector2(1.0f, 0.5f), buttonArea.RectTransform), "+");
|
||||
PlusButton.OnButtonDown += () =>
|
||||
{
|
||||
@@ -201,6 +203,8 @@ namespace Barotrauma
|
||||
TextBox.textFilterFunction = text => new string(text.Where(c => char.IsDigit(c) || c == '.' || c == '-').ToArray());
|
||||
break;
|
||||
}
|
||||
|
||||
LayoutGroup.Recalculate();
|
||||
}
|
||||
|
||||
private void ReduceValue()
|
||||
|
||||
@@ -35,8 +35,6 @@ namespace Barotrauma
|
||||
this.graphicsDevice = graphicsDevice;
|
||||
componentStyles = new Dictionary<string, GUIComponentStyle>();
|
||||
|
||||
GameMain.Instance.OnResolutionChanged += () => { RescaleFonts(); };
|
||||
|
||||
XDocument doc;
|
||||
try
|
||||
{
|
||||
@@ -89,6 +87,8 @@ namespace Barotrauma
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GameMain.Instance.OnResolutionChanged += () => { RescaleFonts(); };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace Barotrauma
|
||||
protected Color textColor;
|
||||
|
||||
private string wrappedText;
|
||||
private string censoredText;
|
||||
|
||||
public delegate string TextGetterHandler();
|
||||
public TextGetterHandler TextGetter;
|
||||
@@ -175,6 +176,17 @@ namespace Barotrauma
|
||||
SetTextPos();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Censor
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string CensoredText
|
||||
{
|
||||
get { return censoredText; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is the new constructor.
|
||||
@@ -204,6 +216,8 @@ namespace Barotrauma
|
||||
|
||||
RectTransform.ScaleChanged += SetTextPos;
|
||||
RectTransform.SizeChanged += SetTextPos;
|
||||
|
||||
Censor = false;
|
||||
}
|
||||
|
||||
public void CalculateHeightFromText()
|
||||
@@ -225,13 +239,19 @@ namespace Barotrauma
|
||||
{
|
||||
if (text == null) return;
|
||||
|
||||
censoredText = "";
|
||||
for (int i=0;i<text.Length;i++)
|
||||
{
|
||||
censoredText += "\u2022";
|
||||
}
|
||||
|
||||
var rect = Rect;
|
||||
|
||||
overflowClipActive = false;
|
||||
wrappedText = text;
|
||||
|
||||
TextSize = MeasureText(text);
|
||||
|
||||
TextSize = MeasureText(text);
|
||||
|
||||
if (Wrap && rect.Width > 0)
|
||||
{
|
||||
wrappedText = ToolBox.WrapText(text, rect.Width - padding.X - padding.Z, Font, textScale);
|
||||
@@ -338,7 +358,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
Font.DrawString(spriteBatch,
|
||||
Wrap ? wrappedText : text,
|
||||
Censor ? censoredText : (Wrap ? wrappedText : text),
|
||||
pos,
|
||||
textColor * (textColor.A / 255.0f),
|
||||
0.0f, origin, TextScale,
|
||||
|
||||
@@ -142,6 +142,12 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public bool Censor
|
||||
{
|
||||
get { return textBlock.Censor; }
|
||||
set { textBlock.Censor = value; }
|
||||
}
|
||||
|
||||
public override string ToolTip
|
||||
{
|
||||
get
|
||||
@@ -253,9 +259,12 @@ namespace Barotrauma
|
||||
textBlock.Text = textBlock.Text.Substring(0, (int)maxTextLength);
|
||||
}
|
||||
}
|
||||
else if (ClampText && Font.MeasureString(textBlock.Text).X > (int)(textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z))
|
||||
else
|
||||
{
|
||||
textBlock.Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1);
|
||||
while (ClampText && textBlock.Text.Length>0 && Font.MeasureString(textBlock.Text).X > (int)(textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z))
|
||||
{
|
||||
textBlock.Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (store)
|
||||
@@ -267,9 +276,10 @@ namespace Barotrauma
|
||||
|
||||
private void CalculateCaretPos()
|
||||
{
|
||||
if (textBlock.WrappedText.Contains("\n"))
|
||||
string textDrawn = Censor ? textBlock.CensoredText : textBlock.WrappedText;
|
||||
if (textDrawn.Contains("\n"))
|
||||
{
|
||||
string[] lines = textBlock.WrappedText.Split('\n');
|
||||
string[] lines = textDrawn.Split('\n');
|
||||
int totalIndex = 0;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
@@ -282,7 +292,7 @@ namespace Barotrauma
|
||||
int index = currentLineLength - diff;
|
||||
Vector2 lineTextSize = Font.MeasureString(lines[i].Substring(0, index));
|
||||
Vector2 lastLineSize = Font.MeasureString(lines[i]);
|
||||
float totalTextHeight = Font.MeasureString(textBlock.WrappedText.Substring(0, totalIndex)).Y;
|
||||
float totalTextHeight = Font.MeasureString(textDrawn.Substring(0, totalIndex)).Y;
|
||||
caretPos = new Vector2(lineTextSize.X, totalTextHeight - lastLineSize.Y) + textBlock.TextPos - textBlock.Origin;
|
||||
break;
|
||||
}
|
||||
@@ -290,7 +300,8 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 textSize = Font.MeasureString(textBlock.Text.Substring(0, CaretIndex));
|
||||
textDrawn = Censor ? textBlock.CensoredText : textBlock.Text;
|
||||
Vector2 textSize = Font.MeasureString(textDrawn.Substring(0, CaretIndex));
|
||||
caretPos = new Vector2(textSize.X, 0) + textBlock.TextPos - textBlock.Origin;
|
||||
}
|
||||
caretPosDirty = false;
|
||||
@@ -298,17 +309,18 @@ namespace Barotrauma
|
||||
|
||||
protected List<Tuple<Vector2, int>> GetAllPositions()
|
||||
{
|
||||
string textDrawn = Censor ? textBlock.CensoredText : textBlock.WrappedText;
|
||||
var positions = new List<Tuple<Vector2, int>>();
|
||||
if (textBlock.WrappedText.Contains("\n"))
|
||||
if (textDrawn.Contains("\n"))
|
||||
{
|
||||
string[] lines = textBlock.WrappedText.Split('\n');
|
||||
string[] lines = textDrawn.Split('\n');
|
||||
int index = 0;
|
||||
int totalIndex = 0;
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
string line = lines[i];
|
||||
totalIndex += line.Length;
|
||||
float totalTextHeight = Font.MeasureString(textBlock.WrappedText.Substring(0, totalIndex)).Y;
|
||||
float totalTextHeight = Font.MeasureString(textDrawn.Substring(0, totalIndex)).Y;
|
||||
for (int j = 0; j <= line.Length; j++)
|
||||
{
|
||||
Vector2 lineTextSize = Font.MeasureString(line.Substring(0, j));
|
||||
@@ -321,9 +333,10 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
textDrawn = Censor ? textBlock.CensoredText : textBlock.Text;
|
||||
for (int i = 0; i <= textBlock.Text.Length; i++)
|
||||
{
|
||||
Vector2 textSize = Font.MeasureString(textBlock.Text.Substring(0, i));
|
||||
Vector2 textSize = Font.MeasureString(textDrawn.Substring(0, i));
|
||||
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));
|
||||
@@ -822,6 +835,7 @@ namespace Barotrauma
|
||||
|
||||
private void CalculateSelection()
|
||||
{
|
||||
string textDrawn = Censor ? textBlock.CensoredText : textBlock.WrappedText;
|
||||
InitSelectionStart();
|
||||
selectionEndIndex = CaretIndex;
|
||||
selectionEndPos = caretPos;
|
||||
@@ -829,12 +843,12 @@ namespace Barotrauma
|
||||
if (IsLeftToRight)
|
||||
{
|
||||
selectedText = Text.Substring(selectionStartIndex, selectedCharacters);
|
||||
selectionRectSize = Font.MeasureString(textBlock.WrappedText.Substring(selectionStartIndex, selectedCharacters));
|
||||
selectionRectSize = Font.MeasureString(textDrawn.Substring(selectionStartIndex, selectedCharacters));
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedText = Text.Substring(selectionEndIndex, selectedCharacters);
|
||||
selectionRectSize = Font.MeasureString(textBlock.WrappedText.Substring(selectionEndIndex, selectedCharacters));
|
||||
selectionRectSize = Font.MeasureString(textDrawn.Substring(selectionEndIndex, selectedCharacters));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,11 @@ namespace Barotrauma
|
||||
BottomLeft, BottomCenter, BottomRight
|
||||
}
|
||||
|
||||
public enum ScaleBasis
|
||||
{
|
||||
Normal, BothWidth, BothHeight
|
||||
}
|
||||
|
||||
public class RectTransform
|
||||
{
|
||||
#region Fields and Properties
|
||||
@@ -286,6 +291,8 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
private ScaleBasis scaleBasis;
|
||||
|
||||
public bool IsLastChild
|
||||
{
|
||||
get
|
||||
@@ -320,9 +327,10 @@ namespace Barotrauma
|
||||
#endregion
|
||||
|
||||
#region Initialization
|
||||
public RectTransform(Vector2 relativeSize, RectTransform parent, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null, Point? minSize = null, Point? maxSize = null)
|
||||
public RectTransform(Vector2 relativeSize, RectTransform parent, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null, Point? minSize = null, Point? maxSize = null, ScaleBasis scaleBasis = ScaleBasis.Normal)
|
||||
{
|
||||
Init(parent, anchor, pivot);
|
||||
this.scaleBasis = scaleBasis;
|
||||
this.relativeSize = relativeSize;
|
||||
this.minSize = minSize;
|
||||
this.maxSize = maxSize;
|
||||
@@ -340,6 +348,7 @@ namespace Barotrauma
|
||||
public RectTransform(Point absoluteSize, RectTransform parent = null, Anchor anchor = Anchor.TopLeft, Pivot? pivot = null)
|
||||
{
|
||||
Init(parent, anchor, pivot);
|
||||
this.scaleBasis = ScaleBasis.Normal;
|
||||
this.nonScaledSize = absoluteSize;
|
||||
RecalculateScale();
|
||||
RecalculateRelativeSize();
|
||||
@@ -416,7 +425,16 @@ namespace Barotrauma
|
||||
|
||||
protected void RecalculateAbsoluteSize()
|
||||
{
|
||||
nonScaledSize = NonScaledParentRect.Size.Multiply(RelativeSize).Clamp(MinSize, MaxSize);
|
||||
Point size = NonScaledParentRect.Size;
|
||||
if (scaleBasis == ScaleBasis.BothWidth)
|
||||
{
|
||||
size.Y = size.X;
|
||||
}
|
||||
else if (scaleBasis == ScaleBasis.BothHeight)
|
||||
{
|
||||
size.X = size.Y;
|
||||
}
|
||||
nonScaledSize = size.Multiply(RelativeSize).Clamp(MinSize, MaxSize);
|
||||
recalculateRect = true;
|
||||
SizeChanged?.Invoke();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user