Story/Subtitles/SubtitleSystem.cs
using Opium.UI;

namespace Opium;

public record struct Subtitle
{
	[KeyProperty] public string Speaker { get; set; }
	[KeyProperty] public string Text { get; set; }
	[KeyProperty] public float Lifetime { get; set; }
}

public sealed class SubtitleSystem : Component
{
	public static SubtitleSystem Current { get; set; }

	[Property] public SubtitlePanel Panel { get; set; }

	public List<Subtitle> Subtitles { get; set; }

	protected override void OnEnabled()
	{
		Current = this;
	}


	public void Add( string speaker, string text, float lifetime = 5 )
	{
		Panel.Insert( new Subtitle() { Speaker = speaker, Text = text, Lifetime = lifetime } );
	}


	[ConCmd( "op_dev_subtitle" )]
	public static void AddSubtitleTest()
	{
		Current.Add( "Crackhead #1", "He's fucking running, get him!", 5 );
	}

	[ActionGraphNode( "opium.subtitle.add" ), Category( "Opium" ), Title( "Add Subtitle" )]
	public static void AddSubtitle( string speaker, string text, float lifetime = 5 )
	{
		Current.Add( speaker, text, lifetime );
	}
}