Remember language selection in user config + fix a few language menu glitches

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7430 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2011-01-15 21:49:15 +00:00
parent 5076006d34
commit 28db1165b1
3 changed files with 46 additions and 19 deletions

View File

@@ -225,7 +225,6 @@ public:
*/
namespace UserConfigParams
{
// ---- Audio
PARAM_PREFIX GroupUserConfigParam m_audio_group
PARAM_DEFAULT( GroupUserConfigParam("Audio", "Audio Settings") );
@@ -318,6 +317,8 @@ namespace UserConfigParams
* must always be printed. */
PARAM_PREFIX int m_verbosity PARAM_DEFAULT( 0 );
PARAM_PREFIX bool m_no_start_screen PARAM_DEFAULT( false ); // not saved to file
// ---- Networking
PARAM_PREFIX StringUserConfigParam m_server_address
PARAM_DEFAULT( StringUserConfigParam("localhost", "server_adress", "Information about last server used") );
@@ -363,7 +364,9 @@ namespace UserConfigParams
PARAM_PREFIX StringUserConfigParam m_server_addons
PARAM_DEFAULT( StringUserConfigParam("http://download.tuxfamily.org/stkaddons/0.7/", "server_addons", "The server used for addon.") );
PARAM_PREFIX bool m_no_start_screen PARAM_DEFAULT( false ); // not saved to file
PARAM_PREFIX StringUserConfigParam m_language
PARAM_DEFAULT( StringUserConfigParam("system", "language", "Which language to use (language code or 'system')") );
// TODO? implement blacklist for new irrlicht device and GUI
PARAM_PREFIX std::vector<std::string> m_blacklist_res;

View File

@@ -724,8 +724,16 @@ int handleCmdLine(int argc, char **argv)
void initUserConfig(char *argv[])
{
file_manager = new FileManager(argv);
translations = new Translations(); // needs file_manager
user_config = new UserConfig(); // needs file_manager
if (UserConfigParams::m_language.toString() != "system")
{
char buffer[1024];
snprintf(buffer, 1024, "LANGUAGE=%s", UserConfigParams::m_language.c_str());
putenv( buffer );
}
translations = new Translations(); // needs file_manager
stk_config = new STKConfig(); // in case of --stk-config
// command line parameters
} // initUserConfig

View File

@@ -126,19 +126,22 @@ void MainMenuScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
w->setText(news_text.c_str());
IconButtonWidget* lang_combo = this->getWidget<IconButtonWidget>("lang_combo");
irr::gui::ScalableFont* font = GUIEngine::getFont();
// I18N: Enter the name of YOUR language here, do not literally translate the word "English"
font->draw(_("English"),
core::rect<s32>(lang_combo->m_x, lang_combo->m_y,
lang_combo->m_x + lang_combo->m_w*0.9f, // multiply to not go over combo arrow
lang_combo->m_y + lang_combo->m_h),
video::SColor(255,0,0,0), true /* hcenter */, true /* vcenter */);
// Close popup when focus lost
if (m_lang_popup != NULL && !m_lang_popup->isFocusedForPlayer(PLAYER_ID_GAME_MASTER))
if (lang_combo != NULL)
{
closeLangPopup();
irr::gui::ScalableFont* font = GUIEngine::getFont();
// I18N: Enter the name of YOUR language here, do not literally translate the word "English"
font->draw(_("English"),
core::rect<s32>(lang_combo->m_x, lang_combo->m_y,
lang_combo->m_x + lang_combo->m_w*0.9f, // multiply to not go over combo arrow
lang_combo->m_y + lang_combo->m_h),
video::SColor(255,0,0,0), true /* hcenter */, true /* vcenter */);
// Close popup when focus lost
if (m_lang_popup != NULL && !m_lang_popup->isFocusedForPlayer(PLAYER_ID_GAME_MASTER))
{
closeLangPopup();
}
}
}
#endif
@@ -151,7 +154,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, cons
if (ribbon == NULL)
{
// Language selection combo
if (name == "lang_combo")
if (name == "lang_combo" && m_lang_popup == NULL)
{
// When the combo is clicked, show a pop-up list with the choices
IconButtonWidget* lang_combo = this->getWidget<IconButtonWidget>("lang_combo");
@@ -176,6 +179,9 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, cons
m_lang_popup->m_properties[PROP_ID] = "language_popup";
// I18N: in the language choice, to select the same language as the OS
m_lang_popup->addItem("system", _("System Language"));
const std::vector<std::string>* lang_list = translations->getLanguageList();
const int amount = lang_list->size();
for (int n=0; n<amount; n++)
@@ -219,12 +225,22 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, cons
delete translations;
char buffer[1024];
snprintf(buffer, 1024, "LANGUAGE=%s", selection.c_str());
putenv( buffer );
if (selection == "system")
{
putenv( "LANGUAGE=" );
}
else
{
char buffer[1024];
snprintf(buffer, 1024, "LANGUAGE=%s", selection.c_str());
putenv( buffer );
}
translations = new Translations();
GUIEngine::getStateManager()->hardResetAndGoToScreen<MainMenuScreen>();
UserConfigParams::m_language = selection.c_str();
user_config->saveConfig();
}
return;