move over rewritten lispreader from tuxkart (with additional fixes), generalized...
[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
18 #include <config.h>
19
20 #include "misc.h"
21 #include "app/globals.h"
22
23 void MyConfig::customload(const lisp::Lisp& reader)
24 {
25   reader.get("keyboard-up", keymap.up);
26   reader.get("keyboard-down", keymap.down);
27   reader.get("keyboard-left", keymap.left);
28   reader.get("keyboard-right", keymap.right);
29   reader.get("keyboard-jump", keymap.jump);
30   reader.get("keyboard-power", keymap.power);
31 }
32
33 void MyConfig::customsave(FILE * config)
34 {
35   fprintf(config, "\t(keyboard-up  %d)\n", keymap.up);
36   fprintf(config, "\t(keyboard-down  %d)\n", keymap.down);
37   fprintf(config, "\t(keyboard-left  %d)\n", keymap.left);
38   fprintf(config, "\t(keyboard-right %d)\n", keymap.right);
39   fprintf(config, "\t(keyboard-jump  %d)\n", keymap.jump);
40   fprintf(config, "\t(keyboard-power  %d)\n", keymap.power);
41 }
42
43 void process_options_menu(void)
44 {
45   switch (options_menu->check())
46     {
47     case MNID_OPENGL:
48 #ifndef NOOPENGL
49       if(use_gl != options_menu->isToggled(MNID_OPENGL))
50         {
51           use_gl = !use_gl;
52           Setup::video(screen->w,screen->h);
53         }
54 #else
55       options_menu->get_item_by_id(MNID_OPENGL).toggled = false;
56 #endif
57       break;
58     case MNID_FULLSCREEN:
59       if(use_fullscreen != options_menu->isToggled(MNID_FULLSCREEN))
60         {
61           use_fullscreen = !use_fullscreen;
62           Setup::video(screen->w,screen->h);
63         }
64       break;
65     case MNID_SOUND:
66       if(SoundManager::get()->sound_enabled() != options_menu->isToggled(MNID_SOUND))
67         SoundManager::get()->enable_sound(!SoundManager::get()->sound_enabled());
68       break;
69     case MNID_MUSIC:
70       if(SoundManager::get()->music_enabled() != options_menu->isToggled(MNID_MUSIC))
71         {
72           SoundManager::get()->enable_music(!SoundManager::get()->music_enabled());
73         }
74       break;
75     case MNID_SHOWFPS:
76       if(show_fps != options_menu->isToggled(MNID_SHOWFPS))
77         show_fps = !show_fps;
78       break;
79     }
80 }
81
82 void st_menu(void)
83 {
84   main_menu      = new Menu();
85   options_menu   = new Menu();
86   options_keys_menu     = new Menu();
87   options_joystick_menu = new Menu();
88   load_game_menu = new Menu();
89   save_game_menu = new Menu();
90   game_menu      = new Menu();
91   highscore_menu = new Menu();
92   contrib_menu   = new Menu();
93   contrib_subset_menu   = new Menu();
94   worldmap_menu  = new Menu();
95
96   main_menu->set_pos(screen->w/2, 335);
97   main_menu->additem(MN_GOTO, _("Start Game"),0,load_game_menu, MNID_STARTGAME);
98   main_menu->additem(MN_GOTO, _("Contrib Levels"),0,contrib_menu, MNID_LEVELS_CONTRIB);
99   main_menu->additem(MN_GOTO, _("Options"),0,options_menu, MNID_OPTIONMENU);
100   main_menu->additem(MN_ACTION, _("Level Editor"),0,0, MNID_LEVELEDITOR);
101   main_menu->additem(MN_ACTION, _("Credits"),0,0, MNID_CREDITS);
102   main_menu->additem(MN_ACTION, _("Quit"),0,0, MNID_QUITMAINMENU);
103
104   options_menu->additem(MN_LABEL,_("Options"),0,0);
105   options_menu->additem(MN_HL,"",0,0);
106 #ifndef NOOPENGL
107   options_menu->additem(MN_TOGGLE,_("OpenGL    "),use_gl,0, MNID_OPENGL);
108 #else
109   options_menu->additem(MN_DEACTIVE,_("OpenGL (not supported)"),use_gl, 0, MNID_OPENGL);
110 #endif
111   options_menu->additem(MN_TOGGLE,_("Fullscreen"),use_fullscreen,0, MNID_FULLSCREEN);
112   if(SoundManager::get()->audio_device_available())
113     {
114       options_menu->additem(MN_TOGGLE,_("Sound     "), SoundManager::get()->sound_enabled(),0, MNID_SOUND);
115       options_menu->additem(MN_TOGGLE,_("Music     "), SoundManager::get()->music_enabled(),0, MNID_MUSIC);
116     }
117   else
118     {
119       options_menu->additem(MN_DEACTIVE,_("Sound     "), false,0, MNID_SOUND);
120       options_menu->additem(MN_DEACTIVE,_("Music     "), false,0, MNID_MUSIC);
121     }
122   options_menu->additem(MN_TOGGLE,_("Show FPS  "),show_fps,0, MNID_SHOWFPS);
123   options_menu->additem(MN_GOTO,_("Setup Keys"),0,options_keys_menu);
124
125   if(use_joystick)
126     options_menu->additem(MN_GOTO,_("Setup Joystick"),0,options_joystick_menu);
127
128   options_menu->additem(MN_HL,"",0,0);
129   options_menu->additem(MN_BACK,_("Back"),0,0);
130   
131   options_keys_menu->additem(MN_LABEL,_("Keyboard Setup"),0,0);
132   options_keys_menu->additem(MN_HL,"",0,0);
133   options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Left move"), 0,0, 0,&keymap.left);
134   options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Right move"), 0,0, 0,&keymap.right);
135   options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Up/Activate"), 0,0, 0,&keymap.up);
136   options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Down/Duck"), 0,0, 0,&keymap.down);
137   options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Jump"), 0,0, 0,&keymap.jump);
138   options_keys_menu->additem(MN_CONTROLFIELD_KB,_("Power/Run"), 0,0, 0,&keymap.power);
139   options_keys_menu->additem(MN_HL,"",0,0);
140   options_keys_menu->additem(MN_BACK,_("Back"),0,0);
141
142   if(use_joystick)
143     {
144     options_joystick_menu->additem(MN_LABEL,_("Joystick Setup"),0,0);
145     options_joystick_menu->additem(MN_HL,"",0,0);
146     //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"X axis", 0,0, 0,&joystick_keymap.x_axis);
147     //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"Y axis", 0,0, 0,&joystick_keymap.y_axis);
148     options_joystick_menu->additem(MN_CONTROLFIELD_JS,_("A button"), 0,0, 0,&joystick_keymap.a_button);
149     options_joystick_menu->additem(MN_CONTROLFIELD_JS,_("B button"), 0,0, 0,&joystick_keymap.b_button);
150     //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"Start", 0,0, 0,&joystick_keymap.start_button);
151     //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"DeadZone", 0,0, 0,&joystick_keymap.dead_zone);
152     options_joystick_menu->additem(MN_HL,"",0,0);
153     options_joystick_menu->additem(MN_BACK,_("Back"),0,0);
154     }
155   
156   load_game_menu->additem(MN_LABEL,_("Start Game"),0,0);
157   load_game_menu->additem(MN_HL,"",0,0);
158   load_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0, 1);
159   load_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0, 2);
160   load_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0, 3);
161   load_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0, 4);
162   load_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0, 5);
163   load_game_menu->additem(MN_HL,"",0,0);
164   load_game_menu->additem(MN_BACK,_("Back"),0,0);
165
166   save_game_menu->additem(MN_LABEL,_("Save Game"),0,0);
167   save_game_menu->additem(MN_HL,"",0,0);
168   save_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0, 1);
169   save_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0, 2);
170   save_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0, 3);
171   save_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0, 4);
172   save_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0, 5);
173   save_game_menu->additem(MN_HL,"",0,0);
174   save_game_menu->additem(MN_BACK,"Back",0,0);
175
176   game_menu->additem(MN_LABEL,_("Pause"),0,0);
177   game_menu->additem(MN_HL,"",0,0);
178   game_menu->additem(MN_ACTION,_("Continue"),0,0,MNID_CONTINUE);
179   game_menu->additem(MN_GOTO,_("Options"),0,options_menu);
180   game_menu->additem(MN_HL,"",0,0);
181   game_menu->additem(MN_ACTION,_("Abort Level"),0,0,MNID_ABORTLEVEL);
182
183   worldmap_menu->additem(MN_LABEL,_("Pause"),0,0);
184   worldmap_menu->additem(MN_HL,"",0,0);
185   worldmap_menu->additem(MN_ACTION,_("Continue"),0,0, WorldMapNS::MNID_RETURNWORLDMAP);
186   worldmap_menu->additem(MN_GOTO,_("Options"),0, options_menu);
187   worldmap_menu->additem(MN_HL,"",0,0);
188   worldmap_menu->additem(MN_ACTION,_("Quit Game"),0,0, WorldMapNS::MNID_QUITWORLDMAP);
189
190   highscore_menu->additem(MN_TEXTFIELD,_("Enter your name:"),0,0);
191 }
192
193 /* Free menus */
194 void st_menu_free()
195 {
196   delete worldmap_menu;
197   delete main_menu;
198   delete game_menu;
199   delete options_menu;
200   delete options_keys_menu;
201   delete options_joystick_menu;
202   delete highscore_menu;
203   delete contrib_menu;
204   delete contrib_subset_menu;
205   delete save_game_menu;
206   delete load_game_menu;
207 }