This week I wanted to start working on story elements. I decided to create a system for any game I make where I can easily navigate a dialogue tree...and one that is dynamic and loops on itself as well.
I just finished it. It does not look pretty at the moment, but the next step will be polishing it.
We have 5 classes for this and a struct, although I think one of them might be redundant.
Firstly is the dialogue manager. This will be listening in on the game and load the dialogue system when it is activated. The screen will go dark. It will then load the dialogue from the dialogue database class. Once loaded, it calls a method to load the next text response. The Response is a struct that contains the NPC Name and the text. If this Queue has text, we will load the text objects on the screen with the name and the portrait of the NPC and what they said...there will then be a continue button to move to the next Response in the queue.
Once the queue is out, we go through and instantiate our options. This is dynamic and created in code, with listeners loaded in code. The Options area is a grid that will line up all the buttons for me, and it can handle however many I want to give it. I need to have it resize things as the options grow, but for now it can handle 9 options without any issues on different screen sizes. Once a button is clicked, it cleans up all the listeners on the buttons and gets rid of the buttons. Later, we can implement a spawning pool here so that we don't constantly destroy game objects. Each button also will update the dialogue map on which node it gets sent to.
The dialogue manager then loads up the responses from the Queue of the new node, and we continue on.
So now with this sytem, the only thing I need to do to add dialogue is to place it all in the database, and then add a listener for this dialogue trigger in the game somewhere. Super cool stuff.
Next time I will have animations polished, and have the UI look a little better to be able to show it off. I'm pretty happy with it.