]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/qe3.cpp
radiant: replace StringBuffer with std::string
[xonotic/netradiant.git] / radiant / qe3.cpp
index 1bce60b9a38acb676709ad12a4edcefa765c3a2d..3b015aa4aeb70564722bbc074304c08780438e6a 100644 (file)
 // Leonardo Zide (leo@lokigames.com)
 //
 
+#include "defaults.h"
 #include "qe3.h"
+#include "globaldefs.h"
+
+#include <gtk/gtk.h>
 
 #include "debugging/debugging.h"
 
@@ -41,7 +45,7 @@
 
 #include <map>
 
-#include <gtk/gtktearoffmenuitem.h>
+#include <uilib/uilib.h>
 
 #include "stream/textfilestream.h"
 #include "cmdlib.h"
@@ -64,7 +68,7 @@
 QEGlobals_t g_qeglobals;
 
 
-#if defined( WIN32 )
+#if GDEF_OS_WINDOWS
 #define PATH_MAX 260
 #endif
 
@@ -75,41 +79,67 @@ void QE_InitVFS(){
        // we need to call in order, the mod ones first, then the base ones .. they will be searched in this order
        // *nix systems have a dual filesystem in ~/.q3a, which is searched first .. so we need to add that too
 
-       const char* gamename = gamename_get();
+       const char* enginepath = EnginePath_get();
+       const char* homepath = g_qeglobals.m_userEnginePath.c_str(); // returns enginepath if not homepath is not set
+
        const char* basegame = basegame_get();
-       const char* userRoot = g_qeglobals.m_userEnginePath.c_str();
-       const char* globalRoot = EnginePath_get();
+       const char* gamename = gamename_get(); // returns basegame if gamename is not set
+
+       // editor builtin VFS
+       StringOutputStream editorGamePath( 256 );
+       editorGamePath << GlobalRadiant().getDataPath() << DEFAULT_EDITORVFS_DIRNAME;
+       GlobalFileSystem().initDirectory( editorGamePath.c_str() );
+
+       globalOutputStream() << "engine path: " << enginepath << "\n";
+       globalOutputStream() << "home path: " << homepath << "\n";
+       globalOutputStream() << "base game: " << basegame << "\n";
+       globalOutputStream() << "game name: " << gamename << "\n";
 
        // if we have a mod dir
        if ( !string_equal( gamename, basegame ) ) {
-               // ~/.<gameprefix>/<fs_game>
-               if ( userRoot ) {
-                       StringOutputStream userGamePath( 256 );
-                       userGamePath << userRoot << gamename << '/';
-                       GlobalFileSystem().initDirectory( userGamePath.c_str() );
+               // if we have a home dir
+               if ( !string_equal( homepath, enginepath ) )
+               {
+                       // ~/.<gameprefix>/<fs_game>
+                       if ( homepath && !g_disableHomePath ) {
+                               StringOutputStream userGamePath( 256 );
+                               userGamePath << homepath << gamename << '/';
+                               GlobalFileSystem().initDirectory( userGamePath.c_str() );
+                       }
                }
 
                // <fs_basepath>/<fs_game>
-               {
+               if ( !g_disableEnginePath ) {
                        StringOutputStream globalGamePath( 256 );
-                       globalGamePath << globalRoot << gamename << '/';
+                       globalGamePath << enginepath << gamename << '/';
                        GlobalFileSystem().initDirectory( globalGamePath.c_str() );
                }
        }
 
-       // ~/.<gameprefix>/<fs_main>
-       if ( userRoot ) {
-               StringOutputStream userBasePath( 256 );
-               userBasePath << userRoot << basegame << '/';
-               GlobalFileSystem().initDirectory( userBasePath.c_str() );
+       // if we have a home dir
+       if ( !string_equal( homepath, enginepath ) )
+       {
+               // ~/.<gameprefix>/<fs_main>
+               if ( homepath && !g_disableHomePath ) {
+                       StringOutputStream userBasePath( 256 );
+                       userBasePath << homepath << basegame << '/';
+                       GlobalFileSystem().initDirectory( userBasePath.c_str() );
+               }
        }
 
        // <fs_basepath>/<fs_main>
-       {
+       if ( !g_disableEnginePath ) {
                StringOutputStream globalBasePath( 256 );
-               globalBasePath << globalRoot << basegame << '/';
+               globalBasePath << enginepath << basegame << '/';
                GlobalFileSystem().initDirectory( globalBasePath.c_str() );
        }
+
+       // extra pakpaths
+       for ( int i = 0; i < g_pakPathCount; i++ ) {
+               if (g_strcmp0( g_strPakPath[i].c_str(), "")) {
+                       GlobalFileSystem().initDirectory( g_strPakPath[i].c_str() );
+               }
+       }
 }
 
 int g_numbrushes = 0;
@@ -140,11 +170,11 @@ bool ConfirmModified( const char* title ){
                return true;
        }
 
-       EMessageBoxReturn result = gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), "The current map has changed since it was last saved.\nDo you want to save the current map before continuing?", title, eMB_YESNOCANCEL, eMB_ICONQUESTION );
-       if ( result == eIDCANCEL ) {
+       auto result = ui::alert( MainFrame_getWindow(), "The current map has changed since it was last saved.\nDo you want to save the current map before continuing?", title, ui::alert_type::YESNOCANCEL, ui::alert_icon::Question );
+       if ( result == ui::alert_response::CANCEL ) {
                return false;
        }
-       if ( result == eIDYES ) {
+       if ( result == ui::alert_response::YES ) {
                if ( Map_Unnamed( g_map ) ) {
                        return Map_SaveAs();
                }
@@ -157,16 +187,45 @@ bool ConfirmModified( const char* title ){
 }
 
 void bsp_init(){
+       // this is expected to not be used since
+       // ".[ExecutableType]" is replaced by "[ExecutableExt]"
+       const char *exe_ext = GDEF_OS_EXE_EXT;
+       build_set_variable( "ExecutableType", exe_ext[0] == '\0' ? exe_ext : exe_ext + 1 );
+
+       build_set_variable( "ExecutableExt", GDEF_OS_EXE_EXT );
        build_set_variable( "RadiantPath", AppPath_get() );
-       build_set_variable( "ExecutableType", RADIANT_EXECUTABLE );
        build_set_variable( "EnginePath", EnginePath_get() );
        build_set_variable( "UserEnginePath", g_qeglobals.m_userEnginePath.c_str() );
+
        build_set_variable( "MonitorAddress", ( g_WatchBSP_Enabled ) ? "127.0.0.1:39000" : "" );
+
        build_set_variable( "GameName", gamename_get() );
 
+       std::string ExtraQ3map2Args;
+       // extra pakpaths
+       for ( int i = 0; i < g_pakPathCount; i++ ) {
+               if ( g_strcmp0( g_strPakPath[i].c_str(), "") ) {
+                       ExtraQ3map2Args += " -fs_pakpath \"";
+                       ExtraQ3map2Args += g_strPakPath[i].c_str();
+                       ExtraQ3map2Args += "\"";
+               }
+       }
+
+       // extra switches
+       if ( g_disableEnginePath ) {
+               ExtraQ3map2Args += " -fs_nobasepath ";
+       }
+
+       if ( g_disableHomePath ) {
+               ExtraQ3map2Args += " -fs_nohomepath ";
+       }
+
+       build_set_variable( "ExtraQ3map2Args", ExtraQ3map2Args.c_str() );
+
        const char* mapname = Map_Name( g_map );
-       StringOutputStream name( 256 );
-       name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".bsp";
+       std::string name;
+       name.append( mapname, path_get_filename_base_end( mapname ) - mapname );
+       name += ".bsp";
 
        build_set_variable( "MapFile", mapname );
        build_set_variable( "BspFile", name.c_str() );
@@ -183,6 +242,7 @@ public:
 ArrayCommandListener(){
        m_array = g_ptr_array_new();
 }
+
 ~ArrayCommandListener(){
        g_ptr_array_free( m_array, TRUE );
 }
@@ -279,10 +339,10 @@ void RunBSP( const char* name ){
                strcat( junkpath, "junk.txt" );
 
                char batpath[PATH_MAX];
-#if defined( POSIX )
+#if GDEF_OS_POSIX
                strcpy( batpath, SettingsPath_get() );
                strcat( batpath, "qe3bsp.sh" );
-#elif defined( WIN32 )
+#elif GDEF_OS_WINDOWS
                strcpy( batpath, SettingsPath_get() );
                strcat( batpath, "qe3bsp.bat" );
 #else
@@ -292,7 +352,7 @@ void RunBSP( const char* name ){
                {
                        TextFileOutputStream batchFile( batpath );
                        if ( !batchFile.failed() ) {
-#if defined ( POSIX )
+#if GDEF_OS_POSIX
                                batchFile << "#!/bin/sh \n\n";
 #endif
                                BatchCommandListener listener( batchFile, junkpath );
@@ -301,7 +361,7 @@ void RunBSP( const char* name ){
                        }
                }
                if ( written ) {
-#if defined ( POSIX )
+#if GDEF_OS_POSIX
                        chmod( batpath, 0744 );
 #endif
                        globalOutputStream() << "Writing the compile script to '" << batpath << "'\n";
@@ -324,7 +384,7 @@ void Sys_SetTitle( const char *text, bool modified ){
                title << " *";
        }
 
-       gtk_window_set_title( MainFrame_getWindow(), title.c_str() );
+       gtk_window_set_title(MainFrame_getWindow(), title.c_str() );
 }
 
 bool g_bWaitCursor = false;
@@ -332,14 +392,14 @@ bool g_bWaitCursor = false;
 void Sys_BeginWait( void ){
        ScreenUpdates_Disable( "Processing...", "Please Wait" );
        GdkCursor *cursor = gdk_cursor_new( GDK_WATCH );
-       gdk_window_set_cursor( GTK_WIDGET( MainFrame_getWindow() )->window, cursor );
+       gdk_window_set_cursor( gtk_widget_get_window(MainFrame_getWindow()), cursor );
        gdk_cursor_unref( cursor );
        g_bWaitCursor = true;
 }
 
 void Sys_EndWait( void ){
        ScreenUpdates_Enable();
-       gdk_window_set_cursor( GTK_WIDGET( MainFrame_getWindow() )->window, 0 );
+       gdk_window_set_cursor(gtk_widget_get_window(MainFrame_getWindow()), 0 );
        g_bWaitCursor = false;
 }