Removed that logo from this bramch aswell..
[dbw.git] / src / options.cpp
blob233a2e380b578853b328220c6fc996eaac8cbb70
1 /*
2 Copyright © 2004 Parallel Realities
3 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "CAudio.h"
23 #include "CGame.h"
24 #include "CGraphics.h"
25 #include "gettext.hpp"
26 #include "options.h"
28 void showCheatConfig()
30 SDL_FillRect(graphics.screen, NULL, graphics.black);
31 //graphics.delay(500);
33 SDL_Surface *header = graphics.getSprite("cheatHeader", true)->image[0];
34 SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
35 SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
37 if (!engine.loadWidgets("data/cheatWidgets"))
39 graphics.showErrorAndExit(ERR_FILE, "data/cheatWidgets");
42 int done = 0;
44 engine.setWidgetVariable("health", &engine.cheatHealth);
45 engine.setWidgetVariable("extras", &engine.cheatExtras);
46 engine.setWidgetVariable("fuel", &engine.cheatFuel);
47 engine.setWidgetVariable("rate", &engine.cheatReload);
48 engine.setWidgetVariable("blood", &engine.cheatBlood);
49 engine.setWidgetVariable("invulnerable", &engine.cheatInvulnerable);
50 engine.setWidgetVariable("speed", &engine.cheatSpeed);
51 engine.setWidgetVariable("levels", &engine.cheatLevels);
52 engine.setWidgetVariable("skip", &engine.cheatSkipLevel);
53 engine.setWidgetVariable("no_out", &engine.cheat_no_out);
54 engine.setWidgetVariable("confirm", &done);
56 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
57 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
58 drawWidgets();
60 engine.flushInput();
61 engine.clearInput();
63 int menuSound = -1;
65 while (!done)
67 graphics.updateScreen();
69 if (menuSound)
70 audio.playMenuSound(menuSound);
72 engine.getInput();
74 menuSound = engine.processWidgets();
76 if (menuSound)
78 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
79 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
80 drawWidgets();
83 if (engine.keyState[SDLK_ESCAPE])
85 engine.clearInput();
86 engine.flushInput();
87 done = 1;
90 SDL_Delay(16);
93 audio.playMenuSound(2);
95 SDL_FillRect(graphics.screen, NULL, graphics.black);
96 //graphics.delay(500);
98 if (!engine.loadWidgets("data/optionWidgets"))
100 graphics.showErrorAndExit(ERR_FILE, "data/optionWidgets");
103 engine.highlightWidget("cheats");
106 void showKeyConfig()
108 SDL_FillRect(graphics.screen, NULL, graphics.black);
109 //graphics.delay(500);
111 if (!engine.loadWidgets("data/keyboardWidgets"))
113 graphics.showErrorAndExit(ERR_FILE, "data/keyboardWidgets");
116 SDL_Surface *header = graphics.getSprite("keyHeader", true)->image[0];
117 SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
118 SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
120 int done = 0;
121 int defaults = 0;
123 engine.setWidgetVariable("left", &engine.keyboard.left);
124 engine.setWidgetVariable("right", &engine.keyboard.right);
125 engine.setWidgetVariable("down", &engine.keyboard.down);
126 engine.setWidgetVariable("fire", &engine.keyboard.fire);
127 engine.setWidgetVariable("jump", &engine.keyboard.jump);
128 engine.setWidgetVariable("pause", &engine.keyboard.pause);
130 engine.setWidgetVariable("jetpack", &engine.keyboard.jetpack);
131 engine.setWidgetVariable("map", &engine.keyboard.map);
133 engine.setWidgetVariable("defaults", &defaults);
134 engine.setWidgetVariable("confirm", &done);
136 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
137 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
138 drawWidgets();
140 engine.flushInput();
141 engine.clearInput();
143 int menuSound = -1;
145 engine.allowJoypad = false;
147 while (!done)
149 graphics.updateScreen();
151 if (menuSound)
153 audio.playMenuSound(menuSound);
156 engine.getInput();
158 menuSound = engine.processWidgets();
160 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
161 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
162 drawWidgets();
164 if (defaults)
166 engine.restoreKeyDefaults();
167 defaults = 0;
170 if (engine.keyState[SDLK_ESCAPE])
172 engine.clearInput();
173 engine.flushInput();
174 done = 1;
177 SDL_Delay(16);
180 engine.allowJoypad = true;
182 engine.saveKeyConfig();
184 audio.playMenuSound(2);
186 SDL_FillRect(graphics.screen, NULL, graphics.black);
187 //graphics.delay(500);
189 if (!engine.loadWidgets("data/optionWidgets"))
191 graphics.showErrorAndExit(ERR_FILE, "data/optionWidgets");
194 engine.highlightWidget("keys");
197 void showJoystickConfig()
199 SDL_FillRect(graphics.screen, NULL, graphics.black);
200 //graphics.delay(500);
202 if (!engine.loadWidgets("data/joystickWidgets"))
203 graphics.showErrorAndExit(ERR_FILE, "data/joystickWidgets");
205 SDL_Surface *header = graphics.getSprite("joystickHeader", true)->image[0];
206 SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
207 SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
209 int done = 0;
211 engine.setWidgetVariable("left", &engine.joypad.left);
212 engine.setWidgetVariable("right", &engine.joypad.right);
213 engine.setWidgetVariable("up", &engine.joypad.up);
214 engine.setWidgetVariable("down", &engine.joypad.down);
215 engine.setWidgetVariable("fire", &engine.joypad.fire);
216 engine.setWidgetVariable("jump", &engine.joypad.jump);
217 engine.setWidgetVariable("pause", &engine.joypad.pause);
219 engine.setWidgetVariable("jetpack", &engine.joypad.jetpack);
220 engine.setWidgetVariable("map", &engine.joypad.map);
222 engine.setWidgetVariable("confirm", &done);
224 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
225 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
226 drawWidgets();
228 engine.flushInput();
229 engine.clearInput();
231 int menuSound = -1;
233 engine.allowJoypad = false;
235 while (!done)
237 graphics.updateScreen();
239 if (menuSound)
240 audio.playMenuSound(menuSound);
242 engine.getInput();
244 menuSound = engine.processWidgets();
246 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
247 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
248 drawWidgets();
250 if (engine.keyState[SDLK_ESCAPE])
252 engine.clearInput();
253 engine.flushInput();
254 done = 1;
257 SDL_Delay(16);
260 engine.allowJoypad = true;
262 engine.saveJoystickConfig();
264 audio.playMenuSound(2);
266 SDL_FillRect(graphics.screen, NULL, graphics.black);
267 //graphics.delay(500);
269 if (!engine.loadWidgets("data/optionWidgets"))
271 graphics.showErrorAndExit(ERR_FILE, "data/optionWidgets");
274 engine.highlightWidget("joysticks");
277 void showOptions()
279 float brightness;
281 SDL_FillRect(graphics.screen, NULL, graphics.black);
282 //graphics.delay(500);
284 if (!engine.loadWidgets("data/optionWidgets"))
286 graphics.showErrorAndExit(ERR_FILE, "data/optionWidgets");
289 SDL_Surface *header = graphics.getSprite("optionsHeader", true)->image[0];
290 SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
291 SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
293 int done = 0;
294 int joysticks = 0;
295 int cheats = 0;
296 int keys = 0;
298 engine.setWidgetVariable("fullscreen", &engine.fullScreen);
299 engine.setWidgetVariable("soundvol", &game.soundVol);
300 engine.setWidgetVariable("musicvol", &game.musicVol);
301 engine.setWidgetVariable("output", &game.output);
302 engine.setWidgetVariable("autosave", &game.autoSave);
303 engine.setWidgetVariable("gamma", &game.brightness);
304 engine.setWidgetVariable("gore", &game.gore);
305 engine.setWidgetVariable("keys", &keys);
306 engine.setWidgetVariable("joysticks", &joysticks);
307 engine.setWidgetVariable("cheats", &cheats);
308 engine.setWidgetVariable("confirm", &done);
310 if (!engine.useAudio)
312 engine.enableWidget("soundvol", false);
313 engine.enableWidget("musicvol", false);
314 engine.enableWidget("output", false);
317 if (SDL_NumJoysticks() == 0)
319 engine.enableWidget("joysticks", false);
322 engine.showWidget("cheats", engine.cheats);
324 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
325 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
326 drawWidgets();
328 engine.flushInput();
329 engine.clearInput();
331 int menuSound = -1;
333 while (!done)
335 graphics.updateScreen();
337 if (menuSound)
338 audio.playMenuSound(menuSound);
340 engine.getInput();
342 if (engine.compareLastKeyInputs())
344 if (engine.cheats)
346 audio.playSound(SND_CHEAT, CH_ANY);
347 engine.clearCheatVars();
350 engine.showWidget("cheats", engine.cheats);
351 drawWidgets();
354 menuSound = engine.processWidgets();
356 if (menuSound)
358 if (engine.widgetChanged("soundvol"))
359 audio.setSoundVolume(game.soundVol);
361 if (engine.widgetChanged("musicvol"))
362 audio.setMusicVolume(game.musicVol);
364 if (engine.widgetChanged("fullscreen"))
365 SDL_WM_ToggleFullScreen(graphics.screen);
367 if (engine.widgetChanged("gamma"))
369 brightness = game.brightness;
370 if (brightness > 0) {
371 brightness /= 10;
372 SDL_SetGamma(brightness, brightness, brightness);
376 if ((joysticks) || (cheats) || (keys))
378 audio.playMenuSound(2);
379 menuSound = 0;
381 if (joysticks)
383 showJoystickConfig();
385 else if (cheats)
387 showCheatConfig();
389 else if (keys)
391 showKeyConfig();
394 joysticks = keys = cheats = 0;
396 engine.setWidgetVariable("fullscreen", &engine.fullScreen);
397 engine.setWidgetVariable("soundvol", &game.soundVol);
398 engine.setWidgetVariable("musicvol", &game.musicVol);
399 engine.setWidgetVariable("output", &game.output);
400 engine.setWidgetVariable("autosave", &game.autoSave);
401 engine.setWidgetVariable("gamma", &game.brightness);
402 engine.setWidgetVariable("gore", &game.gore);
403 engine.setWidgetVariable("keys", &keys);
404 engine.setWidgetVariable("joysticks", &joysticks);
405 engine.setWidgetVariable("cheats", &cheats);
406 engine.setWidgetVariable("confirm", &done);
408 if (!engine.useAudio)
410 engine.enableWidget("soundvol", false);
411 engine.enableWidget("musicvol", false);
412 engine.enableWidget("output", false);
415 if (SDL_NumJoysticks() == 0)
417 engine.enableWidget("joysticks", false);
420 engine.showWidget("cheats", engine.cheats);
423 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
424 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
425 drawWidgets();
428 if (engine.keyState[SDLK_ESCAPE])
430 engine.clearInput();
431 engine.flushInput();
432 done = 1;
435 SDL_Delay(16);
439 if (audio.output != game.output)
441 audio.output = game.output;
443 if (!audio.output)
445 audio.stopMusic();
446 audio.stopAmbiance();
448 else
450 audio.playMusic();
451 audio.playAmbiance();
455 audio.playMenuSound(2);
457 SDL_FillRect(graphics.screen, NULL, graphics.black);
458 //graphics.delay(500);