using Godot; using Godot.Collections; namespace DialogueManagerRuntime { /// /// A special marker node that helps locate the in-world representation of the speaking character. /// Generally, you would position a at the mouth of the character and use /// its location as the origin of a speech balloon. /// [Icon("uid://cim0y62o6g36i")] public partial class DialogueMarker2D : Marker2D { /// /// The name of the character that owns this marker. /// [Export] public string CharacterName = ""; #region Static /// /// Get all nodes. /// public static Array All() { var markers = new Array(); foreach (Node node in ((SceneTree)Engine.GetMainLoop()).GetNodesInGroup("2d_dialogue_markers")) { if (node is DialogueMarker2D marker) { markers.Add(marker); } } return markers; } /// /// Find a marker with a given character name. /// public static DialogueMarker2D FindForCharacter(string targetCharacterName) { foreach (DialogueMarker2D marker in All()) { if (marker.CharacterName == targetCharacterName) { return marker; } } return null; } #endregion public override void _Ready() { AddToGroup("2d_dialogue_markers"); } #region Helpers /// /// Get the marker's position relative to the viewport. /// public Vector2 GetPositionInViewport() { return GetGlobalTransformWithCanvas().Origin; } #endregion } }