38f1ddb...178a853: v0.8.9.1, removed content folder

This commit is contained in:
Joonas Rikkonen
2019-03-18 19:46:58 +02:00
parent 38f1ddb6fe
commit 6c0679c297
1054 changed files with 151673 additions and 144931 deletions
@@ -1,5 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Text;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
@@ -10,20 +12,38 @@ namespace Barotrauma.Items.Components
private Color textColor;
private float scrollAmount;
private string scrollingText;
private float scrollPadding;
private int scrollIndex;
private bool needsScrolling;
private float[] charWidths;
[Serialize("0,0,0,0", true)]
public Vector4 Padding
{
get { return TextBlock.Padding; }
set { TextBlock.Padding = value; }
}
private string text;
[Serialize("", true), Editable(100)]
public string Text
{
get { return textBlock.Text.Replace("\n", ""); }
get { return text; }
set
{
if (value == TextBlock.Text || item.Rect.Width < 5) return;
if (value == text || item.Rect.Width < 5) return;
if (textBlock.Rect.Width != item.Rect.Width || textBlock.Rect.Height != item.Rect.Height)
if (TextBlock.Rect.Width != item.Rect.Width || textBlock.Rect.Height != item.Rect.Height)
{
textBlock = null;
}
text = value;
TextBlock.Text = value;
SetScrollingText();
}
}
@@ -48,42 +68,149 @@ namespace Barotrauma.Items.Components
}
}
private bool scrollable;
[Serialize(false, true)]
public bool Scrollable
{
get { return scrollable; }
set
{
scrollable = value;
IsActive = value;
TextBlock.Wrap = !scrollable;
TextBlock.TextAlignment = scrollable ? Alignment.CenterLeft : Alignment.Center;
}
}
[Serialize(20.0f, true)]
public float ScrollSpeed
{
get;
set;
}
private GUITextBlock TextBlock
{
get
{
if (textBlock == null)
{
textBlock = new GUITextBlock(new Rectangle(item.Rect.X, -item.Rect.Y, item.Rect.Width, item.Rect.Height), "",
Color.Transparent, textColor,
Alignment.TopLeft, Alignment.Center,
null, null, true);
textBlock.Font = GUI.SmallFont;
textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
textBlock.TextDepth = item.Sprite.Depth - 0.0001f;
textBlock.TextScale = TextScale;
textBlock = new GUITextBlock(new RectTransform(item.Rect.Size), "",
textColor: textColor, font: GUI.SmallFont, textAlignment: Alignment.Center, wrap: true, style: null)
{
TextDepth = item.SpriteDepth - 0.0001f,
TextScale = TextScale
};
}
return textBlock;
}
}
public override void Move(Vector2 amount)
{
textBlock.Rect = new Rectangle(item.Rect.X, -item.Rect.Y, item.Rect.Width, item.Rect.Height);
}
public ItemLabel(Item item, XElement element)
: base(item, element)
{
{
}
private void SetScrollingText()
{
if (!scrollable) return;
float totalWidth = textBlock.Font.MeasureString(text).X;
float textAreaWidth = Math.Max(textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z, 0);
if (totalWidth >= textAreaWidth)
{
//add enough spaces to fill the rect
//(so the text can scroll entirely out of view before we reset it back to start)
needsScrolling = true;
float spaceWidth = textBlock.Font.MeasureChar(' ').X;
scrollingText = new string(' ', (int)Math.Ceiling(textAreaWidth / spaceWidth)) + text;
}
else
{
//whole text can fit in the textblock, no need to scroll
needsScrolling = false;
scrollingText = text;
scrollAmount = 0.0f;
scrollIndex = 0;
return;
}
//calculate character widths
scrollPadding = 0;
charWidths = new float[scrollingText.Length];
for (int i = 0; i < scrollingText.Length; i++)
{
float charWidth = TextBlock.Font.MeasureChar(scrollingText[i]).X;
scrollPadding = Math.Max(charWidth, scrollPadding);
charWidths[i] = charWidth;
}
scrollIndex = MathHelper.Clamp(scrollIndex, 0, text.Length);
}
public override void Update(float deltaTime, Camera cam)
{
if (!scrollable) return;
if (scrollingText == null)
{
SetScrollingText();
}
if (!needsScrolling) return;
scrollAmount -= deltaTime * ScrollSpeed;
float currLength = 0;
StringBuilder sb = new StringBuilder();
float textAreaWidth = textBlock.Rect.Width - textBlock.Padding.X - textBlock.Padding.Z;
for (int i = scrollIndex; i < scrollingText.Length; i++)
{
//first character is out of view -> skip to next character
if (i == scrollIndex && scrollAmount < -charWidths[i])
{
scrollIndex++;
scrollAmount = 0;
if (scrollIndex >= scrollingText.Length) //reached the last character, reset
{
scrollIndex = 0;
break;
}
continue;
}
//reached the right edge, stop adding more character
if (scrollAmount + (currLength + charWidths[i] + scrollPadding) >= textAreaWidth)
{
break;
}
else
{
currLength += charWidths[i];
sb.Append(scrollingText[i]);
}
}
TextBlock.Text = sb.ToString();
}
public void Draw(SpriteBatch spriteBatch, bool editing = false)
{
var drawPos = new Vector2(
item.DrawPosition.X - item.Rect.Width / 2.0f,
-(item.DrawPosition.Y + item.Rect.Height / 2.0f));
Rectangle worldRect = item.WorldRect;
if (worldRect.X > Screen.Selected.Cam.WorldView.Right ||
worldRect.Right < Screen.Selected.Cam.WorldView.X ||
worldRect.Y < Screen.Selected.Cam.WorldView.Y - Screen.Selected.Cam.WorldView.Height ||
worldRect.Y - worldRect.Height > Screen.Selected.Cam.WorldView.Y)
{
return;
}
textBlock.Draw(spriteBatch, drawPos - textBlock.Rect.Location.ToVector2());
textBlock.TextOffset = drawPos - textBlock.Rect.Location.ToVector2() + new Vector2(scrollAmount + scrollPadding, 0.0f);
textBlock.DrawManually(spriteBatch);
}
}
}