]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/preferences.cpp
merge branch work back into trunk
[xonotic/netradiant.git] / radiant / preferences.cpp
index 09d6b0f29bca2ebb25d25388dc12efb94a714c8f..9608fbb981737ff33dfa130623b4e5934c31e4e8 100644 (file)
@@ -96,6 +96,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #define WIDETOOLBAR_KEY         "WideToolBar"
 #define PLUGINTOOLBAR_KEY "PluginToolBar"
 #define NOCLAMP_KEY             "NoClamp"
+#define SNAP_KEY                "Snap"
 #define PREFAB_KEY              "PrefabPath"
 #define USERINI_KEY             "UserINIPath"
 #define ROTATION_KEY            "Rotation"
@@ -635,6 +636,7 @@ PrefsDlg::PrefsDlg ()
   m_bWideToolbar = TRUE;
   m_bPluginToolbar = TRUE;
   m_bNoClamp = FALSE;
+  m_bSnap = TRUE;
   m_strUserPath = "";
   m_nRotation = 0;
   m_bChaseMouse = FALSE;
@@ -694,6 +696,25 @@ Games selection dialog
 =========================================================
 */
 
+#if defined(WIN32)
+#define TOOLS_ATTRIBUTE "gametools_win32"
+#define ENGINE_ATTRIBUTE "engine_win32"
+#define ENGINEPATH_ATTRIBUTE "enginepath_win32"
+#define MP_ENGINE_ATTRIBUTE "mp_engine_win32"
+#elif defined(__linux__) || defined (__FreeBSD__)
+#define TOOLS_ATTRIBUTE "gametools_linux"
+#define ENGINE_ATTRIBUTE "engine_linux"
+#define ENGINEPATH_ATTRIBUTE "enginepath_linux"
+#define MP_ENGINE_ATTRIBUTE "mp_engine_linux"
+#elif defined(__APPLE__)
+#define TOOLS_ATTRIBUTE "gametools_macos"
+#define ENGINE_ATTRIBUTE "engine_macos"
+#define ENGINEPATH_ATTRIBUTE "enginepath_macos"
+#define MP_ENGINE_ATTRIBUTE "mp_engine_macos"
+#else
+#error "unsupported platform"
+#endif
+
 CGameDescription::CGameDescription(xmlDocPtr pDoc, const Str &GameFile)
 {
   char *p, *prop;
@@ -708,9 +729,9 @@ CGameDescription::CGameDescription(xmlDocPtr pDoc, const Str &GameFile)
     Error("Didn't find 'game' node in the game description file '%s'\n", pDoc->URL);
   }
   // on win32, game tools path can now be specified relative to the exe's cwd
-  prop = (char*)xmlGetProp( pNode, (xmlChar*)"gametools" );
+  prop = (char*)xmlGetProp( pNode, (xmlChar*)TOOLS_ATTRIBUTE);
   if ( prop == NULL ) {
-         Error( "Didn't find 'gametools' node in the game description file '%s'\n", pDoc->URL );
+       Error( "Didn't find '"TOOLS_ATTRIBUTE"' node in the game description file '%s'\n", pDoc->URL );
   }
   {
        char full[PATH_MAX];
@@ -784,58 +805,78 @@ CGameDescription::CGameDescription(xmlDocPtr pDoc, const Str &GameFile)
     xmlFree(prop);
   }
 
-  // on win32, engine path can now be specified relative to the exe's cwd
-  prop = (char*)xmlGetProp(pNode, (const xmlChar *)"enginepath");
-  if ( prop != NULL ) {
-    char full[PATH_MAX];
+
+       prop = (char*)xmlGetProp(pNode, (const xmlChar*)ENGINE_ATTRIBUTE);
+       if (prop == NULL)
+       {
 #ifdef _WIN32
-       _fullpath( full, prop, PATH_MAX );
-#else
-       strncpy( full, prop, PATH_MAX );
+               mEngine = "quake3.exe";
+#elif __linux__
+               mEngine = "quake3";
+#elif __APPLE__
+               mEngine = "Quake3.app";
 #endif
-    xmlFree( prop );
-       prop = NULL;
-    // process seperators
-    for ( p = full; *p != '\0'; p++ ) {
-         if ( *p == '\\' ) {
-           *p = '/';
-         }
        }
-    mEnginePath = full;
-       if ( p != full && *(p-1) != '/' ) {
-         mEnginePath += "/";
-       }
-  }
-  else
-  {
-    // if engine path was not specified in the .game, it implies we can guess it from the gametools path
-    // on win32, and for most game package, the gametools are installed with the game
-    char aux_path[PATH_MAX]; // aux
-    strcpy( aux_path, mGameToolsPath.GetBuffer() );
-       if ( ( aux_path[ strlen(aux_path)-1 ] == '/' ) || ( aux_path[ strlen(aux_path)-1 ] == '\\' ) ) {
-      aux_path[strlen(aux_path)-1] = '\0'; // strip ending '/' if any
+       else
+       {
+               mEngine = prop;
+               xmlFree(prop);
        }
-    char up_path[PATH_MAX]; // up one level
-    ExtractFilePath( aux_path, up_path );
-    mEnginePath = up_path;
-  }
 
-  prop = (char*)xmlGetProp(pNode, (xmlChar*)"engine");
-  if (prop == NULL)
-  {
+       prop = (char*)xmlGetProp(pNode, (const xmlChar*)MP_ENGINE_ATTRIBUTE);
+       if (prop == NULL)
+       {
 #ifdef _WIN32
-    mEngine = "quake3.exe";
+               mMultiplayerEngine = "quake3.exe";
 #elif __linux__
-    mEngine = "quake3";
+               mMultiplayerEngine = "quake3";
 #elif __APPLE__
-    mEngine = "Quake3.app";
+               mMultiplayerEngine = "Quake3.app";
 #endif
-  }
-  else
-  {
-    mEngine = prop;
-    xmlFree(prop);
-  }
+       }
+       else
+       {
+               mMultiplayerEngine = prop;
+               xmlFree(prop);
+       }
+
+       {
+               // on win32, engine path can now be specified relative to the exe's cwd
+               prop = (char*)xmlGetProp(pNode, (const xmlChar *)ENGINEPATH_ATTRIBUTE);
+               if ( prop != NULL ) {
+                       char full[PATH_MAX];
+               #ifdef _WIN32
+                       _fullpath( full, prop, PATH_MAX );
+               #else
+                       strncpy( full, prop, PATH_MAX );
+               #endif
+                       xmlFree( prop );
+                       prop = NULL;
+                       // process seperators
+                       for ( p = full; *p != '\0'; p++ ) {
+                               if ( *p == '\\' ) {
+                                       *p = '/';
+                               }
+                       }
+                       mEnginePath = full;
+                       if ( p != full && *(p-1) != '/' ) {
+                               mEnginePath += "/";
+                       }
+               }
+               else
+               {
+                       // if engine path was not specified in the .game, it implies we can guess it from the gametools path
+                       // on win32, and for most game package, the gametools are installed with the game
+                       char aux_path[PATH_MAX]; // aux
+                       strcpy( aux_path, mGameToolsPath.GetBuffer() );
+                       if ( ( aux_path[ strlen(aux_path)-1 ] == '/' ) || ( aux_path[ strlen(aux_path)-1 ] == '\\' ) ) {
+                               aux_path[strlen(aux_path)-1] = '\0'; // strip ending '/' if any
+                       }
+                       char up_path[PATH_MAX]; // up one level
+                       ExtractFilePath( aux_path, up_path );
+                       mEnginePath = up_path;
+               }
+       }
 
 #if defined (__linux__) || defined (__APPLE__)
   // *nix specific
@@ -2297,6 +2338,12 @@ void PrefsDlg::BuildDialog ()
   gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
   AddDialogData (check, &m_bNoClamp, DLG_CHECK_BOOL);
 
+  // Snap to grid
+  check = gtk_check_button_new_with_label (_("Snap to grid"));
+  gtk_widget_show (check);
+  gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
+  AddDialogData (check, &m_bSnap, DLG_CHECK_BOOL);
+
   // Select patch by bounding box
   check = gtk_check_button_new_with_label (_("Select patches by bounding box"));
   gtk_widget_show (check);
@@ -2867,6 +2914,7 @@ void PrefsDlg::LoadPrefs ()
   m_nShader = m_nLatchedShader;
 
   mLocalPrefs.GetPref(NOCLAMP_KEY,            &m_bNoClamp,                    FALSE);
+  mLocalPrefs.GetPref(SNAP_KEY,               &m_bSnap,                       TRUE);
   mLocalPrefs.GetPref(USERINI_KEY,            &m_strUserPath,                 "");
   mLocalPrefs.GetPref(ROTATION_KEY,           &m_nRotation,                   45);
   mLocalPrefs.GetPref(CHASEMOUSE_KEY,         &m_bChaseMouse,                 TRUE);
@@ -2884,7 +2932,7 @@ void PrefsDlg::LoadPrefs ()
     // Texture subset on by default (HL specific really, because of halflife.wad's size)
     mLocalPrefs.GetPref(TEXTURE_KEY,            &m_bTextureWindow,              TRUE);
   }
-  else if ( ( g_pGameDescription->mGameFile == "q2.game" ) || ( g_pGameDescription->mGameFile == "heretic2.game" ) )
+  else if (g_pGameDescription->quake2)
   {
     // BSP monitoring is implemented in Quake2 and Heretic2 tools
     mLocalPrefs.GetPref(WATCHBSP_KEY,           &m_bWatchBSP,                   TRUE);
@@ -3181,14 +3229,14 @@ void CGameInstall::OnBtnBrowseEngine( GtkWidget *widget, gpointer data ) {
        Sys_Printf( "OnBtnBrowseEngine\n" );
 
        CGameInstall* i = static_cast<CGameInstall*>( data );
-       char *dir = dir_dialog( widget, _("Select game directory"), NULL );
+       char *dir = dir_dialog( i->m_pWidget, _("Select game directory"), NULL );
 
        i->UpdateData( TRUE );
 
        if ( dir != NULL ) {
                i->m_strEngine = dir;
                i->UpdateData( FALSE );
-               free( dir );
+               g_free( dir );
        }
 }
 
@@ -3322,15 +3370,15 @@ void CGameInstall::Run() {
        Sys_Printf( "game file: %s\n", gameFilePath.GetBuffer() );
 
        FILE *fg = fopen( gameFilePath.GetBuffer(), "w" );
-       if ( fg == NULL ) {
+       if ( fg == NULL || ferror( fg ) ) {
                Error( "Failed to open %s for writing\n", gameFilePath.GetBuffer() );
        }
        fprintf( fg, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"yes\"?>\n<game\n" );
        fprintf( fg, "  name=\"%s\"\n", m_strName.GetBuffer() );
-       fprintf( fg, "  enginepath=\"%s\"\n", m_strEngine.GetBuffer() );
+       fprintf( fg, "  "ENGINEPATH_ATTRIBUTE"=\"%s\"\n", m_strEngine.GetBuffer() );
        switch ( m_availGames[ m_nComboSelect ] ) {
        case GAME_Q2: {
-               fprintf( fg, "  gametools=\"%sinstalls/Quake2Pack/game\"\n", g_strAppPath.GetBuffer() );
+               fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/Quake2Pack/game\"\n", g_strAppPath.GetBuffer() );
                fprintf( fg, "  prefix=\".quake2\"\n" );
                Str source = g_strAppPath.GetBuffer();
                source += "installs/";
@@ -3342,7 +3390,7 @@ void CGameInstall::Run() {
                break;
        }
        case GAME_Q3: {
-               fprintf( fg, "  gametools=\"%sinstalls/Q3Pack/game\"\n", g_strAppPath.GetBuffer() );
+               fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/Q3Pack/game\"\n", g_strAppPath.GetBuffer() );
                fprintf( fg, "  prefix=\".q3a\"\n" );
                Str source = g_strAppPath.GetBuffer();
                source += "installs/";
@@ -3354,7 +3402,7 @@ void CGameInstall::Run() {
                break;
        }
        case GAME_URT: {
-               fprintf( fg, "  gametools=\"%sinstalls/UrTPack/game\"\n", g_strAppPath.GetBuffer() );
+               fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/UrTPack/game\"\n", g_strAppPath.GetBuffer() );
                fprintf( fg, "  prefix=\".q3a\"\n" );
                Str source = g_strAppPath.GetBuffer();
                source += "installs/";
@@ -3366,7 +3414,7 @@ void CGameInstall::Run() {
                break;
        }
        case GAME_UFOAI: {
-               fprintf( fg, "  gametools=\"%sinstalls/UFOAIPack/game\"\n", g_strAppPath.GetBuffer() );
+               fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/UFOAIPack/game\"\n", g_strAppPath.GetBuffer() );
                fprintf( fg, "  prefix=\".ufoai\"\n" );
                Str source = g_strAppPath.GetBuffer();
                source += "installs/";
@@ -3378,7 +3426,7 @@ void CGameInstall::Run() {
                break;
        }
        case GAME_Q2W: {
-               fprintf( fg, "  gametools=\"%sinstalls/Q2WPack/game\"\n", g_strAppPath.GetBuffer() );
+               fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/Q2WPack/game\"\n", g_strAppPath.GetBuffer() );
                fprintf( fg, "  prefix=\".quake2world\"\n" );
                Str source = g_strAppPath.GetBuffer();
                source += "installs/";
@@ -3390,7 +3438,7 @@ void CGameInstall::Run() {
                break;
        }
        case GAME_WARSOW: {
-               fprintf( fg, "  gametools=\"%sinstalls/WarsowPack/game\"\n", g_strAppPath.GetBuffer() );
+               fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/WarsowPack/game\"\n", g_strAppPath.GetBuffer() );
                fprintf( fg, "  prefix=\".warsow\"\n" );
                Str source = g_strAppPath.GetBuffer();
                source += "installs/";
@@ -3402,7 +3450,7 @@ void CGameInstall::Run() {
                break;
        }
        case GAME_NEXUIZ: {
-               fprintf( fg, "  gametools=\"%sinstalls/NexuizPack/game\"\n", g_strAppPath.GetBuffer() );
+               fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/NexuizPack/game\"\n", g_strAppPath.GetBuffer() );
                fprintf( fg, "  prefix=\".nexuiz\"\n" );
                Str source = g_strAppPath.GetBuffer();
                source += "installs/";
@@ -3414,7 +3462,7 @@ void CGameInstall::Run() {
                break;
        }
        case GAME_TREMULOUS: {
-               fprintf( fg, "  gametools=\"%sinstalls/TremulousPack/game\"\n", g_strAppPath.GetBuffer() );
+               fprintf( fg, "  "TOOLS_ATTRIBUTE"=\"%sinstalls/TremulousPack/game\"\n", g_strAppPath.GetBuffer() );
                fprintf( fg, "  prefix=\".tremulous\"\n" );
                Str source = g_strAppPath.GetBuffer();
                source += "installs/";