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