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