naev 0.11.5
options.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
10#include <ctype.h>
11#include "physfs.h"
12#include "SDL.h"
13
14#include "naev.h"
17#include "options.h"
18
19#include "array.h"
20#include "conf.h"
21#include "background.h"
22#include "colour.h"
23#include "dialogue.h"
24#include "difficulty.h"
25#include "input.h"
26#include "log.h"
27#include "music.h"
28#include "ndata.h"
29#include "nfile.h"
30#include "nstring.h"
31#include "player.h"
32#include "plugin.h"
33#include "render.h"
34#include "sound.h"
35#include "toolkit.h"
36
37#define BUTTON_WIDTH 200
38#define BUTTON_HEIGHT 30
40#define OPT_WIN_GAMEPLAY 0
41#define OPT_WIN_VIDEO 1
42#define OPT_WIN_AUDIO 2
43#define OPT_WIN_INPUT 3
44#define OPT_WIN_PLUGINS 4
45#define OPT_WINDOWS 5
46
47#define AUTONAV_RESET_DIST_MAX 10e3
48#define LANG_CODE_START 7
50static unsigned int opt_wid = 0;
51static unsigned int *opt_windows;
52static const char *opt_names[] = {
53 N_("Gameplay"),
54 N_("Video"),
55 N_("Audio"),
56 N_("Input"),
57 N_("Plugins"),
58};
59static const glColour *cHeader = &cFontGrey;
60
61static int opt_restart = 0;
62static PlayerConf_t local_conf;
63
64/*
65 * External stuff.
66 */
67static const char *opt_selectedKeybind;
68static int opt_lastKeyPress = 0;
70/*
71 * prototypes
72 */
73/* Misc. */
74static void opt_close( unsigned int wid, const char *name );
75static void opt_needRestart (void);
76/* Gameplay. */
77static char** lang_list( int *n );
78static void opt_gameplay( unsigned int wid );
79static void opt_setMapOverlayOpacity( unsigned int wid, const char *str );
80static void opt_OK( unsigned int wid, const char *str );
81static int opt_gameplaySave( unsigned int wid, const char *str );
82static void opt_gameplayDefaults( unsigned int wid, const char *str );
83static void opt_gameplayUpdate( unsigned int wid, const char *str );
84/* Video. */
85static void opt_video( unsigned int wid );
86static void opt_videoRes( unsigned int wid, const char *str );
87static int opt_videoSave( unsigned int wid, const char *str );
88static void opt_videoDefaults( unsigned int wid, const char *str );
89static void opt_getVideoMode( int *w, int *h, int *fullscreen );
90static void opt_setGammaCorrection( unsigned int wid, const char *str );
91static void opt_setScalefactor( unsigned int wid, const char *str );
92static void opt_setZoomFar( unsigned int wid, const char *str );
93static void opt_setZoomNear( unsigned int wid, const char *str );
94static void opt_setBGBrightness( unsigned int wid, const char *str );
95static void opt_setNebuNonuniformity( unsigned int wid, const char *str );
96static void opt_setJumpBrightness( unsigned int wid, const char *str );
97static void opt_checkColourblind( unsigned int wid, const char *str );
98static void opt_checkHealth( unsigned int wid, const char *str );
99/* Audio. */
100static void opt_audio( unsigned int wid );
101static int opt_audioSave( unsigned int wid, const char *str );
102static void opt_audioDefaults( unsigned int wid, const char *str );
103static void opt_audioUpdate( unsigned int wid );
104static void opt_audioLevelStr( char *buf, int max, int type, double pos );
105static void opt_setAudioLevel( unsigned int wid, const char *str );
106static void opt_setEngineLevel( unsigned int wid, const char *str );
107static void opt_beep( unsigned int wid, const char *str );
108/* Keybind menu. */
109static void opt_keybinds( unsigned int wid );
110static void menuKeybinds_getDim( unsigned int wid, int *w, int *h,
111 int *lw, int *lh, int *bw, int *bh );
112static void menuKeybinds_genList( unsigned int wid );
113static void menuKeybinds_update( unsigned int wid, const char *name );
114static void opt_keyDefaults( unsigned int wid, const char *str );
115/* Setting keybindings. */
116static int opt_setKeyEvent( unsigned int wid, SDL_Event *event );
117static void opt_setKey( unsigned int wid, const char *str );
118static void opt_unsetKey( unsigned int wid, const char *str );
119/* Plugins menu. */
120static void opt_plugins( unsigned int wid );
121static void opt_plugins_update( unsigned int wid, const char *name );
122
126void opt_menu (void)
127{
128 int w, h;
129 const char **names;
130
131 /* Save current configuration over. */
132 conf_copy( &local_conf, &conf );
133
134 /* Dimensions. */
135 w = 680;
136 h = 525;
137
138 /* Create window and tabs. */
139 opt_wid = window_create( "wdwOptions", _("Options"), -1, -1, w, h );
140 window_setCancel( opt_wid, opt_close );
141
142 /* Create tabbed window. */
143 names = calloc( sizeof(char*), sizeof(opt_names)/sizeof(char*) );
144 for (size_t i=0; i<sizeof(opt_names)/sizeof(char*); i++)
145 names[i] = _(opt_names[i]);
146 opt_windows = window_addTabbedWindow( opt_wid, -1, -1, -1, -1, "tabOpt",
147 OPT_WINDOWS, (const char**)names, 0 );
148 free(names);
149
150 /* Load tabs. */
151 opt_gameplay( opt_windows[ OPT_WIN_GAMEPLAY ] );
152 opt_video( opt_windows[ OPT_WIN_VIDEO ] );
153 opt_audio( opt_windows[ OPT_WIN_AUDIO ] );
154 opt_keybinds( opt_windows[ OPT_WIN_INPUT ] );
155 opt_plugins( opt_windows[ OPT_WIN_PLUGINS ] );
156
157 /* Set as need restart if needed. */
158 if (opt_restart)
160}
161
165static void opt_OK( unsigned int wid, const char *str )
166{
167 int ret, prompted_restart;
168
169 prompted_restart = opt_restart;
170 ret = 0;
171 ret |= opt_gameplaySave( opt_windows[ OPT_WIN_GAMEPLAY ], str);
172 ret |= opt_audioSave( opt_windows[ OPT_WIN_AUDIO ], str);
173 ret |= opt_videoSave( opt_windows[ OPT_WIN_VIDEO ], str);
174
175 if (opt_restart && !prompted_restart)
176 dialogue_msg( _("Warning"), "#r%s#0", _("Restart Naev for changes to take effect.") );
177
178 /* Close window if no errors occurred. */
179 if (!ret) {
180 /* Save current configuration over. */
181 conf_copy( &local_conf, &conf );
182 opt_close(wid, str);
183 }
184}
185
189static void opt_close( unsigned int wid, const char *name )
190{
191 (void) wid;
192 (void) name;
193
194 /* Load old config again. */
195 conf_copy( &conf, &local_conf );
196
197 /* At this point, set sound levels as defined in the config file.
198 * This ensures that sound volumes are reset on "Cancel". */
199 sound_volume( conf.sound );
200 music_volume( conf.music );
201 render_setGamma( conf.gamma_correction );
202
203 window_destroy( opt_wid );
204 opt_wid = 0;
205
206 /* Free config. */
207 conf_free( &local_conf );
208}
209
213void opt_resize (void)
214{
215 int w, h, fullscreen;
216 char buf[16];
217
218 /* Nothing to do if not open. */
219 if (!opt_wid)
220 return;
221
222 /* Update the resolution input widget. */
223 opt_getVideoMode( &w, &h, &fullscreen );
224 snprintf( buf, sizeof(buf), "%dx%d", w, h );
225 window_setInput( opt_windows[OPT_WIN_VIDEO], "inpRes", buf );
226}
227
228/*
229 * Gets the list of languages available. Options look like "[ 81%] de".
230 */
231static char** lang_list( int *n )
232{
233 char **ls;
235 const char *syslang = gettext_getSystemLanguage();
236 double syscoverage = gettext_languageCoverage(syslang);
237
238 /* Default English only. */
239 ls = malloc( sizeof(char*)*128 );
240 SDL_asprintf( &ls[0], _("system (%s[%3.0f%%] %s#0)"), (syscoverage<0.8)?"#r":"", 100.*syscoverage, syslang );
241 *n = 1;
242
243 /* Try to open the available languages. */
244 for (int i=0; i<array_size(opts); i++) {
245 char **item = &ls[(*n)++];
246 SDL_asprintf( item, "%s[%3.0f%%] %s",
247 (opts[i].coverage<0.8)?"#r":"",
248 100.*opts[i].coverage, opts[i].language );
249 free( opts[i].language );
250 }
251 array_free( opts );
252
253 qsort( &ls[1], *n-1, sizeof(char*), strsort_reverse );
254 return ls;
255}
256
260static void opt_gameplay( unsigned int wid )
261{
262 (void) wid;
263 char buf[STRMAX];
264 int cw;
265 int w, h, y, x, by, l, n, i, p;
266 const char *s;
267 char **ls, **diff_text, **diff_alt;
268 const Difficulty *difficulty, *cur_difficulty;
269
270 /* Get size. */
271 window_dimWindow( wid, &w, &h );
272
273 /* Close button */
274 window_addButton( wid, -20, 20,
276 "btnClose", _("OK"), opt_OK );
277 window_addButton( wid, -20 - 1*(BUTTON_WIDTH+20), 20,
279 "btnCancel", _("Cancel"), opt_close );
280 window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20,
282 "btnDefaults", _("Defaults"), opt_gameplayDefaults );
283
284 /* Information. */
285 cw = (w-40);
286 x = 20;
287 y = -35;
288 window_addText( wid, x, y, cw, 20, 1, "txtVersion",
289 NULL, NULL, naev_version(1) );
290 y -= 20;
291
292 snprintf( buf, sizeof(buf), "#n%s#0%s (%s)", _("Platform Info: "), SDL_GetPlatform(), HOST );
293 window_addText( wid, x, y, cw, 20, 1, "txtPlatInfo", NULL, NULL, buf );
294 y -= 20;
295
296 snprintf( buf, sizeof(buf), "#n%s#0%s"CONF_FILE, _("Config Path: "), nfile_configPath() );
297 window_addText( wid, x, y, cw, 20, 1, "txtConfPath", NULL, NULL, buf );
298 y -= 40;
299 by = y;
300
301 /* Language support. */
302 cw = (w-60)/2 - 40;
303 y = by;
304 x = 20;
305 s = _("Language:");
306 l = gl_printWidthRaw( NULL, s );
307 window_addText( wid, x, y, l, 20, 0, "txtLanguage",
308 NULL, NULL, s );
309 ls = lang_list( &n );
310 i = 0;
311 if (conf.language != NULL) {
312 for (i=1; i<n; i++)
313 if (strcmp(conf.language, &ls[i][LANG_CODE_START])==0)
314 break;
315 if (i>=n)
316 i = 0;
317 }
318 window_addList( wid, x+l+20, y, cw-l-50, 100, "lstLanguage", ls, n, i, NULL, NULL );
319 y -= 110;
320
321 /* Game difficulty. */
322 difficulty = difficulty_getAll();
323 n = array_size(difficulty);
324 diff_text = malloc( sizeof(char*) * n );
325 diff_alt = malloc( sizeof(char*) * n );
326 p = 0;
327 if (player.p == NULL)
328 difficulty_setLocal( NULL );
329 cur_difficulty = difficulty_cur();
330 for (i=0; i<n; i++) {
331 const Difficulty *d = &difficulty[i];
332 diff_text[i] = strdup( _(d->name) );
333 diff_alt[i] = difficulty_display(d);
334 if (strcmp(d->name,cur_difficulty->name)==0)
335 p = i;
336 }
337 if (player.p != NULL)
338 s = _("Difficulty (this save):");
339 else
340 s = _("Difficulty (global):");
341 window_addText( wid, x, y, cw, 20, 0, "txtDifficulty", NULL, NULL, s );
342 y -= 20;
343 window_addList( wid, x, y, cw, 100, "lstDifficulty", diff_text, n, p, NULL, NULL );
344 toolkit_setListAltText( wid, "lstDifficulty", diff_alt );
345 y -= 110;
346
347 /* Compilation flags. */
348 window_addText( wid, x, y, cw, 20, 0, "txtCompile",
349 NULL, cHeader, _("Compilation Flags:") );
350 y -= 20;
351 window_addText( wid, x, y, cw, h+y-20, 0, "txtFlags",
352 NULL, &cFontOrange,
353 ""
354#if DEBUGGING
355#if DEBUG_PARANOID
356 "Debug Paranoid\n"
357#else /* DEBUG_PARANOID */
358 "Debug\n"
359#endif /* DEBUG_PARANOID */
360#endif /* DEBUGGING */
361#if HAVE_LUAJIT
362 "Using LuaJIT\n"
363#endif /* HAVE_LUAJIT */
364 );
365
366 y -= window_getTextHeight(wid, "txtFlags") + 10;
367
368 /* Options. */
369 x = 20 + cw + 20;
370 y = by;
371 cw += 80;
372
373 window_addText( wid, x, y, cw, 20, 0, "txtSettings",
374 NULL, cHeader, _("Settings:") );
375 y -= 25;
376
377 window_addCheckbox( wid, x, y, cw, 20,
378 "chkZoomManual", _("Enable manual zoom control"), NULL, conf.zoom_manual );
379 y -= 25;
380 window_addCheckbox( wid, x, y, cw, 20,
381 "chkDoubletap", _("Enable double-tap afterburn/cooldown"), NULL, conf.doubletap_sens );
382 y -= 25;
383 window_addCheckbox( wid, x, y, cw, 20,
384 "chkMouseFly", _("Enable mouse-flying (toggle with middle click)"), NULL, conf.mouse_fly );
385 y -= 25;
386 window_addCheckbox( wid, x, y, cw, 20,
387 "chkMouseAccel", _("Enable mouse-flying accel control"), NULL, conf.mouse_accel );
388 y -= 25;
389 window_addCheckbox( wid, x, y, cw, 20,
390 "chkCompress", _("Enable saved game compression"), NULL, conf.save_compress );
391 y -= 40;
392 s = _("Visible Messages");
393 l = gl_printWidthRaw( NULL, s );
394 window_addText( wid, x, y, l, 20, 1, "txtSMSG",
395 NULL, NULL, s );
396 window_addInput( wid, -50, y, 40, 20, "inpMSG", 4, 1, NULL );
397 y -= 30;
398 s = _("Max Time Compression Factor");
399 l = gl_printWidthRaw( NULL, s );
400 window_addText( wid, x, y, l, 20, 1, "txtTMax",
401 NULL, NULL, s );
402 window_addInput( wid, -50, y, 40, 20, "inpTMax", 4, 1, NULL );
403
404 /* Restart text. */
405 window_addText( wid, 20, 20 + BUTTON_HEIGHT,
406 w - 40, 30, 0, "txtRestart", NULL, NULL, NULL );
407
408 /* Update. */
409 opt_gameplayUpdate( wid, NULL );
410}
411
415static int opt_gameplaySave( unsigned int wid, const char *str )
416{
417 (void) str;
418 int f, p, newlang;
419 const char *vmsg, *s;
420 const Difficulty *difficulty;
421
422 /* List. */
423 p = toolkit_getListPos( wid, "lstLanguage" );
424 s = (p==0) ? NULL : toolkit_getList( wid, "lstLanguage" );
425 newlang = ((s != NULL) != (conf.language != NULL))
426 || ((s != NULL) && (strcmp( &s[LANG_CODE_START], conf.language) != 0));
427 if (newlang) {
428 free( conf.language );
429 conf.language = (s==NULL) ? NULL : strdup( &s[LANG_CODE_START] );
430 LOG("conf.language set to %s", conf.language);
431 /* Apply setting going forward; advise restart to regen other text. */
434
435 /* Probably have to reload some fonts or it'll hate us. */
436 gl_freeFont(NULL);
439 gl_fontInit( &gl_defFont, _(FONT_DEFAULT_PATH), conf.font_size_def, FONT_PATH_PREFIX, 0 ); /* initializes default font to size */
440 gl_fontInit( &gl_smallFont, _(FONT_DEFAULT_PATH), conf.font_size_small, FONT_PATH_PREFIX, 0 ); /* small font */
441 gl_fontInit( &gl_defFontMono, _(FONT_MONOSPACE_PATH), conf.font_size_def, FONT_PATH_PREFIX, 0 );
442 }
443
444 /* Save the difficulty mode. */
445 difficulty = difficulty_getAll();
446 p = toolkit_getListPos( wid, "lstDifficulty" );
447 difficulty = &difficulty[p];
448 if (player.p == NULL) { /* Setting global difficulty. */
449 free(conf.difficulty);
450 if (difficulty->def) {
451 conf.difficulty = NULL; /* Don't save default. */
452 difficulty_setGlobal( NULL );
453 }
454 else {
455 conf.difficulty = strdup( difficulty->name );
456 difficulty_setGlobal( difficulty );
457 }
458 }
459 else { /* Local difficulty. */
460 free(player.difficulty);
461 if (difficulty == difficulty_get(NULL)) {
462 player.difficulty = NULL;
463 difficulty_setLocal( NULL );
464 }
465 else {
466 player.difficulty = strdup( difficulty->name );
467 difficulty_setLocal( difficulty );
468 }
469 }
470 /* Apply difficulty to player ship. */
471 if (player.p != NULL)
472 pilot_calcStats( player.p ); /* TODO apply to all player's ships. */
473
474 /* Checkboxes. */
475 f = window_checkboxState( wid, "chkDoubletap" );
476 if (!!conf.doubletap_sens != f)
477 conf.doubletap_sens = (!!f)*250;
478
479 conf.zoom_manual = window_checkboxState( wid, "chkZoomManual" );
480 conf.mouse_accel = window_checkboxState(wid, "chkMouseAccel" );
481 conf.mouse_fly = window_checkboxState( wid, "chkMouseFly" );
482 conf.save_compress = window_checkboxState( wid, "chkCompress" );
483
484 /* Get rid of mouse if disabled. */
485 if (!conf.mouse_fly)
486 player_rmFlag( PLAYER_MFLY );
487
488 /* Input boxes. */
489 vmsg = window_getInput( wid, "inpMSG" );
490 conf.mesg_visible = atoi(vmsg);
491 if (conf.mesg_visible == 0)
492 conf.mesg_visible = INPUT_MESSAGES_DEFAULT;
493
494 return 0;
495}
496
500static void opt_gameplayDefaults( unsigned int wid, const char *str )
501{
502 (void) str;
503 char vmsg[16];
504
505 /* Restore. */
506 /* Checkboxes. */
507 window_checkboxSet( wid, "chkZoomManual", MANUAL_ZOOM_DEFAULT );
508 window_checkboxSet( wid, "chkDoubletap", DOUBLETAP_SENSITIVITY_DEFAULT );
509 window_checkboxSet( wid, "chkMouseFly", MOUSE_FLY_DEFAULT );
510 window_checkboxSet( wid, "chkMouseAccel", MOUSE_ACCEL_DEFAULT );
511 window_checkboxSet( wid, "chkCompress", SAVE_COMPRESSION_DEFAULT );
512
513 /* Input boxes. */
514 snprintf( vmsg, sizeof(vmsg), "%d", INPUT_MESSAGES_DEFAULT );
515 window_setInput( wid, "inpMSG", vmsg );
516}
517
521static void opt_gameplayUpdate( unsigned int wid, const char *str )
522{
523 (void) str;
524 char vmsg[16];
525
526 /* Checkboxes. */
527 window_checkboxSet( wid, "chkZoomManual", conf.zoom_manual );
528 window_checkboxSet( wid, "chkDoubletap", conf.doubletap_sens );
529 window_checkboxSet( wid, "chkMouseFly", conf.mouse_fly );
530 window_checkboxSet( wid, "chkMouseAccel", conf.mouse_accel );
531 window_checkboxSet( wid, "chkCompress", conf.save_compress );
532
533 /* Input boxes. */
534 snprintf( vmsg, sizeof(vmsg), "%d", conf.mesg_visible );
535 window_setInput( wid, "inpMSG", vmsg );
536}
537
541static void menuKeybinds_getDim( unsigned int wid, int *w, int *h,
542 int *lw, int *lh, int *bw, int *bh )
543{
544 /* Get window dimensions. */
545 window_dimWindow( wid, w, h );
546
547 /* Get button dimensions. */
548 if (bw != NULL)
549 *bw = BUTTON_WIDTH;
550 if (bh != NULL)
551 *bh = BUTTON_HEIGHT;
552
553 /* Get list dimensions. */
554 if (lw != NULL)
555 *lw = 350; //*w - BUTTON_WIDTH - 60;
556 if (lh != NULL)
557 *lh = *h - 60;
558}
559
563static void opt_keybinds( unsigned int wid )
564{
565 int w, h, lw, bw, bh;
566
567 /* Get dimensions. */
568 menuKeybinds_getDim( wid, &w, &h, &lw, NULL, &bw, &bh );
569
570 /* Close button. */
571 window_addButton( wid, -20, 20, bw, bh,
572 "btnClose", _("OK"), opt_OK );
573 /* Restore defaults button. */
574 window_addButton( wid, -20, 40 + bh, bw, bh,
575 "btnDefaults", _("Defaults"), opt_keyDefaults );
576 /* Set button. */
577 window_addButton( wid, -20, 60 + 2*bh, bw, bh,
578 "btnSet", _("Set Key"), opt_setKey );
579
580 /* Text stuff. */
581 window_addText( wid, -20, -40, w-(20+lw+20+20), 30, 1, "txtName",
582 NULL, cHeader, NULL );
583 window_addText( wid, -20, -90, w-(20+lw+20+20), h-170-3*bh,
584 0, "txtDesc", NULL, NULL, NULL );
585
586 /* Generate the list. */
588}
589
595static void menuKeybinds_genList( unsigned int wid )
596{
597 int l, p;
598 char **str, mod_text[64];
599 SDL_Keycode key;
600 KeybindType type;
601 SDL_Keymod mod;
602 int w, h;
603 int lw, lh;
604 int regen, pos, off;
605
606 /* Get dimensions. */
607 menuKeybinds_getDim( wid, &w, &h, &lw, &lh, NULL, NULL );
608
609 /* Create the list. */
610 str = malloc( sizeof( char * ) * input_numbinds );
611 for (int j = 0; j < input_numbinds; j++) {
612 const char *short_desc = _(keybind_info[j][1]);
613 l = 128; /* GCC deduces 68 because we have a format string "%s <%s%c>"
614 * where "char mod_text[64]" is one of the "%s" args.
615 * (that plus brackets plus %c + null gets to 68.
616 * Just set to 128 as it's a power of two. */
617 str[j] = malloc(l);
618 key = input_getKeybind( keybind_info[j][0], &type, &mod );
619 switch (type) {
620 case KEYBIND_KEYBOARD:
621 /* Generate mod text. */
622 if (mod == NMOD_ANY)
623 snprintf( mod_text, sizeof(mod_text), _("any+") );
624 else {
625 p = 0;
626 mod_text[0] = '\0';
627 if (mod & NMOD_SHIFT)
628 p += scnprintf( &mod_text[p], sizeof(mod_text)-p, _("shift+") );
629 if (mod & NMOD_CTRL)
630 p += scnprintf( &mod_text[p], sizeof(mod_text)-p, _("ctrl+") );
631 if (mod & NMOD_ALT)
632 p += scnprintf( &mod_text[p], sizeof(mod_text)-p, _("alt+") );
633 if (mod & NMOD_META)
634 p += scnprintf( &mod_text[p], sizeof(mod_text)-p, _("meta+") );
635 (void)p;
636 }
637
638 /* Print key. Special-case ASCII letters (use uppercase, unlike SDL_GetKeyName.). */
639 if (key < 0x100 && isalpha(key))
640 snprintf(str[j], l, "%s <%s%c>", short_desc, mod_text, toupper(key) );
641 else
642 snprintf(str[j], l, "%s <%s%s>", short_desc, mod_text, pgettext_var("keyname", SDL_GetKeyName(key)) );
643 break;
644 case KEYBIND_JAXISPOS:
645 snprintf(str[j], l, "%s <ja+%d>", short_desc, key);
646 break;
647 case KEYBIND_JAXISNEG:
648 snprintf(str[j], l, "%s <ja-%d>", short_desc, key);
649 break;
650 case KEYBIND_JBUTTON:
651 snprintf(str[j], l, "%s <jb%d>", short_desc, key);
652 break;
653 case KEYBIND_JHAT_UP:
654 snprintf(str[j], l, "%s <jh%d-up>", short_desc, key);
655 break;
656 case KEYBIND_JHAT_DOWN:
657 snprintf(str[j], l, "%s <jh%d-down>", short_desc, key);
658 break;
659 case KEYBIND_JHAT_LEFT:
660 snprintf(str[j], l, "%s <jh%d-left>", short_desc, key);
661 break;
662 case KEYBIND_JHAT_RIGHT:
663 snprintf(str[j], l, "%s <jh%d-right>", short_desc, key);
664 break;
665 default:
666 snprintf(str[j], l, "%s", short_desc);
667 break;
668 }
669 }
670
671 regen = widget_exists( wid, "lstKeybinds" );
672 if (regen) {
673 pos = toolkit_getListPos( wid, "lstKeybinds" );
674 off = toolkit_getListOffset( wid, "lstKeybinds" );
675 window_destroyWidget( wid, "lstKeybinds" );
676 }
677
678 window_addList( wid, 20, -40, lw, lh, "lstKeybinds", str, input_numbinds, 0, menuKeybinds_update, opt_setKey );
679
680 if (regen) {
681 toolkit_setListPos( wid, "lstKeybinds", pos );
682 toolkit_setListOffset( wid, "lstKeybinds", off );
683 }
684}
685
692static void menuKeybinds_update( unsigned int wid, const char *name )
693{
694 (void) name;
695 int selected;
696 const char *keybind;
697 const char *desc;
698 SDL_Keycode key;
699 KeybindType type;
700 SDL_Keymod mod;
701 char buf[STRMAX_SHORT];
702 char binding[64];
703
704 /* Get the keybind. */
705 selected = toolkit_getListPos( wid, "lstKeybinds" );
706
707 /* Remove the excess. */
708 keybind = keybind_info[selected][0];
709 opt_selectedKeybind = keybind;
710 window_modifyText( wid, "txtName", _(keybind_info[selected][1]) );
711
712 /* Get information. */
713 desc = input_getKeybindDescription( keybind );
714 key = input_getKeybind( keybind, &type, &mod );
715
716 /* Create the text. */
717 switch (type) {
718 case KEYBIND_NULL:
719 snprintf(binding, sizeof(binding), _("Not bound"));
720 break;
721 case KEYBIND_KEYBOARD:
722 /* Print key. Special-case ASCII letters (use uppercase, unlike SDL_GetKeyName.). */
723 if (key < 0x100 && isalpha(key))
724 snprintf(binding, sizeof(binding), _("keyboard: %s%s%c"),
725 (mod != KMOD_NONE) ? input_modToText(mod) : "",
726 (mod != KMOD_NONE) ? " + " : "",
727 toupper(key));
728 else
729 snprintf(binding, sizeof(binding), _("keyboard: %s%s%s"),
730 (mod != KMOD_NONE) ? input_modToText(mod) : "",
731 (mod != KMOD_NONE) ? " + " : "",
732 pgettext_var("keyname", SDL_GetKeyName(key)));
733 break;
734 case KEYBIND_JAXISPOS:
735 snprintf(binding, sizeof(binding), _("joy axis pos: <%d>"), key );
736 break;
737 case KEYBIND_JAXISNEG:
738 snprintf(binding, sizeof(binding), _("joy axis neg: <%d>"), key );
739 break;
740 case KEYBIND_JBUTTON:
741 snprintf(binding, sizeof(binding), _("joy button: <%d>"), key);
742 break;
743 case KEYBIND_JHAT_UP:
744 snprintf(binding, sizeof(binding), _("joy hat up: <%d>"), key);
745 break;
746 case KEYBIND_JHAT_DOWN:
747 snprintf(binding, sizeof(binding), _("joy hat down: <%d>"), key);
748 break;
749 case KEYBIND_JHAT_LEFT:
750 snprintf(binding, sizeof(binding), _("joy hat left: <%d>"), key);
751 break;
752 case KEYBIND_JHAT_RIGHT:
753 snprintf(binding, sizeof(binding), _("joy hat right:<%d>"), key);
754 break;
755 }
756
757 /* Update text. */
758 snprintf(buf, sizeof(buf), "%s\n\n%s\n", desc, binding);
759 window_modifyText( wid, "txtDesc", buf );
760}
761
765static void opt_keyDefaults( unsigned int wid, const char *str )
766{
767 (void) str;
768 const char *title, *caption, *ret;
769 int ind;
770
771 const int n = 3;
772 const char *opts[] = {
773 _("WASD"),
774 _("Arrow Keys"),
775 _("Cancel")
776 };
777
778 title = _("Restore Defaults");
779 caption = _("Which layout do you want to use?");
780
781 dialogue_makeChoice( title, caption, n );
782
783 for (int i=0; i<n; i++)
784 dialogue_addChoice( title, caption, opts[i] );
785
786 ret = dialogue_runChoice();
787 if (ret == NULL)
788 return;
789
790 /* Find the index of the matched option. */
791 ind = 0;
792 for (int i=0; i<n; i++)
793 if (strcmp(ret, opts[i]) == 0) {
794 ind = i;
795 break;
796 }
797
798 if (ind == 2)
799 return;
800
801 /* Restore defaults. */
802 input_setDefault( (ind == 0) ? 1 : 0 );
803
804 /* Regenerate list widget. */
806
807 /* Alert user it worked. */
808 dialogue_msgRaw( _("Defaults Restored"), _("Keybindings restored to defaults."));
809}
810
811static void opt_setEngineLevel( unsigned int wid, const char *str )
812{
813 char buf[32];
814 double vol = window_getFaderValue(wid, str);
815 const char *label = _("Engine Volume");
816 double logvol = 1. / pow(2., (1.-vol) * 8.);
817 conf.engine_vol = vol;
818 if (sound_disabled)
819 snprintf( buf, sizeof(buf), _("%s: %s"), label, _("Muted") );
820 else {
821 const double magic = -48. / log(0.00390625); /* -48 dB minimum divided by logarithm of volume floor. */
822 snprintf( buf, sizeof(buf), _("%s: %.2f (%.0f dB)"), label, vol, log(logvol) * magic );
823 }
824 window_modifyText( wid, "txtEngine", buf );
825}
826
833static void opt_setAudioLevel( unsigned int wid, const char *str )
834{
835 char buf[32], *widget;
836 double vol = window_getFaderValue(wid, str);
837 if (strcmp(str,"fadSound")==0) {
838 sound_volume(vol);
839 widget = "txtSound";
840 opt_audioLevelStr( buf, sizeof(buf), 0, vol );
841 }
842 else {
843 music_volume(vol);
844 widget = "txtMusic";
845 opt_audioLevelStr( buf, sizeof(buf), 1, vol );
846 }
847
848 window_modifyText( wid, widget, buf );
849}
850
859static void opt_audioLevelStr( char *buf, int max, int type, double pos )
860{
861 const char *str = type ? _("Music Volume") : _("Sound Volume");
862 double vol = type ? music_getVolumeLog() : sound_getVolumeLog();
863
864 if (vol == 0.)
865 snprintf( buf, max, _("%s: %s"), str, _("Muted") );
866 else {
867 const double magic = -48. / log(0.00390625); /* -48 dB minimum divided by logarithm of volume floor. */
868 snprintf( buf, max, _("%s: %.2f (%.0f dB)"), str, pos, log(vol) * magic );
869 }
870}
871
875static void opt_audio( unsigned int wid )
876{
877 (void) wid;
878 int cw, w, h, y, x;
879
880 /* Get size. */
881 window_dimWindow( wid, &w, &h );
882
883 /* Close button */
884 window_addButton( wid, -20, 20,
886 "btnClose", _("OK"), opt_OK );
887 window_addButton( wid, -20 - 1*(BUTTON_WIDTH+20), 20,
889 "btnCancel", _("Cancel"), opt_close );
890 window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20,
892 "btnDefaults", _("Defaults"), opt_audioDefaults );
893
894 cw = (w-60)/2;
895 x = 20;
896 y = -60;
897 window_addCheckbox( wid, x, y, cw, 20,
898 "chkNosound", _("Disable all sound/music"), NULL, conf.nosound );
899 y -= 30;
900
901 window_addCheckbox( wid, x, y, cw, 20,
902 "chkEFX", _("EFX (More CPU)"), NULL, conf.al_efx );
903
904 /* Sound levels. */
905 x = 20 + cw + 20;
906 y = -60;
907 window_addText( wid, x, y, cw-40, 20, 0, "txtSVolume",
908 NULL, cHeader, _("Volume Levels:") );
909 y -= 30;
910
911 /* Sound fader. */
912 window_addText( wid, x, y, cw, 20, 1, "txtSound",
913 NULL, NULL, NULL );
914 y -= 20;
915 window_addFader( wid, x, y, cw, 20, "fadSound", 0., 1.,
917 window_faderScrollDone( wid, "fadSound", opt_beep );
918 y -= 30;
919
920 /* Music fader. */
921 window_addText( wid, x, y, cw, 20, 1, "txtMusic",
922 NULL, NULL, NULL );
923 y -= 20;
924 window_addFader( wid, x, y, cw, 20, "fadMusic", 0., 1.,
926 y -= 30;
927
928 /* Engine fader. */
929 window_addText( wid, x, y, cw, 20, 1, "txtEngine",
930 NULL, NULL, NULL );
931 y -= 20;
932 window_addFader( wid, x, y, cw, 20, "fadEngine", 0., 1.,
933 conf.engine_vol, opt_setEngineLevel );
934 opt_setEngineLevel( wid, "fadEngine" );
935
936 /* Restart text. */
937 window_addText( wid, 20, 20 + BUTTON_HEIGHT,
938 w - 40, 30, 0, "txtRestart", NULL, NULL, NULL );
939
940 opt_audioUpdate(wid);
941}
942
943static void opt_beep( unsigned int wid, const char *str )
944{
945 (void) wid;
946 (void) str;
948}
949
953static int opt_audioSave( unsigned int wid, const char *str )
954{
955 (void) str;
956 int f;
957
958 f = window_checkboxState( wid, "chkNosound" );
959 if (conf.nosound != f) {
960 conf.nosound = f;
962 }
963
964 f = window_checkboxState( wid, "chkEFX" );
965 if (conf.al_efx != f) {
966 conf.al_efx = f;
968 }
969
970 /* Faders. */
971 conf.sound = window_getFaderValue(wid, "fadSound");
972 conf.music = window_getFaderValue(wid, "fadMusic");
973 conf.engine_vol = window_getFaderValue(wid, "fadEngine");
974
975 return 0;
976}
977
981static void opt_audioDefaults( unsigned int wid, const char *str )
982{
983 (void) str;
984
985 /* Set defaults. */
986 /* Faders. */
987 window_faderValue( wid, "fadSound", SOUND_VOLUME_DEFAULT );
988 window_faderValue( wid, "fadMusic", MUSIC_VOLUME_DEFAULT );
989 window_faderValue( wid, "fadEngine", ENGINE_VOLUME_DEFAULT );
990
991 /* Checkboxes. */
992 window_checkboxSet( wid, "chkNosound", MUTE_SOUND_DEFAULT );
993 window_checkboxSet( wid, "chkEFX", USE_EFX_DEFAULT );
994}
995
999static void opt_audioUpdate( unsigned int wid )
1000{
1001 /* Checkboxes. */
1002 window_checkboxSet( wid, "chkNosound", conf.nosound );
1003 window_checkboxSet( wid, "chkEFX", conf.al_efx );
1004
1005 /* Faders. */
1006 window_faderValue( wid, "fadSound", conf.sound );
1007 window_faderValue( wid, "fadMusic", conf.music );
1008 window_faderValue( wid, "fadEngine", conf.engine_vol );
1009}
1010
1014static int opt_setKeyEvent( unsigned int wid, SDL_Event *event )
1015{
1016 unsigned int parent;
1017 KeybindType type;
1018 int key, test_key_event;
1019 SDL_Keymod mod, ev_mod;
1020 const char *str;
1021
1022 /* See how to handle it. */
1023 switch (event->type) {
1024 case SDL_KEYDOWN:
1025 key = event->key.keysym.sym;
1026 /* If control key make player hit twice. */
1027 test_key_event = (key == SDLK_NUMLOCKCLEAR) ||
1028 (key == SDLK_CAPSLOCK) ||
1029 (key == SDLK_SCROLLLOCK) ||
1030 (key == SDLK_RSHIFT) ||
1031 (key == SDLK_LSHIFT) ||
1032 (key == SDLK_RCTRL) ||
1033 (key == SDLK_LCTRL) ||
1034 (key == SDLK_RALT) ||
1035 (key == SDLK_LALT) ||
1036 (key == SDLK_RGUI) ||
1037 (key == SDLK_LGUI);
1038 if (test_key_event && (opt_lastKeyPress != key)) {
1039 opt_lastKeyPress = key;
1040 return 0;
1041 }
1042 type = KEYBIND_KEYBOARD;
1043 if (window_checkboxState( wid, "chkAny" ))
1044 mod = NMOD_ANY;
1045 else {
1046 ev_mod = event->key.keysym.mod;
1047 mod = 0;
1048 if (ev_mod & (KMOD_LSHIFT | KMOD_RSHIFT))
1049 mod |= NMOD_SHIFT;
1050 if (ev_mod & (KMOD_LCTRL | KMOD_RCTRL))
1051 mod |= NMOD_CTRL;
1052 if (ev_mod & (KMOD_LALT | KMOD_RALT))
1053 mod |= NMOD_ALT;
1054 if (ev_mod & (KMOD_LGUI | KMOD_RGUI))
1055 mod |= NMOD_META;
1056 }
1057 /* Set key. */
1058 opt_lastKeyPress = key;
1059 break;
1060
1061 case SDL_JOYAXISMOTION:
1062 if (event->jaxis.value > 0)
1063 type = KEYBIND_JAXISPOS;
1064 else if (event->jaxis.value < 0)
1065 type = KEYBIND_JAXISNEG;
1066 else
1067 return 0; /* Not handled. */
1068 key = event->jaxis.axis;
1069 mod = NMOD_ANY;
1070 break;
1071
1072 case SDL_JOYBUTTONDOWN:
1073 type = KEYBIND_JBUTTON;
1074 key = event->jbutton.button;
1075 mod = NMOD_ANY;
1076 break;
1077
1078 case SDL_JOYHATMOTION:
1079 switch (event->jhat.value) {
1080 case SDL_HAT_UP:
1081 type = KEYBIND_JHAT_UP;
1082 break;
1083 case SDL_HAT_DOWN:
1084 type = KEYBIND_JHAT_DOWN;
1085 break;
1086 case SDL_HAT_LEFT:
1087 type = KEYBIND_JHAT_LEFT;
1088 break;
1089 case SDL_HAT_RIGHT:
1090 type = KEYBIND_JHAT_RIGHT;
1091 break;
1092 default:
1093 return 0; /* Not handled. */
1094 }
1095 key = event->jhat.hat;
1096 mod = NMOD_ANY;
1097 break;
1098
1099 /* Not handled. */
1100 default:
1101 return 0;
1102 }
1103
1104 /* Warn if already bound. */
1105 str = input_keyAlreadyBound( type, key, mod );
1106 if ((str != NULL) && strcmp(str, opt_selectedKeybind))
1107 dialogue_alert( _("Key '%s' overlaps with key '%s' that was just set. "
1108 "You may want to correct this."),
1109 str, opt_selectedKeybind );
1110
1111 /* Set keybinding. */
1112 input_setKeybind( opt_selectedKeybind, type, key, mod );
1113
1114 /* Close window. */
1115 window_close( wid, NULL );
1116
1117 /* Update parent window. */
1118 parent = window_getParent( wid );
1119 menuKeybinds_genList( parent );
1120
1121 return 0;
1122}
1123
1127static void opt_setKey( unsigned int wid, const char *str )
1128{
1129 (void) wid;
1130 (void) str;
1131 unsigned int new_wid;
1132 int w, h;
1133
1134 /* Reset key. */
1135 opt_lastKeyPress = 0;
1136
1137 /* Create new window. */
1138 w = 20 + 2*(BUTTON_WIDTH + 20);
1139 h = 20 + BUTTON_HEIGHT + 20 + 20 + 80 + 40;
1140 new_wid = window_create( "wdwSetKey", _("Set Keybinding"), -1, -1, w, h );
1142 window_setParent( new_wid, wid );
1143
1144 /* Set text. */
1145 window_addText( new_wid, 20, -40, w-40, 60, 0, "txtInfo",
1146 NULL, NULL,
1147 _("To use a modifier key hit that key twice in a row, otherwise it "
1148 "will register as a modifier. To set with any modifier click the checkbox.") );
1149
1150 /* Create button to cancel. */
1151 window_addButton( new_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
1152 "btnCancel", _("Cancel"), window_close );
1153
1154 /* Button to unset. */
1155 window_addButton( new_wid, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
1156 "btnUnset", _("Unset"), opt_unsetKey );
1157
1158 /* Checkbox to set any modifier. */
1159 window_addCheckbox( new_wid, -20, 20 + BUTTON_HEIGHT + 20, w-40, 20,
1160 "chkAny", _("Set any modifier"), NULL, 0 );
1161}
1162
1166static void opt_unsetKey( unsigned int wid, const char *str )
1167{
1168 (void) str;
1169 unsigned int parent;
1170
1171 /* Unsets the keybind. */
1172 input_setKeybind( opt_selectedKeybind, KEYBIND_NULL, 0, 0 );
1173
1174 /* Close window. */
1175 window_close( wid, NULL );
1176
1177 /* Update parent window. */
1178 parent = window_getParent( wid );
1179 menuKeybinds_genList( parent );
1180}
1181
1185static void opt_video( unsigned int wid )
1186{
1187 (void) wid;
1188 int i, j, nres, res_def;
1189 char buf[16];
1190 int cw, w, h, y, x, l;
1191 char **res;
1192 const char *s;
1193
1194 /* Get size. */
1195 window_dimWindow( wid, &w, &h );
1196
1197 /* Close button */
1198 window_addButton( wid, -20, 20,
1200 "btnClose", _("OK"), opt_OK );
1201 window_addButton( wid, -20 - 1*(BUTTON_WIDTH+20), 20,
1203 "btnCancel", _("Cancel"), opt_close );
1204 window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20,
1206 "btnDefaults", _("Defaults"), opt_videoDefaults );
1207
1208 /* Resolution bits. */
1209 cw = (w-60)/2;
1210 x = 20;
1211 y = -40;
1212 window_addText( wid, x, y, 100, 20, 0, "txtSRes",
1213 NULL, cHeader, _("Resolution:") );
1214 y -= 30;
1215 window_addInput( wid, x, y, 100, 20, "inpRes", 16, 1, NULL );
1216 window_setInputFilter( wid, "inpRes", INPUT_FILTER_RESOLUTION );
1217 window_addCheckbox( wid, x+20+100, y, 100, 20,
1218 "chkFullscreen", _("Fullscreen"), NULL, conf.fullscreen );
1219 y -= 30;
1220 SDL_DisplayMode mode;
1221 int k;
1222 int display_index = SDL_GetWindowDisplayIndex( gl_screen.window );
1223 int n = SDL_GetNumDisplayModes( display_index );
1224 j = 1;
1225 for (i=0; i<n; i++) {
1226 SDL_GetDisplayMode( display_index, i, &mode );
1227 if ((mode.w == conf.width) && (mode.h == conf.height))
1228 j = 0;
1229 }
1230 res = malloc( sizeof(char*) * (i+j) );
1231 nres = 0;
1232 res_def = 0;
1233 if (j) {
1234 SDL_asprintf( &res[0], "%dx%d", conf.width, conf.height );
1235 nres = 1;
1236 }
1237 for (i=0; i<n; i++) {
1238 SDL_GetDisplayMode( display_index, i, &mode );
1239 SDL_asprintf( &res[ nres ], "%dx%d", mode.w, mode.h );
1240
1241 /* Make sure doesn't already exist. */
1242 for (k=0; k<nres; k++)
1243 if (strcmp( res[k], res[nres] )==0)
1244 break;
1245 if (k<nres) {
1246 free( res[nres] );
1247 continue;
1248 }
1249
1250 /* Add as default if necessary and increment. */
1251 if ((mode.w == conf.width) && (mode.h == conf.height))
1252 res_def = i;
1253 nres++;
1254 }
1255 window_addList( wid, x, y, 140, 100, "lstRes", res, nres, -1, opt_videoRes, NULL );
1256 y -= 110;
1257 window_addText( wid, x, y-3, 130, 20, 0, "txtScale",
1258 NULL, NULL, NULL );
1259 window_addFader( wid, x+140, y, cw-160, 20, "fadScale", log(1.), log(3.),
1260 log(conf.scalefactor), opt_setScalefactor );
1261 opt_setScalefactor( wid, "fadScale" );
1262 y -= 30;
1263 window_addText( wid, x, y-3, 130, 20, 0, "txtZoomFar",
1264 NULL, NULL, NULL );
1265 window_addFader( wid, x+140, y, cw-160, 20, "fadZoomFar", log(0.1+1.), log(2.0+1.),
1266 log(conf.zoom_far+1.), opt_setZoomFar );
1267 y -= 30;
1268 window_addText( wid, x, y-3, 130, 20, 0, "txtZoomNear",
1269 NULL, NULL, NULL );
1270 window_addFader( wid, x+140, y, cw-160, 20, "fadZoomNear", log(0.1+1.), log(2.0+1.),
1271 log(conf.zoom_near+1.), opt_setZoomNear );
1272 opt_setZoomFar( wid, "fadZoomFar" );
1273 opt_setZoomNear( wid, "fadZoomNear" );
1274 y -= 30;
1275 window_addText( wid, x, y-3, 130, 20, 0, "txtGammaCorrection",
1276 NULL, NULL, NULL );
1277 window_addFader( wid, x+140, y, cw-160, 20, "fadGammaCorrection", -log(3.), log(3.),
1279 opt_setGammaCorrection( wid, "fadGammaCorrection" );
1280 y -= 40;
1281
1282 /* FPS stuff. */
1283 window_addText( wid, x, y, 100, 20, 0, "txtFPSTitle",
1284 NULL, cHeader, _("FPS Control:") );
1285 y -= 25;
1286 s = _("FPS Limit");
1287 l = gl_printWidthRaw( NULL, s );
1288 window_addText( wid, x, y, l, 20, 1, "txtSFPS",
1289 NULL, NULL, s );
1290 window_addInput( wid, x+l+20, y, 40, 20, "inpFPS", 4, 1, NULL );
1291 toolkit_setListPos( wid, "lstRes", res_def);
1292 window_setInputFilter( wid, "inpFPS", INPUT_FILTER_NUMBER );
1293 snprintf( buf, sizeof(buf), "%d", conf.fps_max );
1294 window_setInput( wid, "inpFPS", buf );
1295 window_addCheckbox( wid, x+l+20+40+20, y, cw, 20,
1296 "chkFPS", _("Show FPS"), NULL, conf.fps_show );
1297
1298 /* Sets inpRes to current resolution, must be after lstRes is added. */
1299 opt_resize();
1300
1301 /* OpenGL options. */
1302 x = 20+cw+20;
1303 y = -40;
1304 window_addText( wid, x, y, 100, 20, 0, "txtSGL",
1305 NULL, cHeader, _("OpenGL:") );
1306 y -= 20;
1307 window_addCheckbox( wid, x, y, cw, 20,
1308 "chkVSync", _("Vertical Sync"), NULL, conf.vsync );
1309 y -= 40;
1310
1311 /* Features. */
1312 window_addText( wid, x, y, 100, 20, 0, "txtSFeatures",
1313 NULL, cHeader, _("Features:") );
1314 y -= 20;
1315 window_addCheckbox( wid, x, y, cw, 20,
1316 "chkMinimize", _("Minimize on focus loss"), NULL, conf.minimize );
1317 y -= 25;
1318 window_addCheckbox( wid, x, y, cw, 20,
1319 "chkColourblind", _("Colourblind mode"), opt_checkColourblind,
1320 conf.colourblind );
1321 y -= 25;
1322 window_addCheckbox( wid, x, y, cw, 20,
1323 "chkHealth", _("Health bars for pilots"), opt_checkHealth,
1324 conf.healthbars );
1325 y -= 30;
1326 window_addText( wid, x, y-3, cw-20, 20, 0, "txtBGBrightness",
1327 NULL, NULL, NULL );
1328 y -= 20;
1329 window_addFader( wid, x+20, y, cw-60, 20, "fadBGBrightness", 0., 1.,
1331 opt_setBGBrightness( wid, "fadBGBrightness" );
1332 y -= 20;
1333 window_addText( wid, x, y-3, cw-20, 20, 0, "txtNebuNonuniformity",
1334 NULL, NULL, NULL );
1335 y -= 20;
1336 window_addFader( wid, x+20, y, cw-60, 20, "fadNebuNonuniformity", 0., 1.,
1338 opt_setNebuNonuniformity( wid, "fadNebuNonuniformity" );
1339 y -= 20;
1340 window_addText( wid, x, y-3, cw-20, 20, 0, "txtJumpBrightness",
1341 NULL, NULL, NULL );
1342 y -= 20;
1343 window_addFader( wid, x+20, y, cw-60, 20, "fadJumpBrightness", 0., 1.,
1345 opt_setJumpBrightness( wid, "fadJumpBrightness" );
1346 y -= 20;
1347 window_addText( wid, x, y-3, cw-20, 20, 0, "txtMOpacity",
1348 NULL, NULL, NULL );
1349 y -= 20;
1350 window_addFader( wid, x+20, y, cw-60, 20, "fadMapOverlayOpacity", 0., 1.,
1352 opt_setMapOverlayOpacity( wid ,"fadMapOverlayOpacity" );
1353 y -= 40;
1354
1355 /* GUI */
1356 window_addText( wid, x, y, 100, 20, 0, "txtSGUI",
1357 NULL, cHeader, _("GUI:") );
1358 y -= 20;
1359 window_addCheckbox( wid, x, y, cw, 20,
1360 "chkBigIcons", _("Bigger icons"), NULL, conf.big_icons );
1361
1362 /* Restart text. */
1363 window_addText( wid, 20, 20 + BUTTON_HEIGHT,
1364 w - 40, 30, 0, "txtRestart", NULL, NULL, NULL );
1365}
1366
1370static void opt_needRestart (void)
1371{
1372 const char *s;
1373
1374 /* Values. */
1375 opt_restart = 1;
1376 s = _("#rRestart Naev for changes to take effect.#0");
1377
1378 /* Modify widgets. */
1379 window_modifyText( opt_windows[ OPT_WIN_GAMEPLAY ], "txtRestart", s );
1380 window_modifyText( opt_windows[ OPT_WIN_VIDEO ], "txtRestart", s );
1381 window_modifyText( opt_windows[ OPT_WIN_AUDIO ], "txtRestart", s );
1382}
1383
1387static void opt_videoRes( unsigned int wid, const char *str )
1388{
1389 const char *buf = toolkit_getList( wid, str );
1390 window_setInput( wid, "inpRes", buf );
1391}
1392
1396static int opt_videoSave( unsigned int wid, const char *str )
1397{
1398 (void) str;
1399 const char *inp;
1400 int ret, w, h, f, fullscreen;
1401
1402 /* Handle resolution. */
1403 inp = window_getInput( wid, "inpRes" );
1404 ret = sscanf( inp, " %d %*[^0-9] %d", &w, &h );
1405 if (ret != 2 || w <= 0 || h <= 0) {
1406 dialogue_alert( _("Height/Width invalid. Should be formatted like 1024x768.") );
1407 return 1;
1408 }
1409
1410 /* Fullscreen. */
1411 fullscreen = window_checkboxState( wid, "chkFullscreen" );
1412
1413 /* Only change if necessary or it causes some flicker. */
1414 if ((conf.width != w) || (conf.height != h) || (fullscreen != conf.fullscreen)) {
1415 ret = opt_setVideoMode( w, h, fullscreen, 1 );
1416 window_checkboxSet( wid, "chkFullscreen", conf.fullscreen );
1417 if (ret != 0)
1418 return ret;
1419 }
1420
1421 /* FPS. */
1422 conf.fps_show = window_checkboxState( wid, "chkFPS" );
1423 inp = window_getInput( wid, "inpFPS" );
1424 conf.fps_max = atoi(inp);
1425
1426 /* OpenGL. */
1427 f = window_checkboxState( wid, "chkVSync" );
1428 if (conf.vsync != f) {
1429 conf.vsync = f;
1431 }
1432
1433 /* Features. */
1434 f = window_checkboxState( wid, "chkMinimize" );
1435 if (conf.minimize != f) {
1436 conf.minimize = f;
1437 SDL_SetHint( SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
1438 conf.minimize ? "1" : "0" );
1439 }
1440
1441 /* GUI. */
1442 conf.big_icons = window_checkboxState( wid, "chkBigIcons" );
1443
1444 /* Reload background. */
1445 background_load( cur_system->background );
1446
1447 return 0;
1448}
1449
1453static void opt_checkColourblind( unsigned int wid, const char *str )
1454{
1455 int f = window_checkboxState( wid, str );
1456 conf.colourblind = f;
1457 gl_colourblind( f );
1458}
1459
1463static void opt_checkHealth( unsigned int wid, const char *str )
1464{
1465 int f = window_checkboxState( wid, str );
1466 conf.healthbars = f;
1467}
1468
1478int opt_setVideoMode( int w, int h, int fullscreen, int confirm )
1479{
1480 int old_conf_w, old_conf_h, old_conf_f, status;
1481 int old_w, old_h, old_f, new_w, new_h, new_f;
1482 int changed_size, maximized;
1483
1484 opt_getVideoMode( &old_w, &old_h, &old_f );
1485 old_conf_w = conf.width;
1486 old_conf_h = conf.height;
1487 old_conf_f = conf.fullscreen;
1488 conf.width = w;
1489 conf.height = h;
1490 conf.fullscreen = fullscreen;
1491
1492 status = gl_setupFullscreen();
1493 if (status == 0 && !fullscreen && (w != old_w || h != old_h)) {
1494 SDL_SetWindowSize( gl_screen.window, w, h );
1495 SDL_SetWindowPosition( gl_screen.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED );
1496 }
1497 naev_resize();
1498
1499 opt_getVideoMode( &new_w, &new_h, &new_f );
1500 changed_size = new_w != old_w || new_h != old_h;
1501 maximized = !new_f && (SDL_GetWindowFlags(gl_screen.window) & SDL_WINDOW_MAXIMIZED);
1502
1503 if (confirm && !changed_size && maximized)
1504 dialogue_alert(_("Resolution can't be changed while maximized."));
1505 if (confirm && (status != 0 || new_f != fullscreen))
1507
1508 if (confirm && (status != 0 || changed_size || new_f != old_f) && !dialogue_YesNo(_("Keep Video Settings"),
1509 _("Do you want to keep running at %dx%d %s?"),
1510 new_w, new_h, new_f ? _("fullscreen") : _("windowed"))) {
1511
1512 opt_setVideoMode( old_conf_w, old_conf_h, old_conf_f, 0 );
1513
1514 dialogue_msg( _("Video Settings Restored"),
1515 _("Resolution reset to %dx%d %s."),
1516 old_w, old_h, conf.fullscreen ? _("fullscreen") : _("windowed") );
1517
1518 return 1;
1519 }
1520
1521 conf.explicit_dim = conf.explicit_dim || w != old_conf_w || h != old_conf_h;
1522 return 0;
1523}
1524
1532static void opt_getVideoMode( int *w, int *h, int *fullscreen )
1533{
1534 SDL_DisplayMode mode;
1535 /* Warning: this test may be inadequate depending on our setup.
1536 * Example (Wayland): if I called SDL_SetWindowDisplayMode with an impossibly large size, then SDL_SetWindowFullscreen,
1537 * I see a window on my desktop whereas SDL2 window flags report a fullscreen mode.
1538 * Mitigation: be strict about how the setup is done in opt_setVideoMode / gl_setupFullscreen, and never bypass them. */
1539 *fullscreen = (SDL_GetWindowFlags(gl_screen.window) & SDL_WINDOW_FULLSCREEN) != 0;
1540 if (*fullscreen && conf.modesetting) {
1541 SDL_GetWindowDisplayMode( gl_screen.window, &mode );
1542 *w = mode.w;
1543 *h = mode.h;
1544 }
1545 else
1546 SDL_GetWindowSize( gl_screen.window, w, h );
1547}
1548
1552static void opt_videoDefaults( unsigned int wid, const char *str )
1553{
1554 (void) str;
1555 char buf[16];
1556
1557 /* Restore settings. */
1558 /* Inputs. */
1559 snprintf( buf, sizeof(buf), "%dx%d", RESOLUTION_W_DEFAULT, RESOLUTION_H_DEFAULT );
1560 window_setInput( wid, "inpRes", buf );
1561 snprintf( buf, sizeof(buf), "%d", FPS_MAX_DEFAULT );
1562 window_setInput( wid, "inpFPS", buf );
1563
1564 /* Checkboxes. */
1565 window_checkboxSet( wid, "chkFullscreen", FULLSCREEN_DEFAULT );
1566 window_checkboxSet( wid, "chkVSync", VSYNC_DEFAULT );
1567 window_checkboxSet( wid, "chkFPS", SHOW_FPS_DEFAULT );
1568 window_checkboxSet( wid, "chkMinimize", MINIMIZE_DEFAULT );
1569 window_checkboxSet( wid, "chkBigIcons", BIG_ICONS_DEFAULT );
1570
1571 /* Faders. */
1572 window_faderSetBoundedValue( wid, "fadScale", log(SCALE_FACTOR_DEFAULT) );
1573 window_faderSetBoundedValue( wid, "fadZoomFar", log(ZOOM_FAR_DEFAULT+1.) );
1574 window_faderSetBoundedValue( wid, "fadZoomNear", log(ZOOM_NEAR_DEFAULT+1.) );
1575 window_faderSetBoundedValue( wid, "fadGammaCorrection", log(GAMMA_CORRECTION_DEFAULT) /* a.k.a. 0. */ );
1576 window_faderSetBoundedValue( wid, "fadBGBrightness", BG_BRIGHTNESS_DEFAULT );
1577 window_faderSetBoundedValue( wid, "fadNebuNonuniformity", NEBU_NONUNIFORMITY_DEFAULT );
1578 window_faderSetBoundedValue( wid, "fadMapOverlayOpacity", MAP_OVERLAY_OPACITY_DEFAULT );
1579}
1580
1587static void opt_setScalefactor( unsigned int wid, const char *str )
1588{
1589 char buf[STRMAX_SHORT];
1590 double scale = window_getFaderValue(wid, str);
1591 //scale = round(scale * 10.) / 10.;
1592 conf.scalefactor = exp(scale);
1593 snprintf( buf, sizeof(buf), _("Scaling: %.1fx"), conf.scalefactor );
1594 window_modifyText( wid, "txtScale", buf );
1595 if (FABS(conf.scalefactor-local_conf.scalefactor) > 1e-4)
1597}
1598
1605static void opt_setZoomFar( unsigned int wid, const char *str )
1606{
1607 char buf[STRMAX_SHORT];
1608 double scale = window_getFaderValue(wid, str);
1609 //scale = round(scale * 10.) / 10.;
1610 conf.zoom_far = exp(scale)-1.;
1611 snprintf( buf, sizeof(buf), _("Far Zoom: %.1fx"), conf.zoom_far );
1612 window_modifyText( wid, "txtZoomFar", buf );
1613 if (conf.zoom_far > conf.zoom_near) {
1614 window_faderSetBoundedValue( wid, "fadZoomNear", log(conf.zoom_far+1.) );
1615 opt_setZoomNear( wid, "fadZoomNear" );
1616 }
1617 if (FABS(conf.zoom_far-local_conf.zoom_far) > 1e-4)
1619}
1620
1627static void opt_setZoomNear( unsigned int wid, const char *str )
1628{
1629 char buf[STRMAX_SHORT];
1630 double scale = window_getFaderValue(wid, str);
1631 //scale = round(scale * 10.) / 10.;
1632 conf.zoom_near = exp(scale)-1.;
1633 snprintf( buf, sizeof(buf), _("Near Zoom: %.1fx"), conf.zoom_near );
1634 window_modifyText( wid, "txtZoomNear", buf );
1635 if (conf.zoom_near < conf.zoom_far) {
1636 window_faderSetBoundedValue( wid, "fadZoomFar", log(conf.zoom_near+1.) );
1637 opt_setZoomFar( wid, "fadZoomFar" );
1638 }
1639 if (FABS(conf.zoom_near-local_conf.zoom_near) > 1e-4)
1641}
1642
1649static void opt_setGammaCorrection( unsigned int wid, const char *str )
1650{
1651 char buf[STRMAX_SHORT];
1652 double scale = window_getFaderValue(wid, str);
1653 conf.gamma_correction = exp(scale);
1654 snprintf( buf, sizeof(buf), _("Gamma: %.1f"), conf.gamma_correction );
1655 window_modifyText( wid, "txtGammaCorrection", buf );
1656 render_setGamma( conf.gamma_correction );
1657}
1658
1665static void opt_setBGBrightness( unsigned int wid, const char *str )
1666{
1667 char buf[STRMAX_SHORT];
1668 double fad = window_getFaderValue(wid, str);
1669 conf.bg_brightness = fad;
1670 snprintf( buf, sizeof(buf), _("BG (Stars, etc.) brightness: %.0f%%"), 100.*fad );
1671 window_modifyText( wid, "txtBGBrightness", buf );
1672}
1673
1680static void opt_setNebuNonuniformity( unsigned int wid, const char *str )
1681{
1682 char buf[STRMAX_SHORT];
1683 double fad = window_getFaderValue(wid, str);
1684 conf.nebu_nonuniformity = fad;
1685 snprintf( buf, sizeof(buf), _("Nebula non-uniformity: %.0f%%"), 100.*fad );
1686 window_modifyText( wid, "txtNebuNonuniformity", buf );
1687}
1688
1695static void opt_setJumpBrightness( unsigned int wid, const char *str )
1696{
1697 char buf[STRMAX_SHORT];
1698 double fad = window_getFaderValue(wid, str);
1699 conf.jump_brightness = fad;
1700 snprintf( buf, sizeof(buf), _("Jump Brightness: %.0f%%"), 100.*fad );
1701 window_modifyText( wid, "txtJumpBrightness", buf );
1702}
1703
1710static void opt_setMapOverlayOpacity( unsigned int wid, const char *str )
1711{
1712 char buf[STRMAX_SHORT];
1713 double fad = window_getFaderValue(wid, str);
1714 conf.map_overlay_opacity = fad;
1715 snprintf( buf, sizeof(buf), _("Map Overlay Opacity: %.0f%%"), 100.*fad );
1716 window_modifyText( wid, "txtMOpacity", buf );
1717}
1718
1722static void opt_plugins( unsigned int wid )
1723{
1724 int w, h, lw, lh, bw, bh, n;
1725 char **str, buf[STRMAX_SHORT];
1726 const plugin_t *plgs = plugin_list();
1727
1728 /* Get dimensions. */
1729 bw = BUTTON_WIDTH;
1730 bh = BUTTON_HEIGHT;
1731 window_dimWindow( wid, &w, &h );
1732 lw = w - bw - 100;
1733 lh = h - 90;
1734
1735 /* Close button. */
1736 window_addButton( wid, -20, 20, bw, bh,
1737 "btnClose", _("OK"), opt_OK );
1738
1739 /* Text stuff. */
1740 snprintf( buf, sizeof(buf), "#n%s#0%s%s", _("Plugins Directory: "), PHYSFS_getRealDir("plugins"), "plugins" );
1741 window_addText( wid, 20, -30, w-40, 30, 1, "txtPath", NULL, NULL, buf );
1742 window_addText( wid, -20, -70, w-(20+lw+20+20), h-100,
1743 0, "txtDesc", NULL, NULL, NULL );
1744
1745 /* Create the list. */
1746 n = array_size(plgs);
1747 if (n <= 0) {
1748 str = malloc( sizeof(char *) * 1 );
1749 str[0] = strdup(_("No Plugins Found"));
1750 n = 1;
1751 }
1752 else {
1753 str = malloc( sizeof(char *) * n );
1754 for (int i=0; i<n; i++)
1755 str[i] = strdup( plugin_name(&plgs[i]) );
1756 }
1757
1758 window_addList( wid, 20, -70, lw, lh, "lstPlugins", str, n, 0, opt_plugins_update, NULL );
1759}
1760
1761static void opt_plugins_update( unsigned int wid, const char *name )
1762{
1763 char buf[STRMAX];
1764 const plugin_t *plg, *plgs;
1765 int pos = toolkit_getListPos( wid, name );
1766 int l = 0;
1767
1768 plgs = plugin_list();
1769 if (array_size(plgs)<=0)
1770 return;
1771 plg = &plgs[pos];
1772 l += scnprintf( &buf[l], sizeof(buf)-l, "#n%s#0\n", p_("plugins", "Name:") );
1773 l += scnprintf( &buf[l], sizeof(buf)-l, " %s\n", _(plugin_name(plg)) );
1774 l += scnprintf( &buf[l], sizeof(buf)-l, "#n%s#0\n", p_("plugins", "Author(s):") );
1775 l += scnprintf( &buf[l], sizeof(buf)-l, " %s\n", _(plg->author) );
1776 l += scnprintf( &buf[l], sizeof(buf)-l, "#n%s#0\n", p_("plugins", "Version:") );
1777 l += scnprintf( &buf[l], sizeof(buf)-l, " %s\n", plg->version );
1778 l += scnprintf( &buf[l], sizeof(buf)-l, "#n%s#0\n", p_("plugins", "Description:") );
1779 l += scnprintf( &buf[l], sizeof(buf)-l, " %s\n", _(plg->description) );
1780 if (plg->total_conversion)
1781 l += scnprintf( &buf[l], sizeof(buf)-l, "#g%s#0", _("Total Conversion") );
1782
1783 window_modifyText( wid, "txtDesc", buf );
1784}
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
Definition array.h:158
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition array.h:168
int background_load(const char *name)
Loads a background script by name.
Definition background.c:427
char * dialogue_runChoice(void)
Run the dialog and return the clicked string.
Definition dialogue.c:795
void dialogue_alert(const char *fmt,...)
Displays an alert popup with only an ok button and a message.
Definition dialogue.c:132
void dialogue_msg(const char *caption, const char *fmt,...)
Opens a dialogue window with an ok button and a message.
Definition dialogue.c:230
void dialogue_addChoice(const char *caption, const char *msg, const char *opt)
Add a choice to the dialog.
Definition dialogue.c:773
void dialogue_makeChoice(const char *caption, const char *msg, int opts)
Create the choice dialog. Need to add choices with below method.
Definition dialogue.c:751
void dialogue_msgRaw(const char *caption, const char *msg)
Opens a dialogue window with an ok button and a fixed message.
Definition dialogue.c:271
int dialogue_YesNo(const char *caption, const char *fmt,...)
Runs a dialogue with both yes and no options.
Definition dialogue.c:352
glFont gl_smallFont
Definition font.c:154
int gl_printWidthRaw(const glFont *ft_font, const char *text)
Gets the width that it would take to print some text.
Definition font.c:961
glFont gl_defFont
Definition font.c:153
void gl_freeFont(glFont *font)
Frees a loaded font. Caution: its glFontStash still has a slot in avail_fonts. At the time of writing...
Definition font.c:1723
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
Definition font.c:1517
glFont gl_defFontMono
Definition font.c:155
double gettext_languageCoverage(const char *lang)
Return the fraction of strings which have a translation into the given language.
Definition gettext.c:285
void gettext_setLanguage(const char *lang)
Set the translation language.
Definition gettext.c:125
const char * pgettext_var(const char *msgctxt, const char *msgid)
Definition gettext.c:318
LanguageOption * gettext_languageOptions(void)
List the available languages, with completeness statistics.
Definition gettext.c:263
const char * gettext_getSystemLanguage(void)
Gets the current system language as detected by Naev.
Definition gettext.c:102
SDL_Keycode input_getKeybind(const char *keybind, KeybindType *type, SDL_Keymod *mod)
Gets the value of a keybind.
Definition input.c:431
const char * keybind_info[][3]
Definition input.c:50
const char * input_keyAlreadyBound(KeybindType type, SDL_Keycode key, SDL_Keymod mod)
Checks to see if a key is already bound.
Definition input.c:537
void input_setDefault(int wasd)
Sets the default input keys.
Definition input.c:172
void input_setKeybind(const char *keybind, KeybindType type, SDL_Keycode key, SDL_Keymod mod)
Binds key of type type to action keybind.
Definition input.c:409
const char * input_getKeybindDescription(const char *keybind)
Gets the description of the keybinding.
Definition input.c:582
const int input_numbinds
Definition input.c:129
const char * input_modToText(SDL_Keymod mod)
Gets the human readable version of mod.
Definition input.c:516
double music_getVolumeLog(void)
Gets the current music volume (logarithmic).
Definition music.c:228
double music_getVolume(void)
Gets the current music volume (linear).
Definition music.c:218
int music_volume(double vol)
Sets the music volume from a linear value.
Definition music.c:191
void naev_resize(void)
Wrapper for gl_resize that handles non-GL reinitialization.
Definition naev.c:790
Header file with generic functions and naev-specifics.
const char * naev_version(int long_version)
Returns the version in a human readable string.
#define FABS(x)
Definition naev.h:37
const char * nfile_configPath(void)
Gets Naev's config path (for user preferences such as conf.lua)
Definition nfile.c:116
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
Definition nstring.c:99
int strsort_reverse(const void *p1, const void *p2)
Order-reversed version of strsort().
Definition nstring.c:89
void gl_colourblind(int enable)
Enables or disables the colourblind shader.
Definition opengl.c:674
glInfo gl_screen
Definition opengl.c:51
int gl_setupFullscreen(void)
Tries to apply the configured display mode to the window.
Definition opengl.c:260
static const char * opt_selectedKeybind
Definition options.c:67
static void opt_gameplay(unsigned int wid)
Opens the gameplay menu.
Definition options.c:260
int opt_setVideoMode(int w, int h, int fullscreen, int confirm)
Applies new video-mode options.
Definition options.c:1478
static void opt_keyDefaults(unsigned int wid, const char *str)
Restores the key defaults.
Definition options.c:765
static void menuKeybinds_getDim(unsigned int wid, int *w, int *h, int *lw, int *lh, int *bw, int *bh)
Gets the keybind menu dimensions.
Definition options.c:541
#define LANG_CODE_START
Definition options.c:48
static void opt_needRestart(void)
Marks that needs restart.
Definition options.c:1370
static void opt_getVideoMode(int *w, int *h, int *fullscreen)
Detects the video-mode options corresponding to the gl_screen we have set up.
Definition options.c:1532
static void opt_checkHealth(unsigned int wid, const char *str)
Handles the fancy background checkbox.
Definition options.c:1463
static void opt_setAudioLevel(unsigned int wid, const char *str)
Callback to set the sound or music level.
Definition options.c:833
static void opt_audioUpdate(unsigned int wid)
Updates the gameplay options.
Definition options.c:999
static void opt_setZoomNear(unsigned int wid, const char *str)
Callback to set the far zoom.
Definition options.c:1627
void opt_resize(void)
Handles resize events for the options menu.
Definition options.c:213
static void opt_setNebuNonuniformity(unsigned int wid, const char *str)
Callback to set the nebula non-uniformity parameter.
Definition options.c:1680
static void opt_setJumpBrightness(unsigned int wid, const char *str)
Callback to set the background brightness.
Definition options.c:1695
static void opt_OK(unsigned int wid, const char *str)
Saves all options and closes the options screen.
Definition options.c:165
static void opt_videoDefaults(unsigned int wid, const char *str)
Sets video defaults.
Definition options.c:1552
static void opt_audioDefaults(unsigned int wid, const char *str)
Sets the audio defaults.
Definition options.c:981
static void opt_setBGBrightness(unsigned int wid, const char *str)
Callback to set the background brightness.
Definition options.c:1665
static void opt_keybinds(unsigned int wid)
Opens the keybindings menu.
Definition options.c:563
static void menuKeybinds_genList(unsigned int wid)
Generates the keybindings list.
Definition options.c:595
static int opt_lastKeyPress
Definition options.c:68
static void opt_plugins(unsigned int wid)
Opens the keybindings menu.
Definition options.c:1722
static int opt_videoSave(unsigned int wid, const char *str)
Saves the video settings.
Definition options.c:1396
#define BUTTON_HEIGHT
Definition options.c:38
static void opt_audioLevelStr(char *buf, int max, int type, double pos)
Sets the sound or music volume string based on level.
Definition options.c:859
static void opt_unsetKey(unsigned int wid, const char *str)
Unsets the key.
Definition options.c:1166
static void opt_video(unsigned int wid)
Initializes the video window.
Definition options.c:1185
static void opt_setMapOverlayOpacity(unsigned int wid, const char *str)
Callback to set autonav abort threshold.
Definition options.c:1710
void opt_menu(void)
Creates the options menu thingy.
Definition options.c:126
static void opt_setKey(unsigned int wid, const char *str)
Rebinds a key.
Definition options.c:1127
static void opt_audio(unsigned int wid)
Opens the audio settings menu.
Definition options.c:875
static void opt_close(unsigned int wid, const char *name)
Closes the options screen without saving.
Definition options.c:189
static void menuKeybinds_update(unsigned int wid, const char *name)
Updates the keybindings menu.
Definition options.c:692
static void opt_checkColourblind(unsigned int wid, const char *str)
Handles the colourblind checkbox being checked.
Definition options.c:1453
static void opt_gameplayUpdate(unsigned int wid, const char *str)
Updates the gameplay options.
Definition options.c:521
static void opt_gameplayDefaults(unsigned int wid, const char *str)
Sets the default gameplay options.
Definition options.c:500
static void opt_setGammaCorrection(unsigned int wid, const char *str)
Callback to set the gamma correction value (reciprocal of exponent).
Definition options.c:1649
static int opt_setKeyEvent(unsigned int wid, SDL_Event *event)
Tries to set the key from an event.
Definition options.c:1014
#define BUTTON_WIDTH
Definition options.c:37
static int opt_gameplaySave(unsigned int wid, const char *str)
Saves the gameplay options.
Definition options.c:415
static void opt_videoRes(unsigned int wid, const char *str)
Callback when resolution changes.
Definition options.c:1387
static int opt_audioSave(unsigned int wid, const char *str)
Saves the audio stuff.
Definition options.c:953
static void opt_setScalefactor(unsigned int wid, const char *str)
Callback to set the scaling factor.
Definition options.c:1587
static void opt_setZoomFar(unsigned int wid, const char *str)
Callback to set the far zoom.
Definition options.c:1605
void pilot_calcStats(Pilot *pilot)
Recalculates the pilot's stats based on his outfits.
int snd_target
Definition player.c:97
Player_t player
Definition player.c:74
void player_soundPlayGUI(int sound, int once)
Plays a GUI sound (unaffected by time accel).
Definition player.c:875
const char * plugin_name(const plugin_t *plg)
Tries to tget the name of a plugin.
Definition plugin.c:218
const plugin_t * plugin_list(void)
Returns the list of all the plugins.
Definition plugin.c:281
static const double d[]
Definition rng.c:273
double sound_getVolumeLog(void)
Gets the current sound volume (logarithmic).
Definition sound.c:1295
double sound_getVolume(void)
Gets the current sound volume (linear).
Definition sound.c:1282
int sound_disabled
Definition sound.c:133
int sound_volume(const double vol)
Sets the volume.
Definition sound.c:1259
StarSystem * cur_system
Definition space.c:106
char * name
Definition difficulty.h:9
Struct containing player options.
Definition conf.h:71
double jump_brightness
Definition conf.h:100
int nosound
Definition conf.h:106
double engine_vol
Definition conf.h:109
double scalefactor
Definition conf.h:89
int healthbars
Definition conf.h:97
int font_size_def
Definition conf.h:141
int colourblind
Definition conf.h:96
int fullscreen
Definition conf.h:91
int vsync
Definition conf.h:83
int modesetting
Definition conf.h:92
int fps_max
Definition conf.h:113
int width
Definition conf.h:86
int minimize
Definition conf.h:95
int font_size_small
Definition conf.h:142
char * language
Definition conf.h:79
int mouse_accel
Definition conf.h:153
int height
Definition conf.h:87
int big_icons
Definition conf.h:125
double music
Definition conf.h:108
int al_efx
Definition conf.h:105
char * difficulty
Definition conf.h:145
int fps_show
Definition conf.h:112
int mesg_visible
Definition conf.h:123
double sound
Definition conf.h:107
double zoom_far
Definition conf.h:134
double gamma_correction
Definition conf.h:101
int explicit_dim
Definition conf.h:88
unsigned int doubletap_sens
Definition conf.h:150
double bg_brightness
Definition conf.h:98
int zoom_manual
Definition conf.h:133
int save_compress
Definition conf.h:149
double map_overlay_opacity
Definition conf.h:124
int mouse_fly
Definition conf.h:152
double nebu_nonuniformity
Definition conf.h:99
double zoom_near
Definition conf.h:135
Pilot * p
Definition player.h:101
char * difficulty
Definition player.h:112
SDL_Window * window
Definition opengl.h:68
char * author
Definition plugin.h:8
char * version
Definition plugin.h:9
int total_conversion
Definition plugin.h:15
char * description
Definition plugin.h:10
unsigned int window_create(const char *name, const char *displayname, const int x, const int y, const int w, const int h)
Creates a window.
Definition toolkit.c:691
unsigned int window_getParent(unsigned int wid)
Gets the window's parent.
Definition toolkit.c:806
void window_dimWindow(unsigned int wid, int *w, int *h)
Gets the dimensions of a window.
Definition toolkit.c:371
void window_setCancel(unsigned int wid, void(*cancel)(unsigned int, const char *))
Sets the default cancel function of the window.
Definition toolkit.c:868
void window_destroyWidget(unsigned int wid, const char *wgtname)
Destroys a widget in a window.
Definition toolkit.c:1165
void window_setParent(unsigned int wid, unsigned int parent)
Sets a window as a window's parent.
Definition toolkit.c:789
int widget_exists(unsigned int wid, const char *wgtname)
Checks to see if a widget exists.
Definition toolkit.c:1142
void window_close(unsigned int wid, const char *str)
Helper function to automatically close the window calling it.
Definition toolkit.c:1026
void window_destroy(unsigned int wid)
Kills the window.
Definition toolkit.c:1037
void window_handleEvents(unsigned int wid, int(*eventhandler)(unsigned int, SDL_Event *))
Sets the event handler for the window.
Definition toolkit.c:977