mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:35:34 +00:00
Custom dialogue node
This commit is contained in:
parent
7cb5bfb593
commit
74dcd6d90c
3 changed files with 50 additions and 14 deletions
|
|
@ -10,21 +10,33 @@ namespace Cirno.Scripts.Activables;
|
|||
public partial class DialogueActor3D : Area3D, IInteractable
|
||||
{
|
||||
[Export] public StringName TimelineName = "";
|
||||
[Export(PropertyHint.MultilineText)]
|
||||
public string CustomDialogue = "";
|
||||
|
||||
private DialogueTools _dialogueInstance;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (Engine.IsEditorHint()) return;
|
||||
if (string.IsNullOrWhiteSpace(TimelineName))
|
||||
if (string.IsNullOrWhiteSpace(TimelineName) && string.IsNullOrWhiteSpace(CustomDialogue))
|
||||
{
|
||||
this.RemoveFromGroup("Interactable");
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_dialogueInstance = new DialogueTools();
|
||||
_dialogueInstance.Init(this, TimelineName);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(TimelineName))
|
||||
{
|
||||
_dialogueInstance.Init(this, TimelineName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_dialogueInstance.Init(this, CustomDialogue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void _func_godot_apply_properties(Dictionary<string, string> props)
|
||||
{
|
||||
TimelineName = props["timeline"];
|
||||
|
|
@ -33,9 +45,9 @@ public partial class DialogueActor3D : Area3D, IInteractable
|
|||
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
if (Engine.IsEditorHint()) return false;
|
||||
if (string.IsNullOrWhiteSpace(TimelineName)) return false;
|
||||
if (string.IsNullOrWhiteSpace(TimelineName) && string.IsNullOrWhiteSpace(CustomDialogue)) return false;
|
||||
_dialogueInstance.Start(this);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +68,7 @@ public partial class DialogueActor3D : Area3D, IInteractable
|
|||
{
|
||||
return this.GetGlobalPosition2D();
|
||||
}
|
||||
|
||||
|
||||
return CameraController3D.Instance.UnprojectPosition(this.GlobalPosition);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,9 @@ public partial class DialogueTools : RefCounted
|
|||
private DialogueSkipListener _listener;
|
||||
|
||||
private StringName TimelineName;
|
||||
|
||||
|
||||
private GodotObject _timelineContent;
|
||||
|
||||
public void Init(Node parent, StringName timelineName)
|
||||
{
|
||||
_dialogic = parent.GetNode("/root/Dialogic");
|
||||
|
|
@ -19,6 +21,21 @@ public partial class DialogueTools : RefCounted
|
|||
TimelineName = timelineName;
|
||||
}
|
||||
|
||||
public void Init(Node parent, string timelineContent)
|
||||
{
|
||||
_dialogic = parent.GetNode("/root/Dialogic");
|
||||
_dialogic.ProcessMode = Node.ProcessModeEnum.Always;
|
||||
|
||||
var contentArray = timelineContent.Split('\n');
|
||||
|
||||
var timelineScript = GD.Load<GDScript>("res://addons/dialogic/Resources/timeline.gd");
|
||||
var timelineResource = (GodotObject)timelineScript.New();
|
||||
|
||||
timelineResource.Set("events", contentArray);
|
||||
|
||||
_timelineContent = timelineResource;
|
||||
}
|
||||
|
||||
public void Start(Node parent)
|
||||
{
|
||||
if (GlobalState.Instance.SessionSettings.SkipDialogues)
|
||||
|
|
@ -26,18 +43,18 @@ public partial class DialogueTools : RefCounted
|
|||
DialogueEndAction();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
CreateSkipListener(parent);
|
||||
|
||||
|
||||
Hud.Instance?.HideHud();
|
||||
|
||||
|
||||
_dialogic.Connect("timeline_ended", Callable.From(OnTimelineEnded));
|
||||
|
||||
var dialogicNode =_dialogic.Call("start", TimelineName.ToString());
|
||||
var dialogicNode = _dialogic.Call("start", string.IsNullOrWhiteSpace(TimelineName) ? _timelineContent : TimelineName.ToString());
|
||||
((Node)dialogicNode).ProcessMode = Node.ProcessModeEnum.Always;
|
||||
ChangeState(GameState.Dialogue);
|
||||
}
|
||||
|
||||
|
||||
private void ChangeState(GameState state)
|
||||
{
|
||||
GameStateManager.Instance.ChangeState(state);
|
||||
|
|
@ -74,5 +91,4 @@ public partial class DialogueTools : RefCounted
|
|||
{
|
||||
_isComplete = true;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue