Add ability to hit NPCs and see different dialogue, add interrupt feature for dialogue controller singleton
This commit is contained in:
@@ -12,24 +12,37 @@ public partial class Npc : Node3D
|
||||
|
||||
[Node] public Area3D DialogueZone { get; set; } = default!;
|
||||
|
||||
[Node] public Area3D Hitbox { get; set; } = default!;
|
||||
|
||||
[Export]
|
||||
public Godot.Collections.Array<Resource> DialogueOptions { get; set; } = default!;
|
||||
public Resource Dialogue { get; set; } = default!;
|
||||
|
||||
private bool _isInDialogueZone = false;
|
||||
|
||||
private Node _dialogueBalloon;
|
||||
private bool _isIntroductionComplete = false;
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
SetPhysicsProcess(true);
|
||||
DialogueZone.BodyEntered += DialogueZone_BodyEntered;
|
||||
DialogueZone.BodyExited += DialogueZone_BodyExited;
|
||||
Hitbox.AreaEntered += Hitbox_AreaEntered;
|
||||
|
||||
}
|
||||
|
||||
private void Hitbox_AreaEntered(Area3D area)
|
||||
{
|
||||
DialogueController.ShowDialogue(Dialogue, "hit");
|
||||
}
|
||||
|
||||
private void Hitbox_BodyEntered(Node body)
|
||||
{
|
||||
DialogueController.ShowDialogue(Dialogue, "hit");
|
||||
}
|
||||
|
||||
private void DialogueZone_BodyExited(Node3D body)
|
||||
{
|
||||
_isInDialogueZone = false;
|
||||
if (_dialogueBalloon != null)
|
||||
_dialogueBalloon.QueueFree();
|
||||
DialogueController.Interrupt();
|
||||
}
|
||||
|
||||
private void DialogueZone_BodyEntered(Node3D body)
|
||||
@@ -40,6 +53,14 @@ public partial class Npc : Node3D
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (Input.IsActionJustPressed(GameInputs.Throw) && _isInDialogueZone)
|
||||
_dialogueBalloon = DialogueManager.ShowDialogueBalloonScene(DialogueController.DialogueBalloon, DialogueOptions.First(), "introduction");
|
||||
{
|
||||
if (_isIntroductionComplete)
|
||||
DialogueController.ShowDialogue(Dialogue, "general");
|
||||
else
|
||||
{
|
||||
DialogueController.ShowDialogue(Dialogue, "introduction");
|
||||
_isIntroductionComplete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user