Editor/ChitChat/ControlWidgets/CharacterPictureControlWidget.cs
using Sandbox;
using Editor;
namespace ChitChat.Editor;
[CustomEditor(typeof(CharacterPicture))]
public class CharacterPictureControlWidget : ControlWidget
{
public override bool SupportsMultiEdit => false;
public CharacterPictureControlWidget(SerializedProperty property) : base(property)
{
Layout = Layout.Column();
Layout.Spacing = 8;
Layout.Margin = 5;
SetStyles("background-color: #424242;");
if (!property.TryGetAsObject(out var serializedObject))
{
Log.Error("Could not convert SerializedProperty to SerializedObject!");
return;
}
//Draw Name
if (serializedObject.TryGetProperty(nameof(CharacterPicture.Name), out SerializedProperty name))
{
Widget nameContainer = Layout.Add(new Widget(this));
nameContainer.Layout = Layout.Row();
nameContainer.Layout.Add(new Label("Picture Name") { ContentMargins = new Sandbox.UI.Margin(0, 0, 5, 0) });
nameContainer.Layout.Add(new StringControlWidget(name) { HorizontalSizeMode = SizeMode.Default, FixedHeight = 20 });
}
//Draw texture
if (serializedObject.TryGetProperty(nameof(CharacterPicture.Picture), out SerializedProperty picture))
{
Layout.Add(new ResourceWrapperControlWidget(picture) { HorizontalSizeMode = SizeMode.Flexible });
}
Layout.Add(new Separator(5) { Color = new Color(0.4f), ContentMargins = 5 });
}
protected override void OnPaint() { }
}