Building the Dialogue System for Neon Atelier

As we have planned narrative elements for Project Neon Atelier, we need a way to present to the conversation between in-game characters. Our idea is to implement a dialogue system similar to that of visual visual, with clicking to proceed through the dialogue line. 

Each dialogue line is defined as a DialogueLine instance, each consisting of the speaker's name, the speaker's position reference, and also callbacks for when displaying a line and finish reading a line. 

An dialogue path system is be added, so that we can group together some of the related dialogues, and allow the player to go back to a selection menu to load the dialogue sections one at a time. However, the path is not meant for dynamic storyline, as our narrative is not meant to be driven by player decision.

 Each point of path divergence is represented by DialogueOption object, which consist of the description for selection, a list of tuple with text and custom callbacks for each selection option, and also callbacks for when displaying a line and finish reading a line. The list of tuple will be dynamically loaded as the button into the dialogue box, and provide onClick that jump to specific lines or enter into mission. 

For such a dialogue system, an common parent for DialogueLine and DialogueOption  would be very useful, as this enables them to be stacked in one (or perhaps a few) IEnumerable set that is(are) easier to access. As both DialogueLine and DialogueOption has an character position reference, text(or description or dialog text), onStart and onComplete callback, these are extracted into an base abstract class DialogueItem


After defining the representation for dialogue data, we moved on to implement ways to visualize the dialogue in our game. The DialogueBoxHandler script is implemented to take in any DialogueLine instance, and then reuse the received data to display a dialog box with animation. The dialog box also has click trigger to load the next dialogue. 


And the DialogueOptionHandler script implemented to display the data from the DialogueOption instances. The script provide method that can accept up to four DialogueOption  object at a time, and then bind their texts and click events onto the buttons on a selection menu. 



On top of the handler scripts, a DialogueManager script is implemented as the centralized handler for the dialogue flow. As mention above,  both DialogueLine and DialogueOption is based upon the DialogueItem type. The DialogueManager therefore only have hold a list of DialogueItem object of the current dialogue, and inject the data to DialogueBoxHandler and DialogueOptionHandler  as it check the item's type during runtime.


To make our code more concise, we implemented a AppendDialogueTo() and AppendOptionsTo() to loop through params of dialogue line/option as the ending parameter. This enable us to define our dialogue in the following neat syntax, avoid constructor boilerplate such as list.add(new DialogueLine(...)). This spares us from a lot of coding noise, as we expect to writing perhaps up to a hundred dialogue lines.

With the above implementation, we now have elementary but neat and system to present dialogues and option menus in our game : )