Add ability to hit NPCs and see different dialogue, add interrupt feature for dialogue controller singleton

This commit is contained in:
2024-09-09 17:20:54 -07:00
parent 699b4b95cf
commit fc33b07dc7
12 changed files with 489 additions and 420 deletions

View File

@@ -89,7 +89,8 @@ namespace DialogueManagerRuntime
public static async Task<GodotObject> GetSingleton()
{
if (instance != null) return instance;
if (instance != null)
return instance;
var tree = Engine.GetMainLoop();
int x = 0;
@@ -116,7 +117,8 @@ namespace DialogueManagerRuntime
Instance.Call("_bridge_get_next_dialogue_line", dialogueResource, key, extraGameStates ?? new Array<Variant>());
var result = await Instance.ToSignal(Instance, "bridge_get_next_dialogue_line_completed");
if ((RefCounted)result[0] == null) return null;
if ((RefCounted)result[0] == null)
return null;
return new DialogueLine((RefCounted)result[0]);
}
@@ -168,7 +170,8 @@ namespace DialogueManagerRuntime
{
MethodInfo? info = thing.GetType().GetMethod(method, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
if (info == null) return;
if (info == null)
return;
#nullable disable
// Convert the method args to something reflection can handle

View File

@@ -140,7 +140,7 @@ Throw={
[internationalization]
locale/translations_pot_files=PackedStringArray("res://src/dialog/Dialogue.dialogue", "res://src/ui/dialogue/FloorExit.dialogue", "res://src/npc/rat/ratdialogue.dialogue")
locale/translations_pot_files=PackedStringArray("res://src/dialog/Dialogue.dialogue", "res://src/ui/dialogue/FloorExit.dialogue", "res://src/npc/rat/ratdialogue.dialogue", "res://src/ui/dialogue/DialogueControl.dialogue")
[layer_names]

View File

@@ -5,8 +5,24 @@ public partial class DialogueController : Node
{
public static PackedScene DialogueBalloon { get; set; }
public DialogueController()
private static Node _currentlyActiveDialogue { get; set; } = new Node();
private static Resource _currentDialogue { get; set; }
public override void _Ready()
{
DialogueBalloon = GD.Load<PackedScene>("res://src/ui/dialogue/DialogueBalloon.tscn");
}
public static void ShowDialogue(Resource dialogueResource, string dialogueTitle)
{
Interrupt();
_currentlyActiveDialogue = DialogueManager.ShowDialogueBalloonScene(DialogueBalloon, dialogueResource, dialogueTitle);
}
public static void Interrupt()
{
if (IsInstanceValid(_currentlyActiveDialogue))
_currentlyActiveDialogue.QueueFree();
}
}

View File

@@ -68,7 +68,7 @@ public partial class Game : Node3D, IGame
GameRepo.Pause();
DialogueManager.GetCurrentScene = (() => this);
var dialogueResource = GD.Load<Resource>("res://src/ui/dialogue/FloorExit.dialogue");
DialogueManager.ShowDialogueBalloonScene(DialogueController.DialogueBalloon, dialogueResource, "floor_exit");
DialogueController.ShowDialogue(dialogueResource, "floor_exit");
DialogueManager.DialogueEnded += (Resource resource) => { GameRepo.Resume(); };
}

View File

@@ -1,6 +1,7 @@
[gd_scene load_steps=8 format=3 uid="uid://1fl6s352e2ej"]
[gd_scene load_steps=9 format=3 uid="uid://1fl6s352e2ej"]
[ext_resource type="Script" path="res://src/items/throwable/ThrowableItem.cs" id="1_nac2l"]
[ext_resource type="Resource" uid="uid://bph8c6by4s047" path="res://src/items/throwable/resources/GeomanticDice.tres" id="2_pefeg"]
[ext_resource type="Script" path="res://src/hitbox/Hitbox.cs" id="3_qpunu"]
[sub_resource type="BoxShape3D" id="BoxShape3D_qihtb"]
@@ -48,6 +49,7 @@ _data = {
[node name="ThrowableItem" type="Node3D"]
script = ExtResource("1_nac2l")
ThrowableItemInfo = ExtResource("2_pefeg")
[node name="Hitbox" type="Area3D" parent="."]
unique_name_in_owner = true

File diff suppressed because one or more lines are too long

View File

@@ -12,26 +12,10 @@ public partial class Overworld : Node3D, IDungeonFloor
[Dependency]
public IGameRepo GameRepo => this.DependOn<IGameRepo>();
[Node] public Area3D NPCBox { get; set; } = default!;
[Node] public Marker3D PlayerSpawnPoint { get; set; } = default!;
[Export] public Resource Dialogue { get; set; }
public void InitializeDungeon()
{
NPCBox.AreaEntered += NPCBox_AreaEntered;
NPCBox.AreaExited += NPCBox_AreaExited;
GameRepo.SetPlayerGlobalPosition(PlayerSpawnPoint.GlobalPosition);
}
private void NPCBox_AreaExited(Area3D area)
{
GameRepo.IsWithinDialogueSpace = false;
}
private void NPCBox_AreaEntered(Area3D area)
{
GameRepo.IsWithinDialogueSpace = true;
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -1,15 +1,23 @@
[gd_scene load_steps=5 format=3 uid="uid://d4l4qutp8x40c"]
[gd_scene load_steps=7 format=3 uid="uid://d4l4qutp8x40c"]
[ext_resource type="Texture2D" uid="uid://t7fbfplu2js7" path="res://src/npc/rat/ROYAL_RAT_PRINCEP.png" id="1_0r0wh"]
[ext_resource type="Script" path="res://src/npc/Npc.cs" id="1_cpdf2"]
[ext_resource type="Resource" uid="uid://cf7ycgdiihyh" path="res://src/npc/rat/ratdialogue.dialogue" id="2_uo38w"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_wfhgc"]
radius = 2.5
radius = 3.0
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_kg3qv"]
radius = 0.837722
height = 2.8375
[sub_resource type="CylinderShape3D" id="CylinderShape3D_nwuwj"]
height = 2.24425
radius = 1.00578
[node name="NPC" type="Node3D"]
script = ExtResource("1_cpdf2")
DialogueOptions = Array[Resource]([ExtResource("2_uo38w")])
Dialogue = ExtResource("2_uo38w")
[node name="Sprite" type="Sprite3D" parent="."]
unique_name_in_owner = true
@@ -28,3 +36,19 @@ collision_mask = 2
[node name="CollisionShape3D" type="CollisionShape3D" parent="DialogueZone"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00131226, 0, -0.00723076)
shape = SubResource("CylinderShape3D_wfhgc")
[node name="Collision" type="RigidBody3D" parent="."]
collision_mask = 0
gravity_scale = 0.0
[node name="CollisionShape3D" type="CollisionShape3D" parent="Collision"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.169075, 0, 0)
shape = SubResource("CapsuleShape3D_kg3qv")
[node name="Hitbox" type="Area3D" parent="."]
unique_name_in_owner = true
collision_layer = 16
collision_mask = 16
[node name="CollisionShape3D" type="CollisionShape3D" parent="Hitbox"]
shape = SubResource("CylinderShape3D_nwuwj")

View File

@@ -8,3 +8,41 @@ Royal Rat Princep, Tekohcyo: Alas, the tower has rejected me, so here I reside.
Unable to return home, but unable to climb it.
=> END
~ general
% => B1
% => B2
% => B3
% => B4
% => B5
=> END
~ B1
Royal Rat Princep, Tekohcyo: It became too much to bear, imagining what secrets they spoke within the walls.
The Goddess could change their hearts…
At least, it is what I dreamed of.
=> END
~ B2
Royal Rat Princep, Tekohcyo: I knew the Tower would save me. When it showed itself to me, I felt a hope I hadnt felt since I was a child.
Though it must have been a false hope in those days. What despairs did I possibly have to define that hope by?
I was surrounded by love and play. The ideal environment for all living creatures.
=> END
~ B3
Royal Rat Princep, Tekohcyo: Though I am fearful of what my resolve could lead me to, I have yet to step foot in the audience chamber at the top.
The thousand hands of the tower have always placed me gently where I fell, where I wished, and where I appear before you...
=> END
~ B4
Royal Rat Princep, Tekohcyo: Is it my own heart that needs to change, or the subjects around me?
=> END
~ B5
Royal Rat Princep, Tekohcyo: The walls of the Tower may deceive you.
=> END
~ hit
Royal Rat Princep, Tekohcyo: I suppose in the end, any end is, relievingly, an end.
=> END

View File

@@ -124,7 +124,6 @@ namespace GameJamDungeon
})
.Handle((in PlayerLogic.Output.ThrowItem output) =>
{
ThrowItem();
});
this.Provide();

View File

@@ -107,15 +107,14 @@ theme = SubResource("Theme_qq3yp")
[node name="Dialogue" type="MarginContainer" parent="Balloon"]
layout_mode = 1
anchors_preset = 15
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 21.0
offset_top = 897.0
offset_right = 21.0
offset_bottom = 897.0
offset_top = -124.0
offset_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
grow_vertical = 0
[node name="VBoxContainer" type="VBoxContainer" parent="Balloon/Dialogue"]
layout_mode = 2
@@ -147,7 +146,6 @@ theme_override_styles/fill = SubResource("StyleBoxEmpty_vtj1a")
theme_override_styles/background = SubResource("StyleBoxEmpty_c2c5i")
theme_override_styles/focus = SubResource("StyleBoxEmpty_wv0ko")
theme_override_styles/normal = SubResource("StyleBoxEmpty_dboi3")
text = "Dialogue..."
[node name="CenterContainer" type="CenterContainer" parent="Balloon"]
layout_mode = 1