047ab3e20f5fa3ca54f8088d49f126bcb7e04b12
[supertux.git] / src / misc.cpp
1 //  SuperTux
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 "misc.hpp"
20 #include "main.hpp"
21 #include "gameconfig.hpp"
22 #include "game_session.hpp"
23 #include "gui/menu.hpp"
24 #include "gui/button.hpp"
25 #include "audio/sound_manager.hpp"
26 #include "title.hpp"
27 #include "resources.hpp"
28 #include "worldmap.hpp"
29 #include "gettext.hpp"
30 #include "control/joystickkeyboardcontroller.hpp"
31
32 Menu* main_menu      = 0;
33 Menu* game_menu      = 0;
34 Menu* options_menu   = 0;
35
36 void process_options_menu()
37 {
38   switch (options_menu->check()) {
39     case MNID_FULLSCREEN:
40       if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
41         config->use_fullscreen = !config->use_fullscreen;
42         init_video();
43         config->save();
44       }
45       break;
46     case MNID_SOUND:
47       if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
48         config->sound_enabled = !config->sound_enabled;
49         sound_manager->enable_sound(config->sound_enabled);
50         config->save();
51       }
52       break;
53     case MNID_MUSIC:
54       if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
55         config->music_enabled = !config->music_enabled;
56         sound_manager->enable_music(config->music_enabled);
57         config->save();
58       }
59       break;
60     default:
61       break;
62   }
63 }
64
65 void setup_menu()
66 {
67   main_menu      = new Menu();
68   options_menu   = new Menu();
69   game_menu      = new Menu();
70   worldmap_menu  = new Menu();
71
72   main_menu->set_pos(SCREEN_WIDTH/2, 335);
73   main_menu->add_entry(MNID_STARTGAME, _("Start Game"));
74   main_menu->add_entry(MNID_LEVELS_CONTRIB, _("Contrib Levels"));
75   main_menu->add_submenu(_("Options"), options_menu);
76   //main_menu->add_entry(MNID_LEVELEDITOR, _("Level Editor"));
77   main_menu->add_entry(MNID_CREDITS, _("Credits"));
78   main_menu->add_entry(MNID_QUITMAINMENU, _("Quit"));
79   
80   options_menu->add_label(_("Options"));
81   options_menu->add_hl();
82   options_menu->add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen);
83   options_menu->add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled);
84   options_menu->add_toggle(MNID_MUSIC, _("Music"), config->music_enabled);
85   options_menu->add_submenu(_("Setup Keys"),
86                             main_controller->get_key_options_menu());
87   options_menu->add_submenu(_("Setup Joystick"),
88                             main_controller->get_joystick_options_menu());
89   options_menu->add_hl();
90   options_menu->add_back(_("Back"));
91   
92   game_menu->add_label(_("Pause"));
93   game_menu->add_hl();
94   game_menu->add_entry(MNID_CONTINUE, _("Continue"));
95   game_menu->add_submenu(_("Options"), options_menu);
96   game_menu->add_hl();
97   game_menu->add_entry(MNID_ABORTLEVEL, _("Abort Level"));
98
99   worldmap_menu->add_label(_("Pause"));
100   worldmap_menu->add_hl();
101   worldmap_menu->add_entry(WorldMapNS::MNID_RETURNWORLDMAP, _("Continue"));
102   worldmap_menu->add_submenu(_("Options"), options_menu);
103   worldmap_menu->add_hl();
104   worldmap_menu->add_entry(WorldMapNS::MNID_QUITWORLDMAP, _("Quit Game"));
105 }
106
107 void free_menu()
108 {
109   delete worldmap_menu;
110   delete main_menu;
111   delete game_menu;
112   delete options_menu;
113 }
114