Editor/ChitChat/ControlWidgets/EventActionControlWidget.cs
using Sandbox;
using Editor;

namespace ChitChat.Editor;

[CustomEditor(typeof(SpeakAction))]
public class EventActionControlWidget : ControlWidget
{
	private StringControlWidget _eventNameControl;

	public EventActionControlWidget(SerializedProperty property) : base(property)
	{
		Layout = Layout.Row();
		Layout.Spacing = 8;
		Layout.Margin = 5;

		MinimumSize = new Vector2(600, 20);

		SetStyles("background-color: #424242; border-radius: 5px;");

		EventAction eventAction = property.GetValue<DialogueActionBase>() as EventAction;
		SerializedObject serializedObject = eventAction.GetSerialized();

		if (serializedObject == null)
		{
			Log.Error("Couldn't get " + nameof(EventAction) + " as serializedObject!");
			return;
		}

		Widget eventContainer = new Widget(this);
		eventContainer.Layout = Layout.Row();
		eventContainer.Layout.Alignment = TextFlag.Center;

		if (serializedObject.TryGetProperty(nameof(EventAction.EventName), out SerializedProperty eventNameProp))
		{
			Label eventActionLabel = new Label("Event Name", eventContainer);
			eventActionLabel.ContentMargins = new Sandbox.UI.Margin(3, 0, 5, 0);

			eventContainer.Layout.Add(eventActionLabel);

			_eventNameControl = new StringControlWidget(eventNameProp);

			eventContainer.Layout.Add(_eventNameControl);
		}
		else
			Log.Error(nameof(EventAction) + " could not get " + nameof(EventAction.EventName) + "!");
		
		Layout.Add(eventContainer);
	}

	protected override void OnMouseRightClick(MouseEvent e)
	{
		if(_eventNameControl.IsUnderMouse)
		{
			e.Accepted = true;
		}

		base.OnMouseRightClick(e);
	}

	protected override void OnPaint() { }
}