]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
radiant: ask user to restart the editor when map load switches the brush format
authorThomas Debesse <dev@illwieckz.net>
Fri, 27 Aug 2021 21:25:25 +0000 (23:25 +0200)
committerThomas Debesse <dev@illwieckz.net>
Fri, 27 Aug 2021 23:26:16 +0000 (01:26 +0200)
radiant/brushmodule.cpp
radiant/brushmodule.h
radiant/main.cpp
radiant/mainframe.cpp
radiant/map.cpp
radiant/preferences.cpp
radiant/preferences.h

index 2ab573e514601c7d8b451eca7a8caa448b1e1ae3..6a9565df8906a24823573a8ff180c288d3be49bb 100644 (file)
@@ -100,6 +100,16 @@ int Brush_toggleFormatCount(){
        return 1;
 }
 
+void Brush_switchFormat( bool switch_format ){
+       if ( switch_format )
+       {
+               g_useAlternativeTextureProjection.m_latched = g_useAlternativeTextureProjection.m_value;
+               g_useAlternativeTextureProjection.m_value = !g_useAlternativeTextureProjection.m_value;
+               PreferencesDialog_restartRequired( g_useAlternativeTextureProjection.m_description );
+               PreferencesDialog_restartIfRequired();
+       }
+}
+
 void Brush_Construct( EBrushType type ){
        if ( type == eBrushTypeQuake3 ) {
                g_showAlternativeTextureProjectionOption = true;
@@ -113,6 +123,7 @@ void Brush_Construct( EBrushType type ){
                        "AlternativeTextureProjection",
                        make_property_string( g_useAlternativeTextureProjection.m_latched )
                        );
+
                g_useAlternativeTextureProjection.useLatched();
 
                if ( g_useAlternativeTextureProjection.m_value ) {
index a5c67e3c88d65819779499089974e173000ec0e1..5d8deee836967a8b113e7033b9a5c90311cb7cd4 100644 (file)
@@ -26,5 +26,6 @@ void Brush_clipperColourChanged();
 void Brush_unlatchPreferences();
 int Brush_toggleFormatCount();
 void Brush_toggleFormat( int i );
+void Brush_switchFormat( bool switch_format );
 
 #endif
index 3df10170085eddb32f17e53830fa55b3495ad5dc..6c8ffd037992e5173a564986264232adbd9f2562 100644 (file)
@@ -502,6 +502,15 @@ void user_shortcuts_save(){
        SaveCommandMap( path.c_str() );
 }
 
+/* HACK: If ui::main is not called yet,
+gtk_main_quit will not quit, so tell main
+to not call ui::main. This happens when a
+map is loaded from command line and require
+a restart because of wrong format.
+Delete this when the code to not have to
+restart to load another format is merged. */
+bool g_dontStart = false;
+
 int main( int argc, char* argv[] ){
 #if GTK_TARGET == 3
        // HACK: force legacy GL backend as we don't support GL3 yet
@@ -636,7 +645,17 @@ int main( int argc, char* argv[] ){
 
        remove_local_pid();
 
-       ui::main();
+       /* HACK: If ui::main is not called yet,
+       gtk_main_quit will not quit, so tell main
+       to not call ui::main. This happens when a
+       map is loaded from command line and require
+       a restart because of wrong format.
+       Delete this when the code to not have to
+       restart to load another format is merged. */
+       if ( !g_dontStart )
+       {
+               ui::main();
+       }
 
        // avoid saving prefs when the app is minimized
        if ( g_pParentWnd->IsSleeping() ) {
index 994c320af33253ef0fffc0fb8f4646a0e0446527..17e53efc7279a87a92f409641c3024c7b5acba43 100644 (file)
@@ -3623,6 +3623,15 @@ void GLWindow_Construct(){
 void GLWindow_Destroy(){
 }
 
+/* HACK: If ui::main is not called yet,
+gtk_main_quit will not quit, so tell main
+to not call ui::main. This happens when a
+map is loaded from command line and require
+a restart because of wrong format.
+Delete this when the code to not have to
+restart to load another format is merged. */
+extern bool g_dontStart;
+
 void Radiant_Restart(){
        // preferences are expected to be already saved in any way
        // this is just to be sure and be future proof
@@ -3661,5 +3670,13 @@ void Radiant_Restart(){
        // quit if radiant successfully started
        if ( status == 0 ) {
                gtk_main_quit();
+               /* HACK: If ui::main is not called yet,
+               gtk_main_quit will not quit, so tell main
+               to not call ui::main. This happens when a
+               map is loaded from command line and require
+               a restart because of wrong format.
+               Delete this when the code to not have to
+               restart to load another format is merged. */
+               g_dontStart = true;
        }
 }
index 36b77ae1b828478767148f91738b156287139b5f..a5ac53f899e63e2a27e863482a12091851efd4ce 100644 (file)
@@ -966,6 +966,8 @@ void Map_LoadFile( const char *filename ){
        MRU_AddFile( filename );
        g_strLastMapFolder = g_path_get_dirname( filename );
 
+       bool switch_format = false;
+
        {
                ScopeTimer timer( "map load" );
 
@@ -992,6 +994,7 @@ void Map_LoadFile( const char *filename ){
                                if ( !format->wrongFormat ) {
                                        break;
                                }
+                               switch_format = !switch_format;
                        }
                }
 
@@ -1012,6 +1015,8 @@ void Map_LoadFile( const char *filename ){
        Map_StartPosition();
 
        g_currentMap = &g_map;
+
+       Brush_switchFormat( switch_format );
 }
 
 class Excluder
index b52fb73be5321c8cb99db21fe7d0667699b68bc0..8aaa30b59e720646f00aadfeda890eacb33e402c 100644 (file)
@@ -934,31 +934,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";
+
+               for ( std::vector<const char*>::iterator i = g_restart_required.begin(); i != g_restart_required.end(); ++i )
+               {
+                       message << ( *i ) << '\n';
+               }
 
-                       message << "\nRestart now?";
+               message << "\nRestart now?";
 
-                       auto ret = ui::alert( MainFrame_getWindow(), message.c_str(), "Restart " RADIANT_NAME "?", ui::alert_type::YESNO, ui::alert_icon::Question );
+               auto ret = ui::alert( MainFrame_getWindow(), message.c_str(), "Restart " RADIANT_NAME "?", ui::alert_type::YESNO, ui::alert_icon::Question );
 
-                       g_restart_required.clear();
+               g_restart_required.clear();
 
-                       if ( ret == ui::alert_response::YES ) {
-                               g_GamesDialog.m_bSkipGamePromptOnce = true;
-                               Radiant_Restart();
-                       }
+               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());
index dbaae1354714a9f78f0752c52ed49a119f66de86..8c657fe7251fd80605ad5dd818227a235b5dffe5 100644 (file)
@@ -129,6 +129,7 @@ void PreferencesDialog_addDisplayPage( const PreferenceGroupCallback& callback )
 void PreferencesDialog_addSettingsPreferences( const PreferencesPageCallback& callback );
 void PreferencesDialog_addSettingsPage( const PreferenceGroupCallback& callback );
 
+bool PreferencesDialog_isRestartRequired();
 void PreferencesDialog_restartRequired( const char* staticName );
 
 template<typename Value>
@@ -410,6 +411,8 @@ extern preferences_globals_t g_preferences_globals;
 void PreferencesDialog_constructWindow( ui::Window main_window );
 void PreferencesDialog_destroyWindow();
 
+
+void PreferencesDialog_restartIfRequired();
 void PreferencesDialog_showDialog();
 
 void GlobalPreferences_Init();