a0d606ef5f
- Add support for some of the most common types (vectors, colors, rects) so there's no need to parse the values in the setters of the serializable properties (see Holdable.HoldPos for example). - Make a generic version of the item editing HUD that can be used on any IPropertyObject. Should make it easier to implement things like the character editor, editing structure properties, particle editor, etc. - Improve the interface of the editing HUD. Instead of having to type in a string value into a textbox, there should be number input fields for numeric properties, sliders for properties that only accept a range of values, a color picker, etc. And tooltips.
89 lines
2.7 KiB
C#
89 lines
2.7 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Barotrauma.Items.Components
|
|
{
|
|
partial class ItemLabel : ItemComponent, IDrawableComponent
|
|
{
|
|
private GUITextBlock textBlock;
|
|
|
|
private Color textColor;
|
|
|
|
[SerializableProperty("", true), Editable(100)]
|
|
public string Text
|
|
{
|
|
get { return textBlock.Text.Replace("\n", ""); }
|
|
set
|
|
{
|
|
if (value == TextBlock.Text || item.Rect.Width < 5) return;
|
|
|
|
if (textBlock.Rect.Width != item.Rect.Width || textBlock.Rect.Height != item.Rect.Height)
|
|
{
|
|
textBlock = null;
|
|
}
|
|
|
|
TextBlock.Text = value;
|
|
}
|
|
}
|
|
|
|
[Editable, SerializableProperty("0.0,0.0,0.0,1.0", true)]
|
|
public Color TextColor
|
|
{
|
|
get { return textColor; }
|
|
set
|
|
{
|
|
if (textBlock != null) textBlock.TextColor = value;
|
|
}
|
|
}
|
|
|
|
[Editable, SerializableProperty(1.0f, true)]
|
|
public float TextScale
|
|
{
|
|
get { return textBlock == null ? 1.0f : textBlock.TextScale; }
|
|
set
|
|
{
|
|
if (textBlock != null) textBlock.TextScale = MathHelper.Clamp(value, 0.1f, 10.0f);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
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)
|
|
{
|
|
}
|
|
|
|
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));
|
|
|
|
textBlock.Draw(spriteBatch, drawPos - textBlock.Rect.Location.ToVector2());
|
|
}
|
|
}
|
|
}
|