added basic dialogue bubble functionality
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"dialogTitle": "Brain damaged Debug Character",
|
|
||||||
"dialogType": "villager",
|
"dialogType": "villager",
|
||||||
"playerbeginoptions": {
|
"playerbeginoptions": {
|
||||||
"talk": [
|
"talk": [
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
[gd_scene load_steps=4 format=3 uid="uid://cg86tsupfq53i"]
|
[gd_scene load_steps=4 format=3 uid="uid://bkm7365u1mm3o"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/scene-scripts/dialog_bubble.cs" id="1_210k6"]
|
[ext_resource type="Script" path="res://src/scene-scripts/dialogue-system/dialog_bubble.cs" id="1_5xn2c"]
|
||||||
[ext_resource type="FontFile" uid="uid://cx6bvqk0ghmjv" path="res://assets/fonts/urbane-rounded-medium.otf" id="2_qrihj"]
|
[ext_resource type="FontFile" uid="uid://cx6bvqk0ghmjv" path="res://assets/fonts/urbane-rounded-medium.otf" id="2_qrihj"]
|
||||||
|
|
||||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_5w2xu"]
|
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_5w2xu"]
|
||||||
|
|
||||||
[node name="dialog_bubble" type="CanvasLayer"]
|
[node name="dialog_bubble" type="CanvasLayer"]
|
||||||
script = ExtResource("1_210k6")
|
script = ExtResource("1_5xn2c")
|
||||||
metadata/_edit_use_anchors_ = true
|
metadata/_edit_use_anchors_ = true
|
||||||
|
|
||||||
[node name="color_rect" type="ColorRect" parent="."]
|
[node name="box" type="ColorRect" parent="."]
|
||||||
anchors_preset = -1
|
anchors_preset = -1
|
||||||
anchor_left = 0.083
|
anchor_left = 0.083
|
||||||
anchor_top = 0.694
|
anchor_top = 0.694
|
||||||
@@ -22,7 +22,7 @@ offset_bottom = 19.6479
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
|
||||||
[node name="text_label" type="RichTextLabel" parent="color_rect"]
|
[node name="rich_text_label" type="RichTextLabel" parent="box"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = -1
|
anchors_preset = -1
|
||||||
anchor_left = 0.034
|
anchor_left = 0.034
|
||||||
@@ -40,10 +40,9 @@ theme_override_fonts/normal_font = ExtResource("2_qrihj")
|
|||||||
theme_override_font_sizes/normal_font_size = 32
|
theme_override_font_sizes/normal_font_size = 32
|
||||||
theme_override_font_sizes/bold_font_size = 80
|
theme_override_font_sizes/bold_font_size = 80
|
||||||
bbcode_enabled = true
|
bbcode_enabled = true
|
||||||
text = "this is test text or [center][b][wave amp=50 freq=15][rainbow]This is test text[/rainbow][/wave][/b][/center]"
|
|
||||||
scroll_active = false
|
scroll_active = false
|
||||||
|
|
||||||
[node name="name_label" type="Label" parent="color_rect"]
|
[node name="name_label" type="Label" parent="box"]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = -1
|
anchors_preset = -1
|
||||||
anchor_left = 0.01
|
anchor_left = 0.01
|
||||||
@@ -56,42 +55,44 @@ offset_right = 0.389984
|
|||||||
offset_bottom = 0.118996
|
offset_bottom = 0.118996
|
||||||
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||||
theme_override_fonts/font = ExtResource("2_qrihj")
|
theme_override_fonts/font = ExtResource("2_qrihj")
|
||||||
theme_override_font_sizes/font_size = 32
|
theme_override_font_sizes/font_size = 36
|
||||||
text = "???"
|
text = "???"
|
||||||
|
|
||||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
[node name="panel_container" type="PanelContainer" parent="box"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 1
|
||||||
anchors_preset = 3
|
anchors_preset = 3
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
anchor_top = 1.0
|
anchor_top = 1.0
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = -466.0
|
offset_left = -307.0
|
||||||
offset_top = -312.0
|
offset_top = -304.0
|
||||||
offset_right = -144.0
|
offset_right = 15.0
|
||||||
offset_bottom = -239.0
|
offset_bottom = -231.0
|
||||||
grow_horizontal = 0
|
grow_horizontal = 0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
size_flags_horizontal = 8
|
size_flags_horizontal = 8
|
||||||
size_flags_vertical = 8
|
size_flags_vertical = 8
|
||||||
theme_override_styles/panel = SubResource("StyleBoxEmpty_5w2xu")
|
theme_override_styles/panel = SubResource("StyleBoxEmpty_5w2xu")
|
||||||
|
|
||||||
[node name="NinePatchRect" type="NinePatchRect" parent="PanelContainer"]
|
[node name="nine_patch_rect" type="NinePatchRect" parent="box/panel_container"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
|
[node name="margin_container" type="MarginContainer" parent="box/panel_container"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
theme_override_constants/margin_left = 15
|
theme_override_constants/margin_left = 15
|
||||||
theme_override_constants/margin_top = 15
|
theme_override_constants/margin_top = 15
|
||||||
theme_override_constants/margin_right = 15
|
theme_override_constants/margin_right = 15
|
||||||
theme_override_constants/margin_bottom = 15
|
theme_override_constants/margin_bottom = 15
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
|
[node name="v_box_container" type="VBoxContainer" parent="box/panel_container/margin_container"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
|
[node name="button" type="Button" parent="box/panel_container/margin_container/v_box_container"]
|
||||||
custom_minimum_size = Vector2(128, 32)
|
custom_minimum_size = Vector2(128, 32)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
theme_override_fonts/font = ExtResource("2_qrihj")
|
theme_override_fonts/font = ExtResource("2_qrihj")
|
||||||
theme_override_font_sizes/font_size = 28
|
theme_override_font_sizes/font_size = 28
|
||||||
text = "i want to hear more"
|
text = "---"
|
||||||
alignment = 0
|
alignment = 0
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
|
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
|
||||||
[ext_resource type="Texture2D" uid="uid://olceowuycu8c" path="res://assets/textures/debug/dummy-player-atlas.png" id="2_yu1q5"]
|
[ext_resource type="Texture2D" uid="uid://olceowuycu8c" path="res://assets/textures/debug/dummy-player-atlas.png" id="2_yu1q5"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cg86tsupfq53i" path="res://scenes/gui/dialog_bubble.tscn" id="3_8f573"]
|
[ext_resource type="PackedScene" uid="uid://bkm7365u1mm3o" path="res://scenes/gui/dialog_bubble.tscn" id="3_8f573"]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_tokqm"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_tokqm"]
|
||||||
atlas = ExtResource("2_yu1q5")
|
atlas = ExtResource("2_yu1q5")
|
||||||
@@ -132,3 +132,4 @@ editor_draw_drag_margin = true
|
|||||||
current = true
|
current = true
|
||||||
|
|
||||||
[node name="dialog_bubble" parent="." instance=ExtResource("3_8f573")]
|
[node name="dialog_bubble" parent="." instance=ExtResource("3_8f573")]
|
||||||
|
visible = false
|
||||||
|
@@ -19,7 +19,8 @@ position = Vector2(0, 20.625)
|
|||||||
shape = SubResource("RectangleShape2D_pchpi")
|
shape = SubResource("RectangleShape2D_pchpi")
|
||||||
|
|
||||||
[node name="dialog_trigger_area" parent="." instance=ExtResource("2_blpmd")]
|
[node name="dialog_trigger_area" parent="." instance=ExtResource("2_blpmd")]
|
||||||
dialogFile = "res://dialogue/npcs/villager_normal.json"
|
file = "res://dialogue/npcs/villager_normal.json"
|
||||||
|
title = "Debug cupcake"
|
||||||
|
|
||||||
[node name="collision_shape_2d" parent="dialog_trigger_area" index="0"]
|
[node name="collision_shape_2d" parent="dialog_trigger_area" index="0"]
|
||||||
shape = SubResource("RectangleShape2D_d78tr")
|
shape = SubResource("RectangleShape2D_d78tr")
|
||||||
|
@@ -1,29 +0,0 @@
|
|||||||
using Godot;
|
|
||||||
using Godot.Collections;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
public partial class dialog_bubble : CanvasLayer
|
|
||||||
{
|
|
||||||
public Variant parsedDialog;
|
|
||||||
public Variant test;
|
|
||||||
public override void _Process(double delta)
|
|
||||||
{
|
|
||||||
if (Input.IsActionJustPressed("ui_filedialog_refresh"))//F5
|
|
||||||
{
|
|
||||||
if (test.VariantType == Variant.Type.Array)
|
|
||||||
test = test.AsGodotArray()[0];
|
|
||||||
GD.Print(test);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void GetDialog(string dialogFile)
|
|
||||||
{
|
|
||||||
parsedDialog = Json.ParseString(FileAccess.Open(dialogFile, FileAccess.ModeFlags.Read).GetAsText());
|
|
||||||
GetNode<Label>("color_rect/name_label").Text = parsedDialog.AsGodotDictionary()["dialogTitle"].AsString();
|
|
||||||
Array<string> dialogLinestest = new Array<string>();
|
|
||||||
dialogLinestest.Add("test");
|
|
||||||
dialogLinestest.Add("test2");
|
|
||||||
GD.Print();
|
|
||||||
test = parsedDialog.AsGodotDictionary()["tipp"];
|
|
||||||
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
|
||||||
}
|
|
||||||
}
|
|
45
src/scene-scripts/dialogue-system/dialog_bubble.cs
Normal file
45
src/scene-scripts/dialogue-system/dialog_bubble.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using Godot;
|
||||||
|
using System.Collections;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public partial class dialog_bubble : CanvasLayer
|
||||||
|
{
|
||||||
|
public Variant parsedDlg;
|
||||||
|
public ArrayList dlgLines = new ArrayList();
|
||||||
|
public int dlgPointer = 0;
|
||||||
|
|
||||||
|
public override void _Ready()
|
||||||
|
{
|
||||||
|
dlgLines.Add("Hello! I'm a debug character and...");
|
||||||
|
dlgLines.Add("[center][b][wave amp=50 freq=15][rainbow]This is cool test text[/rainbow][/wave][/b][/center]");
|
||||||
|
}
|
||||||
|
public void GetDialog(string file, string title, Variant actor)
|
||||||
|
{
|
||||||
|
parsedDlg = Json.ParseString(FileAccess.Open(file, FileAccess.ModeFlags.Read).GetAsText());
|
||||||
|
GetNode<Label>("box/name_label").Text = title;
|
||||||
|
GD.Print("Now talking to: " + actor);
|
||||||
|
if (GetParent().Name == "player") GetParent<player>().allowMovement = false;
|
||||||
|
Visible = true;
|
||||||
|
}
|
||||||
|
public void CloseDialog()
|
||||||
|
{
|
||||||
|
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
||||||
|
Visible = false;
|
||||||
|
dlgPointer = 0;
|
||||||
|
GetNode<RichTextLabel>("box/rich_text_label").Text = "";
|
||||||
|
GetNode<Label>("box/name_label").Text = "???";
|
||||||
|
}
|
||||||
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
if (Input.IsActionJustPressed("ui_accept"))
|
||||||
|
{
|
||||||
|
var textBlock = GetNode<RichTextLabel>("box/rich_text_label");
|
||||||
|
if (dlgPointer < dlgLines.Count && dlgLines[dlgPointer] is string) textBlock.Text = dlgLines[dlgPointer].ToString();
|
||||||
|
dlgPointer++;
|
||||||
|
}
|
||||||
|
if (dlgPointer > dlgLines.Count)
|
||||||
|
CloseDialog();
|
||||||
|
}
|
||||||
|
//get dialogue inside dialogLines and add them to
|
||||||
|
//richtextlabel and detect dictionarys in them and display them as prompts
|
||||||
|
}
|
@@ -3,10 +3,11 @@ using System;
|
|||||||
|
|
||||||
public partial class dialog_trigger_area : Area2D
|
public partial class dialog_trigger_area : Area2D
|
||||||
{
|
{
|
||||||
[Signal] public delegate void InteractDialogueEventHandler();
|
[Export(PropertyHint.File, "*json")] string file;
|
||||||
[Export(PropertyHint.File, "*json")] string dialogFile;
|
[Export] string title;
|
||||||
public void OnInteraction(string playerName)
|
public Variant actor;
|
||||||
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
actor = GetParent(); //must be the scene's root node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ public partial class player : CharacterBody2D
|
|||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("ui_accept") && dialogRayCast.IsColliding() && allowMovement)
|
if (Input.IsActionJustPressed("ui_accept") && dialogRayCast.IsColliding() && allowMovement)
|
||||||
GetNode<dialog_bubble>("dialog_bubble").GetDialog(dialogRayCast.GetCollider().Get("dialogFile").AsString());
|
GetNode<dialog_bubble>("dialog_bubble").GetDialog(dialogRayCast.GetCollider().Get("file").AsString(), dialogRayCast.GetCollider().Get("title").AsString(), dialogRayCast.GetCollider().Get("actor"));
|
||||||
|
|
||||||
//animation system (with controller support wich cant get normalized vector)
|
//animation system (with controller support wich cant get normalized vector)
|
||||||
if (allowMovement == false)
|
if (allowMovement == false)
|
||||||
|
Reference in New Issue
Block a user