hopefully fixed the crash on exit, keep sectors script bundled in the sector and...
[supertux.git] / src / options_menu.cpp
1 //  $Id$
2 //  Copyright (C) 2004 Tobas Glaesser <tobi.web@gmx.de>
3 //
4 //  This program is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU General Public License
6 //  as published by the Free Software Foundation; either version 2
7 //  of the License, or (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 // 
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 #include <config.h>
18
19 #include "options_menu.hpp"
20 #include "gui/menu.hpp"
21 #include "audio/sound_manager.hpp"
22 #include "control/joystickkeyboardcontroller.hpp"
23 #include "main.hpp"
24 #include "gettext.hpp"
25 #include "gameconfig.hpp"
26
27 Menu* options_menu   = 0;
28
29 enum OptionsMenuIDs {
30   MNID_FULLSCREEN,
31   MNID_SOUND,
32   MNID_MUSIC
33 };
34
35 class OptionsMenu : public Menu
36 {
37 public:
38   OptionsMenu();
39   virtual ~OptionsMenu();
40
41   virtual void menu_action(MenuItem* item);
42 };
43
44 OptionsMenu::OptionsMenu()
45 {
46   add_label(_("Options"));
47   add_hl();
48   add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen);
49   add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled);
50   add_toggle(MNID_MUSIC, _("Music"), config->music_enabled);
51   add_submenu(_("Setup Keys"), main_controller->get_key_options_menu());
52   add_submenu(_("Setup Joystick"),main_controller->get_joystick_options_menu());
53   add_hl();
54   add_back(_("Back"));
55 }
56
57 OptionsMenu::~OptionsMenu()
58 {
59 }
60
61 void
62 OptionsMenu::menu_action(MenuItem* item)
63 {
64   switch (item->id) {
65     case MNID_FULLSCREEN:
66       if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
67         config->use_fullscreen = !config->use_fullscreen;
68         init_video();
69         config->save();
70       }
71       break;
72     case MNID_SOUND:
73       if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
74         config->sound_enabled = !config->sound_enabled;
75         sound_manager->enable_sound(config->sound_enabled);
76         config->save();
77       }
78       break;
79     case MNID_MUSIC:
80       if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
81         config->music_enabled = !config->music_enabled;
82         sound_manager->enable_music(config->music_enabled);
83         config->save();
84       }
85       break;
86     default:
87       break;
88   }
89 }
90
91 Menu* get_options_menu()
92 {
93   if(options_menu == NULL)
94     options_menu = new OptionsMenu();
95
96   return options_menu;
97 }
98
99 void free_options_menu()
100 {
101   delete options_menu;
102   options_menu = NULL;
103 }