]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/options.cpp
Coalesce printf() statements in main.cpp, make them translatable.
[quix0rs-blobwars.git] / src / options.cpp
1 /*
2 Copyright (C) 2004-2011 Parallel Realities
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.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "options.h"
22
23 void showCheatConfig()
24 {
25         SDL_FillRect(graphics.screen, NULL, graphics.black);
26         graphics.delay(500);
27
28         SDL_Surface *header = graphics.getSprite("cheatHeader", true)->image[0];
29         SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
30         SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
31
32         if (!engine.loadWidgets(_("data/cheatWidgets")))
33         {
34                 graphics.showErrorAndExit(ERR_FILE, _("data/cheatWidgets"));
35         }
36                 
37         int done = 0;
38
39         engine.setWidgetVariable("health", &engine.cheatHealth);
40         engine.setWidgetVariable("extras", &engine.cheatExtras);
41         engine.setWidgetVariable("fuel", &engine.cheatFuel);
42         engine.setWidgetVariable("rate", &engine.cheatReload);
43         engine.setWidgetVariable("blood", &engine.cheatBlood);
44         engine.setWidgetVariable("invulnerable", &engine.cheatInvulnerable);
45         engine.setWidgetVariable("speed", &engine.cheatSpeed);
46         engine.setWidgetVariable("levels", &engine.cheatLevels);
47         engine.setWidgetVariable("skip", &engine.cheatSkipLevel);
48         engine.setWidgetVariable("confirm", &done);
49         
50         graphics.blit(optionsBackground, 0, 0, graphics.screen, false);
51         graphics.blit(header, 320, 25, graphics.screen, true);
52         drawWidgets();
53
54         engine.flushInput();
55         engine.clearInput();
56         
57         int menuSound = -1;
58
59         while (!done)
60         {
61                 graphics.updateScreen();
62                 
63                 if (menuSound)
64                         audio.playMenuSound(menuSound);
65
66                 engine.getInput();
67                 config.populate();
68
69                 menuSound = engine.processWidgets();
70
71                 if (menuSound)
72                 {
73                         graphics.blit(optionsBackground, 0, 0, graphics.screen, false);
74                         graphics.blit(header, 320, 25, graphics.screen, true);
75                         drawWidgets();
76                 }
77
78                 if (engine.keyState[SDL_SCANCODE_ESCAPE])
79                 {
80                         engine.clearInput();
81                         engine.flushInput();
82                         done = 1;
83                 }
84
85                 SDL_Delay(16);
86         }
87         
88         audio.playMenuSound(2);
89
90         SDL_FillRect(graphics.screen, NULL, graphics.black);
91         graphics.delay(500);
92
93         if (!engine.loadWidgets(_("data/optionWidgets")))
94         {
95                 graphics.showErrorAndExit(ERR_FILE, _("data/optionWidgets"));
96         }
97         
98         engine.highlightWidget("cheats");
99 }
100
101 void showKeyConfig()
102 {
103         SDL_FillRect(graphics.screen, NULL, graphics.black);
104         graphics.delay(500);
105
106         if (!engine.loadWidgets(_("data/keyboardWidgets")))
107         {
108                 graphics.showErrorAndExit(ERR_FILE, _("data/keyboardWidgets"));
109         }
110                 
111         SDL_Surface *header = graphics.getSprite("keyHeader", true)->image[0];
112         SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
113         SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
114
115         int done = 0;
116         int defaults = 0;
117
118         engine.setWidgetVariable("left", &config.keyboard.control[CONTROL::LEFT]);
119         engine.setWidgetVariable("right", &config.keyboard.control[CONTROL::RIGHT]);
120         engine.setWidgetVariable("down", &config.keyboard.control[CONTROL::DOWN]);
121         engine.setWidgetVariable("fire", &config.keyboard.control[CONTROL::FIRE]);
122         engine.setWidgetVariable("jump", &config.keyboard.control[CONTROL::JUMP]);
123         engine.setWidgetVariable("pause", &config.keyboard.control[CONTROL::PAUSE]);
124
125         engine.setWidgetVariable("jetpack", &config.keyboard.control[CONTROL::JETPACK]);
126         engine.setWidgetVariable("map", &config.keyboard.control[CONTROL::MAP]);
127
128         engine.setWidgetVariable("defaults", &defaults);
129         engine.setWidgetVariable("confirm", &done);
130         
131         graphics.blit(optionsBackground, 0, 0, graphics.screen, false);
132         graphics.blit(header, 320, 25, graphics.screen, true);
133         drawWidgets();
134
135         engine.flushInput();
136         engine.clearInput();
137         
138         int menuSound = -1;
139         
140         engine.allowJoypad = false;
141
142         while (!done)
143         {
144                 graphics.updateScreen();
145                 
146                 if (menuSound)
147                 {
148                         audio.playMenuSound(menuSound);
149                 }
150
151                 engine.getInput();
152                 config.populate();
153
154                 menuSound = engine.processWidgets();
155
156                 graphics.blit(optionsBackground, 0, 0, graphics.screen, false);
157                 graphics.blit(header, 320, 25, graphics.screen, true);
158                 drawWidgets();
159                 
160                 if (defaults)
161                 {
162                         config.restoreKeyDefaults();
163                         defaults = 0;
164                 }
165
166                 if (engine.keyState[SDL_SCANCODE_ESCAPE])
167                 {
168                         engine.clearInput();
169                         engine.flushInput();
170                         done = 1;
171                 }
172
173                 SDL_Delay(16);
174         }
175         
176         engine.allowJoypad = true;
177         
178         config.saveKeyConfig();
179
180         audio.playMenuSound(2);
181
182         SDL_FillRect(graphics.screen, NULL, graphics.black);
183         graphics.delay(500);
184
185         if (!engine.loadWidgets(_("data/optionWidgets")))
186         {
187                 graphics.showErrorAndExit(ERR_FILE, _("data/optionWidgets"));
188         }
189         
190         engine.highlightWidget("keys");
191 }
192
193 void showJoystickConfig()
194 {
195         SDL_FillRect(graphics.screen, NULL, graphics.black);
196         graphics.delay(500);
197
198         if (!engine.loadWidgets(_("data/joystickWidgets")))
199                 graphics.showErrorAndExit(ERR_FILE, _("data/joystickWidgets"));
200                 
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));
204
205         int done = 0;
206         int sensitivity = (config.joystick.sensitivity / 100);
207
208         engine.setWidgetVariable("left", &config.joystick.control[CONTROL::LEFT]);
209         engine.setWidgetVariable("right", &config.joystick.control[CONTROL::RIGHT]);
210         engine.setWidgetVariable("up", &config.joystick.control[CONTROL::UP]);
211         engine.setWidgetVariable("down", &config.joystick.control[CONTROL::DOWN]);
212         engine.setWidgetVariable("fire", &config.joystick.control[CONTROL::FIRE]);
213         engine.setWidgetVariable("jump", &config.joystick.control[CONTROL::JUMP]);
214         engine.setWidgetVariable("pause", &config.joystick.control[CONTROL::PAUSE]);
215
216         engine.setWidgetVariable("jetpack", &config.joystick.control[CONTROL::JETPACK]);
217         engine.setWidgetVariable("map", &config.joystick.control[CONTROL::MAP]);
218         
219         engine.setWidgetVariable("sensitivity", &sensitivity);
220
221         engine.setWidgetVariable("confirm", &done);
222         
223         graphics.blit(optionsBackground, 0, 0, graphics.screen, false);
224         graphics.blit(header, 320, 25, graphics.screen, true);
225         drawWidgets();
226
227         engine.flushInput();
228         engine.clearInput();
229         
230         int menuSound = -1;
231         
232         engine.allowJoypad = false;
233
234         while (!done)
235         {
236                 graphics.updateScreen();
237                 
238                 if (menuSound)
239                         audio.playMenuSound(menuSound);
240
241                 engine.getInput();
242                 config.populate();
243
244                 menuSound = engine.processWidgets();
245
246                 graphics.blit(optionsBackground, 0, 0, graphics.screen, false);
247                 graphics.blit(header, 320, 25, graphics.screen, true);
248                 drawWidgets();
249
250                 if (engine.keyState[SDL_SCANCODE_ESCAPE])
251                 {
252                         engine.clearInput();
253                         engine.flushInput();
254                         done = 1;
255                 }
256
257                 SDL_Delay(16);
258         }
259         
260         config.joystick.sensitivity = (sensitivity * 100);
261         
262         engine.allowJoypad = true;
263         
264         config.saveJoystickConfig();
265
266         audio.playMenuSound(2);
267
268         SDL_FillRect(graphics.screen, NULL, graphics.black);
269         graphics.delay(500);
270
271         if (!engine.loadWidgets(_("data/optionWidgets")))
272         {
273                 graphics.showErrorAndExit(ERR_FILE, _("data/optionWidgets"));
274         }
275         
276         engine.highlightWidget("joysticks");
277 }
278
279 void showOptions()
280 {
281         float brightness;
282
283         SDL_FillRect(graphics.screen, NULL, graphics.black);
284         graphics.delay(500);
285
286         if (!engine.loadWidgets(_("data/optionWidgets")))
287         {
288                 graphics.showErrorAndExit(ERR_FILE, _("data/optionWidgets"));
289         }
290                 
291         SDL_Surface *header = graphics.getSprite("optionsHeader", true)->image[0];
292         SDL_Surface *optionsBackground = graphics.getSprite("optionsBackground", true)->image[0];
293         SDL_SetColorKey(optionsBackground, 0, SDL_MapRGB(optionsBackground->format, 0, 0, 0));
294
295         int done = 0;
296         int joysticks = 0;
297         int cheats = 0;
298         int keys = 0;
299
300         engine.setWidgetVariable("fullscreen", &engine.fullScreen);
301         engine.setWidgetVariable("soundvol", &game.soundVol);
302         engine.setWidgetVariable("musicvol", &game.musicVol);
303         engine.setWidgetVariable("output", &game.output);
304         engine.setWidgetVariable("autosave", &game.autoSave);
305         engine.setWidgetVariable("gamma", &game.brightness);
306         engine.setWidgetVariable("gore", &game.gore);
307         engine.setWidgetVariable("keys", &keys);
308         engine.setWidgetVariable("joysticks", &joysticks);
309         engine.setWidgetVariable("cheats", &cheats);
310         engine.setWidgetVariable("confirm", &done);
311
312         if (!engine.useAudio)
313         {
314                 engine.enableWidget("soundvol", false);
315                 engine.enableWidget("musicvol", false);
316                 engine.enableWidget("output", false);
317         }
318
319         if (SDL_NumJoysticks() == 0)
320         {
321                 engine.enableWidget("joysticks", false);
322         }
323
324         engine.showWidget("cheats", engine.cheats);
325
326         graphics.blit(optionsBackground, 0, 0, graphics.screen, false);
327         graphics.blit(header, 320, 25, graphics.screen, true);
328         drawWidgets();
329
330         engine.flushInput();
331         engine.clearInput();
332         
333         int menuSound = -1;
334
335         while (!done)
336         {
337                 graphics.updateScreen();
338                 
339                 if (menuSound)
340                         audio.playMenuSound(menuSound);
341
342                 engine.getInput();
343                 config.populate();
344
345                 if (engine.compareLastKeyInputs())
346                 {
347                         if (engine.cheats)
348                         {
349                                 audio.playSound(SND_CHEAT, CH_ANY);
350                                 engine.clearCheatVars();
351                         }
352
353                         engine.showWidget("cheats", engine.cheats);
354                         drawWidgets();
355                 }
356                 
357                 menuSound = engine.processWidgets();
358
359                 if (menuSound)
360                 {
361                         if (engine.widgetChanged("soundvol"))
362                                 audio.setSoundVolume(game.soundVol);
363
364                         if (engine.widgetChanged("musicvol"))
365                                 audio.setMusicVolume(game.musicVol);
366
367                         if (engine.widgetChanged("fullscreen"))
368                                 SDL_SetWindowFullscreen(graphics.window, engine.fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
369
370                         if (engine.widgetChanged("gamma"))
371                         {
372                                 brightness = game.brightness;
373                                 if (brightness > 0) {
374                                         brightness /= 10;
375                                         uint16_t ramp[256];
376                                         SDL_CalculateGammaRamp(brightness, ramp);
377                                         SDL_SetWindowGammaRamp(graphics.window, ramp, ramp, ramp);
378                                 }
379                         }
380                         
381                         if ((joysticks) || (cheats) || (keys))
382                         {
383                                 audio.playMenuSound(2);
384                                 menuSound = 0;
385
386                                 if (joysticks)
387                                 {
388                                         showJoystickConfig();
389                                 }
390                                 else if (cheats)
391                                 {
392                                         showCheatConfig();
393                                 }
394                                 else if (keys)
395                                 {
396                                         showKeyConfig();
397                                 }
398                                 
399                                 joysticks = keys = cheats = 0;
400
401                                 engine.setWidgetVariable("fullscreen", &engine.fullScreen);
402                                 engine.setWidgetVariable("soundvol", &game.soundVol);
403                                 engine.setWidgetVariable("musicvol", &game.musicVol);
404                                 engine.setWidgetVariable("output", &game.output);
405                                 engine.setWidgetVariable("autosave", &game.autoSave);
406                                 engine.setWidgetVariable("gamma", &game.brightness);
407                                 engine.setWidgetVariable("gore", &game.gore);
408                                 engine.setWidgetVariable("keys", &keys);
409                                 engine.setWidgetVariable("joysticks", &joysticks);
410                                 engine.setWidgetVariable("cheats", &cheats);
411                                 engine.setWidgetVariable("confirm", &done);
412
413                                 if (!engine.useAudio)
414                                 {
415                                         engine.enableWidget("soundvol", false);
416                                         engine.enableWidget("musicvol", false);
417                                         engine.enableWidget("output", false);
418                                 }
419                                 
420                                 if (SDL_NumJoysticks() == 0)
421                                 {
422                                         engine.enableWidget("joysticks", false);
423                                 }
424                                 
425                                 engine.showWidget("cheats", engine.cheats);
426                         }
427
428                         graphics.blit(optionsBackground, 0, 0, graphics.screen, false);
429                         graphics.blit(header, 320, 25, graphics.screen, true);
430                         drawWidgets();
431                 }
432
433                 if (engine.keyState[SDL_SCANCODE_ESCAPE])
434                 {
435                         engine.clearInput();
436                         engine.flushInput();
437                         done = 1;
438                 }
439
440                 SDL_Delay(16);
441         }
442         
443         
444         if (audio.output  != game.output)
445         {
446                 audio.output = game.output;
447                 
448                 if (!audio.output)
449                 {
450                         audio.stopMusic();
451                         audio.stopAmbiance();
452                 }
453                 else
454                 {
455                         audio.playMusic();
456                         audio.playAmbiance();
457                 }
458         }
459
460         audio.playMenuSound(2);
461
462         SDL_FillRect(graphics.screen, NULL, graphics.black);
463         graphics.delay(500);
464 }