Dark Age Dialog Editor & Dialogs

Published January 11, 2010
Advertisement
I have finally managed to implement the first dialog system into the game.It is a very simple system which consists of strings stored in text files in a hierarchical manner.

The first step was to create a tool to create these dialog files.I was very tired of doing everything in pure c++ and win32 so this time I used c# to create the dialog editor.The dialog editor can work as a stand alone program or it can be launched from Dark Age World Editor.It can add new nodes delete nodes save and load dialog files from the disk.Here is a screen shot of the the dialog editor.





As you can see its pretty simple.This hierarchy is saved to a text file,I used white spaces to keep the hierarchy intact so the above dialog looks like this in a text file.

Greetings , how can I help you? I am looking for wooden logs for the guards.Do you know where I can find them?  Yes,you can find them south of here behind the barracks,under the trees.   Can I ask you something else?   Thanks,bye! Where can I get training?  Master Isdali can train you.You can find him inside the barracks.   Can I ask you something else?   I see, bye. Where can I buy equipment?  Talk to a merchant in the town you can sell and buy equipment from any merchant.   Can I ask you something else?   Ok,farewell.


While reading this back I check the white spaces and recreate the dialog hiearchy with the following code.The following code is in C++ but the same code is ported to C# for the dialog editor.

#include #include #include "DialogueNode.h"DialogueNode::DialogueNode(const std::string& text,DialogueNode* parent):m_Text(text),m_Parent(parent){}DialogueNode* DialogueNode::addNode(const std::string& text,DialogueNode* parent){	boost::shared_ptr newNode(new DialogueNode(text,parent));	m_ChildNodes.push_back(newNode);	return newNode.get();}bool StartsWith(const std::string& text,const std::string& token){	if(text.length() < token.length())		return false;	return (text.compare(0, token.length(), token) == 0);}void DialogueNode::recurseNode(std::ifstream& file,std::string text,int level,DialogueNode* node){	if (text.length() == 0)		return;	std::string whiteSpace = "";	for (int i = 0; i < level; ++i)	{		whiteSpace += " ";	}		if(StartsWith(text,whiteSpace))	{				std::string key = text.substr(whiteSpace.length());				DialogueNode* addedNode = node->addNode(key,node);				std::getline(file,text);				recurseNode(file,text, level + 1, addedNode);	}	else	{		recurseNode(file,text, level - 1, node->m_Parent);	}}Dialogue::Dialogue(const std::string& filename){	std::ifstream file(filename.c_str());	int level= 0;	std::string text;	std::getline(file,text);	//create root node	if(text.length())	{		m_Root.reset(new DialogueNode(text,NULL));				std::getline(file,text);		if(text.length())		{			m_Root->recurseNode(file,text,level+1,m_Root.get());		}	}}


Once the dialog is read from the file the only thing left is to display it through the interface.I created buttons from my interface and gave them a Dialog Node member each time a button is clicked the current root is changed to the current clicked button's first child member node.

The only hackish thing at the moment is when the dialog reaches the leaf nodes,there are only two options.The first on always returns the dialog to the root and the second one always ends the dialog,this is currently hard coded and should change in the future.

Here is how it looks in the game.







It is possible to give each dialog node different properties.For example certain nodes might give xp,gold when clicked or trigger other stuff.This requires the functionality to disable dialogue nodes once they are triggered.At the moment the dialog structure is static and all nodes are always visible.

Each unit entity in the game has a member called DialogFile.This is a string member indicating the dialog file to use for this unit and it is set from the world editor.So you can use the same dialog text for multiple units but that doesn't make sense :),If this member is an empty string that character doesn't have a dialog.

That's all about the dialog system for now.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

Advertisement