Massive copyright update. I'm sorry if I'm crediting Matze for something he didn...
[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 "options_menu.hpp"
23 #include "gui/menu.hpp"
24 #include "audio/sound_manager.hpp"
25 #include "control/joystickkeyboardcontroller.hpp"
26 #include "main.hpp"
27 #include "gettext.hpp"
28 #include "gameconfig.hpp"
29
30 Menu* options_menu   = 0;
31
32 enum OptionsMenuIDs {
33   MNID_FULLSCREEN,
34   MNID_SOUND,
35   MNID_MUSIC
36 };
37
38 class OptionsMenu : public Menu
39 {
40 public:
41   OptionsMenu();
42   virtual ~OptionsMenu();
43
44   virtual void menu_action(MenuItem* item);
45 };
46
47 OptionsMenu::OptionsMenu()
48 {
49   add_label(_("Options"));
50   add_hl();
51   add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen);
52   add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled);
53   add_toggle(MNID_MUSIC, _("Music"), config->music_enabled);
54   add_submenu(_("Setup Keys"), main_controller->get_key_options_menu());
55   add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu());
56   add_hl();
57   add_back(_("Back"));
58 }
59
60 OptionsMenu::~OptionsMenu()
61 {
62 }
63
64 void
65 OptionsMenu::menu_action(MenuItem* item)
66 {
67   switch (item->id) {
68     case MNID_FULLSCREEN:
69       if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
70         config->use_fullscreen = !config->use_fullscreen;
71         init_video();
72         config->save();
73       }
74       break;
75     case MNID_SOUND:
76       if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
77         config->sound_enabled = !config->sound_enabled;
78         sound_manager->enable_sound(config->sound_enabled);
79         config->save();
80       }
81       break;
82     case MNID_MUSIC:
83       if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
84         config->music_enabled = !config->music_enabled;
85         sound_manager->enable_music(config->music_enabled);
86         config->save();
87       }
88       break;
89     default:
90       break;
91   }
92 }
93
94 Menu* get_options_menu()
95 {
96   if(options_menu == NULL)
97     options_menu = new OptionsMenu();
98
99   return options_menu;
100 }
101
102 void free_options_menu()
103 {
104   delete options_menu;
105   options_menu = NULL;
106 }