/** * @brief Saves the audio stuff. */ static void opt_audioSave( unsigned int wid, char *str ) { (void) str; int f; char *s; /* General. */ f = window_checkboxState( wid, "chkNosound" ); if (conf.nosound != f) { conf.nosound = f; opt_needRestart(); } /* Backend. */ s = toolkit_getList( wid, "lstSound" ); if (conf.sound_backend != NULL) { if (strcmp(s,conf.sound_backend)!=0) { free(conf.sound_backend); conf.sound_backend = strdup(s); opt_needRestart(); } } else { conf.sound_backend = strdup(s); opt_needRestart(); } /* OpenAL. */ f = window_checkboxState( wid, "chkEFX" ); if (conf.al_efx != f) { conf.al_efx = f; opt_needRestart(); } }
/** * @brief Updates the mission list. * @param wid Window of the mission computer. * @param str Unused. */ static void misn_update( unsigned int wid, char* str ) { (void) str; char *active_misn; Mission* misn; char txt[256], *buf; /* Clear computer markers. */ space_clearComputerMarkers(); /* Update date stuff. */ buf = ntime_pretty( 0, 2 ); snprintf( txt, sizeof(txt), "%s\n%d Tons", buf, player.p->cargo_free ); free(buf); window_modifyText( wid, "txtDate", txt ); active_misn = toolkit_getList( wid, "lstMission" ); if (strcmp(active_misn,"No Missions")==0) { window_modifyText( wid, "txtReward", "None" ); window_modifyText( wid, "txtDesc", "There are no missions available here." ); window_disableButton( wid, "btnAcceptMission" ); return; } misn = &mission_computer[ toolkit_getListPos( wid, "lstMission" ) ]; mission_sysComputerMark( misn ); if (misn->markers != NULL) map_center( system_getIndex( misn->markers[0].sys )->name ); window_modifyText( wid, "txtReward", misn->reward ); window_modifyText( wid, "txtDesc", misn->desc ); window_enableButton( wid, "btnAcceptMission" ); }
/** * @brief Updates the mission menu mission information based on what's selected. * @param str Unused. */ static void mission_menu_update( unsigned int wid, char* str ) { (void)str; char *active_misn; Mission* misn; active_misn = toolkit_getList( wid, "lstMission" ); if ((active_misn==NULL) || (strcmp(active_misn,"No Missions")==0)) { window_modifyText( wid, "txtReward", "None" ); window_modifyText( wid, "txtDesc", "You currently have no active missions." ); window_disableButton( wid, "btnAbortMission" ); return; } /* Modify the text. */ misn = &player_missions[ toolkit_getListPos(wid, "lstMission" ) ]; window_modifyText( wid, "txtReward", misn->reward ); window_modifyText( wid, "txtDesc", misn->desc ); window_enableButton( wid, "btnAbortMission" ); /* Select the system. */ if (misn->markers != NULL) map_center( system_getIndex( misn->markers[0].sys )->name ); }
/** * @brief Attempts to sell a commodity. * @param wid Window selling commodity from. * @param str Unused. */ static void commodity_sell( unsigned int wid, char* str ) { (void)str; char *comname; Commodity *com; unsigned int q; credits_t price; HookParam hparam[3]; /* Get parameters. */ q = commodity_getMod(); comname = toolkit_getList( wid, "lstGoods" ); com = commodity_get( comname ); price = planet_commodityPrice( land_planet, com ); /* Remove commodity. */ q = pilot_cargoRm( player.p, com, q ); price = price * (credits_t)q; player_modCredits( price ); land_checkAddRefuel(); commodity_update(wid, NULL); /* Run hooks. */ hparam[0].type = HOOK_PARAM_STRING; hparam[0].u.str = comname; hparam[1].type = HOOK_PARAM_NUMBER; hparam[1].u.num = q; hparam[2].type = HOOK_PARAM_SENTINEL; hooks_runParam( "comm_sell", hparam ); if (land_takeoff) takeoff(1); }
/** * @brief Updates the commodity window. * @param wid Window to update. * @param str Unused. */ static void commodity_update( unsigned int wid, char* str ) { (void)str; char buf[PATH_MAX]; char *comname; Commodity *com; comname = toolkit_getList( wid, "lstGoods" ); if ((comname==NULL) || (strcmp( comname, "None" )==0)) { snprintf( buf, PATH_MAX, "NA Tons\n" "NA Credits/Ton\n" "\n" "NA Tons\n" ); window_modifyText( wid, "txtDInfo", buf ); window_modifyText( wid, "txtDesc", "No outfits available." ); } com = commodity_get( comname ); /* modify text */ snprintf( buf, PATH_MAX, "%d Tons\n" "%"CREDITS_PRI" Credits/Ton\n" "\n" "%d Tons\n", pilot_cargoOwned( player.p, comname ), planet_commodityPrice( land_planet, com ), pilot_cargoFree(player.p)); window_modifyText( wid, "txtDInfo", buf ); window_modifyText( wid, "txtDesc", com->description ); }
/** * @brief Aborts a mission in the mission menu. * @param str Unused. */ static void mission_menu_abort( unsigned int wid, char* str ) { (void)str; char *selected_misn; int pos; Mission* misn; int ret; selected_misn = toolkit_getList( wid, "lstMission" ); if (dialogue_YesNo( "Abort Mission", "Are you sure you want to abort this mission?" )) { /* Get the mission. */ pos = toolkit_getListPos(wid, "lstMission" ); misn = &player_missions[pos]; /* We run the "abort" function if it's found. */ ret = misn_tryRun( misn, "abort" ); /* Now clean up mission. */ if (ret != 2) { mission_cleanup( misn ); memmove( misn, &player_missions[pos+1], sizeof(Mission) * (MISSION_MAX-pos-1) ); memset( &player_missions[MISSION_MAX-1], 0, sizeof(Mission) ); } /* Reset markers. */ mission_sysMark(); /* Regenerate list. */ mission_menu_genList(wid ,0); } }
/** * @brief Loads a GUI. * * @param wdw Window triggering function. * @param str Unused. */ static void setgui_load( unsigned int wdw, char *str ) { (void)str; char *gui; int wid; wid = window_get( _("Select GUI") ); gui = toolkit_getList( wid, "lstGUI" ); if (strcmp(gui,_("None")) == 0) return; if (player.guiOverride == 0) { if (dialogue_YesNo( _("GUI Override is not set."), _("Enable GUI Override and change GUI to '%s'?"), gui )) { player.guiOverride = 1; window_checkboxSet( wid, "chkOverride", player.guiOverride ); } else { return; } } /* Set the GUI. */ if (player.gui != NULL) free( player.gui ); player.gui = strdup( gui ); /* Close menus before loading for proper rendering. */ setgui_close(wdw, NULL); /* Load the GUI. */ gui_load( gui_pick() ); }
/** * @brief Updates the keybindings menu. * * @param wid Window to update. * @param name Unused. */ static void menuKeybinds_update( unsigned int wid, char *name ) { (void) name; int i; char *selected, *keybind; const char *desc; SDLKey key; KeybindType type; SDLMod mod; char buf[1024]; char binding[32]; /* Get the keybind. */ selected = toolkit_getList( wid, "lstKeybinds" ); /* Remove the excess. */ for (i=0; (selected[i] != '\0') && (selected[i] != ' '); i++) opt_selectedKeybind[i] = selected[i]; opt_selectedKeybind[i] = '\0'; keybind = opt_selectedKeybind; window_modifyText( wid, "txtName", keybind ); /* Get information. */ desc = input_getKeybindDescription( keybind ); key = input_getKeybind( keybind, &type, &mod ); /* Create the text. */ switch (type) { case KEYBIND_NULL: snprintf(binding, 64, "Not bound"); break; case KEYBIND_KEYBOARD: /* SDL_GetKeyName returns lowercase which is ugly. */ if (nstd_isalpha(key)) snprintf(binding, 32, "keyboard: %s%s%c", (mod != KMOD_NONE) ? input_modToText(mod) : "", (mod != KMOD_NONE) ? " + " : "", nstd_toupper(key)); else snprintf(binding, 32, "keyboard: %s%s%s", (mod != KMOD_NONE) ? input_modToText(mod) : "", (mod != KMOD_NONE) ? " + " : "", SDL_GetKeyName(key)); break; case KEYBIND_JAXISPOS: snprintf(binding, 64, "joy axis pos: <%d>", key ); break; case KEYBIND_JAXISNEG: snprintf(binding, 64, "joy axis neg: <%d>", key ); break; case KEYBIND_JBUTTON: snprintf(binding, 64, "joy button: <%d>", key); break; } /* Update text. */ snprintf(buf, 1024, "%s\n\n%s\n", desc, binding); window_modifyText( wid, "txtDesc", buf ); }
/** * @brief Accepts the selected mission. * @param wid Window of the mission computer. * @param str Unused. */ static void misn_accept( unsigned int wid, char* str ) { (void) str; char* misn_name; Mission* misn; int pos; int i, ret; misn_name = toolkit_getList( wid, "lstMission" ); /* Make sure you have missions. */ if (strcmp(misn_name,"No Missions")==0) return; /* Make sure player can accept the mission. */ for (i=0; i<MISSION_MAX; i++) if (player_missions[i].data == NULL) break; if (i >= MISSION_MAX) { dialogue_alert("You have too many active missions."); return; } if (dialogue_YesNo("Accept Mission", "Are you sure you want to accept this mission?")) { pos = toolkit_getListPos( wid, "lstMission" ); misn = &mission_computer[pos]; ret = mission_accept( misn ); if ((ret==0) || (ret==2) || (ret==-1)) { /* success in accepting the mission */ if (ret==-1) mission_cleanup( &mission_computer[pos] ); memmove( &mission_computer[pos], &mission_computer[pos+1], sizeof(Mission) * (mission_ncomputer-pos-1) ); mission_ncomputer--; /* Regenerate list. */ misn_genList(wid, 0); /* Add position persistancey after a mission has been accepted */ /* NOTE: toolkit_setListPos protects us from a bad position by clamping */ toolkit_setListPos( wid, "lstMission", pos-1 ); /*looks better without the -1, makes more sense with*/ } /* Reset markers. */ mission_sysMark(); } }
/** * @brief Buys the selected commodity. * @param wid Window buying from. * @param str Unused. */ static void commodity_buy( unsigned int wid, char* str ) { (void)str; char *comname; Commodity *com; unsigned int q; credits_t price; HookParam hparam[3]; /* Get selected. */ q = commodity_getMod(); comname = toolkit_getList( wid, "lstGoods" ); com = commodity_get( comname ); price = planet_commodityPrice( land_planet, com ); price *= q; /* Check stuff. */ if (!player_hasCredits( price )) { dialogue_alert( "Insufficient credits!" ); return; } else if (pilot_cargoFree(player.p) <= 0) { dialogue_alert( "Insufficient free space!" ); return; } /* Make the buy. */ q = pilot_cargoAdd( player.p, com, q ); player_modCredits( -price ); land_checkAddRefuel(); commodity_update(wid, NULL); /* Run hooks. */ hparam[0].type = HOOK_PARAM_STRING; hparam[0].u.str = comname; hparam[1].type = HOOK_PARAM_NUMBER; hparam[1].u.num = q; hparam[2].type = HOOK_PARAM_SENTINEL; hooks_runParam( "comm_buy", hparam ); if (land_takeoff) takeoff(1); }
/** * @brief Loads a GUI. * * @param wdw Window triggering function. * @param str Unused. */ static void setgui_load( unsigned int wdw, char *str ) { (void)str; char *gui; int wid; wid = window_get( "Select GUI" ); gui = toolkit_getList( wid, "lstGUI" ); if (strcmp(gui,"None") == 0) return; /* Set the GUI. */ if (player.gui != NULL) free( player.gui ); player.gui = strdup( gui ); /* Close menus before loading for proper rendering. */ setgui_close(wdw, NULL); /* Load the GUI. */ gui_load( gui_pick() ); }
/** * @brief Deletes an old game. * @param wdw Window to delete. * @param str Unused. */ static void load_menu_delete( unsigned int wdw, char *str ) { (void)str; char *save, path[PATH_MAX]; int wid; wid = window_get( "Load Game" ); save = toolkit_getList( wid, "lstSaves" ); if (strcmp(save,"None") == 0) return; if (dialogue_YesNo( "Permanently Delete?", "Are you sure you want to permanently delete '%s'?", save) == 0) return; snprintf( path, PATH_MAX, "%ssaves/%s.ns", nfile_basePath(), save ); remove(path); /* remove is portable and will call unlink on linux. */ /* need to reload the menu */ load_menu_close(wdw, NULL); load_game_menu(); }
/** * @brief Loads a new game. * @param wdw Window triggering function. * @param str Unused. */ static void load_menu_load( unsigned int wdw, char *str ) { (void)str; char *save, path[PATH_MAX]; int wid; wid = window_get( "Load Game" ); save = toolkit_getList( wid, "lstSaves" ); if (strcmp(save,"None") == 0) return; snprintf( path, PATH_MAX, "%ssaves/%s.ns", nfile_basePath(), save ); /* Close menus before loading for proper rendering. */ load_menu_close(wdw, NULL); menu_main_close(); if (load_game( path )) { menu_main(); load_game_menu(); } }
/** * @brief Callback when resolution changes. */ static void opt_videoRes( unsigned int wid, char *str ) { char *buf; buf = toolkit_getList( wid, str ); window_setInput( wid, "inpRes", buf ); }