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