]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/preferences.cpp
Merge commit 'ca4a8002f895c3474b3a5087ff027c31dadc712f' into master-merge
[xonotic/netradiant.git] / radiant / preferences.cpp
index 659308aee02766f0b31d2a9036a6f57974dea299..30758606c0ce174a93f8dd4a312536e3b871e9f0 100644 (file)
@@ -59,7 +59,7 @@ void Global_constructPreferences( PreferencesPage& page ){
 
 void Interface_constructPreferences( PreferencesPage& page ){
 #if GDEF_OS_WINDOWS
-       page.appendCheckBox( "", "Default Text Editor", g_TextEditor_useWin32Editor );
+       page.appendCheckBox( "", "External Shader Editor", g_TextEditor_useWin32Editor );
 #else
        {
                ui::CheckButton use_custom = page.appendCheckBox( "Text Editor", "Custom", g_TextEditor_useCustomEditor );
@@ -75,6 +75,7 @@ void Mouse_constructPreferences( PreferencesPage& page ){
                page.appendRadio( "Mouse Type",  g_glwindow_globals.m_nMouseType, STRING_ARRAY_RANGE( buttons ) );
        }
        page.appendCheckBox( "Right Button", "Activates Context Menu", g_xywindow_globals.m_bRightClick );
+       page.appendCheckBox( "", "Improved mousewheel zoom", g_xywindow_globals.m_bImprovedWheelZoom );
 }
 void Mouse_constructPage( PreferenceGroup& group ){
        PreferencesPage page( group.createPage( "Mouse", "Mouse Preferences" ) );
@@ -204,13 +205,10 @@ bool Preferences_Save( PreferenceDictionary& preferences, const char* filename )
 }
 
 bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filename ){
-       Array<char> 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 );
 }
@@ -223,7 +221,7 @@ struct LogConsole {
 
        static void Import(bool value) {
                g_Console_enableLogging = value;
-               Sys_LogFile(g_Console_enableLogging);
+               Sys_EnableLogFile(g_Console_enableLogging);
        }
 };
 
@@ -231,6 +229,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<LogConsole>() );
 }
 
@@ -283,9 +282,16 @@ void CGameDialog::GameFileImport( int value ){
        }
 
        if ( ( *iGame )->mGameFile != m_sGameFile ) {
-               m_sGameFile = ( *iGame )->mGameFile;
-               PreferencesDialog_restartRequired( "Selected Game" );
+       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<void(int)> & importCallback ) const {
@@ -343,6 +349,30 @@ ui::Window CGameDialog::BuildDialog(){
        return create_simple_modal_dialog_window( "Global Preferences", m_modal, frame );
 }
 
+static void StringReplace( std::string& input, const std::string& first, const std::string& second )
+{
+       size_t found = 0;
+       while ( ( found = input.find(first, found) ) != std::string::npos )
+       {
+               input.replace( found, first.length(), second );
+       }
+}
+
+// FIXME, for some unknown reason it sorts “Quake 3” after “Quake 4”.
+static bool CompareGameName( CGameDescription *first, CGameDescription *second )
+{
+       std::string string1( first->getRequiredKeyValue( "name" ) );
+       std::string string2( second->getRequiredKeyValue( "name" ) );
+
+       // HACK: Replace some roman numerals.
+       StringReplace( string1, " III", " 3" );
+       StringReplace( string2, " III", " 3" );
+       StringReplace( string1, " II", " 2" );
+       StringReplace( string2, " II", " 2" );
+
+       return string1 < string2;
+}
+
 void CGameDialog::ScanForGames(){
        StringOutputStream strGamesPath( 256 );
        strGamesPath << DataPath_get() << "gamepacks/games/";
@@ -374,6 +404,8 @@ void CGameDialog::ScanForGames(){
                } else {
                        globalErrorStream() << "XML parser failed on '" << strPath.c_str() << "'\n";
                }
+
+               mGames.sort(CompareGameName);
        });
 }
 
@@ -403,9 +435,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" );
        }
@@ -426,7 +461,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<CGameDescription *>::iterator iGame;
                for ( iGame = mGames.begin(); iGame != mGames.end(); ++iGame )
@@ -437,13 +480,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();
@@ -682,6 +731,9 @@ ui::Window PrefsDlg::BuildDialog(){
 
        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 );
                dialog.add(mainvbox);
@@ -909,30 +961,39 @@ void PreferencesDialog_restartRequired( const char* staticName ){
        g_restart_required.push_back( staticName );
 }
 
-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\n";
+bool PreferencesDialog_isRestartRequired(){
+       return !g_restart_required.empty();
+}
 
-                       for ( std::vector<const char*>::iterator i = g_restart_required.begin(); i != g_restart_required.end(); ++i )
-                       {
-                               message << ( *i ) << '\n';
-                       }
+void PreferencesDialog_restartIfRequired(){
+       if ( !g_restart_required.empty() ) {
+               StringOutputStream message( 256 );
+               message << "Preference changes require a restart:\n\n";
 
-                       message << "\nRestart now?";
+               for ( std::vector<const char*>::iterator i = g_restart_required.begin(); i != g_restart_required.end(); ++i )
+               {
+                       message << ( *i ) << '\n';
+               }
 
-                       auto ret = ui::alert( MainFrame_getWindow(), message.c_str(), "Restart " RADIANT_NAME "?", ui::alert_type::YESNO, ui::alert_icon::Question );
+               message << "\nRestart now?";
 
-                       g_restart_required.clear();
+               auto ret = ui::alert( MainFrame_getWindow(), message.c_str(), "Restart " RADIANT_NAME "?", ui::alert_type::YESNO, ui::alert_icon::Question );
 
-                       if ( ret == ui::alert_response::YES ) {
-                               Radiant_Restart();
-                       }
+               g_restart_required.clear();
+
+               if ( ret == ui::alert_response::YES ) {
+                       g_GamesDialog.m_bSkipGamePromptOnce = true;
+                       Radiant_Restart();
                }
        }
 }
 
+void PreferencesDialog_showDialog(){
+       if ( ConfirmModified( "Edit Preferences" ) && g_Preferences.DoModal() == eIDOK ) {
+               PreferencesDialog_restartIfRequired();
+       }
+}
+
 struct GameName {
        static void Export(const Callback<void(const char *)> &returnz) {
                returnz(gamename_get());