Week of Awesome III - Initial ground work

posted in Journal of Mussi
Published August 15, 2015
Advertisement
So, I've set up some initial ground work for my text based game. As I mentioned previously, I'm using the ImGui library. At the time of this posting there's no support for multi-line colored text, so I had to write that myself. I went for an approach where I can just place tags within a string to colorize sections of the string, much like html tags. Took me a couple of hours, but I'm sure it'll be worth it, not only is staring at a single color really boring, it's also hard to convey some information to the player without it. Like if there's some object the player should interact with, it makes it easier if it's colored within the text.

I ran into some interesting problems when implementing this. Say you have text with tags in them that you have to parse, this text also need to be broken up into lines manually, what would you do first? Splitting the text up for the colors first leaves you with chunks that may or may not fit on a single line, having to split up these parts again seems like a lot of work. The second approach is breaking the text up by lines first, but this time you run into the problem that the tags are still there so you'll end up with lines not filling the entire width. Oh noes!

I went for the second option, but on determining where to break the lines I keep the tags in mind. That means that every time I need a length or offset into a string I manually count said length or offset and ignore tags in the process.

Another thing was that ImGui is (obviously) an immediate mode UI library, which has it's drawbacks. I would have to parse tags and break up lines on every frame, which might not be a problem for the length of my game on modern day computers, but it felt wrong to keep it like that. So I implemented some retention for my multi-line colored text, I only have to parse tags and break lines once. Okay maybe that's not exactly true... once per window resize.

That's all for now, of to some gameplay programming!

Screenshot:
first-console-test.jpg
3 likes 3 comments

Comments

Orymus3

Using RichText enabled Unity engine for the past one year, it's easy to forget just how much trouble it is to get colored text in a any given body of text. Gratz on achieving this and having to deal with what many take for granted!

August 16, 2015 12:59 AM
Mussi

Hehe thanks, yeah it really is easy to forget, but 200 lines of code will make you remember :P.

August 16, 2015 01:36 AM
slicer4ever
yea, RichText is definitely a pickle to say the least. I do something similar to you, but since the text being rendered is generally passed in as a literal string, i have no immediate struct to store the different components, so i have to reparse each frame. (maybe i should support sometype of object that does this?)

anywho, looking good mussi, but not much time left!
August 16, 2015 03:03 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement