X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fpreferences.cpp;h=e57380eb1f3a32e071501d901b365762cb4fb417;hb=832101b1611ef0ae21f2b0bc9854ee8481727b89;hp=ea993de5e6b1cbcae7bb3f80d26bec4f6e0ed7a6;hpb=fea0d2e6575b21945c4800805d66e43a2247ded5;p=xonotic%2Fnetradiant.git diff --git a/radiant/preferences.cpp b/radiant/preferences.cpp index ea993de5..e57380eb 100644 --- a/radiant/preferences.cpp +++ b/radiant/preferences.cpp @@ -121,7 +121,7 @@ CGameDescription::CGameDescription( xmlDocPtr pDoc, const CopiedString& gameFile { StringOutputStream path( 256 ); - path << AppPath_get() << gameFile.c_str() << "/"; + path << DataPath_get() << "gamepacks/" << gameFile.c_str() << "/"; mGameToolsPath = path.c_str(); } @@ -204,13 +204,10 @@ bool Preferences_Save( PreferenceDictionary& preferences, const char* filename ) } bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filename ){ - Array tmpName( filename, filename + strlen( filename ) + 1 + 3 ); - *( tmpName.end() - 4 ) = 'T'; - *( tmpName.end() - 3 ) = 'M'; - *( tmpName.end() - 2 ) = 'P'; - *( tmpName.end() - 1 ) = '\0'; + std::string tmpName( filename ); + tmpName += "TMP"; - return Preferences_Save( preferences, tmpName.data() ) + return Preferences_Save( preferences, tmpName.c_str() ) && ( !file_exists( filename ) || file_remove( filename ) ) && file_move( tmpName.data(), filename ); } @@ -231,6 +228,7 @@ struct LogConsole { void RegisterGlobalPreferences( PreferenceSystem& preferences ){ preferences.registerPreference( "gamefile", make_property_string( g_GamesDialog.m_sGameFile ) ); preferences.registerPreference( "gamePrompt", make_property_string( g_GamesDialog.m_bGamePrompt ) ); + preferences.registerPreference( "skipGamePromptOnce", make_property_string( g_GamesDialog.m_bSkipGamePromptOnce ) ); preferences.registerPreference( "log console", make_property_string() ); } @@ -281,7 +279,18 @@ void CGameDialog::GameFileImport( int value ){ { ++iGame; } - m_sGameFile = ( *iGame )->mGameFile; + + if ( ( *iGame )->mGameFile != m_sGameFile ) { + m_sGameFile = ( *iGame )->mGameFile; + + // do not trigger radiant restart when switching game on startup using Global Preferences dialog + if ( !onStartup ) { + PreferencesDialog_restartRequired( "Selected Game" ); + } + } + + // onStartup can only be true once, when Global Preferences are displayed at startup + onStartup = false; } void CGameDialog::GameFileExport( const Callback & importCallback ) const { @@ -341,7 +350,7 @@ ui::Window CGameDialog::BuildDialog(){ void CGameDialog::ScanForGames(){ StringOutputStream strGamesPath( 256 ); - strGamesPath << AppPath_get() << "games/"; + strGamesPath << DataPath_get() << "gamepacks/games/"; const char *path = strGamesPath.c_str(); globalOutputStream() << "Scanning for game description files: " << path << '\n'; @@ -399,9 +408,12 @@ void CGameDialog::Reset(){ } void CGameDialog::Init(){ + bool gamePrompt = false; + InitGlobalPrefPath(); LoadPrefs(); ScanForGames(); + if ( mGames.empty() ) { Error( "Didn't find any valid game file descriptions, aborting\n" ); } @@ -422,7 +434,15 @@ void CGameDialog::Init(){ CGameDescription* currentGameDescription = 0; - if ( !m_bGamePrompt ) { + // m_bSkipGamePromptOnce is used to not prompt for game on restart, only on fresh startup + if ( m_bGamePrompt && !m_bSkipGamePromptOnce ) { + gamePrompt = true; + } + + m_bSkipGamePromptOnce = false; + g_GamesDialog.SavePrefs(); + + if ( !gamePrompt ) { // search by .game name std::list::iterator iGame; for ( iGame = mGames.begin(); iGame != mGames.end(); ++iGame ) @@ -433,13 +453,19 @@ void CGameDialog::Init(){ } } } - if ( m_bGamePrompt || !currentGameDescription ) { + + if ( gamePrompt || !currentGameDescription ) { + onStartup = true; Create(); DoGameDialog(); // use m_nComboSelect to identify the game to run as and set the globals currentGameDescription = GameDescriptionForComboItem(); ASSERT_NOTNULL( currentGameDescription ); } + else { + onStartup = false; + } + g_pGameDescription = currentGameDescription; g_pGameDescription->Dump(); @@ -475,8 +501,8 @@ CGameDialog g_GamesDialog; static void OnButtonClean( ui::Widget widget, gpointer data ){ // make sure this is what the user wants - if ( g_Preferences.GetWidget().alert( "This will close Radiant and clean the corresponding registry entries.\n" - "Next time you start Radiant it will be good as new. Do you wish to continue?", + if ( ui::alert( g_Preferences.GetWidget(), "This will close " RADIANT_NAME " and clean the corresponding registry entries.\n" + "Next time you start " RADIANT_NAME " it will be good as new. Do you wish to continue?", "Reset Registry", ui::alert_type::YESNO, ui::alert_icon::Asterisk ) == ui::alert_response::YES ) { PrefsDlg *dlg = (PrefsDlg*)data; dlg->EndModal( eIDCANCEL ); @@ -676,7 +702,10 @@ ui::Window PrefsDlg::BuildDialog(){ PreferencesDialog_addInterfacePreferences( makeCallbackF(Interface_constructPreferences) ); Mouse_registerPreferencesPage(); - ui::Window dialog = ui::Window(create_floating_window( "NetRadiant Preferences", m_parent )); + ui::Window dialog = ui::Window(create_floating_window( RADIANT_NAME " Preferences", m_parent )); + + gtk_window_set_transient_for( dialog, m_parent ); + gtk_window_set_position( dialog, GTK_WIN_POS_CENTER_ON_PARENT ); { auto mainvbox = ui::VBox( FALSE, 5 ); @@ -716,7 +745,7 @@ ui::Window PrefsDlg::BuildDialog(){ gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( sc_win ), GTK_SHADOW_IN ); // prefs pages notebook - m_notebook = ui::Widget(gtk_notebook_new()); + m_notebook = ui::Widget::from(gtk_notebook_new()); // hide the notebook tabs since its not supposed to look like a notebook gtk_notebook_set_show_tabs( GTK_NOTEBOOK( m_notebook ), FALSE ); hbox.pack_start( m_notebook, TRUE, TRUE, 0 ); @@ -724,9 +753,9 @@ ui::Window PrefsDlg::BuildDialog(){ { - auto store = ui::TreeStore(gtk_tree_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER )); + auto store = ui::TreeStore::from(gtk_tree_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER )); - auto view = ui::TreeView(ui::TreeModel(store)); + auto view = ui::TreeView(ui::TreeModel::from(store._handle)); gtk_tree_view_set_headers_visible(view, FALSE ); { @@ -736,7 +765,7 @@ ui::Window PrefsDlg::BuildDialog(){ } { - auto selection = ui::TreeSelection(gtk_tree_view_get_selection(view )); + auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection(view)); selection.connect( "changed", G_CALLBACK( treeSelection ), this ); } @@ -877,6 +906,7 @@ void Preferences_Save(){ return; } + // save global preferences g_GamesDialog.SavePrefs(); globalOutputStream() << "saving local preferences to " << g_Preferences.m_inipath->str << "\n"; @@ -908,13 +938,23 @@ void PreferencesDialog_showDialog(){ if ( ConfirmModified( "Edit Preferences" ) && g_Preferences.DoModal() == eIDOK ) { if ( !g_restart_required.empty() ) { StringOutputStream message( 256 ); - message << "Preference changes require a restart:\n"; + message << "Preference changes require a restart:\n\n"; + for ( std::vector::iterator i = g_restart_required.begin(); i != g_restart_required.end(); ++i ) { message << ( *i ) << '\n'; } - MainFrame_getWindow().alert( message.c_str() ); + + message << "\nRestart now?"; + + auto ret = ui::alert( MainFrame_getWindow(), message.c_str(), "Restart " RADIANT_NAME "?", ui::alert_type::YESNO, ui::alert_icon::Question ); + g_restart_required.clear(); + + if ( ret == ui::alert_response::YES ) { + g_GamesDialog.m_bSkipGamePromptOnce = true; + Radiant_Restart(); + } } } }