/** * @brief Opens the console. */ void cli_open (void) { unsigned int wid; /* Lazy loading. */ if (cli_state == NULL) if (cli_init()) return; /* Must not be already open. */ if (window_exists( "Lua Console" )) return; /* Create the window. */ wid = window_create( "Lua Console", -1, -1, cli_width, cli_height ); /* Window settings. */ window_setAccept( wid, cli_input ); window_setCancel( wid, window_close ); window_handleKeys( wid, cli_keyhandler ); /* Input box. */ window_addInput( wid, 20, 20, cli_width-60-BUTTON_WIDTH, BUTTON_HEIGHT, "inpInput", LINE_LENGTH, 1 ); /* Buttons. */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* Custom console widget. */ window_addCust( wid, 20, -40, cli_width-40, cli_height-80-BUTTON_HEIGHT, "cstConsole", 0, cli_render, NULL ); }
/** * @brief Creates a dialogue that allows the player to write a message. * * You must free the result if it's not null. * * @param title Title of the dialogue window. * @param min Minimum length of the message (must be non-zero). * @param max Maximum length of the message (must be non-zero). * @param msg Message to be displayed. * @return The message the player typed or NULL if it was cancelled. */ char* dialogue_inputRaw( const char* title, int min, int max, const char *msg ) { char *input; int h, done; /* get text height */ h = gl_printHeightRaw( &gl_smallFont, 200, msg ); /* create window */ input_dialogue.input_wid = window_create( title, -1, -1, 240, h+140 ); window_setData( input_dialogue.input_wid, &done ); window_setAccept( input_dialogue.input_wid, dialogue_inputClose ); window_setCancel( input_dialogue.input_wid, dialogue_cancel ); /* text */ window_addText( input_dialogue.input_wid, 30, -30, 200, h, 0, "txtInput", &gl_smallFont, &cDConsole, msg ); /* input */ window_addInput( input_dialogue.input_wid, 20, -50-h, 200, 20, "inpInput", max, 1, NULL ); window_setInputFilter( input_dialogue.input_wid, "inpInput", "/" ); /* Remove illegal stuff. */ /* button */ window_addButton( input_dialogue.input_wid, -20, 20, 80, 30, "btnClose", "Done", dialogue_inputClose ); /* tricky secondary loop */ dialogue_open++; done = 0; input = NULL; while ((done >= 0) && (!input || ((int)strlen(input) < min))) { /* must be longer than min */ if (input) { dialogue_alert( "Input must be at least %d character%s long!", min, (min==1) ? "s" : "" ); free(input); input = NULL; } if (toolkit_loop( &done ) != 0) /* error in loop -> quit */ return NULL; /* save the input */ if (done < 0) input = NULL; else input = strdup( window_getInput( input_dialogue.input_wid, "inpInput" ) ); } /* cleanup */ if (input != NULL) { window_destroy( input_dialogue.input_wid ); dialogue_open--; } input_dialogue.input_wid = 0; /* return the result */ return input; }
/** * @brief Opens the console. */ void cli_open (void) { unsigned int wid; /* Lazy loading. */ if (cli_state == NULL) if (cli_init()) return; /* Make sure main menu isn't open. */ if (menu_isOpen(MENU_MAIN)) return; /* Must not be already open. */ if (window_exists( "Lua Console" )) return; /* Put a friendly message at first. */ if (cli_firstOpen) { char buf[256]; cli_addMessage( "" ); cli_addMessage( "\egWelcome to the Lua console!" ); nsnprintf( buf, sizeof(buf), "\eg "APPNAME" v%s", naev_version(0) ); cli_addMessage( buf ); cli_addMessage( "" ); cli_firstOpen = 0; } /* Create the window. */ wid = window_create( "Lua Console", -1, -1, CLI_WIDTH, CLI_HEIGHT ); /* Window settings. */ window_setAccept( wid, cli_input ); window_setCancel( wid, window_close ); window_handleKeys( wid, cli_keyhandler ); /* Input box. */ window_addInput( wid, 20, 20, CLI_WIDTH-60-BUTTON_WIDTH, BUTTON_HEIGHT, "inpInput", LINE_LENGTH, 1, cli_font ); /* Buttons. */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* Custom console widget. */ window_addCust( wid, 20, -40, CLI_WIDTH-40, CLI_HEIGHT-80-BUTTON_HEIGHT, "cstConsole", 0, cli_render, NULL, NULL ); /* Cache current height in case the window is resized. */ cli_height = CLI_HEIGHT; }
/** * @brief Opens the gameplay menu. */ static void opt_gameplay( unsigned int wid ) { (void) wid; char buf[PATH_MAX]; const char *path; int cw; int w, h, y, x, by, l; char *s; /* Get size. */ window_dimWindow( wid, &w, &h ); /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", opt_close ); window_addButton( wid, -20 - 1*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnApply", "Apply", opt_gameplaySave ); window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnDefaults", "Defaults", opt_gameplayDefaults ); /* Information. */ cw = (w-40); x = 20; y = -60; window_addText( wid, x, y, cw, 20, 1, "txtVersion", NULL, NULL, naev_version(1) ); y -= 20; #ifdef GIT_COMMIT window_addText( wid, x, y, cw, 20, 1, "txtCommit", NULL, NULL, "Commit: "GIT_COMMIT ); #endif /* GIT_COMMIT */ y -= 20; path = ndata_getPath(); if (path == NULL) snprintf( buf, sizeof(buf), "not using ndata" ); else snprintf( buf, sizeof(buf), "ndata: %s", path); window_addText( wid, x, y, cw, 20, 1, "txtNdata", NULL, NULL, buf ); y -= 40; by = y; /* Compiletime stuff. */ cw = (w-60)/2; y = by; x = 20; window_addText( wid, x+20, y, cw, 20, 0, "txtCompile", NULL, &cDConsole, "Compilation Flags" ); y -= 30; window_addText( wid, x, y, cw, h+y-20, 0, "txtFlags", NULL, NULL, "" #ifdef DEBUGGING #ifdef DEBUG_PARANOID "Debug Paranoid\n" #else /* DEBUG_PARANOID */ "Debug\n" #endif /* DEBUG_PARANOID */ #endif /* DEBUGGING */ #if defined(LINUX) "Linux\n" #elif defined(FREEBSD) "FreeBSD\n" #elif defined(MACOSX) "Mac OS X\n" #elif defined(WIN32) "Windows\n" #else "Unknown OS\n" #endif #ifdef USE_OPENAL "With OpenAL\n" #endif /* USE_OPENAL */ #ifdef USE_SDLMIX "With SDL_mixer\n" #endif #ifdef HAVE_LUAJIT "Using Lua JIT\n" #endif #ifdef NDATA_DEF "ndata: "NDATA_DEF"\n" #endif /* NDATA_DEF */ #ifdef PREFSDIR_DEF "preference directory: "PREFSDIR_DEF"\n" #endif /* PREFSDIR_DEF */ ); /* Options. */ y = by; x += cw; /* Autonav abort. */ x = 20 + cw + 20; window_addText( wid, x+65, y, 150, 150, 0, "txtAAutonav", NULL, &cDConsole, "Abort Autonav At:" ); y -= 20; /* Autonav abort fader. */ opt_getAutonavAbortStr( buf, sizeof(buf) ); window_addText( wid, x, y, cw, 20, 1, "txtAutonav", NULL, NULL, buf ); y -= 20; window_addFader( wid, x, y, cw, 20, "fadAutonav", 0., 1., conf.autonav_abort, opt_setAutonavAbort ); y -= 40; window_addText( wid, x+20, y, cw, 20, 0, "txtSettings", NULL, &cDConsole, "Settings" ); y -= 25; window_addCheckbox( wid, x, y, cw, 20, "chkZoomManual", "Enable manual zoom control", NULL, conf.zoom_manual ); y -= 25; window_addCheckbox( wid, x, y, cw, 20, "chkAfterburn", "Enable double-tap afterburn", NULL, conf.afterburn_sens ); y -= 25; window_addCheckbox( wid, x, y, cw, 20, "chkMouseThrust", "Enable mouse-flying thrust control", NULL, conf.mouse_thrust ); y -= 25; window_addCheckbox( wid, x, y, cw, 20, "chkCompress", "Enable savegame compression", NULL, conf.save_compress ); y -= 30; s = "Visible Messages"; l = gl_printWidthRaw( NULL, s ); window_addText( wid, -100, y, l, 20, 1, "txtSMSG", NULL, &cBlack, s ); window_addInput( wid, -50, y, 40, 20, "inpMSG", 4, 1, NULL ); y -= 30; s = "Max Time Compression Factor"; l = gl_printWidthRaw( NULL, s ); window_addText( wid, -100, y, l, 20, 1, "txtTMax", NULL, &cBlack, s ); window_addInput( wid, -50, y, 40, 20, "inpTMax", 4, 1, NULL ); y -= 30; /* Restart text. */ window_addText( wid, 20, 10, 3*(BUTTON_WIDTH + 20), 30, 0, "txtRestart", &gl_smallFont, &cBlack, NULL ); /* Update. */ opt_gameplayUpdate( wid, NULL ); }
/** * @brief Initializes the video window. */ static void opt_video( unsigned int wid ) { (void) wid; int i, j, nres, res_def; char buf[16]; int cw; int w, h, y, x, l; SDL_Rect** modes; char **res; const char *s; /* Get size. */ window_dimWindow( wid, &w, &h ); /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", opt_close ); window_addButton( wid, -20 - 1*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnApply", "Apply", opt_videoSave ); window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnDefaults", "Defaults", opt_videoDefaults ); /* Resolution bits. */ cw = (w-60)/2; x = 20; y = -60; window_addText( wid, x+20, y, 100, 20, 0, "txtSRes", NULL, &cDConsole, "Resolution" ); y -= 40; window_addInput( wid, x, y, 100, 20, "inpRes", 16, 1, NULL ); snprintf( buf, sizeof(buf), "%dx%d", conf.width, conf.height ); window_setInput( wid, "inpRes", buf ); window_setInputFilter( wid, "inpRes", "abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWXYZ[]{}()-=*/\\'\"~<>!@#$%^&|_`" ); window_addCheckbox( wid, x+20+100, y, 100, 20, "chkFullscreen", "Fullscreen", NULL, conf.fullscreen ); y -= 30; modes = SDL_ListModes( NULL, SDL_OPENGL | SDL_FULLSCREEN ); j = 1; for (i=0; modes[i]; i++) { if ((modes[i]->w == conf.width) && (modes[i]->h == conf.height)) j = 0; } res = malloc( sizeof(char*) * (i+j) ); nres = 0; if (j) { res[0] = malloc(16); snprintf( res[0], 16, "%dx%d", conf.width, conf.height ); res_def = 0; nres = 1; } for (i=0; modes[i]; i++) { res[ nres ] = malloc(16); snprintf( res[ nres ], 16, "%dx%d", modes[i]->w, modes[i]->h ); if ((modes[i]->w == conf.width) && (modes[i]->h == conf.height)) res_def = i; nres++; } window_addList( wid, x, y, 140, 100, "lstRes", res, nres, -1, opt_videoRes ); y -= 150; /* FPS stuff. */ window_addText( wid, x+20, y, 100, 20, 0, "txtFPSTitle", NULL, &cDConsole, "FPS Control" ); y -= 30; s = "FPS Limit"; l = gl_printWidthRaw( NULL, s ); window_addText( wid, x, y, l, 20, 1, "txtSFPS", NULL, &cBlack, s ); window_addInput( wid, x+l+20, y, 40, 20, "inpFPS", 4, 1, NULL ); toolkit_setListPos( wid, "lstRes", res_def); window_setInputFilter( wid, "inpFPS", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ[]{}()-=*/\\'\"~<>!@#$%^&|_`" ); y -= 30; window_addCheckbox( wid, x, y, cw, 20, "chkFPS", "Show FPS", NULL, conf.fps_show ); y -= 40; /* OpenGL options. */ x = 20+cw+20; y = -60; window_addText( wid, x+20, y, 100, 20, 0, "txtSGL", NULL, &cDConsole, "OpenGL" ); y -= 30; window_addCheckbox( wid, x, y, cw, 20, "chkVSync", "Vertical Sync", NULL, conf.vsync ); y -= 20; window_addCheckbox( wid, x, y, cw, 20, "chkVBO", "Vertex Buffer Objects*", NULL, conf.vbo ); y -= 20; window_addCheckbox( wid, x, y, cw, 20, "chkMipmaps", "Mipmaps*", NULL, conf.mipmaps ); y -= 20; window_addCheckbox( wid, x, y, cw, 20, "chkInterpolate", "Interpolation*", NULL, conf.interpolate ); y -= 20; window_addCheckbox( wid, x, y, cw, 20, "chkNPOT", "NPOT Textures*", NULL, conf.npot ); y -= 30; window_addText( wid, x, y, cw, 20, 1, "txtSCompat", NULL, &cBlack, "*Disable for compatibility." ); y -= 40; /* Features. */ window_addText( wid, x+20, y, 100, 20, 0, "txtSFeatures", NULL, &cDConsole, "Features" ); y -= 30; window_addCheckbox( wid, x, y, cw, 20, "chkEngineGlow", "Engine Glow (More RAM)", NULL, conf.engineglow ); y -= 20; /* Restart text. */ window_addText( wid, 20, 10, 3*(BUTTON_WIDTH + 20), 30, 0, "txtRestart", &gl_smallFont, &cBlack, NULL ); }
/** * @brief Opens the gameplay menu. */ static void opt_gameplay( unsigned int wid ) { (void) wid; char buf[PATH_MAX]; const char *path; int cw; int w, h, y, x, by, l; char *s; /* Get size. */ window_dimWindow( wid, &w, &h ); /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", opt_close ); window_addButton( wid, -20 - 1*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnApply", "Apply", opt_gameplaySave ); window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnDefaults", "Defaults", opt_gameplayDefaults ); /* Information. */ cw = (w-40); x = 20; y = -60; window_addText( wid, x, y, cw, 20, 1, "txtVersion", NULL, NULL, naev_version(1) ); y -= 20; #ifdef GIT_COMMIT window_addText( wid, x, y, cw, 20, 1, "txtCommit", NULL, NULL, "Commit: "GIT_COMMIT ); #endif /* GIT_COMMIT */ y -= 20; path = ndata_getPath(); if (path == NULL) snprintf( buf, sizeof(buf), "not using ndata" ); else snprintf( buf, sizeof(buf), "ndata: %s", path); window_addText( wid, x, y, cw, 20, 1, "txtNdata", NULL, NULL, buf ); y -= 50; by = y; /* Compiletime stuff. */ cw = (w-60)/2; y = by; x = 20; window_addText( wid, x+20, y, cw, 20, 0, "txtCompile", NULL, &cDConsole, "Compilation Flags" ); y -= 30; window_addText( wid, x, y, cw, h+y-20, 0, "txtFlags", NULL, NULL, "" #ifdef DEBUGGING #ifdef DEBUG_PARANOID "Debug Paranoid\n" #else /* DEBUG_PARANOID */ "Debug\n" #endif /* DEBUG_PARANOID */ #endif /* DEBUGGING */ #if defined(LINUX) "Linux\n" #elif defined(FREEBSD) "FreeBSD\n" #elif defined(MACOSX) "Mac OS X\n" #elif defined(WIN32) "Windows\n" #else "Unknown OS\n" #endif #ifdef USE_OPENAL "With OpenAL\n" #endif /* USE_OPENAL */ #ifdef USE_SDLMIX "With SDL_mixer\n" #endif #ifdef NDATA_DEF "ndata: "NDATA_DEF"\n" #endif /* NDATA_DEF */ ); /* Options. */ y = by; x += cw; window_addText( wid, x+20, y, cw, 20, 0, "txtSettings", NULL, &cDConsole, "Settings" ); y -= 30; window_addCheckbox( wid, x, y, cw, 20, "chkAfterburn", "Enable doubletap afterburn", NULL, conf.afterburn_sens ); y -= 20; window_addCheckbox( wid, x, y, cw, 20, "chkCompress", "Enable savegame compression", NULL, conf.save_compress ); y -= 50; s = "Visible messages"; l = gl_printWidthRaw( NULL, s ); window_addText( wid, x, y, l, 20, 1, "txtSMSG", NULL, &cBlack, s ); window_addInput( wid, x+l+20, y, 40, 20, "inpMSG", 4, 1 ); y -= 20; /* Restart text. */ window_addText( wid, -20, 20+BUTTON_HEIGHT+20, 3*(BUTTON_WIDTH + 20), 30, 1, "txtRestart", &gl_smallFont, &cBlack, NULL ); /* Update. */ opt_gameplayUpdate( wid, NULL ); }