21#include "background.h"
24#include "difficulty.h"
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
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[] = {
59static const glColour *cHeader = &cFontGrey;
61static int opt_restart = 0;
74static void opt_close(
unsigned int wid,
const char *name );
77static char** lang_list(
int *n );
80static void opt_OK(
unsigned int wid,
const char *str );
86static void opt_videoRes(
unsigned int wid,
const char *str );
100static void opt_audio(
unsigned int wid );
101static int opt_audioSave(
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 );
111 int *lw,
int *lh,
int *bw,
int *bh );
117static void opt_setKey(
unsigned int wid,
const char *str );
118static void opt_unsetKey(
unsigned int wid,
const char *str );
121static void opt_plugins_update(
unsigned int wid,
const char *name );
132 conf_copy( &local_conf, &conf );
139 opt_wid =
window_create(
"wdwOptions", _(
"Options"), -1, -1, w, h );
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 );
152 opt_video( opt_windows[ OPT_WIN_VIDEO ] );
153 opt_audio( opt_windows[ OPT_WIN_AUDIO ] );
165static void opt_OK(
unsigned int wid,
const char *str )
167 int ret, prompted_restart;
169 prompted_restart = opt_restart;
175 if (opt_restart && !prompted_restart)
176 dialogue_msg( _(
"Warning"),
"#r%s#0", _(
"Restart Naev for changes to take effect.") );
181 conf_copy( &local_conf, &conf );
189static void opt_close(
unsigned int wid,
const char *name )
195 conf_copy( &conf, &local_conf );
207 conf_free( &local_conf );
215 int w, h, fullscreen;
224 snprintf( buf,
sizeof(buf),
"%dx%d", w, h );
225 window_setInput( opt_windows[OPT_WIN_VIDEO],
"inpRes", buf );
231static char** lang_list(
int *n )
239 ls = malloc(
sizeof(
char*)*128 );
240 SDL_asprintf( &ls[0], _(
"system (%s[%3.0f%%] %s#0)"), (syscoverage<0.8)?
"#r":
"", 100.*syscoverage, syslang );
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 );
265 int w, h, y, x, by, l, n, i, p;
267 char **ls, **diff_text, **diff_alt;
268 const Difficulty *difficulty, *cur_difficulty;
274 window_addButton( wid, -20, 20,
276 "btnClose", _(
"OK"),
opt_OK );
288 window_addText( wid, x, y, cw, 20, 1,
"txtVersion",
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 );
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 );
307 window_addText( wid, x, y, l, 20, 0,
"txtLanguage",
309 ls = lang_list( &n );
318 window_addList( wid, x+l+20, y, cw-l-50, 100,
"lstLanguage", ls, n, i, NULL, NULL );
322 difficulty = difficulty_getAll();
324 diff_text = malloc(
sizeof(
char*) * n );
325 diff_alt = malloc(
sizeof(
char*) * n );
328 difficulty_setLocal( NULL );
329 cur_difficulty = difficulty_cur();
330 for (i=0; i<n; i++) {
332 diff_text[i] = strdup( _(
d->name) );
333 diff_alt[i] = difficulty_display(
d);
334 if (strcmp(
d->name,cur_difficulty->
name)==0)
338 s = _(
"Difficulty (this save):");
340 s = _(
"Difficulty (global):");
341 window_addText( wid, x, y, cw, 20, 0,
"txtDifficulty", NULL, NULL, s );
343 window_addList( wid, x, y, cw, 100,
"lstDifficulty", diff_text, n, p, NULL, NULL );
344 toolkit_setListAltText( wid,
"lstDifficulty", diff_alt );
348 window_addText( wid, x, y, cw, 20, 0,
"txtCompile",
349 NULL, cHeader, _(
"Compilation Flags:") );
351 window_addText( wid, x, y, cw, h+y-20, 0,
"txtFlags",
366 y -= window_getTextHeight(wid,
"txtFlags") + 10;
373 window_addText( wid, x, y, cw, 20, 0,
"txtSettings",
374 NULL, cHeader, _(
"Settings:") );
377 window_addCheckbox( wid, x, y, cw, 20,
378 "chkZoomManual", _(
"Enable manual zoom control"), NULL, conf.
zoom_manual );
380 window_addCheckbox( wid, x, y, cw, 20,
381 "chkDoubletap", _(
"Enable double-tap afterburn/cooldown"), NULL, conf.
doubletap_sens );
383 window_addCheckbox( wid, x, y, cw, 20,
384 "chkMouseFly", _(
"Enable mouse-flying (toggle with middle click)"), NULL, conf.
mouse_fly );
386 window_addCheckbox( wid, x, y, cw, 20,
387 "chkMouseAccel", _(
"Enable mouse-flying accel control"), NULL, conf.
mouse_accel );
389 window_addCheckbox( wid, x, y, cw, 20,
390 "chkCompress", _(
"Enable saved game compression"), NULL, conf.
save_compress );
392 s = _(
"Visible Messages");
394 window_addText( wid, x, y, l, 20, 1,
"txtSMSG",
396 window_addInput( wid, -50, y, 40, 20,
"inpMSG", 4, 1, NULL );
398 s = _(
"Max Time Compression Factor");
400 window_addText( wid, x, y, l, 20, 1,
"txtTMax",
402 window_addInput( wid, -50, y, 40, 20,
"inpTMax", 4, 1, NULL );
406 w - 40, 30, 0,
"txtRestart", NULL, NULL, NULL );
419 const char *vmsg, *s;
423 p = toolkit_getListPos( wid,
"lstLanguage" );
424 s = (p==0) ? NULL : toolkit_getList( wid,
"lstLanguage" );
425 newlang = ((s != NULL) != (conf.
language != NULL))
430 LOG(
"conf.language set to %s", conf.
language);
445 difficulty = difficulty_getAll();
446 p = toolkit_getListPos( wid,
"lstDifficulty" );
447 difficulty = &difficulty[p];
450 if (difficulty->
def) {
452 difficulty_setGlobal( NULL );
456 difficulty_setGlobal( difficulty );
461 if (difficulty == difficulty_get(NULL)) {
463 difficulty_setLocal( NULL );
467 difficulty_setLocal( difficulty );
475 f = window_checkboxState( wid,
"chkDoubletap" );
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" );
486 player_rmFlag( PLAYER_MFLY );
489 vmsg = window_getInput( wid,
"inpMSG" );
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 );
514 snprintf( vmsg,
sizeof(vmsg),
"%d", INPUT_MESSAGES_DEFAULT );
515 window_setInput( wid,
"inpMSG", vmsg );
527 window_checkboxSet( wid,
"chkZoomManual", conf.
zoom_manual );
529 window_checkboxSet( wid,
"chkMouseFly", conf.
mouse_fly );
530 window_checkboxSet( wid,
"chkMouseAccel", conf.
mouse_accel );
531 window_checkboxSet( wid,
"chkCompress", conf.
save_compress );
534 snprintf( vmsg,
sizeof(vmsg),
"%d", conf.
mesg_visible );
535 window_setInput( wid,
"inpMSG", vmsg );
542 int *lw,
int *lh,
int *bw,
int *bh )
565 int w, h, lw, bw, bh;
571 window_addButton( wid, -20, 20, bw, bh,
572 "btnClose", _(
"OK"),
opt_OK );
574 window_addButton( wid, -20, 40 + bh, bw, bh,
577 window_addButton( wid, -20, 60 + 2*bh, bw, bh,
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 );
598 char **str, mod_text[64];
620 case KEYBIND_KEYBOARD:
623 snprintf( mod_text,
sizeof(mod_text), _(
"any+") );
627 if (mod & NMOD_SHIFT)
628 p +=
scnprintf( &mod_text[p],
sizeof(mod_text)-p, _(
"shift+") );
630 p +=
scnprintf( &mod_text[p],
sizeof(mod_text)-p, _(
"ctrl+") );
632 p +=
scnprintf( &mod_text[p],
sizeof(mod_text)-p, _(
"alt+") );
634 p +=
scnprintf( &mod_text[p],
sizeof(mod_text)-p, _(
"meta+") );
639 if (key < 0x100 && isalpha(key))
640 snprintf(str[j], l,
"%s <%s%c>", short_desc, mod_text, toupper(key) );
642 snprintf(str[j], l,
"%s <%s%s>", short_desc, mod_text,
pgettext_var(
"keyname", SDL_GetKeyName(key)) );
644 case KEYBIND_JAXISPOS:
645 snprintf(str[j], l,
"%s <ja+%d>", short_desc, key);
647 case KEYBIND_JAXISNEG:
648 snprintf(str[j], l,
"%s <ja-%d>", short_desc, key);
650 case KEYBIND_JBUTTON:
651 snprintf(str[j], l,
"%s <jb%d>", short_desc, key);
653 case KEYBIND_JHAT_UP:
654 snprintf(str[j], l,
"%s <jh%d-up>", short_desc, key);
656 case KEYBIND_JHAT_DOWN:
657 snprintf(str[j], l,
"%s <jh%d-down>", short_desc, key);
659 case KEYBIND_JHAT_LEFT:
660 snprintf(str[j], l,
"%s <jh%d-left>", short_desc, key);
662 case KEYBIND_JHAT_RIGHT:
663 snprintf(str[j], l,
"%s <jh%d-right>", short_desc, key);
666 snprintf(str[j], l,
"%s", short_desc);
673 pos = toolkit_getListPos( wid,
"lstKeybinds" );
674 off = toolkit_getListOffset( wid,
"lstKeybinds" );
678 window_addList( wid, 20, -40, lw, lh,
"lstKeybinds", str,
input_numbinds, 0,
menuKeybinds_update,
opt_setKey );
681 toolkit_setListPos( wid,
"lstKeybinds", pos );
682 toolkit_setListOffset( wid,
"lstKeybinds", off );
701 char buf[STRMAX_SHORT];
705 selected = toolkit_getListPos( wid,
"lstKeybinds" );
710 window_modifyText( wid,
"txtName", _(
keybind_info[selected][1]) );
719 snprintf(binding,
sizeof(binding), _(
"Not bound"));
721 case KEYBIND_KEYBOARD:
723 if (key < 0x100 && isalpha(key))
724 snprintf(binding,
sizeof(binding), _(
"keyboard: %s%s%c"),
726 (mod != KMOD_NONE) ?
" + " :
"",
729 snprintf(binding,
sizeof(binding), _(
"keyboard: %s%s%s"),
731 (mod != KMOD_NONE) ?
" + " :
"",
734 case KEYBIND_JAXISPOS:
735 snprintf(binding,
sizeof(binding), _(
"joy axis pos: <%d>"), key );
737 case KEYBIND_JAXISNEG:
738 snprintf(binding,
sizeof(binding), _(
"joy axis neg: <%d>"), key );
740 case KEYBIND_JBUTTON:
741 snprintf(binding,
sizeof(binding), _(
"joy button: <%d>"), key);
743 case KEYBIND_JHAT_UP:
744 snprintf(binding,
sizeof(binding), _(
"joy hat up: <%d>"), key);
746 case KEYBIND_JHAT_DOWN:
747 snprintf(binding,
sizeof(binding), _(
"joy hat down: <%d>"), key);
749 case KEYBIND_JHAT_LEFT:
750 snprintf(binding,
sizeof(binding), _(
"joy hat left: <%d>"), key);
752 case KEYBIND_JHAT_RIGHT:
753 snprintf(binding,
sizeof(binding), _(
"joy hat right:<%d>"), key);
758 snprintf(buf,
sizeof(buf),
"%s\n\n%s\n", desc, binding);
759 window_modifyText( wid,
"txtDesc", buf );
768 const char *title, *caption, *ret;
772 const char *opts[] = {
778 title = _(
"Restore Defaults");
779 caption = _(
"Which layout do you want to use?");
783 for (
int i=0; i<n; i++)
792 for (
int i=0; i<n; i++)
793 if (strcmp(ret, opts[i]) == 0) {
808 dialogue_msgRaw( _(
"Defaults Restored"), _(
"Keybindings restored to defaults."));
811static void opt_setEngineLevel(
unsigned int wid,
const char *str )
814 double vol = window_getFaderValue(wid, str);
815 const char *label = _(
"Engine Volume");
816 double logvol = 1. / pow(2., (1.-vol) * 8.);
819 snprintf( buf,
sizeof(buf), _(
"%s: %s"), label, _(
"Muted") );
821 const double magic = -48. / log(0.00390625);
822 snprintf( buf,
sizeof(buf), _(
"%s: %.2f (%.0f dB)"), label, vol, log(logvol) * magic );
824 window_modifyText( wid,
"txtEngine", buf );
835 char buf[32], *widget;
836 double vol = window_getFaderValue(wid, str);
837 if (strcmp(str,
"fadSound")==0) {
848 window_modifyText( wid, widget, buf );
861 const char *str = type ? _(
"Music Volume") : _(
"Sound Volume");
865 snprintf( buf, max, _(
"%s: %s"), str, _(
"Muted") );
867 const double magic = -48. / log(0.00390625);
868 snprintf( buf, max, _(
"%s: %.2f (%.0f dB)"), str, pos, log(vol) * magic );
884 window_addButton( wid, -20, 20,
886 "btnClose", _(
"OK"),
opt_OK );
897 window_addCheckbox( wid, x, y, cw, 20,
898 "chkNosound", _(
"Disable all sound/music"), NULL, conf.
nosound );
901 window_addCheckbox( wid, x, y, cw, 20,
902 "chkEFX", _(
"EFX (More CPU)"), NULL, conf.
al_efx );
907 window_addText( wid, x, y, cw-40, 20, 0,
"txtSVolume",
908 NULL, cHeader, _(
"Volume Levels:") );
912 window_addText( wid, x, y, cw, 20, 1,
"txtSound",
915 window_addFader( wid, x, y, cw, 20,
"fadSound", 0., 1.,
917 window_faderScrollDone( wid,
"fadSound", opt_beep );
921 window_addText( wid, x, y, cw, 20, 1,
"txtMusic",
924 window_addFader( wid, x, y, cw, 20,
"fadMusic", 0., 1.,
929 window_addText( wid, x, y, cw, 20, 1,
"txtEngine",
932 window_addFader( wid, x, y, cw, 20,
"fadEngine", 0., 1.,
934 opt_setEngineLevel( wid,
"fadEngine" );
938 w - 40, 30, 0,
"txtRestart", NULL, NULL, NULL );
943static void opt_beep(
unsigned int wid,
const char *str )
958 f = window_checkboxState( wid,
"chkNosound" );
964 f = window_checkboxState( wid,
"chkEFX" );
971 conf.
sound = window_getFaderValue(wid,
"fadSound");
972 conf.
music = window_getFaderValue(wid,
"fadMusic");
973 conf.
engine_vol = window_getFaderValue(wid,
"fadEngine");
987 window_faderValue( wid,
"fadSound", SOUND_VOLUME_DEFAULT );
988 window_faderValue( wid,
"fadMusic", MUSIC_VOLUME_DEFAULT );
989 window_faderValue( wid,
"fadEngine", ENGINE_VOLUME_DEFAULT );
992 window_checkboxSet( wid,
"chkNosound", MUTE_SOUND_DEFAULT );
993 window_checkboxSet( wid,
"chkEFX", USE_EFX_DEFAULT );
1002 window_checkboxSet( wid,
"chkNosound", conf.
nosound );
1003 window_checkboxSet( wid,
"chkEFX", conf.
al_efx );
1006 window_faderValue( wid,
"fadSound", conf.
sound );
1007 window_faderValue( wid,
"fadMusic", conf.
music );
1008 window_faderValue( wid,
"fadEngine", conf.
engine_vol );
1016 unsigned int parent;
1018 int key, test_key_event;
1019 SDL_Keymod mod, ev_mod;
1023 switch (event->type) {
1025 key =
event->key.keysym.sym;
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) ||
1042 type = KEYBIND_KEYBOARD;
1043 if (window_checkboxState( wid,
"chkAny" ))
1046 ev_mod =
event->key.keysym.mod;
1048 if (ev_mod & (KMOD_LSHIFT | KMOD_RSHIFT))
1050 if (ev_mod & (KMOD_LCTRL | KMOD_RCTRL))
1052 if (ev_mod & (KMOD_LALT | KMOD_RALT))
1054 if (ev_mod & (KMOD_LGUI | KMOD_RGUI))
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;
1068 key =
event->jaxis.axis;
1072 case SDL_JOYBUTTONDOWN:
1073 type = KEYBIND_JBUTTON;
1074 key =
event->jbutton.button;
1078 case SDL_JOYHATMOTION:
1079 switch (event->jhat.value) {
1081 type = KEYBIND_JHAT_UP;
1084 type = KEYBIND_JHAT_DOWN;
1087 type = KEYBIND_JHAT_LEFT;
1090 type = KEYBIND_JHAT_RIGHT;
1095 key =
event->jhat.hat;
1107 dialogue_alert( _(
"Key '%s' overlaps with key '%s' that was just set. "
1108 "You may want to correct this."),
1131 unsigned int new_wid;
1140 new_wid =
window_create(
"wdwSetKey", _(
"Set Keybinding"), -1, -1, w, h );
1145 window_addText( new_wid, 20, -40, w-40, 60, 0,
"txtInfo",
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.") );
1159 window_addCheckbox( new_wid, -20, 20 +
BUTTON_HEIGHT + 20, w-40, 20,
1160 "chkAny", _(
"Set any modifier"), NULL, 0 );
1169 unsigned int parent;
1188 int i, j, nres, res_def;
1190 int cw, w, h, y, x, l;
1198 window_addButton( wid, -20, 20,
1200 "btnClose", _(
"OK"),
opt_OK );
1212 window_addText( wid, x, y, 100, 20, 0,
"txtSRes",
1213 NULL, cHeader, _(
"Resolution:") );
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 );
1220 SDL_DisplayMode mode;
1223 int n = SDL_GetNumDisplayModes( display_index );
1225 for (i=0; i<n; i++) {
1226 SDL_GetDisplayMode( display_index, i, &mode );
1227 if ((mode.w == conf.
width) && (mode.h == conf.
height))
1230 res = malloc(
sizeof(
char*) * (i+j) );
1234 SDL_asprintf( &res[0],
"%dx%d", conf.
width, conf.
height );
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 );
1242 for (k=0; k<nres; k++)
1243 if (strcmp( res[k], res[nres] )==0)
1251 if ((mode.w == conf.
width) && (mode.h == conf.
height))
1255 window_addList( wid, x, y, 140, 100,
"lstRes", res, nres, -1,
opt_videoRes, NULL );
1257 window_addText( wid, x, y-3, 130, 20, 0,
"txtScale",
1259 window_addFader( wid, x+140, y, cw-160, 20,
"fadScale", log(1.), log(3.),
1263 window_addText( wid, x, y-3, 130, 20, 0,
"txtZoomFar",
1265 window_addFader( wid, x+140, y, cw-160, 20,
"fadZoomFar", log(0.1+1.), log(2.0+1.),
1268 window_addText( wid, x, y-3, 130, 20, 0,
"txtZoomNear",
1270 window_addFader( wid, x+140, y, cw-160, 20,
"fadZoomNear", log(0.1+1.), log(2.0+1.),
1275 window_addText( wid, x, y-3, 130, 20, 0,
"txtGammaCorrection",
1277 window_addFader( wid, x+140, y, cw-160, 20,
"fadGammaCorrection", -log(3.), log(3.),
1283 window_addText( wid, x, y, 100, 20, 0,
"txtFPSTitle",
1284 NULL, cHeader, _(
"FPS Control:") );
1288 window_addText( wid, x, y, l, 20, 1,
"txtSFPS",
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 );
1304 window_addText( wid, x, y, 100, 20, 0,
"txtSGL",
1305 NULL, cHeader, _(
"OpenGL:") );
1307 window_addCheckbox( wid, x, y, cw, 20,
1308 "chkVSync", _(
"Vertical Sync"), NULL, conf.
vsync );
1312 window_addText( wid, x, y, 100, 20, 0,
"txtSFeatures",
1313 NULL, cHeader, _(
"Features:") );
1315 window_addCheckbox( wid, x, y, cw, 20,
1316 "chkMinimize", _(
"Minimize on focus loss"), NULL, conf.
minimize );
1318 window_addCheckbox( wid, x, y, cw, 20,
1322 window_addCheckbox( wid, x, y, cw, 20,
1326 window_addText( wid, x, y-3, cw-20, 20, 0,
"txtBGBrightness",
1329 window_addFader( wid, x+20, y, cw-60, 20,
"fadBGBrightness", 0., 1.,
1333 window_addText( wid, x, y-3, cw-20, 20, 0,
"txtNebuNonuniformity",
1336 window_addFader( wid, x+20, y, cw-60, 20,
"fadNebuNonuniformity", 0., 1.,
1340 window_addText( wid, x, y-3, cw-20, 20, 0,
"txtJumpBrightness",
1343 window_addFader( wid, x+20, y, cw-60, 20,
"fadJumpBrightness", 0., 1.,
1347 window_addText( wid, x, y-3, cw-20, 20, 0,
"txtMOpacity",
1350 window_addFader( wid, x+20, y, cw-60, 20,
"fadMapOverlayOpacity", 0., 1.,
1356 window_addText( wid, x, y, 100, 20, 0,
"txtSGUI",
1357 NULL, cHeader, _(
"GUI:") );
1359 window_addCheckbox( wid, x, y, cw, 20,
1360 "chkBigIcons", _(
"Bigger icons"), NULL, conf.
big_icons );
1364 w - 40, 30, 0,
"txtRestart", NULL, NULL, NULL );
1376 s = _(
"#rRestart Naev for changes to take effect.#0");
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 );
1389 const char *buf = toolkit_getList( wid, str );
1390 window_setInput( wid,
"inpRes", buf );
1400 int ret, w, h, f, fullscreen;
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.") );
1411 fullscreen = window_checkboxState( wid,
"chkFullscreen" );
1416 window_checkboxSet( wid,
"chkFullscreen", conf.
fullscreen );
1422 conf.
fps_show = window_checkboxState( wid,
"chkFPS" );
1423 inp = window_getInput( wid,
"inpFPS" );
1427 f = window_checkboxState( wid,
"chkVSync" );
1428 if (conf.
vsync != f) {
1434 f = window_checkboxState( wid,
"chkMinimize" );
1437 SDL_SetHint( SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
1442 conf.
big_icons = window_checkboxState( wid,
"chkBigIcons" );
1455 int f = window_checkboxState( wid, str );
1465 int f = window_checkboxState( wid, str );
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;
1485 old_conf_w = conf.
width;
1486 old_conf_h = conf.
height;
1493 if (status == 0 && !fullscreen && (w != old_w || h != old_h)) {
1495 SDL_SetWindowPosition(
gl_screen.
window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED );
1500 changed_size = new_w != old_w || new_h != old_h;
1501 maximized = !new_f && (SDL_GetWindowFlags(
gl_screen.
window) & SDL_WINDOW_MAXIMIZED);
1503 if (confirm && !changed_size && maximized)
1504 dialogue_alert(_(
"Resolution can't be changed while maximized."));
1505 if (confirm && (status != 0 || new_f != fullscreen))
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"))) {
1515 _(
"Resolution reset to %dx%d %s."),
1516 old_w, old_h, conf.
fullscreen ? _(
"fullscreen") : _(
"windowed") );
1534 SDL_DisplayMode mode;
1539 *fullscreen = (SDL_GetWindowFlags(
gl_screen.
window) & SDL_WINDOW_FULLSCREEN) != 0;
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 );
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 );
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) );
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 );
1589 char buf[STRMAX_SHORT];
1590 double scale = window_getFaderValue(wid, str);
1593 snprintf( buf,
sizeof(buf), _(
"Scaling: %.1fx"), conf.
scalefactor );
1594 window_modifyText( wid,
"txtScale", buf );
1607 char buf[STRMAX_SHORT];
1608 double scale = window_getFaderValue(wid, str);
1611 snprintf( buf,
sizeof(buf), _(
"Far Zoom: %.1fx"), conf.
zoom_far );
1612 window_modifyText( wid,
"txtZoomFar", buf );
1614 window_faderSetBoundedValue( wid,
"fadZoomNear", log(conf.
zoom_far+1.) );
1629 char buf[STRMAX_SHORT];
1630 double scale = window_getFaderValue(wid, str);
1633 snprintf( buf,
sizeof(buf), _(
"Near Zoom: %.1fx"), conf.
zoom_near );
1634 window_modifyText( wid,
"txtZoomNear", buf );
1636 window_faderSetBoundedValue( wid,
"fadZoomFar", log(conf.
zoom_near+1.) );
1651 char buf[STRMAX_SHORT];
1652 double scale = window_getFaderValue(wid, str);
1655 window_modifyText( wid,
"txtGammaCorrection", buf );
1667 char buf[STRMAX_SHORT];
1668 double fad = window_getFaderValue(wid, str);
1670 snprintf( buf,
sizeof(buf), _(
"BG (Stars, etc.) brightness: %.0f%%"), 100.*fad );
1671 window_modifyText( wid,
"txtBGBrightness", buf );
1682 char buf[STRMAX_SHORT];
1683 double fad = window_getFaderValue(wid, str);
1685 snprintf( buf,
sizeof(buf), _(
"Nebula non-uniformity: %.0f%%"), 100.*fad );
1686 window_modifyText( wid,
"txtNebuNonuniformity", buf );
1697 char buf[STRMAX_SHORT];
1698 double fad = window_getFaderValue(wid, str);
1700 snprintf( buf,
sizeof(buf), _(
"Jump Brightness: %.0f%%"), 100.*fad );
1701 window_modifyText( wid,
"txtJumpBrightness", buf );
1712 char buf[STRMAX_SHORT];
1713 double fad = window_getFaderValue(wid, str);
1715 snprintf( buf,
sizeof(buf), _(
"Map Overlay Opacity: %.0f%%"), 100.*fad );
1716 window_modifyText( wid,
"txtMOpacity", buf );
1724 int w, h, lw, lh, bw, bh, n;
1725 char **str, buf[STRMAX_SHORT];
1736 window_addButton( wid, -20, 20, bw, bh,
1737 "btnClose", _(
"OK"),
opt_OK );
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 );
1748 str = malloc(
sizeof(
char *) * 1 );
1749 str[0] = strdup(_(
"No Plugins Found"));
1753 str = malloc(
sizeof(
char *) * n );
1754 for (
int i=0; i<n; i++)
1758 window_addList( wid, 20, -70, lw, lh,
"lstPlugins", str, n, 0, opt_plugins_update, NULL );
1761static void opt_plugins_update(
unsigned int wid,
const char *name )
1765 int pos = toolkit_getListPos( wid, name );
1772 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", p_(
"plugins",
"Name:") );
1774 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", p_(
"plugins",
"Author(s):") );
1776 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", p_(
"plugins",
"Version:") );
1778 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", p_(
"plugins",
"Description:") );
1781 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#g%s#0", _(
"Total Conversion") );
1783 window_modifyText( wid,
"txtDesc", buf );
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
int background_load(const char *name)
Loads a background script by name.
char * dialogue_runChoice(void)
Run the dialog and return the clicked string.
void dialogue_alert(const char *fmt,...)
Displays an alert popup with only an ok button and a message.
void dialogue_msg(const char *caption, const char *fmt,...)
Opens a dialogue window with an ok button and a message.
void dialogue_addChoice(const char *caption, const char *msg, const char *opt)
Add a choice to the dialog.
void dialogue_makeChoice(const char *caption, const char *msg, int opts)
Create the choice dialog. Need to add choices with below method.
void dialogue_msgRaw(const char *caption, const char *msg)
Opens a dialogue window with an ok button and a fixed message.
int dialogue_YesNo(const char *caption, const char *fmt,...)
Runs a dialogue with both yes and no options.
int gl_printWidthRaw(const glFont *ft_font, const char *text)
Gets the width that it would take to print some text.
void gl_freeFont(glFont *font)
Frees a loaded font. Caution: its glFontStash still has a slot in avail_fonts. At the time of writing...
int gl_fontInit(glFont *font, const char *fname, const unsigned int h, const char *prefix, unsigned int flags)
Initializes a font.
double gettext_languageCoverage(const char *lang)
Return the fraction of strings which have a translation into the given language.
void gettext_setLanguage(const char *lang)
Set the translation language.
const char * pgettext_var(const char *msgctxt, const char *msgid)
LanguageOption * gettext_languageOptions(void)
List the available languages, with completeness statistics.
const char * gettext_getSystemLanguage(void)
Gets the current system language as detected by Naev.
double music_getVolumeLog(void)
Gets the current music volume (logarithmic).
double music_getVolume(void)
Gets the current music volume (linear).
int music_volume(double vol)
Sets the music volume from a linear value.
void naev_resize(void)
Wrapper for gl_resize that handles non-GL reinitialization.
Header file with generic functions and naev-specifics.
const char * naev_version(int long_version)
Returns the version in a human readable string.
const char * nfile_configPath(void)
Gets Naev's config path (for user preferences such as conf.lua)
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
int strsort_reverse(const void *p1, const void *p2)
Order-reversed version of strsort().
void gl_colourblind(int enable)
Enables or disables the colourblind shader.
int gl_setupFullscreen(void)
Tries to apply the configured display mode to the window.
static const char * opt_selectedKeybind
static void opt_gameplay(unsigned int wid)
Opens the gameplay menu.
int opt_setVideoMode(int w, int h, int fullscreen, int confirm)
Applies new video-mode options.
static void opt_keyDefaults(unsigned int wid, const char *str)
Restores the key defaults.
static void menuKeybinds_getDim(unsigned int wid, int *w, int *h, int *lw, int *lh, int *bw, int *bh)
Gets the keybind menu dimensions.
static void opt_needRestart(void)
Marks that needs restart.
static void opt_getVideoMode(int *w, int *h, int *fullscreen)
Detects the video-mode options corresponding to the gl_screen we have set up.
static void opt_checkHealth(unsigned int wid, const char *str)
Handles the fancy background checkbox.
static void opt_setAudioLevel(unsigned int wid, const char *str)
Callback to set the sound or music level.
static void opt_audioUpdate(unsigned int wid)
Updates the gameplay options.
static void opt_setZoomNear(unsigned int wid, const char *str)
Callback to set the far zoom.
void opt_resize(void)
Handles resize events for the options menu.
static void opt_setNebuNonuniformity(unsigned int wid, const char *str)
Callback to set the nebula non-uniformity parameter.
static void opt_setJumpBrightness(unsigned int wid, const char *str)
Callback to set the background brightness.
static void opt_OK(unsigned int wid, const char *str)
Saves all options and closes the options screen.
static void opt_videoDefaults(unsigned int wid, const char *str)
Sets video defaults.
static void opt_audioDefaults(unsigned int wid, const char *str)
Sets the audio defaults.
static void opt_setBGBrightness(unsigned int wid, const char *str)
Callback to set the background brightness.
static void opt_keybinds(unsigned int wid)
Opens the keybindings menu.
static void menuKeybinds_genList(unsigned int wid)
Generates the keybindings list.
static int opt_lastKeyPress
static void opt_plugins(unsigned int wid)
Opens the keybindings menu.
static int opt_videoSave(unsigned int wid, const char *str)
Saves the video settings.
static void opt_audioLevelStr(char *buf, int max, int type, double pos)
Sets the sound or music volume string based on level.
static void opt_unsetKey(unsigned int wid, const char *str)
Unsets the key.
static void opt_video(unsigned int wid)
Initializes the video window.
static void opt_setMapOverlayOpacity(unsigned int wid, const char *str)
Callback to set autonav abort threshold.
void opt_menu(void)
Creates the options menu thingy.
static void opt_setKey(unsigned int wid, const char *str)
Rebinds a key.
static void opt_audio(unsigned int wid)
Opens the audio settings menu.
static void opt_close(unsigned int wid, const char *name)
Closes the options screen without saving.
static void menuKeybinds_update(unsigned int wid, const char *name)
Updates the keybindings menu.
static void opt_checkColourblind(unsigned int wid, const char *str)
Handles the colourblind checkbox being checked.
static void opt_gameplayUpdate(unsigned int wid, const char *str)
Updates the gameplay options.
static void opt_gameplayDefaults(unsigned int wid, const char *str)
Sets the default gameplay options.
static void opt_setGammaCorrection(unsigned int wid, const char *str)
Callback to set the gamma correction value (reciprocal of exponent).
static int opt_setKeyEvent(unsigned int wid, SDL_Event *event)
Tries to set the key from an event.
static int opt_gameplaySave(unsigned int wid, const char *str)
Saves the gameplay options.
static void opt_videoRes(unsigned int wid, const char *str)
Callback when resolution changes.
static int opt_audioSave(unsigned int wid, const char *str)
Saves the audio stuff.
static void opt_setScalefactor(unsigned int wid, const char *str)
Callback to set the scaling factor.
static void opt_setZoomFar(unsigned int wid, const char *str)
Callback to set the far zoom.
void pilot_calcStats(Pilot *pilot)
Recalculates the pilot's stats based on his outfits.
void player_soundPlayGUI(int sound, int once)
Plays a GUI sound (unaffected by time accel).
const char * plugin_name(const plugin_t *plg)
Tries to tget the name of a plugin.
const plugin_t * plugin_list(void)
Returns the list of all the plugins.
double sound_getVolumeLog(void)
Gets the current sound volume (logarithmic).
double sound_getVolume(void)
Gets the current sound volume (linear).
int sound_volume(const double vol)
Sets the volume.
Struct containing player options.
unsigned int doubletap_sens
double map_overlay_opacity
double nebu_nonuniformity