/** * @brief Handles the CLI input. * * @param wid Window recieving the input. * @param unused Unused. */ static void cli_input( unsigned int wid, char *unused ) { (void) unused; int status; char *str; lua_State *L; char buf[LINE_LENGTH]; /* Get the input. */ str = window_getInput( wid, "inpInput" ); /* Ignore useless stuff. */ if ((str == NULL) || (str[0] == '\0')) return; /* Put the message in the console. */ snprintf( buf, LINE_LENGTH, "%s %s", cli_firstline ? "> " : ">>", str ); cli_addMessage( buf ); /* Set up state. */ L = cli_state; /* Load the string. */ lua_pushstring( L, str ); /* Concat string if needed. */ if (!cli_firstline) { lua_pushliteral(L, "\n"); /* add a new line... */ lua_insert(L, -2); /* ...between the two lines */ lua_concat(L, 3); /* join them */ } status = luaL_loadbuffer( L, lua_tostring(L,-1), lua_strlen(L,-1), "=cli" ); /* String isn't proper Lua yet. */ if (status == LUA_ERRSYNTAX) { size_t lmsg; const char *msg = lua_tolstring(L, -1, &lmsg); const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1); if (strstr(msg, LUA_QL("<eof>")) == tp) { /* Pop the loaded buffer. */ lua_pop(L, 1); cli_firstline = 0; } else { /* Real error, spew message and break. */ cli_addMessage( lua_tostring(L, -1) ); lua_settop(L, 0); cli_firstline = 1; } } /* Print results - all went well. */ else if (status == 0) { if (lua_pcall(L, 0, LUA_MULTRET, 0)) cli_addMessage( lua_tostring(L, -1) ); /* Clear stack. */ lua_settop(L, 0); cli_firstline = 1; } /* Clear the box now. */ window_setInput( wid, "inpInput", 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 Saves the gameplay options. */ static void opt_gameplaySave( unsigned int wid, char *str ) { (void) str; int f; char *vmsg, *tmax; /* Checkboxes. */ f = window_checkboxState( wid, "chkAfterburn" ); if (!!conf.afterburn_sens != f) { conf.afterburn_sens = (!!f)*250; } conf.zoom_manual = window_checkboxState( wid, "chkZoomManual" ); conf.mouse_thrust = window_checkboxState(wid, "chkMouseThrust" ); conf.save_compress = window_checkboxState( wid, "chkCompress" ); /* Input boxes. */ vmsg = window_getInput( wid, "inpMSG" ); tmax = window_getInput( wid, "inpTMax" ); conf.mesg_visible = atoi(vmsg); conf.compression_mult = atoi(tmax); if (conf.mesg_visible == 0) conf.mesg_visible = 5; }
/** * @brief Saves the gameplay options. */ static void opt_gameplaySave( unsigned int wid, char *str ) { (void) str; int f; char *inp; /* Checkboxes. */ f = window_checkboxState( wid, "chkAfterburn" ); if (!!conf.afterburn_sens != f) { conf.afterburn_sens = (!!f)*250; } conf.save_compress = window_checkboxState( wid, "chkCompress" ); /* Input boxes. */ inp = window_getInput( wid, "inpMSG" ); conf.mesg_visible = atoi(inp); if (conf.mesg_visible == 0) conf.mesg_visible = 5; }
/** * @brief Saves the video settings. */ static void opt_videoSave( unsigned int wid, char *str ) { (void) str; int i, j, s; char *inp, buf[16], width[16], height[16]; int w, h, f; /* Handle resolution. */ inp = window_getInput( wid, "inpRes" ); memset( width, '\0', sizeof(width) ); memset( height, '\0', sizeof(height) ); j = 0; s = 0; for (i=0; i<16; i++) { if (isdigit(inp[i])) { if (j==0) width[s++] = inp[i]; else height[s++] = inp[i]; } else { j++; s = 0; } } w = atoi(width); h = atoi(height); if ((w==0) || (h==0)) { dialogue_alert( "Height/Width invalid. Should be formatted like 1024x768." ); return; } if ((w != conf.width) || (h != conf.height)) { conf.explicit_dim = 1; conf.width = w; conf.height = h; opt_needRestart(); snprintf( buf, sizeof(buf), "%dx%d", conf.width, conf.height ); window_setInput( wid, "inpRes", buf ); } /* Fullscreen. */ f = window_checkboxState( wid, "chkFullscreen" ); if (conf.fullscreen != f) { conf.fullscreen = f; opt_needRestart(); } /* FPS. */ conf.fps_show = window_checkboxState( wid, "chkFPS" ); inp = window_getInput( wid, "inpFPS" ); conf.fps_max = atoi(inp); /* OpenGL. */ f = window_checkboxState( wid, "chkVSync" ); if (conf.vsync != f) { conf.vsync = f; opt_needRestart(); } f = window_checkboxState( wid, "chkVBO" ); if (conf.vbo != f) { conf.vbo = f; opt_needRestart(); } f = window_checkboxState( wid, "chkMipmaps" ); if (conf.mipmaps != f) { conf.mipmaps = f; opt_needRestart(); } f = window_checkboxState( wid, "chkInterpolate" ); if (conf.interpolate != f) { conf.interpolate = f; opt_needRestart(); } f = window_checkboxState( wid, "chkNPOT" ); if (conf.npot != f) { conf.npot = f; opt_needRestart(); } /* Features. */ f = window_checkboxState( wid, "chkEngineGlow" ); if (conf.engineglow != f) { conf.engineglow = f; opt_needRestart(); } }