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

namespace ChitChat.Editor;

[CustomEditor(typeof(ChoiceAction))]
public class ChoiceActionControlWidget : ControlWidget
{
	public ChoiceActionControlWidget(SerializedProperty prop) : base(prop)
	{
		Layout = Layout.Column();
		Layout.Spacing = 8;
		Layout.Margin = 5;
		PaintBackground = false;

		SetStyles("background-color: #424242; border-radius: 5px;");
		ChoiceAction choice = prop.GetValue<DialogueActionBase>() as ChoiceAction;

		//If no choices exist
		if (choice.Choices.Count <= 0)
		{
			Label continuesLabel = new Label("No Choices", this)
			{
				ContentMargins = new Sandbox.UI.Margin(0, 0, 5, 0),
			};
			Layout.Add(continuesLabel);
		}
		else //Add choices
		{
			for (int i = 0; i < choice.Choices.Count; i++)
			{
				if (i >= 4)
				{
					Label continuesLabel = new Label("...", this)
					{
						ContentMargins = new Sandbox.UI.Margin(0, 0, 5, 0),
					};
					Layout.Add(continuesLabel);
					break;
				}

				Widget choiceContainer = Layout.Add(new Widget(this));
				choiceContainer.Layout = Layout.Row();

				Label choiceLabel = new Label("Choice " + i, choiceContainer)
				{
					ContentMargins = new Sandbox.UI.Margin(0, 0, 5, 0)
				};
				choiceContainer.Layout.Add(choiceLabel);

				Widget textBackground = new Widget(choiceContainer);
				textBackground.Name = "Text Background";
				textBackground.HorizontalSizeMode = SizeMode.Flexible;
				textBackground.FixedHeight = 20;
				textBackground.Layout = Layout.Column();
				textBackground.SetStyles("background-color: #303030; border-radius: 5px;");

				Label textLabel = new Label(choice.Choices[i].Text, textBackground) { ContentMargins = new Sandbox.UI.Margin(5, 0, 5, 0) };
				textBackground.Layout.Add(textLabel);

				choiceContainer.Layout.Add(textBackground);
				Layout.Add(choiceContainer);
			}
		}
	}
}