oops
[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 Menu* options_keys_menu     = 0;
36 Menu* options_joystick_menu = 0;
37 Menu* highscore_menu = 0;
38 Menu* load_game_menu = 0;
39 Menu* save_game_menu = 0;
40 Menu* contrib_menu   = 0;
41 Menu* contrib_subset_menu   = 0;
42
43 void process_options_menu()
44 {
45   switch (options_menu->check()) {
46     case MNID_FULLSCREEN:
47       if(config->use_fullscreen != options_menu->is_toggled(MNID_FULLSCREEN)) {
48         config->use_fullscreen = !config->use_fullscreen;
49         init_video();
50         config->save();
51       }
52       break;
53     case MNID_SOUND:
54       if(config->sound_enabled != options_menu->is_toggled(MNID_SOUND)) {
55         config->sound_enabled = !config->sound_enabled;
56         sound_manager->enable_sound(config->sound_enabled);
57         config->save();
58       }
59       break;
60     case MNID_MUSIC:
61       if(config->music_enabled != options_menu->is_toggled(MNID_MUSIC)) {
62         config->music_enabled = !config->music_enabled;
63         sound_manager->enable_music(config->music_enabled);
64         config->save();
65       }
66       break;
67     default:
68       break;
69   }
70 }
71
72 void setup_menu()
73 {
74   main_menu      = new Menu();
75   options_menu   = new Menu();
76   load_game_menu = new Menu();
77   game_menu      = new Menu();
78   contrib_menu   = new Menu();
79   contrib_subset_menu   = new Menu();
80   worldmap_menu  = new Menu();
81
82   main_menu->set_pos(SCREEN_WIDTH/2, 335);
83   main_menu->add_submenu(_("Start Game"), load_game_menu, MNID_STARTGAME);
84   main_menu->add_submenu(_("Contrib Levels"), contrib_menu, MNID_LEVELS_CONTRIB);
85   main_menu->add_submenu(_("Options"), options_menu);
86   //main_menu->add_entry(MNID_LEVELEDITOR, _("Level Editor"));
87   main_menu->add_entry(MNID_CREDITS, _("Credits"));
88   main_menu->add_entry(MNID_QUITMAINMENU, _("Quit"));
89   
90   options_menu->add_label(_("Options"));
91   options_menu->add_hl();
92   options_menu->add_toggle(MNID_FULLSCREEN,_("Fullscreen"), config->use_fullscreen);
93   options_menu->add_toggle(MNID_SOUND, _("Sound"), config->sound_enabled);
94   options_menu->add_toggle(MNID_MUSIC, _("Music"), config->music_enabled);
95   options_menu->add_submenu(_("Setup Keys"),
96                             main_controller->get_key_options_menu());
97   options_menu->add_submenu(_("Setup Joystick"),
98                             main_controller->get_joystick_options_menu());
99   options_menu->add_hl();
100   options_menu->add_back(_("Back"));
101   
102   load_game_menu->add_label(_("Start Game"));
103   load_game_menu->add_hl();
104   load_game_menu->add_deactive(1, "Slot 1");
105   load_game_menu->add_deactive(2, "Slot 2");
106   load_game_menu->add_deactive(3, "Slot 3");
107   load_game_menu->add_deactive(4, "Slot 4");
108   load_game_menu->add_deactive(5, "Slot 5");
109   load_game_menu->add_hl();
110   load_game_menu->add_back(_("Back"));
111   
112   game_menu->add_label(_("Pause"));
113   game_menu->add_hl();
114   game_menu->add_entry(MNID_CONTINUE, _("Continue"));
115   game_menu->add_submenu(_("Options"), options_menu);
116   game_menu->add_hl();
117   game_menu->add_entry(MNID_ABORTLEVEL, _("Abort Level"));
118
119   worldmap_menu->add_label(_("Pause"));
120   worldmap_menu->add_hl();
121   worldmap_menu->add_entry(WorldMapNS::MNID_RETURNWORLDMAP, _("Continue"));
122   worldmap_menu->add_submenu(_("Options"), options_menu);
123   worldmap_menu->add_hl();
124   worldmap_menu->add_entry(WorldMapNS::MNID_QUITWORLDMAP, _("Quit Game"));
125 }
126
127 void free_menu()
128 {
129   delete worldmap_menu;
130   delete main_menu;
131   delete game_menu;
132   delete options_menu;
133   delete contrib_menu;
134   delete contrib_subset_menu;
135   delete load_game_menu;
136 }
137