Envoi sur GitHub du projet updated
This commit is contained in:
@@ -5,6 +5,9 @@ namespace DialogueManagerRuntime
|
||||
{
|
||||
public partial class ExampleBalloon : CanvasLayer
|
||||
{
|
||||
[Export] public Resource DialogueResource;
|
||||
[Export] public string StartFromTitle = "";
|
||||
[Export] public bool AutoStart = false;
|
||||
[Export] public string NextAction = "ui_accept";
|
||||
[Export] public string SkipAction = "ui_cancel";
|
||||
|
||||
@@ -13,8 +16,8 @@ namespace DialogueManagerRuntime
|
||||
RichTextLabel characterLabel;
|
||||
RichTextLabel dialogueLabel;
|
||||
VBoxContainer responsesMenu;
|
||||
Polygon2D progress;
|
||||
|
||||
Resource resource;
|
||||
Array<Variant> temporaryGameStates = new Array<Variant>();
|
||||
bool isWaitingForInput = false;
|
||||
bool willHideBalloon = false;
|
||||
@@ -25,21 +28,27 @@ namespace DialogueManagerRuntime
|
||||
get => dialogueLine;
|
||||
set
|
||||
{
|
||||
isWaitingForInput = false;
|
||||
balloon.FocusMode = Control.FocusModeEnum.All;
|
||||
balloon.GrabFocus();
|
||||
|
||||
// Dialogue has finished so close the balloon
|
||||
if (value == null)
|
||||
{
|
||||
QueueFree();
|
||||
if (Owner == null)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
else
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
dialogueLine = value;
|
||||
UpdateDialogue();
|
||||
ApplyDialogueLine();
|
||||
}
|
||||
}
|
||||
|
||||
Timer MutationCooldown = new Timer();
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -47,6 +56,7 @@ namespace DialogueManagerRuntime
|
||||
characterLabel = GetNode<RichTextLabel>("%CharacterLabel");
|
||||
dialogueLabel = GetNode<RichTextLabel>("%DialogueLabel");
|
||||
responsesMenu = GetNode<VBoxContainer>("%ResponsesMenu");
|
||||
progress = GetNode<Polygon2D>("%Progress");
|
||||
|
||||
balloon.Hide();
|
||||
|
||||
@@ -88,7 +98,28 @@ namespace DialogueManagerRuntime
|
||||
Next(response.NextId);
|
||||
}));
|
||||
|
||||
|
||||
// Hide the balloon when a mutation is running
|
||||
MutationCooldown.Timeout += () =>
|
||||
{
|
||||
if (willHideBalloon)
|
||||
{
|
||||
willHideBalloon = false;
|
||||
balloon.Hide();
|
||||
}
|
||||
};
|
||||
AddChild(MutationCooldown);
|
||||
|
||||
DialogueManager.Mutated += OnMutated;
|
||||
|
||||
if (AutoStart)
|
||||
{
|
||||
if (!IsInstanceValid(DialogueResource))
|
||||
{
|
||||
throw new System.Exception(DialogueManager.GetErrorMessage(143));
|
||||
}
|
||||
Start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +142,7 @@ namespace DialogueManagerRuntime
|
||||
if (what == NotificationTranslationChanged && IsInstanceValid(dialogueLabel))
|
||||
{
|
||||
float visibleRatio = dialogueLabel.VisibleRatio;
|
||||
DialogueLine = await DialogueManager.GetNextDialogueLine(resource, DialogueLine.Id, temporaryGameStates);
|
||||
DialogueLine = await DialogueManager.GetNextDialogueLine(DialogueResource, DialogueLine.Id, temporaryGameStates);
|
||||
if (visibleRatio < 1.0f)
|
||||
{
|
||||
dialogueLabel.Call("skip_typing");
|
||||
@@ -120,36 +151,52 @@ namespace DialogueManagerRuntime
|
||||
}
|
||||
|
||||
|
||||
public async void Start(Resource dialogueResource, string title, Array<Variant> extraGameStates = null)
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (!IsNodeReady())
|
||||
base._Process(delta);
|
||||
|
||||
if (IsInstanceValid(dialogueLine))
|
||||
{
|
||||
await ToSignal(this, SignalName.Ready);
|
||||
progress.Visible = !(bool)dialogueLabel.Get("is_typing") && dialogueLine.Responses.Count == 0 && !dialogueLine.HasTag("voice");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async void Start(Resource dialogueResource = null, string title = "", Array<Variant> extraGameStates = null)
|
||||
{
|
||||
temporaryGameStates = new Array<Variant> { this } + (extraGameStates ?? new Array<Variant>());
|
||||
isWaitingForInput = false;
|
||||
|
||||
if (IsInstanceValid(dialogueResource))
|
||||
{
|
||||
DialogueResource = dialogueResource;
|
||||
}
|
||||
if (title != "")
|
||||
{
|
||||
StartFromTitle = title;
|
||||
}
|
||||
|
||||
temporaryGameStates = extraGameStates ?? new Array<Variant>();
|
||||
isWaitingForInput = false;
|
||||
resource = dialogueResource;
|
||||
|
||||
DialogueLine = await DialogueManager.GetNextDialogueLine(resource, title, temporaryGameStates);
|
||||
DialogueLine = await DialogueManager.GetNextDialogueLine(DialogueResource, StartFromTitle, temporaryGameStates);
|
||||
Show();
|
||||
}
|
||||
|
||||
|
||||
public async void Next(string nextId)
|
||||
{
|
||||
DialogueLine = await DialogueManager.GetNextDialogueLine(resource, nextId, temporaryGameStates);
|
||||
DialogueLine = await DialogueManager.GetNextDialogueLine(DialogueResource, nextId, temporaryGameStates);
|
||||
}
|
||||
|
||||
|
||||
#region Helpers
|
||||
|
||||
|
||||
private async void UpdateDialogue()
|
||||
private async void ApplyDialogueLine()
|
||||
{
|
||||
if (!IsNodeReady())
|
||||
{
|
||||
await ToSignal(this, SignalName.Ready);
|
||||
}
|
||||
MutationCooldown.Stop();
|
||||
|
||||
isWaitingForInput = false;
|
||||
balloon.FocusMode = Control.FocusModeEnum.All;
|
||||
balloon.GrabFocus();
|
||||
|
||||
// Set up the character name
|
||||
characterLabel.Visible = !string.IsNullOrEmpty(dialogueLine.Character);
|
||||
@@ -208,14 +255,7 @@ namespace DialogueManagerRuntime
|
||||
{
|
||||
isWaitingForInput = false;
|
||||
willHideBalloon = true;
|
||||
GetTree().CreateTimer(0.1f).Timeout += () =>
|
||||
{
|
||||
if (willHideBalloon)
|
||||
{
|
||||
willHideBalloon = false;
|
||||
balloon.Hide();
|
||||
}
|
||||
};
|
||||
MutationCooldown.Start(0.1f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user