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 );
81static void opt_OK(
unsigned int wid,
const char *str );
87static void opt_videoRes(
unsigned int wid,
const char *str );
101static void opt_audio(
unsigned int wid );
102static int opt_audioSave(
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 );
112 int *lw,
int *lh,
int *bw,
int *bh );
118static void opt_setKey(
unsigned int wid,
const char *str );
119static void opt_unsetKey(
unsigned int wid,
const char *str );
122static void opt_plugins_update(
unsigned int wid,
const char *name );
133 conf_copy( &local_conf, &conf );
140 opt_wid =
window_create(
"wdwOptions", _(
"Options"), -1, -1, w, h );
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 );
153 opt_video( opt_windows[ OPT_WIN_VIDEO ] );
154 opt_audio( opt_windows[ OPT_WIN_AUDIO ] );
166static void opt_OK(
unsigned int wid,
const char *str )
168 int ret, prompted_restart;
170 prompted_restart = opt_restart;
176 if (opt_restart && !prompted_restart)
177 dialogue_msg( _(
"Warning"),
"#r%s#0", _(
"Restart Naev for changes to take effect.") );
182 conf_copy( &local_conf, &conf );
190static void opt_close(
unsigned int wid,
const char *name )
196 conf_copy( &conf, &local_conf );
208 conf_free( &local_conf );
216 int w, h, fullscreen;
225 snprintf( buf,
sizeof(buf),
"%dx%d", w, h );
226 window_setInput( opt_windows[OPT_WIN_VIDEO],
"inpRes", buf );
232static char** lang_list(
int *n )
238 ls = malloc(
sizeof(
char*)*128 );
239 ls[0] = strdup(_(
"system"));
244 char **item = &ls[(*n)++];
245 asprintf( item,
"[%3.0f%%] %s", 100.*opts[i].coverage, opts[i].language );
246 free( opts[i].language );
262 int w, h, y, x, by, l, n, i, p;
264 char **ls, **diff_text, **diff_alt;
265 const Difficulty *difficulty, *cur_difficulty;
271 window_addButton( wid, -20, 20,
273 "btnClose", _(
"OK"),
opt_OK );
285 window_addText( wid, x, y, cw, 20, 1,
"txtVersion",
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 );
300 window_addText( wid, x, y, l, 20, 0,
"txtLanguage",
302 ls = lang_list( &n );
311 window_addList( wid, x+l+20, y, cw-l-50, 100,
"lstLanguage", ls, n, i, NULL, NULL );
315 difficulty = difficulty_getAll();
317 diff_text = malloc(
sizeof(
char*) * n );
318 diff_alt = malloc(
sizeof(
char*) * n );
321 difficulty_setLocal( NULL );
322 cur_difficulty = difficulty_cur();
323 for (i=0; i<n; i++) {
325 diff_text[i] = strdup( _(
d->name) );
326 diff_alt[i] = difficulty_display(
d);
327 if (strcmp(
d->name,cur_difficulty->
name)==0)
331 s = _(
"Difficulty (this save):");
333 s = _(
"Difficulty (global):");
334 window_addText( wid, x, y, cw, 20, 0,
"txtDifficulty", NULL, NULL, s );
336 window_addList( wid, x, y, cw, 100,
"lstDifficulty", diff_text, n, p, NULL, NULL );
337 toolkit_setListAltText( wid,
"lstDifficulty", diff_alt );
341 window_addText( wid, x, y, cw, 20, 0,
"txtCompile",
342 NULL, cHeader, _(
"Compilation Flags:") );
344 window_addText( wid, x, y, cw, h+y-20, 0,
"txtFlags",
370 y -= window_getTextHeight(wid,
"txtFlags") + 10;
378 window_addText( wid, x, y, cw-130, 20, 0,
"txtAAutonav",
379 NULL, NULL, _(
"Stop Speedup At:") );
383 window_addText( wid, x, y, cw, 20, 1,
"txtAutonav",
386 window_addFader( wid, x, y, cw, 20,
"fadAutonav", 0., 1.,
390 window_addText( wid, x, y, cw, 20, 0,
"txtSettings",
391 NULL, cHeader, _(
"Settings:") );
394 window_addCheckbox( wid, x, y, cw, 20,
395 "chkZoomManual", _(
"Enable manual zoom control"), NULL, conf.
zoom_manual );
397 window_addCheckbox( wid, x, y, cw, 20,
398 "chkDoubletap", _(
"Enable double-tap afterburn/cooldown"), NULL, conf.
doubletap_sens );
400 window_addCheckbox( wid, x, y, cw, 20,
401 "chkMouseFly", _(
"Enable mouse-flying (toggle with middle click)"), NULL, conf.
mouse_fly );
403 window_addCheckbox( wid, x, y, cw, 20,
404 "chkMouseThrust", _(
"Enable mouse-flying thrust control"), NULL, conf.
mouse_thrust );
406 window_addCheckbox( wid, x, y, cw, 20,
407 "chkCompress", _(
"Enable saved game compression"), NULL, conf.
save_compress );
409 s = _(
"Visible Messages");
411 window_addText( wid, x, y, l, 20, 1,
"txtSMSG",
413 window_addInput( wid, -50, y, 40, 20,
"inpMSG", 4, 1, NULL );
415 s = _(
"Max Time Compression Factor");
417 window_addText( wid, x, y, l, 20, 1,
"txtTMax",
419 window_addInput( wid, -50, y, 40, 20,
"inpTMax", 4, 1, NULL );
423 w - 40, 30, 0,
"txtRestart", NULL, NULL, NULL );
436 const char *vmsg, *tmax;
442 p = toolkit_getListPos( wid,
"lstLanguage" );
443 s = (p==0) ? NULL : toolkit_getList( wid,
"lstLanguage" );
444 newlang = ((s != NULL) != (conf.
language != NULL))
449 LOG(
"conf.language set to %s", conf.
language);
464 difficulty = difficulty_getAll();
465 p = toolkit_getListPos( wid,
"lstDifficulty" );
466 difficulty = &difficulty[p];
469 if (difficulty->
def) {
471 difficulty_setGlobal( NULL );
475 difficulty_setGlobal( difficulty );
480 if (difficulty == difficulty_get(NULL)) {
482 difficulty_setLocal( NULL );
486 difficulty_setLocal( difficulty );
494 f = window_checkboxState( wid,
"chkDoubletap" );
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" );
505 player_rmFlag( PLAYER_MFLY );
508 reset = window_getFaderValue(wid,
"fadAutonav");
513 else if (reset > 0.5) {
523 vmsg = window_getInput( wid,
"inpMSG" );
524 tmax = window_getInput( wid,
"inpTMax" );
539 char vmsg[16], tmax[16];
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 );
549 window_faderValue( wid,
"fadAutonav", 0.75 );
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 );
564 char vmsg[16], tmax[16];
568 window_checkboxSet( wid,
"chkZoomManual", conf.
zoom_manual );
570 window_checkboxSet( wid,
"chkMouseFly", conf.
mouse_fly );
571 window_checkboxSet( wid,
"chkMouseThrust", conf.
mouse_thrust );
572 window_checkboxSet( wid,
"chkCompress", conf.
save_compress );
580 window_faderValue( wid,
"fadAutonav", reset );
583 snprintf( vmsg,
sizeof(vmsg),
"%d", conf.
mesg_visible );
584 window_setInput( wid,
"inpMSG", vmsg );
586 window_setInput( wid,
"inpTMax", tmax );
597 char buf[STRMAX_SHORT];
598 double autonav_reset;
601 autonav_reset = window_getFaderValue(wid, str);
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. );
611 snprintf( buf,
sizeof(buf), _(
"Armour Damage") );
613 window_modifyText( wid,
"txtAutonav", buf );
620 int *lw,
int *lh,
int *bw,
int *bh )
643 int w, h, lw, bw, bh;
649 window_addButton( wid, -20, 20, bw, bh,
650 "btnClose", _(
"OK"),
opt_OK );
652 window_addButton( wid, -20, 40 + bh, bw, bh,
655 window_addButton( wid, -20, 60 + 2*bh, bw, bh,
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 );
676 char **str, mod_text[64];
698 case KEYBIND_KEYBOARD:
701 snprintf( mod_text,
sizeof(mod_text), _(
"any+") );
705 if (mod & NMOD_SHIFT)
706 p +=
scnprintf( &mod_text[p],
sizeof(mod_text)-p, _(
"shift+") );
708 p +=
scnprintf( &mod_text[p],
sizeof(mod_text)-p, _(
"ctrl+") );
710 p +=
scnprintf( &mod_text[p],
sizeof(mod_text)-p, _(
"alt+") );
712 p +=
scnprintf( &mod_text[p],
sizeof(mod_text)-p, _(
"meta+") );
717 if (key < 0x100 && isalpha(key))
718 snprintf(str[j], l,
"%s <%s%c>", short_desc, mod_text, toupper(key) );
720 snprintf(str[j], l,
"%s <%s%s>", short_desc, mod_text,
pgettext_var(
"keyname", SDL_GetKeyName(key)) );
722 case KEYBIND_JAXISPOS:
723 snprintf(str[j], l,
"%s <ja+%d>", short_desc, key);
725 case KEYBIND_JAXISNEG:
726 snprintf(str[j], l,
"%s <ja-%d>", short_desc, key);
728 case KEYBIND_JBUTTON:
729 snprintf(str[j], l,
"%s <jb%d>", short_desc, key);
731 case KEYBIND_JHAT_UP:
732 snprintf(str[j], l,
"%s <jh%d-up>", short_desc, key);
734 case KEYBIND_JHAT_DOWN:
735 snprintf(str[j], l,
"%s <jh%d-down>", short_desc, key);
737 case KEYBIND_JHAT_LEFT:
738 snprintf(str[j], l,
"%s <jh%d-left>", short_desc, key);
740 case KEYBIND_JHAT_RIGHT:
741 snprintf(str[j], l,
"%s <jh%d-right>", short_desc, key);
744 snprintf(str[j], l,
"%s", short_desc);
751 pos = toolkit_getListPos( wid,
"lstKeybinds" );
752 off = toolkit_getListOffset( wid,
"lstKeybinds" );
756 window_addList( wid, 20, -40, lw, lh,
"lstKeybinds", str,
input_numbinds, 0,
menuKeybinds_update,
opt_setKey );
759 toolkit_setListPos( wid,
"lstKeybinds", pos );
760 toolkit_setListOffset( wid,
"lstKeybinds", off );
779 char buf[STRMAX_SHORT];
783 selected = toolkit_getListPos( wid,
"lstKeybinds" );
788 window_modifyText( wid,
"txtName", _(
keybind_info[selected][1]) );
797 snprintf(binding,
sizeof(binding), _(
"Not bound"));
799 case KEYBIND_KEYBOARD:
801 if (key < 0x100 && isalpha(key))
802 snprintf(binding,
sizeof(binding), _(
"keyboard: %s%s%c"),
804 (mod != KMOD_NONE) ?
" + " :
"",
807 snprintf(binding,
sizeof(binding), _(
"keyboard: %s%s%s"),
809 (mod != KMOD_NONE) ?
" + " :
"",
812 case KEYBIND_JAXISPOS:
813 snprintf(binding,
sizeof(binding), _(
"joy axis pos: <%d>"), key );
815 case KEYBIND_JAXISNEG:
816 snprintf(binding,
sizeof(binding), _(
"joy axis neg: <%d>"), key );
818 case KEYBIND_JBUTTON:
819 snprintf(binding,
sizeof(binding), _(
"joy button: <%d>"), key);
821 case KEYBIND_JHAT_UP:
822 snprintf(binding,
sizeof(binding), _(
"joy hat up: <%d>"), key);
824 case KEYBIND_JHAT_DOWN:
825 snprintf(binding,
sizeof(binding), _(
"joy hat down: <%d>"), key);
827 case KEYBIND_JHAT_LEFT:
828 snprintf(binding,
sizeof(binding), _(
"joy hat left: <%d>"), key);
830 case KEYBIND_JHAT_RIGHT:
831 snprintf(binding,
sizeof(binding), _(
"joy hat right:<%d>"), key);
836 snprintf(buf,
sizeof(buf),
"%s\n\n%s\n", desc, binding);
837 window_modifyText( wid,
"txtDesc", buf );
846 const char *title, *caption, *ret;
850 const char *opts[] = {
856 title = _(
"Restore Defaults");
857 caption = _(
"Which layout do you want to use?");
861 for (
int i=0; i<n; i++)
870 for (
int i=0; i<n; i++)
871 if (strcmp(ret, opts[i]) == 0) {
886 dialogue_msgRaw( _(
"Defaults Restored"), _(
"Keybindings restored to defaults."));
889static void opt_setEngineLevel(
unsigned int wid,
const char *str )
892 double vol = window_getFaderValue(wid, str);
893 const char *label = _(
"Engine Volume");
894 double logvol = 1. / pow(2., (1.-vol) * 8.);
897 snprintf( buf,
sizeof(buf), _(
"%s: %s"), label, _(
"Muted") );
899 const double magic = -48. / log(0.00390625);
900 snprintf( buf,
sizeof(buf), _(
"%s: %.2f (%.0f dB)"), label, vol, log(logvol) * magic );
902 window_modifyText( wid,
"txtEngine", buf );
913 char buf[32], *widget;
914 double vol = window_getFaderValue(wid, str);
915 if (strcmp(str,
"fadSound")==0) {
926 window_modifyText( wid, widget, buf );
939 const char *str = type ? _(
"Music Volume") : _(
"Sound Volume");
943 snprintf( buf, max, _(
"%s: %s"), str, _(
"Muted") );
945 const double magic = -48. / log(0.00390625);
946 snprintf( buf, max, _(
"%s: %.2f (%.0f dB)"), str, pos, log(vol) * magic );
962 window_addButton( wid, -20, 20,
964 "btnClose", _(
"OK"),
opt_OK );
975 window_addCheckbox( wid, x, y, cw, 20,
976 "chkNosound", _(
"Disable all sound/music"), NULL, conf.
nosound );
979 window_addCheckbox( wid, x, y, cw, 20,
980 "chkEFX", _(
"EFX (More CPU)"), NULL, conf.
al_efx );
985 window_addText( wid, x, y, cw-40, 20, 0,
"txtSVolume",
986 NULL, cHeader, _(
"Volume Levels:") );
990 window_addText( wid, x, y, cw, 20, 1,
"txtSound",
993 window_addFader( wid, x, y, cw, 20,
"fadSound", 0., 1.,
995 window_faderScrollDone( wid,
"fadSound", opt_beep );
999 window_addText( wid, x, y, cw, 20, 1,
"txtMusic",
1002 window_addFader( wid, x, y, cw, 20,
"fadMusic", 0., 1.,
1007 window_addText( wid, x, y, cw, 20, 1,
"txtEngine",
1010 window_addFader( wid, x, y, cw, 20,
"fadEngine", 0., 1.,
1012 opt_setEngineLevel( wid,
"fadEngine" );
1016 w - 40, 30, 0,
"txtRestart", NULL, NULL, NULL );
1021static void opt_beep(
unsigned int wid,
const char *str )
1036 f = window_checkboxState( wid,
"chkNosound" );
1042 f = window_checkboxState( wid,
"chkEFX" );
1049 conf.
sound = window_getFaderValue(wid,
"fadSound");
1050 conf.
music = window_getFaderValue(wid,
"fadMusic");
1051 conf.
engine_vol = window_getFaderValue(wid,
"fadEngine");
1065 window_faderValue( wid,
"fadSound", SOUND_VOLUME_DEFAULT );
1066 window_faderValue( wid,
"fadMusic", MUSIC_VOLUME_DEFAULT );
1067 window_faderValue( wid,
"fadEngine", ENGINE_VOLUME_DEFAULT );
1070 window_checkboxSet( wid,
"chkNosound", MUTE_SOUND_DEFAULT );
1071 window_checkboxSet( wid,
"chkEFX", USE_EFX_DEFAULT );
1080 window_checkboxSet( wid,
"chkNosound", conf.
nosound );
1081 window_checkboxSet( wid,
"chkEFX", conf.
al_efx );
1084 window_faderValue( wid,
"fadSound", conf.
sound );
1085 window_faderValue( wid,
"fadMusic", conf.
music );
1086 window_faderValue( wid,
"fadEngine", conf.
engine_vol );
1094 unsigned int parent;
1096 int key, test_key_event;
1097 SDL_Keymod mod, ev_mod;
1101 switch (event->type) {
1103 key =
event->key.keysym.sym;
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) ||
1120 type = KEYBIND_KEYBOARD;
1121 if (window_checkboxState( wid,
"chkAny" ))
1124 ev_mod =
event->key.keysym.mod;
1126 if (ev_mod & (KMOD_LSHIFT | KMOD_RSHIFT))
1128 if (ev_mod & (KMOD_LCTRL | KMOD_RCTRL))
1130 if (ev_mod & (KMOD_LALT | KMOD_RALT))
1132 if (ev_mod & (KMOD_LGUI | KMOD_RGUI))
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;
1146 key =
event->jaxis.axis;
1150 case SDL_JOYBUTTONDOWN:
1151 type = KEYBIND_JBUTTON;
1152 key =
event->jbutton.button;
1156 case SDL_JOYHATMOTION:
1157 switch (event->jhat.value) {
1159 type = KEYBIND_JHAT_UP;
1162 type = KEYBIND_JHAT_DOWN;
1165 type = KEYBIND_JHAT_LEFT;
1168 type = KEYBIND_JHAT_RIGHT;
1173 key =
event->jhat.hat;
1185 dialogue_alert( _(
"Key '%s' overlaps with key '%s' that was just set. "
1186 "You may want to correct this."),
1209 unsigned int new_wid;
1218 new_wid =
window_create(
"wdwSetKey", _(
"Set Keybinding"), -1, -1, w, h );
1223 window_addText( new_wid, 20, -40, w-40, 60, 0,
"txtInfo",
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.") );
1237 window_addCheckbox( new_wid, -20, 20 +
BUTTON_HEIGHT + 20, w-40, 20,
1238 "chkAny", _(
"Set any modifier"), NULL, 0 );
1247 unsigned int parent;
1266 int i, j, nres, res_def;
1268 int cw, w, h, y, x, l;
1276 window_addButton( wid, -20, 20,
1278 "btnClose", _(
"OK"),
opt_OK );
1290 window_addText( wid, x, y, 100, 20, 0,
"txtSRes",
1291 NULL, cHeader, _(
"Resolution:") );
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 );
1298 SDL_DisplayMode mode;
1301 int n = SDL_GetNumDisplayModes( display_index );
1303 for (i=0; i<n; i++) {
1304 SDL_GetDisplayMode( display_index, i, &mode );
1305 if ((mode.w == conf.
width) && (mode.h == conf.
height))
1308 res = malloc(
sizeof(
char*) * (i+j) );
1315 for (i=0; i<n; i++) {
1316 SDL_GetDisplayMode( display_index, i, &mode );
1317 asprintf( &res[ nres ],
"%dx%d", mode.w, mode.h );
1320 for (k=0; k<nres; k++)
1321 if (strcmp( res[k], res[nres] )==0)
1329 if ((mode.w == conf.
width) && (mode.h == conf.
height))
1333 window_addList( wid, x, y, 140, 100,
"lstRes", res, nres, -1,
opt_videoRes, NULL );
1335 window_addText( wid, x, y-3, 130, 20, 0,
"txtScale",
1337 window_addFader( wid, x+140, y, cw-160, 20,
"fadScale", log(1.), log(3.),
1341 window_addText( wid, x, y-3, 130, 20, 0,
"txtZoomFar",
1343 window_addFader( wid, x+140, y, cw-160, 20,
"fadZoomFar", log(0.1+1.), log(2.0+1.),
1346 window_addText( wid, x, y-3, 130, 20, 0,
"txtZoomNear",
1348 window_addFader( wid, x+140, y, cw-160, 20,
"fadZoomNear", log(0.1+1.), log(2.0+1.),
1353 window_addText( wid, x, y-3, 130, 20, 0,
"txtGammaCorrection",
1355 window_addFader( wid, x+140, y, cw-160, 20,
"fadGammaCorrection", -log(3.), log(3.),
1361 window_addText( wid, x, y, 100, 20, 0,
"txtFPSTitle",
1362 NULL, cHeader, _(
"FPS Control:") );
1366 window_addText( wid, x, y, l, 20, 1,
"txtSFPS",
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 );
1382 window_addText( wid, x, y, 100, 20, 0,
"txtSGL",
1383 NULL, cHeader, _(
"OpenGL:") );
1385 window_addCheckbox( wid, x, y, cw, 20,
1386 "chkVSync", _(
"Vertical Sync"), NULL, conf.
vsync );
1390 window_addText( wid, x, y, 100, 20, 0,
"txtSFeatures",
1391 NULL, cHeader, _(
"Features:") );
1393 window_addCheckbox( wid, x, y, cw, 20,
1394 "chkMinimize", _(
"Minimize on focus loss"), NULL, conf.
minimize );
1396 window_addCheckbox( wid, x, y, cw, 20,
1400 window_addCheckbox( wid, x, y, cw, 20,
1404 window_addText( wid, x, y-3, cw-20, 20, 0,
"txtBGBrightness",
1407 window_addFader( wid, x+20, y, cw-60, 20,
"fadBGBrightness", 0., 1.,
1411 window_addText( wid, x, y-3, cw-20, 20, 0,
"txtNebuNonuniformity",
1414 window_addFader( wid, x+20, y, cw-60, 20,
"fadNebuNonuniformity", 0., 1.,
1418 window_addText( wid, x, y-3, cw-20, 20, 0,
"txtJumpBrightness",
1421 window_addFader( wid, x+20, y, cw-60, 20,
"fadJumpBrightness", 0., 1.,
1425 window_addText( wid, x, y-3, cw-20, 20, 0,
"txtMOpacity",
1428 window_addFader( wid, x+20, y, cw-60, 20,
"fadMapOverlayOpacity", 0., 1.,
1434 window_addText( wid, x, y, 100, 20, 0,
"txtSGUI",
1435 NULL, cHeader, _(
"GUI:") );
1437 window_addCheckbox( wid, x, y, cw, 20,
1438 "chkBigIcons", _(
"Bigger icons"), NULL, conf.
big_icons );
1442 w - 40, 30, 0,
"txtRestart", NULL, NULL, NULL );
1454 s = _(
"#rRestart Naev for changes to take effect.#0");
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 );
1467 const char *buf = toolkit_getList( wid, str );
1468 window_setInput( wid,
"inpRes", buf );
1478 int ret, w, h, f, fullscreen;
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.") );
1489 fullscreen = window_checkboxState( wid,
"chkFullscreen" );
1494 window_checkboxSet( wid,
"chkFullscreen", conf.
fullscreen );
1500 conf.
fps_show = window_checkboxState( wid,
"chkFPS" );
1501 inp = window_getInput( wid,
"inpFPS" );
1505 f = window_checkboxState( wid,
"chkVSync" );
1506 if (conf.
vsync != f) {
1512 f = window_checkboxState( wid,
"chkMinimize" );
1515 SDL_SetHint( SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
1520 conf.
big_icons = window_checkboxState( wid,
"chkBigIcons" );
1533 int f = window_checkboxState( wid, str );
1543 int f = window_checkboxState( wid, str );
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;
1563 old_conf_w = conf.
width;
1564 old_conf_h = conf.
height;
1571 if (status == 0 && !fullscreen && (w != old_w || h != old_h)) {
1573 SDL_SetWindowPosition(
gl_screen.
window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED );
1578 changed_size = new_w != old_w || new_h != old_h;
1579 maximized = !new_f && (SDL_GetWindowFlags(
gl_screen.
window) & SDL_WINDOW_MAXIMIZED);
1581 if (confirm && !changed_size && maximized)
1582 dialogue_alert(_(
"Resolution can't be changed while maximized."));
1583 if (confirm && (status != 0 || new_f != fullscreen))
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"))) {
1593 _(
"Resolution reset to %dx%d %s."),
1594 old_w, old_h, conf.
fullscreen ? _(
"fullscreen") : _(
"windowed") );
1612 SDL_DisplayMode mode;
1617 *fullscreen = (SDL_GetWindowFlags(
gl_screen.
window) & SDL_WINDOW_FULLSCREEN) != 0;
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 );
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 );
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) );
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 );
1667 char buf[STRMAX_SHORT];
1668 double scale = window_getFaderValue(wid, str);
1671 snprintf( buf,
sizeof(buf), _(
"Scaling: %.1fx"), conf.
scalefactor );
1672 window_modifyText( wid,
"txtScale", buf );
1685 char buf[STRMAX_SHORT];
1686 double scale = window_getFaderValue(wid, str);
1689 snprintf( buf,
sizeof(buf), _(
"Far Zoom: %.1fx"), conf.
zoom_far );
1690 window_modifyText( wid,
"txtZoomFar", buf );
1692 window_faderSetBoundedValue( wid,
"fadZoomNear", log(conf.
zoom_far+1.) );
1707 char buf[STRMAX_SHORT];
1708 double scale = window_getFaderValue(wid, str);
1711 snprintf( buf,
sizeof(buf), _(
"Near Zoom: %.1fx"), conf.
zoom_near );
1712 window_modifyText( wid,
"txtZoomNear", buf );
1714 window_faderSetBoundedValue( wid,
"fadZoomFar", log(conf.
zoom_near+1.) );
1729 char buf[STRMAX_SHORT];
1730 double scale = window_getFaderValue(wid, str);
1733 window_modifyText( wid,
"txtGammaCorrection", buf );
1745 char buf[STRMAX_SHORT];
1746 double fad = window_getFaderValue(wid, str);
1748 snprintf( buf,
sizeof(buf), _(
"BG (Stars, etc.) brightness: %.0f%%"), 100.*fad );
1749 window_modifyText( wid,
"txtBGBrightness", buf );
1760 char buf[STRMAX_SHORT];
1761 double fad = window_getFaderValue(wid, str);
1763 snprintf( buf,
sizeof(buf), _(
"Nebula non-uniformity: %.0f%%"), 100.*fad );
1764 window_modifyText( wid,
"txtNebuNonuniformity", buf );
1775 char buf[STRMAX_SHORT];
1776 double fad = window_getFaderValue(wid, str);
1778 snprintf( buf,
sizeof(buf), _(
"Jump Brightness: %.0f%%"), 100.*fad );
1779 window_modifyText( wid,
"txtJumpBrightness", buf );
1790 char buf[STRMAX_SHORT];
1791 double fad = window_getFaderValue(wid, str);
1793 snprintf( buf,
sizeof(buf), _(
"Map Overlay Opacity: %.0f%%"), 100.*fad );
1794 window_modifyText( wid,
"txtMOpacity", buf );
1802 int w, h, lw, lh, bw, bh, n;
1803 char **str, buf[STRMAX_SHORT];
1814 window_addButton( wid, -20, 20, bw, bh,
1815 "btnClose", _(
"OK"),
opt_OK );
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 );
1826 str = malloc(
sizeof(
char *) * 1 );
1827 str[0] = strdup(_(
"No Plugins Found"));
1831 str = malloc(
sizeof(
char *) * n );
1832 for (
int i=0; i<n; i++)
1836 window_addList( wid, 20, -70, lw, lh,
"lstPlugins", str, n, 0, opt_plugins_update, NULL );
1839static void opt_plugins_update(
unsigned int wid,
const char *name )
1843 int pos = toolkit_getListPos( wid, name );
1850 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", p_(
"plugins",
"Name:") );
1852 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", p_(
"plugins",
"Author(s):") );
1854 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", p_(
"plugins",
"Version:") );
1856 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", p_(
"plugins",
"Description:") );
1859 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#g%s#0", _(
"Total Conversion") );
1861 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.
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.
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 asprintf(char **strp, const char *fmt,...)
Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument....
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().
const char * num2strU(double n, int decimals)
Unsafe version of num2str that uses an internal buffer. Every call overwrites the return value.
void gl_colorblind(int enable)
Enables or disables the colorblind 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_setAutonavResetSpeed(unsigned int wid, const char *str)
Callback to set autonav abort threshold.
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_checkColorblind(unsigned int wid, const char *str)
Handles the colorblind 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.
double autonav_reset_shield
double autonav_reset_dist
unsigned int doubletap_sens
double map_overlay_opacity
double nebu_nonuniformity