From 855fd02286986787febd68a6d53bf37982bf96ce Mon Sep 17 00:00:00 2001 From: grumbel Date: Wed, 18 Nov 2009 03:25:12 +0000 Subject: [PATCH] Split supertux/options_menu.?pp git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6026 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- src/supertux/language_menu.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++ src/supertux/language_menu.hpp | 36 ++++++++++++++++++++ src/supertux/options_menu.cpp | 66 +------------------------------------ src/supertux/options_menu.hpp | 20 +++++++++++- 4 files changed, 130 insertions(+), 66 deletions(-) create mode 100644 src/supertux/language_menu.cpp create mode 100644 src/supertux/language_menu.hpp diff --git a/src/supertux/language_menu.cpp b/src/supertux/language_menu.cpp new file mode 100644 index 000000000..d7a0fb174 --- /dev/null +++ b/src/supertux/language_menu.cpp @@ -0,0 +1,74 @@ +// SuperTux +// Copyright (C) 2004 Tobas Glaesser +// Copyright (C) 2006 Matthias Braun +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "supertux/language_menu.hpp" + +#include "gui/menu_item.hpp" +#include "supertux/gameconfig.hpp" + +LanguageMenu::LanguageMenu() +{ + add_label(_("Language")); + add_hl(); + add_entry(0, std::string("<")+_("auto-detect")+">"); + add_entry(1, "English"); + + int mnid = 10; + std::set languages = dictionary_manager.get_languages(); + for (std::set::iterator i = languages.begin(); i != languages.end(); i++) { + std::string locale_name = *i; + TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name); + std::string locale_fullname = locale_name; + if (std::string(ldef.code) == locale_name) { + locale_fullname = ldef.name; + } + add_entry(mnid++, locale_fullname); + } + + add_hl(); + add_back(_("Back")); +} + +void +LanguageMenu::menu_action(MenuItem* item) +{ + if (item->id == 0) { + g_config->locale = ""; + dictionary_manager.set_language(g_config->locale); + g_config->save(); + Menu::pop_current(); + } + else if (item->id == 1) { + g_config->locale = "en"; + dictionary_manager.set_language(g_config->locale); + g_config->save(); + Menu::pop_current(); + } + int mnid = 10; + std::set languages = dictionary_manager.get_languages(); + for (std::set::iterator i = languages.begin(); i != languages.end(); i++) { + std::string locale_name = *i; + if (item->id == mnid++) { + g_config->locale = locale_name; + dictionary_manager.set_language(g_config->locale); + g_config->save(); + Menu::pop_current(); + } + } +} + +/* EOF */ diff --git a/src/supertux/language_menu.hpp b/src/supertux/language_menu.hpp new file mode 100644 index 000000000..c2d3a0f58 --- /dev/null +++ b/src/supertux/language_menu.hpp @@ -0,0 +1,36 @@ +// SuperTux +// Copyright (C) 2004 Tobas Glaesser +// Copyright (C) 2006 Matthias Braun +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_SUPERTUX_LANGUAGE_MENU_HPP +#define HEADER_SUPERTUX_SUPERTUX_LANGUAGE_MENU_HPP + +#include + +#include "util/gettext.hpp" +#include "gui/menu.hpp" + +class LanguageMenu : public Menu +{ +public: + LanguageMenu(); + + virtual void menu_action(MenuItem* item); +}; + +#endif + +/* EOF */ diff --git a/src/supertux/options_menu.cpp b/src/supertux/options_menu.cpp index 06556bdd6..e218a1037 100644 --- a/src/supertux/options_menu.cpp +++ b/src/supertux/options_menu.cpp @@ -24,6 +24,7 @@ #include "supertux/gameconfig.hpp" #include "supertux/main.hpp" #include "supertux/profile_menu.hpp" +#include "supertux/language_menu.hpp" #include "util/gettext.hpp" #include "video/renderer.hpp" @@ -39,71 +40,6 @@ enum OptionsMenuIDs { MNID_MUSIC }; -class LanguageMenu : public Menu -{ -public: - LanguageMenu() { - add_label(_("Language")); - add_hl(); - add_entry(0, std::string("<")+_("auto-detect")+">"); - add_entry(1, "English"); - - int mnid = 10; - std::set languages = dictionary_manager.get_languages(); - for (std::set::iterator i = languages.begin(); i != languages.end(); i++) { - std::string locale_name = *i; - TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name); - std::string locale_fullname = locale_name; - if (std::string(ldef.code) == locale_name) { - locale_fullname = ldef.name; - } - add_entry(mnid++, locale_fullname); - } - - add_hl(); - add_back(_("Back")); - } - - virtual void menu_action(MenuItem* item) { - if (item->id == 0) { - g_config->locale = ""; - dictionary_manager.set_language(g_config->locale); - g_config->save(); - Menu::pop_current(); - } - else if (item->id == 1) { - g_config->locale = "en"; - dictionary_manager.set_language(g_config->locale); - g_config->save(); - Menu::pop_current(); - } - int mnid = 10; - std::set languages = dictionary_manager.get_languages(); - for (std::set::iterator i = languages.begin(); i != languages.end(); i++) { - std::string locale_name = *i; - if (item->id == mnid++) { - g_config->locale = locale_name; - dictionary_manager.set_language(g_config->locale); - g_config->save(); - Menu::pop_current(); - } - } - } -}; - -class OptionsMenu : public Menu -{ -public: - OptionsMenu(); - virtual ~OptionsMenu(); - - virtual void menu_action(MenuItem* item); - -protected: - std::auto_ptr language_menu; - -}; - OptionsMenu::OptionsMenu() : language_menu() { diff --git a/src/supertux/options_menu.hpp b/src/supertux/options_menu.hpp index 998bd2727..be2264d71 100644 --- a/src/supertux/options_menu.hpp +++ b/src/supertux/options_menu.hpp @@ -18,10 +18,28 @@ #ifndef HEADER_SUPERTUX_SUPERTUX_OPTIONS_MENU_HPP #define HEADER_SUPERTUX_SUPERTUX_OPTIONS_MENU_HPP -class Menu; +#include + +#include "gui/menu.hpp" + +class LanguageMenu; + Menu* get_options_menu(); void free_options_menu(); +class OptionsMenu : public Menu +{ +public: + OptionsMenu(); + virtual ~OptionsMenu(); + + virtual void menu_action(MenuItem* item); + +protected: + std::auto_ptr language_menu; + +}; + #endif /* EOF */ -- 2.11.0