4 // Copyright (C) 2004 Tobas Glaesser <tobi.web@gmx.de>
5 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <math.h> //for log10()
23 #include "profile_menu.hpp"
24 #include "options_menu.hpp"
25 #include "gui/menu.hpp"
26 #include "audio/sound_manager.hpp"
27 #include "control/joystickkeyboardcontroller.hpp"
29 #include "gettext.hpp"
30 #include "gameconfig.hpp"
32 Menu* options_menu = 0;
41 class LanguageMenu : public Menu
45 add_label(_("Language"));
47 add_entry(0, std::string("(")+_("auto-detect language")+")");
48 add_entry(1, "English");
51 std::set<std::string> languages = dictionary_manager.get_languages();
52 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
53 std::string locale_name = *i;
54 TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name);
55 std::string locale_fullname = locale_name;
56 if (std::string(ldef.code) == locale_name) {
57 locale_fullname = ldef.name;
59 add_entry(mnid++, locale_fullname);
66 virtual void menu_action(MenuItem* item) {
69 dictionary_manager.set_language(config->locale);
73 else if (item->id == 1) {
74 config->locale = "en";
75 dictionary_manager.set_language(config->locale);
80 std::set<std::string> languages = dictionary_manager.get_languages();
81 for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
82 std::string locale_name = *i;
83 if (item->id == mnid++) {
84 config->locale = locale_name;
85 dictionary_manager.set_language(config->locale);
94 class OptionsMenu : public Menu
98 virtual ~OptionsMenu();
100 virtual void menu_action(MenuItem* item);
103 std::auto_ptr<LanguageMenu> language_menu;
107 OptionsMenu::OptionsMenu()
109 language_menu.reset(new LanguageMenu());
111 add_label(_("Options"));
114 add_submenu(_("Select Language"), language_menu.get())
115 ->set_help(_("Switch to another language"));
117 add_submenu(_("Select Profile"), get_profile_menu())
118 ->set_help(_("Switch between different savegames"));
120 add_toggle(MNID_SOUND, _("Profile on Startup"), config->sound_enabled)
121 ->set_help(_("Display the profile menu when the game is newly started"));
123 // FIXME: Implement me: if (get_parent() == main_menu)
124 add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen)
125 ->set_help(_("Let the game cover the whole screen"));
127 MenuItem* aspect = add_string_select(MNID_ASPECTRATIO, _("Aspect Ratio"));
128 aspect->set_help(_("Adjust the aspect ratio"));
130 aspect->list.push_back("16:9");
131 aspect->list.push_back("16:10");
132 aspect->list.push_back("4:3");
133 aspect->list.push_back("5:4");
135 std::ostringstream out;
136 out << config->aspect_width << ":" << config->aspect_height;
137 std::string aspect_ratio = out.str();
138 for(std::vector<std::string>::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i)
140 if(*i == aspect_ratio)
142 aspect_ratio.clear();
147 if (!aspect_ratio.empty())
149 aspect->selected = aspect->list.size();
150 aspect->list.push_back(aspect_ratio);
153 if (sound_manager->is_audio_enabled()) {
154 add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled)
155 ->set_help(_("Disable all sound effects in the game"));
156 add_toggle(MNID_MUSIC, _("Music"), config->music_enabled)
157 ->set_help(_("Disable all music in the game"));
159 add_deactive(MNID_SOUND, _("Sound (disabled)"));
160 add_deactive(MNID_SOUND, _("Music (disabled)"));
163 add_submenu(_("Setup Keyboard"), main_controller->get_key_options_menu())
164 ->set_help(_("Configure how your keyboard maps to the game"));
166 add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu())
167 ->set_help(_("Configure how your joystick maps to the game"));
172 OptionsMenu::~OptionsMenu()
177 OptionsMenu::menu_action(MenuItem* item)
180 case MNID_ASPECTRATIO:
181 { // FIXME: Really crude and ugly here, move to video or so
182 if(sscanf(item->list[item->selected].c_str(), "%d:%d", &config->aspect_width, &config->aspect_height) == 2)
184 float aspect_ratio = static_cast<double>(config->aspect_width) /
185 static_cast<double>(config->aspect_height);
187 if (aspect_ratio > 1) {
188 SCREEN_WIDTH = static_cast<int> (600 * aspect_ratio + 0.5);
192 SCREEN_HEIGHT = static_cast<int> (600 * 1/aspect_ratio + 0.5);
195 glMatrixMode(GL_PROJECTION);
197 glOrtho(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1.0, 1.0);
198 std::cout << __FILE__ << ":" << __LINE__ << ": change aspect ratio to " << item->list[item->selected] << std::endl;
200 // Reposition the menu to be in the center of the screen again
201 set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
206 case MNID_FULLSCREEN:
207 if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
208 config->use_fullscreen = !config->use_fullscreen;
214 if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
215 config->sound_enabled = !config->sound_enabled;
216 sound_manager->enable_sound(config->sound_enabled);
221 if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
222 config->music_enabled = !config->music_enabled;
223 sound_manager->enable_music(config->music_enabled);
232 Menu* get_options_menu()
234 //static OptionsMenu menu;
235 options_menu = new OptionsMenu();
239 void free_options_menu()