reorganized some files and deleted some for dialogue rewrite
This commit is contained in:
@@ -7,6 +7,6 @@ public partial class dialog_trigger_area : Area2D
|
||||
string dialogFile;
|
||||
public void OnInteraction(string playerName)
|
||||
{
|
||||
GetNode("/root/main/dialog_bubble").Call("ImportString",dialogFile,playerName);
|
||||
GetNode("/root/main/dialog_bubble").Call("ImportString",dialogFile,playerName);//signal instead of call?
|
||||
}
|
||||
}
|
||||
|
@@ -1,61 +1,10 @@
|
||||
//WORK IN PROGRESS this code is very messy and will be fixed when it works
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class dialog_bubble : CanvasLayer
|
||||
{
|
||||
public Dictionary allDialog;
|
||||
public List<string> currentDialogList = new List<string>();
|
||||
public string currentKey;
|
||||
public string currentDialogLine;
|
||||
public int dialogCounter;
|
||||
public string userName;
|
||||
public void ImportString(string dialogFile, string playerName)
|
||||
{
|
||||
userName = playerName;
|
||||
GetNode("/root/main/player").Call("ChangeProcess", false);
|
||||
currentKey = "multiTipp2";//2 is a selection menu needs to be planned before coding
|
||||
using var file = FileAccess.Open(dialogFile, FileAccess.ModeFlags.Read);
|
||||
string text = file.GetAsText();
|
||||
allDialog = (Dictionary)JSON.ParseString(text);
|
||||
GetNode<Label>("NameLabel").Text = allDialog["dialogTitle"].ToString();
|
||||
addText();
|
||||
|
||||
|
||||
//Todo: Implement the better json file structure.
|
||||
|
||||
}
|
||||
public void EndDialog()
|
||||
{
|
||||
currentDialogList = new List<string>();
|
||||
dialogCounter = 0;
|
||||
Visible = false;
|
||||
GetNode("/root/main/player").Call("ChangeProcess", true);
|
||||
}
|
||||
public void addText()
|
||||
{
|
||||
var dialogWithKey = allDialog[currentKey].AsStringArray();
|
||||
if (currentKey.StartsWith("random"))
|
||||
currentDialogList.Add(dialogWithKey[GD.Randi() % dialogWithKey.Length]);
|
||||
if (currentKey.StartsWith("multi"))
|
||||
currentDialogList.AddRange(dialogWithKey);
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("ui_accept"))
|
||||
{
|
||||
dialogCounter++;
|
||||
if (currentDialogList.Count >= dialogCounter)
|
||||
{
|
||||
Visible = true;
|
||||
currentDialogLine = currentDialogList[dialogCounter - 1];
|
||||
currentDialogLine = String.Format(currentDialogLine, userName);
|
||||
GetNode<Label>("TextLabel").Text = currentDialogLine;
|
||||
}
|
||||
if (dialogCounter > currentDialogList.Count)
|
||||
EndDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,8 +31,8 @@ public partial class player : CharacterBody2D
|
||||
Vector2 rayCastPosition = new Vector2((float)Math.Round(movement.x), (float)Math.Round(movement.y)) * rayCastLength;
|
||||
if (rayCastPosition.Length() != 0) rayCast.TargetPosition = rayCastPosition;
|
||||
//call event in raycasted object
|
||||
if (Input.IsActionJustPressed("ui_accept") && rayCast.IsColliding())
|
||||
rayCast.GetCollider().Call("OnInteraction", playerName);
|
||||
/*if (Input.IsActionJustPressed("ui_accept") && rayCast.IsColliding())
|
||||
rayCast.GetCollider().Call("OnInteraction", playerName);*/
|
||||
//animation system (with controller support wcih cant get normalized vector)
|
||||
if (movement.Length() != 0)
|
||||
animatedSprite.Play();
|
||||
|
Reference in New Issue
Block a user