Display some additional help text on Option Menu entries
[supertux.git] / src / options_menu.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2004 Tobas Glaesser <tobi.web@gmx.de>
5 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 //
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.
11 //
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.
16 //
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.
20 #include <config.h>
21
22 #include "profile_menu.hpp"
23 #include "options_menu.hpp"
24 #include "gui/menu.hpp"
25 #include "audio/sound_manager.hpp"
26 #include "control/joystickkeyboardcontroller.hpp"
27 #include "main.hpp"
28 #include "gettext.hpp"
29 #include "gameconfig.hpp"
30
31 Menu* options_menu   = 0;
32
33 enum OptionsMenuIDs {
34   MNID_FULLSCREEN,
35   MNID_SOUND,
36   MNID_MUSIC
37 };
38
39 class LanguageMenu : public Menu
40 {
41 public:
42   LanguageMenu() {
43     add_label(_("Language"));
44     add_hl();
45     add_entry(0, std::string("(")+_("auto-detect language")+")");
46     add_entry(1, "English");
47
48     int mnid = 10;    
49     std::set<std::string> languages = dictionary_manager.get_languages();
50     for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
51       std::string locale_name = *i;
52       TinyGetText::LanguageDef ldef = TinyGetText::get_language_def(locale_name);
53       std::string locale_fullname = locale_name;
54       if (std::string(ldef.code) == locale_name) {
55         locale_fullname = ldef.name;
56       }
57       add_entry(mnid++, locale_fullname);
58     } 
59
60     add_hl();
61     add_back(_("Back"));
62   }
63
64   virtual void menu_action(MenuItem* item) {
65     if (item->id == 0) {
66       config->locale = "";
67       dictionary_manager.set_language(config->locale);
68       config->save();
69       Menu::set_current(0);
70     }
71     else if (item->id == 1) {
72       config->locale = "en";
73       dictionary_manager.set_language(config->locale);
74       config->save();
75       Menu::set_current(0);
76     }
77     int mnid = 10;    
78     std::set<std::string> languages = dictionary_manager.get_languages();
79     for (std::set<std::string>::iterator i = languages.begin(); i != languages.end(); i++) {
80       std::string locale_name = *i;
81       if (item->id == mnid++) {
82         config->locale = locale_name;
83         dictionary_manager.set_language(config->locale);
84         config->save();
85         Menu::set_current(0);
86       }
87     }
88   }
89 };
90
91
92 class OptionsMenu : public Menu
93 {
94 public:
95   OptionsMenu();
96   virtual ~OptionsMenu();
97
98   virtual void menu_action(MenuItem* item);
99
100 protected:
101   std::auto_ptr<LanguageMenu> language_menu;
102   
103 };
104
105 OptionsMenu::OptionsMenu()
106 {
107   language_menu.reset(new LanguageMenu());
108
109   add_label(_("Options"));
110   add_hl();
111
112   add_submenu(_("Select Language"), language_menu.get())
113     ->set_help(_("Switch to another language"));
114
115   add_submenu(_("Select Profile"), get_profile_menu())
116     ->set_help(_("Switch between different savegames"));
117
118   add_toggle(MNID_SOUND, _("Profile on Startup"), config->sound_enabled)
119     ->set_help(_("Display the profile menu when the game is newly started"));
120   
121   // FIXME: Implement me: if (get_parent() == main_menu)
122   add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen)
123     ->set_help(_("Let the game cover the whole screen"));
124
125   add_toggle(MNID_SOUND, _("Aspect Ration"), config->sound_enabled)
126     ->set_help(_("Change the aspect ratio"));
127
128   if (sound_manager->is_audio_enabled()) {
129     add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled)
130       ->set_help(_("Disable all sound effects in the game"));
131     add_toggle(MNID_MUSIC, _("Music"), config->music_enabled)
132       ->set_help(_("Disable all music in the game"));
133   } else {
134     add_deactive(MNID_SOUND, _("Sound (disabled)"));
135     add_deactive(MNID_SOUND, _("Music (disabled)"));
136   }
137   
138   add_submenu(_("Setup Keyboard"), main_controller->get_key_options_menu())
139     ->set_help(_("Configure how your keyboard maps to the game"));
140
141   add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu())
142     ->set_help(_("Configure how your joystick maps to the game"));
143   add_hl();
144   add_back(_("Back"));
145 }
146
147 OptionsMenu::~OptionsMenu()
148 {
149 }
150
151 void
152 OptionsMenu::menu_action(MenuItem* item)
153 {
154   switch (item->id) {
155     case MNID_FULLSCREEN:
156       if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
157         config->use_fullscreen = !config->use_fullscreen;
158         init_video();
159         config->save();
160       }
161       break;
162     case MNID_SOUND:
163       if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
164         config->sound_enabled = !config->sound_enabled;
165         sound_manager->enable_sound(config->sound_enabled);
166         config->save();
167       }
168       break;
169     case MNID_MUSIC:
170       if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
171         config->music_enabled = !config->music_enabled;
172         sound_manager->enable_music(config->music_enabled);
173         config->save();
174       }
175       break;
176     default:
177       break;
178   }
179 }
180
181 Menu* get_options_menu()
182 {
183   //static OptionsMenu menu;
184   options_menu = new OptionsMenu();
185   return options_menu;
186 }
187
188 void free_options_menu()
189 {
190   delete options_menu;
191   options_menu = 0;
192 }