Task2.begin() – Moving GUI to use U32Strings!

This week, I got started with my new task – Moving GUI to U32Strings.
Before I tell more about it, some miscellaneous things that happened this week:

A team-member of ScummVM had previously worked on adding the achievements for some Wintermute games. He was very nice to offer me a game copy to test out the achievements for my task, but I had some steam credit so I thought there was finally a use for them! This way, I have bought my first ever steam game! I have run out of games – pre-2011 – that I can play on potato pc, so I never really bought anything from Steam. I have yet to try out the game, maybe sometime soon!

While cleaning up the history and adding more code, I came across a merge conflict. Previously, I would just find a way around them, but this time I tried to solve it following step-by-step. This way, I learned how to solve merge conflicts! It was quite simple (at least for my small changes), and not as complicated as I thought it would be. I will try to solve more small issues with merge conflicts now.

Another member of the community is testing out new things and making some improvement patches for my previous task – “RTL GUI”. He has written very clean and minimal code compared to the original code for Editables (widgets to type in) and Tabs. It was also a very great improvement over my code. It was very interesting to see how much a specific piece of code could be improved.

The new task:

So, how did I get started with my new task? In my last task, there were visual changes and behaviors I needed to change, and everything was pretty visible from the get-go. In this task, not so much. So, I decided to start small. Every widget in ScummVM has “Name” and “Label”, amongst other things.
Names are used internally, while labels are the text that widgets have attached which eventually get rendered. So, at the very base, I changed the label of ButtonWidgets from String to U32String. Apart from Labels, there are also many other things needed to be converted, but this seemed like a great place to start.
In ScummVM, there is a very neat little system and macros defined for translations. To use them in code, you would just do something like
_(“Message”)
and I get my translated piece of string (if any present) as type const char *. Because translations are used everywhere in the project, I can’t just change the return type here, because that will break too many things at 1 time and become a pain to solve each one without seeing any progress. So, after changing the label for one specific widget, I simply followed errors and converted the strings to U32Strings on a temporary basis like:
…, convertToU32(_(“Message”)), …
When all compilation errors got solved, I moved widget by widget. First, I covered all types of Buttons, then TextWidgets, Tabs, and so on.
To make them draw as U32String, I also changed the internal code to the appropriate type. At one further internal step, the drawing function only accepted Strings. So, there and many places, I used overloading to temporarily accept U32Strings as well as Strings – so all other unconverted widgets also draw properly.
After converting all widgets and using a bunch of temporary code, I gave my code a try. It worked near-perfectly for English but broke a lot of things in other languages, which was expected. Hebrew broke it nearly completely (as in the picture below).
On Friday evening, I sat down to finally change translations to return U32Strings, which would mean that they affected the whole project. Because I had converted most widgets to U32Strings, I thought it was time. I hit compile and there were ~650 errors and 50 warnings! After widgets, I focused on converting tooltips from const char* to U32String. In code, everywhere a tooltip was not to be used, we used nullptr to mark a tooltip as absent. So, that also had to be changed. The issue with tooltips and my old temporary code made up half of the errors.
So, that day I spent clearing out all of them.

Firstly I decided to focus on the small issues with nullptr and my previous temp code. Finally, my shell-scripting classes came to see real use! I was a little rusty and unsure because I haven’t really used it in a project of this big size. But after some careful commits and checking, I was able to wipe these errors (~350-400) in a short period of time with minimal other side-effects.

Afterward, I manually went through the remaining to solve them out one-by-one. I found a lot of missing places where drawable text could be made as U32Strings.
I succeeded in solving all of them, but there was a small problem with a formatting function, which caused runtime exceptions when I tried to change the languages. Below is the result, with most things working properly! Now it is not broken compared to the previous image, which is nice!

I’m thinking by next week, I will be polishing up this task! I’m happy that this task also has a good little progress.

Thanks for reading!