Join GitHub today
GUI: Restore previous settings if GUI cannot be rendered #921
This PR focuses on GlobalOptionsDialog::apply() to determine incompatible font/charset and fallback to previous settings on error.
I have not looked at this code yet. The mapping I wrote assumes that:
Based on that I mapped what happens when changing both the language and theme, if the language is changed first (as was done before PR #919) and when the theme is changed first (as was done in PR #919). The 7 cases I considered are a combination of 3 incompatibilities:
This gave me the following table:
Note: The issue you see with greek is likely related to missing Helvetica font for charset iso-8859-7 in our code base.
The behavior described in the table of criezy's post has changed drastically with this PR.
What's currently left on my list:
There is an issue with this change.
Have you noticed what is done at the end of OptionsDialog::apply() and thus before your change was done at the end of GlobalOptionsDialog::apply() but is not done there anymore?
Answer: the changes to ConfMan done by GlobalOptionsDialog::apply() after calling OptionsDialog::apply() are not flushed to disk anymore. This needs to be addressed.
Edit: This comment refers to commit 8959dee. Despite adding this comment in the commit view, it seems it is not associated to the commit apparently, which makes it confusing.
Edit: this comment refers to commit d39beb7.
I don't think this is the correct change to fix this issue. With your change, when selecting the default language, you save to the config file the language actually used. This means that if the user then closes ScummVM, changes the system language and then reopen ScummVM, he will not get the default language (the system language) but the old system language instead.
Currently, when selecting the "gui_language" setting is removed from the config file, which is as it should be. Next time ScummVM is started it will use the system language, whatever it is.
The issue is with the way the ConfigManager works: after calling ConfMan::set("gui_language", Common::String()), ConfMan::hasKey("gui_language") will return true, despite the value being empty. And TransMan.parseLanguage("") returns the kTranslationBuiltinId and not the kTranslationAutodetectId. So if you set the language to and apply the change (or click on OK and then reopen the options dialog), the language selector is initialized to English. This is what needs to be fixed.
Note: when the config is saved to disk it skips config that have an empty value. So setting the language to default, clicking on OK and then closing ScummVM will behave as expected. After restarting ScummVM since the gui_language setting is not defined in the config file, ConfMan::hasKey("gui_language") will be false and opening the option dialog will correctly initialize the language selector.
The behaviour you propose in case of language/theme incompatibility seems fine to me. At least it is simple. I have not checked but I suspect we might get some confusing warning messages though (for example the one from ThemeEngine that says that it fails to load the localized font and use stye default language instead, when in the end we revert to the previous language, which might not be the default language). So I think it might be nice to expand a bit the error MessageDialog you have in GlobalOptionsDialog::apply() when reverting changes.
Another remark is that with your change it seems that it is rebuilding the dialog whenever redraw is true, which happens when changing the language or the theme or the renderer. But rebuild is only needed when changing the language. When changing the theme or renderer without changing the language calls to loadNewTheme() and draw() are sufficient. So it would be nice to avoid rebuilding the dialog in such a case.