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