/** * @brief Creates the current mission list for the mission menu. * @param first 1 if it's the first time run. */ static void mission_menu_genList( unsigned int wid, int first ) { int i,j; char** misn_names; if (!first) window_destroyWidget( wid, "lstMission" ); /* list */ misn_names = malloc(sizeof(char*) * MISSION_MAX); j = 0; for (i=0; i<MISSION_MAX; i++) if (player_missions[i].id != 0) misn_names[j++] = strdup(player_missions[i].title); if (j==0) { /* no missions */ free(misn_names); misn_names = malloc(sizeof(char*)); misn_names[0] = strdup("No Missions"); j = 1; } window_addList( wid, 20, -40, 300, MISSIONS_HEIGHT-340, "lstMission", misn_names, j, 0, mission_menu_update ); mission_menu_update(wid ,NULL); }
/** * @brief Opens the licenses menu. */ static void info_licenses_menu( unsigned int parent, char* str ) { (void) str; unsigned int wid; char **licenses; int nlicenses; int i; char **buf; /* Create window */ wid = window_create( "Licenses", -1, -1, LICENSES_WIDTH, LICENSES_HEIGHT ); window_setParent( wid, parent ); /* List. */ buf = player_getLicenses( &nlicenses ); licenses = malloc(sizeof(char*)*nlicenses); for (i=0; i<nlicenses; i++) licenses[i] = strdup(buf[i]); window_addList( wid, 20, -40, LICENSES_WIDTH-40, LICENSES_HEIGHT-80-BUTTON_HEIGHT, "lstLicenses", licenses, nlicenses, 0, NULL ); /* Buttons */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "closeLicenses", "Close", window_close ); }
/** * @brief Generates the weapons list. */ static void weapons_genList( unsigned int wid ) { const char *str; char **buf; int i; int w, h; /* Get the dimensions. */ window_dimWindow( wid, &w, &h ); /* Destroy widget if needed. */ if (widget_exists( wid, "lstWeapSets" )) window_destroyWidget( wid, "lstWeapSets" ); /* List */ buf = malloc( sizeof(char*) * PILOT_WEAPON_SETS ); for (i=0; i<PILOT_WEAPON_SETS; i++) { str = pilot_weapSetName( info_eq_weaps.selected, i ); if (str == NULL) { buf[i] = malloc( sizeof(char) * PATH_MAX ); snprintf( buf[i], PATH_MAX, "Weapon Set %d", (i+1)%10 ); } else { buf[i] = strdup( str ); } } window_addList( wid, 20+180+20, -40, w - (20+180+20+20), 160, "lstWeapSets", buf, PILOT_WEAPON_SETS, 0, weapons_update ); /* Update. */ weapons_update( wid, NULL ); }
/** * @brief Creates the current mission list for the mission menu. * @param first 1 if it's the first time run. */ static void mission_menu_genList( unsigned int wid, int first ) { int i,j; char** misn_names; int w, h; if (!first) window_destroyWidget( wid, "lstMission" ); /* Get the dimensions. */ window_dimWindow( wid, &w, &h ); /* list */ misn_names = malloc(sizeof(char*) * MISSION_MAX); j = 0; for (i=0; i<MISSION_MAX; i++) if (player_missions[i].id != 0) misn_names[j++] = (player_missions[i].title!=NULL) ? strdup(player_missions[i].title) : NULL; if (j==0) { /* no missions */ misn_names[0] = strdup("No Missions"); j = 1; } window_addList( wid, 20, -40, 300, h-340, "lstMission", misn_names, j, 0, mission_menu_update ); }
/** * @brief Opens the main info window. */ static void info_openMain( unsigned int wid ) { char str[128], **buf, creds[ECON_CRED_STRLEN]; char **licenses; int nlicenses; int i; char *nt; int w, h; /* Get the dimensions. */ window_dimWindow( wid, &w, &h ); /* pilot generics */ nt = ntime_pretty( ntime_get(), 2 ); window_addText( wid, 40, 20, 120, h-80, 0, "txtDPilot", &gl_smallFont, &cDConsole, "Pilot:\n" "Date:\n" "Combat Rating:\n" "\n" "Money:\n" "Ship:\n" "Fuel:" ); credits2str( creds, player.p->credits, 2 ); snprintf( str, 128, "%s\n" "%s\n" "%s\n" "\n" "%s Credits\n" "%s\n" "%.0f (%d Jumps)", player.name, nt, player_rating(), creds, player.p->name, player.p->fuel, pilot_getJumps(player.p) ); window_addText( wid, 140, 20, 200, h-80, 0, "txtPilot", &gl_smallFont, &cBlack, str ); free(nt); /* menu */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", info_close ); /* List. */ buf = player_getLicenses( &nlicenses ); licenses = malloc(sizeof(char*)*nlicenses); for (i=0; i<nlicenses; i++) licenses[i] = strdup(buf[i]); window_addText( wid, -20, -40, w-80-200-40, 20, 1, "txtList", NULL, &cDConsole, "Licenses" ); window_addList( wid, -20, -70, w-80-200-40, h-110-BUTTON_HEIGHT, "lstLicenses", licenses, nlicenses, 0, NULL ); }
/** * @brief Opens the local market window. */ static void commodity_exchange_open( unsigned int wid ) { int i, ngoods; char **goods; int w, h; /* Get window dimensions. */ window_dimWindow( wid, &w, &h ); /* buttons */ window_addButton( wid, -20, 20, LAND_BUTTON_WIDTH, LAND_BUTTON_HEIGHT, "btnCommodityClose", "Takeoff", land_buttonTakeoff ); window_addButton( wid, -40-((LAND_BUTTON_WIDTH-20)/2), 20*2 + LAND_BUTTON_HEIGHT, (LAND_BUTTON_WIDTH-20)/2, LAND_BUTTON_HEIGHT, "btnCommodityBuy", "Buy", commodity_buy ); window_addButton( wid, -20, 20*2 + LAND_BUTTON_HEIGHT, (LAND_BUTTON_WIDTH-20)/2, LAND_BUTTON_HEIGHT, "btnCommoditySell", "Sell", commodity_sell ); /* cust draws the modifier */ window_addCust( wid, -40-((LAND_BUTTON_WIDTH-20)/2), 60+ 2*LAND_BUTTON_HEIGHT, (LAND_BUTTON_WIDTH-20)/2, LAND_BUTTON_HEIGHT, "cstMod", 0, commodity_renderMod, NULL, NULL ); /* text */ window_addText( wid, -20, -40, LAND_BUTTON_WIDTH, 60, 0, "txtSInfo", &gl_smallFont, &cDConsole, "You have:\n" "Market price:\n" "\n" "Free Space:\n" ); window_addText( wid, -20, -40, LAND_BUTTON_WIDTH/2, 60, 0, "txtDInfo", &gl_smallFont, &cBlack, NULL ); window_addText( wid, -40, -120, LAND_BUTTON_WIDTH-20, h-140-LAND_BUTTON_HEIGHT, 0, "txtDesc", &gl_smallFont, &cBlack, NULL ); /* goods list */ if (land_planet->ncommodities > 0) { goods = malloc(sizeof(char*) * land_planet->ncommodities); for (i=0; i<land_planet->ncommodities; i++) goods[i] = strdup(land_planet->commodities[i]->name); ngoods = land_planet->ncommodities; } else { goods = malloc( sizeof(char*) ); goods[0] = strdup("None"); ngoods = 1; } window_addList( wid, 20, -40, w-LAND_BUTTON_WIDTH-60, h-80-LAND_BUTTON_HEIGHT, "lstGoods", goods, ngoods, 0, commodity_update ); /* update */ commodity_update(wid, NULL); }
/** * @brief Allows the player to set a different GUI. * * @param wid Window id. * @param name of widget. */ static void info_setGui( unsigned int wid, char* str ) { (void)str; int i; char **guis; int nguis; char **gui_copy; /* Get the available GUIs. */ guis = player_guiList( &nguis ); /* In case there are none. */ if (guis == NULL) { WARN("No GUI available."); dialogue_alert( "There are no GUI available, this means something went wrong somewhere. Inform the Naev maintainer." ); return; } /* window */ wid = window_create( "Select GUI", -1, -1, SETGUI_WIDTH, SETGUI_HEIGHT ); window_setCancel( wid, setgui_close ); /* Copy GUI. */ gui_copy = malloc( sizeof(char*) * nguis ); for (i=0; i<nguis; i++) gui_copy[i] = strdup( guis[i] ); /* List */ window_addList( wid, 20, -50, SETGUI_WIDTH-BUTTON_WIDTH/2 - 60, SETGUI_HEIGHT-110, "lstGUI", gui_copy, nguis, 0, NULL ); toolkit_setList( wid, "lstGUI", gui_pick() ); /* buttons */ window_addButton( wid, -20, 20, BUTTON_WIDTH/2, BUTTON_HEIGHT, "btnBack", "Cancel", setgui_close ); window_addButton( wid, -20, 30 + BUTTON_HEIGHT, BUTTON_WIDTH/2, BUTTON_HEIGHT, "btnLoad", "Load", setgui_load ); /* Checkboxes */ window_addCheckbox( wid, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "chkOverride", "Override GUI", info_toggleGuiOverride, player.guiOverride ); info_toggleGuiOverride( wid, "chkOverride" ); /* default action */ window_setAccept( wid, setgui_load ); }
static void menuKeybinds_genList( unsigned int wid ) { int i, j; char **str; SDLKey key; KeybindType type; SDLMod mod; int w, h; int lw, lh; /* Get dimensions. */ menuKeybinds_getDim( wid, &w, &h, &lw, &lh, NULL, NULL ); /* Create the list. */ for (i=0; strcmp(keybindNames[i],"end"); i++); str = malloc(sizeof(char*) * i); for (j=0; j < i; j++) { str[j] = malloc(sizeof(char) * 64); key = input_getKeybind( keybindNames[j], &type, &mod ); switch (type) { case KEYBIND_KEYBOARD: /* SDL_GetKeyName returns lowercase which is ugly. */ if (nstd_isalpha(key)) snprintf(str[j], 64, "%s <%c>", keybindNames[j], nstd_toupper(key) ); else snprintf(str[j], 64, "%s <%s>", keybindNames[j], SDL_GetKeyName(key) ); break; case KEYBIND_JAXISPOS: snprintf(str[j], 64, "%s <ja+%d>", keybindNames[j], key); break; case KEYBIND_JAXISNEG: snprintf(str[j], 64, "%s <ja-%d>", keybindNames[j], key); break; case KEYBIND_JBUTTON: snprintf(str[j], 64, "%s <jb%d>", keybindNames[j], key); break; default: snprintf(str[j], 64, "%s", keybindNames[j]); break; } } window_addList( wid, 20, -40, lw, lh, "lstKeybinds", str, i, 0, menuKeybinds_update ); /* Update the list. */ menuKeybinds_update( wid, NULL ); }
/** * @brief Opens the load game menu. */ void load_game_menu (void) { unsigned int wid; char **files; int nfiles, i, len; /* window */ wid = window_create( "Load Game", -1, -1, LOAD_WIDTH, LOAD_HEIGHT ); window_setCancel( wid, load_menu_close ); /* load the saves */ files = nfile_readDir( &nfiles, "%ssaves", nfile_basePath() ); for (i=0; i<nfiles; i++) { len = strlen(files[i]); /* no save extension */ if ((len < 5) || strcmp(&files[i][len-3],".ns")) { free(files[i]); memmove( &files[i], &files[i+1], sizeof(char*) * (nfiles-i-1) ); nfiles--; i--; } else /* remove the extension */ files[i][len-3] = '\0'; } /* case there are no files */ if (files == NULL) { files = malloc(sizeof(char*)); files[0] = strdup("None"); nfiles = 1; } window_addList( wid, 20, -50, LOAD_WIDTH-BUTTON_WIDTH-50, LOAD_HEIGHT-110, "lstSaves", files, nfiles, 0, NULL ); /* buttons */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnBack", "Back", load_menu_close ); window_addButton( wid, -20, 30 + BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT, "btnLoad", "Load", load_menu_load ); window_addButton( wid, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnDelete", "Del", load_menu_delete ); /* default action */ window_setAccept( wid, load_menu_load ); }
/** * @brief Shows the player his cargo. * * @param str Unused. */ static void info_cargo_menu( unsigned int parent, char* str ) { (void) str; unsigned int wid; char **buf; int nbuf; int i; /* Create the window */ wid = window_create( "Cargo", -1, -1, CARGO_WIDTH, CARGO_HEIGHT ); window_setParent( wid, parent ); /* Buttons */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "closeCargo", "Back", window_close ); window_addButton( wid, -40 - BUTTON_WIDTH, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnJettisonCargo", "Jettison", cargo_jettison ); window_disableButton( wid, "btnJettisonCargo" ); /* List */ if (player->ncommodities==0) { /* No cargo */ buf = malloc(sizeof(char*)); buf[0] = strdup("None"); nbuf = 1; } else { /* List the player's cargo */ buf = malloc(sizeof(char*)*player->ncommodities); for (i=0; i<player->ncommodities; i++) { buf[i] = malloc(sizeof(char)*128); snprintf(buf[i],128, "%s%s %d", player->commodities[i].commodity->name, (player->commodities[i].id != 0) ? "*" : "", player->commodities[i].quantity); } nbuf = player->ncommodities; } window_addList( wid, 20, -40, CARGO_WIDTH - 40, CARGO_HEIGHT - BUTTON_HEIGHT - 80, "lstCargo", buf, nbuf, 0, cargo_update ); cargo_update(wid, NULL); }
/** * @brief Displays the player's standings. */ static void info_openStandings( unsigned int wid ) { int i; int n, m; char **str; int w, h, lw; /* Get dimensions. */ info_getDim( wid, &w, &h, &lw ); /* On close. */ window_onClose( wid, standings_close ); /* Buttons */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "closeMissions", "Close", info_close ); /* Graphics. */ window_addImage( wid, 0, 0, 0, 0, "imgLogo", NULL, 0 ); /* Text. */ window_addText( wid, lw+40, 0, (w-(lw+60)), 20, 1, "txtName", &gl_defFont, &cDConsole, NULL ); window_addText( wid, lw+40, 0, (w-(lw+60)), 20, 1, "txtStanding", &gl_smallFont, &cBlack, NULL ); /* Gets the faction standings. */ info_factions = faction_getAll( &n ); str = malloc( sizeof(char*) * n ); /* Create list. */ for (i=0; i<n; i++) { str[i] = malloc( 256 ); m = round( faction_getPlayer( info_factions[i] ) ); snprintf( str[i], 256, "%s [ %+d%% ]", faction_name( info_factions[i] ), m ); } /* Display list. */ window_addList( wid, 20, -40, lw, h-60, "lstStandings", str, n, 0, standings_update ); standings_update( wid , NULL ); }
/** * @brief Generates the mission list. * @param wid Window to generate the mission list for. * @param first Is it the first time generated? */ static void misn_genList( unsigned int wid, int first ) { int i,j; char** misn_names, *focused; int w,h; /* Save focus. */ focused = strdup(window_getFocus(wid)); if (!first) window_destroyWidget( wid, "lstMission" ); /* Get window dimensions. */ window_dimWindow( wid, &w, &h ); /* list */ j = 1; /* make sure we don't accidentally free the memory twice. */ misn_names = NULL; if (mission_ncomputer > 0) { /* there are missions */ misn_names = malloc(sizeof(char*) * mission_ncomputer); j = 0; for (i=0; i<mission_ncomputer; i++) if (mission_computer[i].title != NULL) misn_names[j++] = strdup(mission_computer[i].title); } if ((misn_names==NULL) || (mission_ncomputer==0) || (j==0)) { /* no missions. */ if (j==0) free(misn_names); misn_names = malloc(sizeof(char*)); misn_names[0] = strdup("No Missions"); j = 1; } window_addList( wid, 20, -40, w/2 - 30, h/2 - 35, "lstMission", misn_names, j, 0, misn_update ); /* Restore focus. */ window_setFocus( wid, focused ); free(focused); /* duplicateed the save focus functionaility from the bar */ }
/** * @brief Generates the cargo list. */ static void cargo_genList( unsigned int wid ) { char **buf; int nbuf; int i; int w, h; /* Get the dimensions. */ window_dimWindow( wid, &w, &h ); /* Destroy widget if needed. */ if (widget_exists( wid, "lstCargo" )) window_destroyWidget( wid, "lstCargo" ); /* List */ if (player.p->ncommodities==0) { /* No cargo */ buf = malloc(sizeof(char*)); buf[0] = strdup("None"); nbuf = 1; } else { /* List the player's cargo */ buf = malloc(sizeof(char*)*player.p->ncommodities); for (i=0; i<player.p->ncommodities; i++) { buf[i] = malloc(sizeof(char)*128); snprintf(buf[i],128, "%s%s %d", player.p->commodities[i].commodity->name, (player.p->commodities[i].id != 0) ? "*" : "", player.p->commodities[i].quantity); } nbuf = player.p->ncommodities; } window_addList( wid, 20, -40, w - 40, h - BUTTON_HEIGHT - 80, "lstCargo", buf, nbuf, 0, cargo_update ); cargo_update(wid, NULL); }
/** * @brief Generates the weapons list. */ static void weapons_genList( unsigned int wid ) { const char *str; char **buf, tbuf[256]; int i, n; int w, h; /* Get the dimensions. */ window_dimWindow( wid, &w, &h ); /* Destroy widget if needed. */ if (widget_exists( wid, "lstWeapSets" )) { window_destroyWidget( wid, "lstWeapSets" ); n = toolkit_getListPos( wid, "lstWeapSets" ); } else n = -1; /* List */ buf = malloc( sizeof(char*) * PILOT_WEAPON_SETS ); for (i=0; i<PILOT_WEAPON_SETS; i++) { str = pilot_weapSetName( info_eq_weaps.selected, i ); if (str == NULL) snprintf( tbuf, sizeof(tbuf), "%d - ??", (i+1)%10 ); else snprintf( tbuf, sizeof(tbuf), "%d - %s", (i+1)%10, str ); buf[i] = strdup( tbuf ); } window_addList( wid, 20+180+20, -40, w - (20+180+20+20), 160, "lstWeapSets", buf, PILOT_WEAPON_SETS, 0, weapons_update ); /* Restore position. */ if (n >= 0) toolkit_setListPos( wid, "lstWeapSets", n ); }
/** * @brief Generates the mission list. * @param wid Window to generate the mission list for. * @param first Is it the first time generated? */ static void misn_genList( unsigned int wid, int first ) { int i,j; char** misn_names; int w,h; if (!first) window_destroyWidget( wid, "lstMission" ); /* Get window dimensions. */ window_dimWindow( wid, &w, &h ); /* list */ j = 1; /* make sure we don't accidentally free the memory twice. */ misn_names = NULL; if (mission_ncomputer > 0) { /* there are missions */ misn_names = malloc(sizeof(char*) * mission_ncomputer); j = 0; for (i=0; i<mission_ncomputer; i++) if (mission_computer[i].title != NULL) misn_names[j++] = strdup(mission_computer[i].title); } if ((misn_names==NULL) || (mission_ncomputer==0) || (j==0)) { /* no missions. */ if (j==0) free(misn_names); misn_names = malloc(sizeof(char*)); misn_names[0] = strdup("No Missions"); j = 1; } window_addList( wid, 20, -40, w/2 - 30, h/2 - 35, "lstMission", misn_names, j, 0, misn_update ); /* Update the list. */ misn_update( wid, NULL ); }
/** * @brief Opens the audio settings menu. */ static void opt_audio( unsigned int wid ) { (void) wid; int i, j; int cw; int w, h, y, x, l; char buf[32], **s; const char *str; /* 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_audioSave ); window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnDefaults", "Defaults", opt_audioDefaults ); /* General options. */ cw = (w-60)/2; x = 20; y = -60; window_addText( wid, x+20, y, cw, 20, 0, "txtSGeneral", NULL, &cDConsole, "General" ); y -= 30; window_addCheckbox( wid, x, y, cw, 20, "chkNosound", "Disable all sound/music", NULL, conf.nosound ); y -= 30; str = "Backends"; l = gl_printWidthRaw( NULL, str ); window_addText( wid, x, y, l, 40, 0, "txtSBackends", NULL, NULL, str ); l += 10; i = 0; j = 0; s = malloc(sizeof(char*)*2); #if USE_OPENAL if (strcmp(conf.sound_backend,"openal")==0) j = i; s[i++] = strdup("openal"); #endif /* USE_OPENAL */ #if USE_SDLMIX if (strcmp(conf.sound_backend,"sdlmix")==0) j = i; s[i++] = strdup("sdlmix"); #endif /* USE_SDLMIX */ if (i==0) s[i++] = strdup("none"); window_addList( wid, x+l, y, cw-(x+l), 40, "lstSound", s, i, j, NULL ); y -= 50; /* OpenAL options. */ window_addText( wid, x+20, y, cw, 20, 0, "txtSOpenal", NULL, &cDConsole, "OpenAL" ); y -= 30; window_addCheckbox( wid, x, y, cw, 20, "chkEFX", "EFX (More CPU)", NULL, conf.al_efx ); y -= 20; /* Sound levels. */ x = 20 + cw + 20; y = -60; window_addText( wid, x+20, y, 100, 20, 0, "txtSVolume", NULL, &cDConsole, "Volume Levels" ); y -= 30; /* Sound fader. */ opt_audioLevelStr( buf, sizeof(buf), 0, sound_getVolume() ); window_addText( wid, x, y, cw, 20, 1, "txtSound", NULL, NULL, buf ); y -= 20; window_addFader( wid, x, y, cw, 20, "fadSound", 0., 1., sound_getVolume(), opt_setAudioLevel ); window_faderScrollDone( wid, "fadSound", opt_beep ); y -= 40; /* Music fader. */ opt_audioLevelStr( buf, sizeof(buf), 1, music_getVolume() ); window_addText( wid, x, y, cw, 20, 1, "txtMusic", NULL, NULL, buf ); y -= 20; window_addFader( wid, x, y, cw, 20, "fadMusic", 0., 1., music_getVolume(), opt_setAudioLevel ); y -= 20; /* Restart text. */ window_addText( wid, 20, 10, 3*(BUTTON_WIDTH + 20), 30, 0, "txtRestart", &gl_smallFont, &cBlack, NULL ); }
/** * @brief Generates the keybindings list. */ static void menuKeybinds_genList( unsigned int wid ) { int i, j, l, p; char **str, mod_text[64]; SDLKey key; KeybindType type; SDLMod mod; int w, h; int lw, lh; /* Get dimensions. */ menuKeybinds_getDim( wid, &w, &h, &lw, &lh, NULL, NULL ); /* Create the list. */ for (i=0; strcmp(keybind_info[i][0],"end"); i++); str = malloc(sizeof(char*) * i); for (j=0; j < i; j++) { l = 64; str[j] = malloc(sizeof(char) * l); key = input_getKeybind( keybind_info[j][0], &type, &mod ); switch (type) { case KEYBIND_KEYBOARD: /* Generate mod text. */ if (mod == NMOD_ALL) snprintf( mod_text, sizeof(mod_text), "any+" ); else { p = 0; mod_text[0] = '\0'; if (mod & NMOD_SHIFT) p += snprintf( &mod_text[p], sizeof(mod_text)-p, "shift+" ); if (mod & NMOD_CTRL) p += snprintf( &mod_text[p], sizeof(mod_text)-p, "ctrl+" ); if (mod & NMOD_ALT) p += snprintf( &mod_text[p], sizeof(mod_text)-p, "alt+" ); if (mod & NMOD_META) p += snprintf( &mod_text[p], sizeof(mod_text)-p, "meta+" ); } /* SDL_GetKeyName returns lowercase which is ugly. */ if (nstd_isalpha(key)) snprintf(str[j], l, "%s <%s%c>", keybind_info[j][1], mod_text, nstd_toupper(key) ); else snprintf(str[j], l, "%s <%s%s>", keybind_info[j][1], mod_text, SDL_GetKeyName(key) ); break; case KEYBIND_JAXISPOS: snprintf(str[j], l, "%s <ja+%d>", keybind_info[j][1], key); break; case KEYBIND_JAXISNEG: snprintf(str[j], l, "%s <ja-%d>", keybind_info[j][1], key); break; case KEYBIND_JBUTTON: snprintf(str[j], l, "%s <jb%d>", keybind_info[j][1], key); break; default: snprintf(str[j], l, "%s", keybind_info[j][1]); break; } } window_addList( wid, 20, -40, lw, lh, "lstKeybinds", str, i, 0, menuKeybinds_update ); }
/** * @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 Creates a list dialogue with OK and Cancel buttons, with a fixed message, * as well as a small extra area for the list to react to item selected events. * * @param title Title of the dialogue. * @param items Items in the list (should be all malloced, automatically freed). * @param nitems Number of items. * @param extrawidth Width of area to add for select_call callback. * @param minheight Minimum height for the window. * @param add_widgets This function is called with the new window as an argument * allowing for initial population of the extra area. * @param select_call (optional) This function is called when a new item in the list * is selected, receiving the window's id and the selected widgets name as * arguments. * @param msg string with text to display. */ int dialogue_listPanelRaw( const char* title, char **items, int nitems, int extrawidth, int minheight, void (*add_widgets) (unsigned int wid, int x, int y, int w, int h), void (*select_call) (unsigned int wid, char* wgtname, int x, int y, int w, int h), const char *msg ) { int i; int w, h, winw, winh; glFont* font; unsigned int wid; int list_width, list_height; int text_height, text_width; int done; if (input_dialogue.input_wid) return -1; font = dialogue_getSize( title, msg, &text_width, &text_height ); /* Calculate size stuff. */ list_width = 0; list_height = 0; for (i=0; i<nitems; i++) { list_width = MAX( list_width, gl_printWidthRaw( &gl_defFont, items[i] ) ); list_height += gl_defFont.h + 5; } list_height += 100; if (list_height > 500) h = (list_height*8)/10; else h = MAX( 300, list_height ); h = MIN( (SCREEN_H*2)/3, h ); w = MAX( list_width + 60, 200 ); winw = w + extrawidth; winh = MAX( h, minheight ); h = winh; /* Create the window. */ wid = window_create( title, -1, -1, winw, winh ); window_setData( wid, &done ); window_addText( wid, 20, -40, w-40, text_height, 0, "txtMsg", font, &cDConsole, msg ); window_setAccept( wid, dialogue_listClose ); window_setCancel( wid, dialogue_listCancel ); if(add_widgets) add_widgets(wid, w, 0, winw, winh); if(select_call) { input_dialogue.x = w; input_dialogue.y = 0; input_dialogue.w = winw; input_dialogue.h = winh; input_dialogue.item_select_cb = select_call; } /* Create the list. */ window_addList( wid, 20, -40-text_height-20, w-40, h - (40+text_height+20) - (20+30+20), "lstDialogue", items, nitems, 0, select_call_wrapper ); /* Create the buttons. */ window_addButton( wid, -20, 20, 60, 30, "btnOK", "OK", dialogue_listClose ); window_addButton( wid, -20-60-20, 20, 60, 30, "btnCancel", "Cancel", dialogue_listCancel ); dialogue_open++; toolkit_loop( &done ); /* cleanup */ input_dialogue.x = 0; input_dialogue.y = 0; input_dialogue.w = 0; input_dialogue.h = 0; input_dialogue.item_select_cb = NULL; return dialogue_listSelected; }