Some Window$ specific edits.
[dbw.git] / src / options.cpp
blobff1f6ea532540f300498f2512a795a9c14282f7f
1 /*
2 Copyright (C) 2004 Parallel Realities
3 Copyright (C) 2007 Kővágó Zoltán
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 "options.h"
23 #include "gettext.hpp"
25 void showCheatConfig()
27 SDL_FillRect(graphics.screen, NULL, graphics.black);
28 //graphics.delay(500);
30 SDL_Surface *header = graphics.getSprite("cheatHeader", true)->image[0];
31 SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
32 SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
34 if (!engine.loadWidgets("data/cheatWidgets"))
36 graphics.showErrorAndExit(ERR_FILE, "data/cheatWidgets");
39 int done = 0;
41 engine.setWidgetVariable("health", &engine.cheatHealth);
42 engine.setWidgetVariable("extras", &engine.cheatExtras);
43 engine.setWidgetVariable("fuel", &engine.cheatFuel);
44 engine.setWidgetVariable("rate", &engine.cheatReload);
45 engine.setWidgetVariable("blood", &engine.cheatBlood);
46 engine.setWidgetVariable("invulnerable", &engine.cheatInvulnerable);
47 engine.setWidgetVariable("speed", &engine.cheatSpeed);
48 engine.setWidgetVariable("levels", &engine.cheatLevels);
49 engine.setWidgetVariable("skip", &engine.cheatSkipLevel);
50 engine.setWidgetVariable("confirm", &done);
52 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
53 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
54 drawWidgets();
56 engine.flushInput();
57 engine.clearInput();
59 int menuSound = -1;
61 while (!done)
63 graphics.updateScreen();
65 if (menuSound)
66 audio.playMenuSound(menuSound);
68 engine.getInput();
70 menuSound = engine.processWidgets();
72 if (menuSound)
74 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
75 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
76 drawWidgets();
79 if (engine.keyState[SDLK_ESCAPE])
81 engine.clearInput();
82 engine.flushInput();
83 done = 1;
86 SDL_Delay(16);
89 audio.playMenuSound(2);
91 SDL_FillRect(graphics.screen, NULL, graphics.black);
92 //graphics.delay(500);
94 if (!engine.loadWidgets("data/optionWidgets"))
96 graphics.showErrorAndExit(ERR_FILE, "data/optionWidgets");
99 engine.highlightWidget("cheats");
102 void showKeyConfig()
104 SDL_FillRect(graphics.screen, NULL, graphics.black);
105 //graphics.delay(500);
107 if (!engine.loadWidgets("data/keyboardWidgets"))
109 graphics.showErrorAndExit(ERR_FILE, "data/keyboardWidgets");
112 SDL_Surface *header = graphics.getSprite("keyHeader", true)->image[0];
113 SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
114 SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
116 int done = 0;
117 int defaults = 0;
119 engine.setWidgetVariable("left", &engine.keyboard.left);
120 engine.setWidgetVariable("right", &engine.keyboard.right);
121 engine.setWidgetVariable("down", &engine.keyboard.down);
122 engine.setWidgetVariable("fire", &engine.keyboard.fire);
123 engine.setWidgetVariable("jump", &engine.keyboard.jump);
124 engine.setWidgetVariable("pause", &engine.keyboard.pause);
126 engine.setWidgetVariable("jetpack", &engine.keyboard.jetpack);
127 engine.setWidgetVariable("map", &engine.keyboard.map);
129 engine.setWidgetVariable("defaults", &defaults);
130 engine.setWidgetVariable("confirm", &done);
132 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
133 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
134 drawWidgets();
136 engine.flushInput();
137 engine.clearInput();
139 int menuSound = -1;
141 engine.allowJoypad = false;
143 while (!done)
145 graphics.updateScreen();
147 if (menuSound)
149 audio.playMenuSound(menuSound);
152 engine.getInput();
154 menuSound = engine.processWidgets();
156 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
157 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
158 drawWidgets();
160 if (defaults)
162 engine.restoreKeyDefaults();
163 defaults = 0;
166 if (engine.keyState[SDLK_ESCAPE])
168 engine.clearInput();
169 engine.flushInput();
170 done = 1;
173 SDL_Delay(16);
176 engine.allowJoypad = true;
178 engine.saveKeyConfig();
180 audio.playMenuSound(2);
182 SDL_FillRect(graphics.screen, NULL, graphics.black);
183 //graphics.delay(500);
185 if (!engine.loadWidgets("data/optionWidgets"))
187 graphics.showErrorAndExit(ERR_FILE, "data/optionWidgets");
190 engine.highlightWidget("keys");
193 void showJoystickConfig()
195 SDL_FillRect(graphics.screen, NULL, graphics.black);
196 //graphics.delay(500);
198 if (!engine.loadWidgets("data/joystickWidgets"))
199 graphics.showErrorAndExit(ERR_FILE, "data/joystickWidgets");
201 SDL_Surface *header = graphics.getSprite("joystickHeader", true)->image[0];
202 SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
203 SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
205 int done = 0;
207 engine.setWidgetVariable("left", &engine.joypad.left);
208 engine.setWidgetVariable("right", &engine.joypad.right);
209 engine.setWidgetVariable("up", &engine.joypad.up);
210 engine.setWidgetVariable("down", &engine.joypad.down);
211 engine.setWidgetVariable("fire", &engine.joypad.fire);
212 engine.setWidgetVariable("jump", &engine.joypad.jump);
213 engine.setWidgetVariable("pause", &engine.joypad.pause);
215 engine.setWidgetVariable("jetpack", &engine.joypad.jetpack);
216 engine.setWidgetVariable("map", &engine.joypad.map);
218 engine.setWidgetVariable("confirm", &done);
220 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
221 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
222 drawWidgets();
224 engine.flushInput();
225 engine.clearInput();
227 int menuSound = -1;
229 engine.allowJoypad = false;
231 while (!done)
233 graphics.updateScreen();
235 if (menuSound)
236 audio.playMenuSound(menuSound);
238 engine.getInput();
240 menuSound = engine.processWidgets();
242 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
243 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
244 drawWidgets();
246 if (engine.keyState[SDLK_ESCAPE])
248 engine.clearInput();
249 engine.flushInput();
250 done = 1;
253 SDL_Delay(16);
256 engine.allowJoypad = true;
258 engine.saveJoystickConfig();
260 audio.playMenuSound(2);
262 SDL_FillRect(graphics.screen, NULL, graphics.black);
263 //graphics.delay(500);
265 if (!engine.loadWidgets("data/optionWidgets"))
267 graphics.showErrorAndExit(ERR_FILE, "data/optionWidgets");
270 engine.highlightWidget("joysticks");
273 void showOptions()
275 float brightness;
277 SDL_FillRect(graphics.screen, NULL, graphics.black);
278 //graphics.delay(500);
280 if (!engine.loadWidgets("data/optionWidgets"))
282 graphics.showErrorAndExit(ERR_FILE, "data/optionWidgets");
285 SDL_Surface *header = graphics.getSprite("optionsHeader", true)->image[0];
286 SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
287 SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
289 int done = 0;
290 int joysticks = 0;
291 int cheats = 0;
292 int keys = 0;
294 engine.setWidgetVariable("fullscreen", &engine.fullScreen);
295 engine.setWidgetVariable("soundvol", &game.soundVol);
296 engine.setWidgetVariable("musicvol", &game.musicVol);
297 engine.setWidgetVariable("output", &game.output);
298 engine.setWidgetVariable("autosave", &game.autoSave);
299 engine.setWidgetVariable("gamma", &game.brightness);
300 engine.setWidgetVariable("gore", &game.gore);
301 engine.setWidgetVariable("keys", &keys);
302 engine.setWidgetVariable("joysticks", &joysticks);
303 engine.setWidgetVariable("cheats", &cheats);
304 engine.setWidgetVariable("confirm", &done);
306 if (!engine.useAudio)
308 engine.enableWidget("soundvol", false);
309 engine.enableWidget("musicvol", false);
310 engine.enableWidget("output", false);
313 if (SDL_NumJoysticks() == 0)
315 engine.enableWidget("joysticks", false);
318 engine.showWidget("cheats", engine.cheats);
320 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
321 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
322 drawWidgets();
324 engine.flushInput();
325 engine.clearInput();
327 int menuSound = -1;
329 while (!done)
331 graphics.updateScreen();
333 if (menuSound)
334 audio.playMenuSound(menuSound);
336 engine.getInput();
338 if (engine.compareLastKeyInputs())
340 if (engine.cheats)
342 audio.playSound(SND_CHEAT, CH_ANY);
343 engine.clearCheatVars();
346 engine.showWidget("cheats", engine.cheats);
347 drawWidgets();
350 menuSound = engine.processWidgets();
352 if (menuSound)
354 if (engine.widgetChanged("soundvol"))
355 audio.setSoundVolume(game.soundVol);
357 if (engine.widgetChanged("musicvol"))
358 audio.setMusicVolume(game.musicVol);
360 if (engine.widgetChanged("fullscreen"))
361 SDL_WM_ToggleFullScreen(graphics.screen);
363 if (engine.widgetChanged("gamma"))
365 brightness = game.brightness;
366 if (brightness > 0) {
367 brightness /= 10;
368 SDL_SetGamma(brightness, brightness, brightness);
372 if ((joysticks) || (cheats) || (keys))
374 audio.playMenuSound(2);
375 menuSound = 0;
377 if (joysticks)
379 showJoystickConfig();
381 else if (cheats)
383 showCheatConfig();
385 else if (keys)
387 showKeyConfig();
390 joysticks = keys = cheats = 0;
392 engine.setWidgetVariable("fullscreen", &engine.fullScreen);
393 engine.setWidgetVariable("soundvol", &game.soundVol);
394 engine.setWidgetVariable("musicvol", &game.musicVol);
395 engine.setWidgetVariable("output", &game.output);
396 engine.setWidgetVariable("autosave", &game.autoSave);
397 engine.setWidgetVariable("gamma", &game.brightness);
398 engine.setWidgetVariable("gore", &game.gore);
399 engine.setWidgetVariable("keys", &keys);
400 engine.setWidgetVariable("joysticks", &joysticks);
401 engine.setWidgetVariable("cheats", &cheats);
402 engine.setWidgetVariable("confirm", &done);
404 if (!engine.useAudio)
406 engine.enableWidget("soundvol", false);
407 engine.enableWidget("musicvol", false);
408 engine.enableWidget("output", false);
411 if (SDL_NumJoysticks() == 0)
413 engine.enableWidget("joysticks", false);
416 engine.showWidget("cheats", engine.cheats);
419 graphics.blit(optionsBackground, bx, by, graphics.screen, false);
420 graphics.blit(header, bx + 320, by + 25, graphics.screen, true);
421 drawWidgets();
424 if (engine.keyState[SDLK_ESCAPE])
426 engine.clearInput();
427 engine.flushInput();
428 done = 1;
431 SDL_Delay(16);
435 if (audio.output != game.output)
437 audio.output = game.output;
439 if (!audio.output)
441 audio.stopMusic();
442 audio.stopAmbiance();
444 else
446 audio.playMusic();
447 audio.playAmbiance();
451 audio.playMenuSound(2);
453 SDL_FillRect(graphics.screen, NULL, graphics.black);
454 //graphics.delay(500);