added basic dialogue bubble functionality

This commit is contained in:
2023-02-03 20:24:45 +01:00
parent d119321104
commit bf09061c5e
8 changed files with 74 additions and 55 deletions

View 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
}

View File

@@ -3,10 +3,11 @@ using System;
public partial class dialog_trigger_area : Area2D
{
[Signal] public delegate void InteractDialogueEventHandler();
[Export(PropertyHint.File, "*json")] string dialogFile;
public void OnInteraction(string playerName)
[Export(PropertyHint.File, "*json")] string file;
[Export] string title;
public Variant actor;
public override void _Ready()
{
actor = GetParent(); //must be the scene's root node
}
}