- fix debugging functions for killing player
[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   if (sound_manager->is_audio_enabled()) {
53     add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled);
54     add_toggle(MNID_MUSIC, _("Music"), config->music_enabled);
55   } else {
56     add_deactive(MNID_SOUND, _("Sound disabled"));
57     add_deactive(MNID_SOUND, _("Music disabled"));
58   }
59   add_submenu(_("Setup Keys"), main_controller->get_key_options_menu());
60   add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu());
61   add_hl();
62   add_back(_("Back"));
63 }
64
65 OptionsMenu::~OptionsMenu()
66 {
67 }
68
69 void
70 OptionsMenu::menu_action(MenuItem* item)
71 {
72   switch (item->id) {
73     case MNID_FULLSCREEN:
74       if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
75         config->use_fullscreen = !config->use_fullscreen;
76         init_video();
77         config->save();
78       }
79       break;
80     case MNID_SOUND:
81       if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
82         config->sound_enabled = !config->sound_enabled;
83         sound_manager->enable_sound(config->sound_enabled);
84         config->save();
85       }
86       break;
87     case MNID_MUSIC:
88       if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
89         config->music_enabled = !config->music_enabled;
90         sound_manager->enable_music(config->music_enabled);
91         config->save();
92       }
93       break;
94     default:
95       break;
96   }
97 }
98
99 Menu* get_options_menu()
100 {
101   if(options_menu == NULL)
102     options_menu = new OptionsMenu();
103
104   return options_menu;
105 }
106
107 void free_options_menu()
108 {
109   delete options_menu;
110   options_menu = NULL;
111 }