]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/map.cpp
image: add crn support to the image plugin.
[xonotic/netradiant.git] / radiant / map.cpp
index adf69f46d974fac354bf0e3a097ae90775ac7596..978d83daaeb2355c32efc7098cc28c55f2d74809 100644 (file)
@@ -59,6 +59,7 @@ MapModules &ReferenceAPI_getMapModules();
 #include "cmdlib.h"
 #include "stream/textfilestream.h"
 #include "os/path.h"
+#include "os/file.h"
 #include "uniquenames.h"
 #include "modulesystem/singletonmodule.h"
 #include "modulesystem/moduleregistry.h"
@@ -86,6 +87,8 @@ MapModules &ReferenceAPI_getMapModules();
 #include "brushmodule.h"
 #include "brush.h"
 
+bool g_writeMapComments = true;
+
 class NameObserver {
     UniqueNames &m_names;
     CopiedString m_name;
@@ -988,7 +991,7 @@ public:
     }
 };
 
-CopiedString g_strLastFolder = "";
+CopiedString g_strLastMapFolder = "";
 
 /*
    ================
@@ -998,11 +1001,17 @@ CopiedString g_strLastFolder = "";
 
 void Map_LoadFile(const char *filename)
 {
+    g_map.m_name = filename;
+
+    // refresh VFS to apply new pak filtering based on mapname
+    // needed for daemon DPK VFS
+    VFS_Refresh();
+
     globalOutputStream() << "Loading map from " << filename << "\n";
     ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Loading Map");
 
     MRU_AddFile(filename);
-    g_strLastFolder = g_path_get_dirname(filename);
+    g_strLastMapFolder = g_path_get_dirname(filename);
 
     {
         ScopeTimer timer("map load");
@@ -1018,8 +1027,8 @@ void Map_LoadFile(const char *filename)
                 Map_Free();
             }
             Brush_toggleFormat(i);
-            g_map.m_name = filename;
             Map_UpdateTitle(g_map);
+
             g_map.m_resource = GlobalReferenceCache().capture(g_map.m_name.c_str());
             if (format) {
                 format->wrongFormat = false;
@@ -1049,10 +1058,6 @@ void Map_LoadFile(const char *filename)
     Map_StartPosition();
 
     g_currentMap = &g_map;
-
-    // restart VFS to apply new pak filtering based on mapname
-    // needed for daemon DPK VFS
-    VFS_Restart();
 }
 
 class Excluder {
@@ -1214,7 +1219,7 @@ void Map_Traverse_Selected(scene::Node &root, const scene::Traversable::Walker &
 
 void Map_ExportSelected(TextOutputStream &out, const MapFormat &format)
 {
-    format.writeGraph(GlobalSceneGraph().root(), Map_Traverse_Selected, out);
+    format.writeGraph(GlobalSceneGraph().root(), Map_Traverse_Selected, out, g_writeMapComments);
 }
 
 void Map_Traverse(scene::Node &root, const scene::Traversable::Walker &walker)
@@ -1596,7 +1601,7 @@ bool Map_ImportFile(const char *filename)
 {
     ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Loading Map");
 
-    g_strLastFolder = g_path_get_dirname(filename);
+    g_strLastMapFolder = g_path_get_dirname(filename);
 
     bool success = false;
 
@@ -1641,7 +1646,7 @@ bool Map_ImportFile(const char *filename)
 
     tryDecompile:
 
-    const char *type = GlobalRadiant().getRequiredGameDescriptionKeyValue("q3map2_type");
+    const char *type = GlobalRadiant().getGameDescriptionKeyValue("q3map2_type");
     int n = string_length(path_get_extension(filename));
     if (n && (extension_equal(path_get_extension(filename), "bsp") ||
               extension_equal(path_get_extension(filename), "map"))) {
@@ -1940,30 +1945,36 @@ const char *getMapsPath()
     return g_mapsPath.c_str();
 }
 
-const char *getLastFolderPath()
+const char *getLastMapFolderPath()
 {
-    if (g_strLastFolder.empty()) {
-        GlobalPreferenceSystem().registerPreference("LastFolder", make_property_string(g_strLastFolder));
-        if (g_strLastFolder.empty()) {
-            g_strLastFolder = g_qeglobals.m_userGamePath;
+    if (g_strLastMapFolder.empty()) {
+        GlobalPreferenceSystem().registerPreference("LastMapFolder", make_property_string(g_strLastMapFolder));
+        if (g_strLastMapFolder.empty()) {
+            StringOutputStream buffer(1024);
+            buffer << getMapsPath();
+            if (!file_readable(buffer.c_str())) {
+                buffer.clear();
+                buffer << g_qeglobals.m_userGamePath.c_str() << "/";
+            }
+            g_strLastMapFolder = buffer.c_str();
         }
     }
-    return g_strLastFolder.c_str();
+    return g_strLastMapFolder.c_str();
 }
 
 const char *map_open(const char *title)
 {
-    return MainFrame_getWindow().file_dialog(TRUE, title, getLastFolderPath(), MapFormat::Name(), true, false, false);
+    return MainFrame_getWindow().file_dialog(TRUE, title, getLastMapFolderPath(), MapFormat::Name(), true, false, false);
 }
 
 const char *map_import(const char *title)
 {
-    return MainFrame_getWindow().file_dialog(TRUE, title, getLastFolderPath(), MapFormat::Name(), false, true, false);
+    return MainFrame_getWindow().file_dialog(TRUE, title, getLastMapFolderPath(), MapFormat::Name(), false, true, false);
 }
 
 const char *map_save(const char *title)
 {
-    return MainFrame_getWindow().file_dialog(FALSE, title, getLastFolderPath(), MapFormat::Name(), false, false, true);
+    return MainFrame_getWindow().file_dialog(FALSE, title, getLastMapFolderPath(), MapFormat::Name(), false, false, true);
 }
 
 void OpenMap()
@@ -1997,7 +2008,7 @@ bool Map_SaveAs()
     const char *filename = map_save("Save Map");
 
     if (filename != NULL) {
-        g_strLastFolder = g_path_get_dirname(filename);
+        g_strLastMapFolder = g_path_get_dirname(filename);
         MRU_AddFile(filename);
         Map_Rename(filename);
         return Map_Save();
@@ -2024,7 +2035,7 @@ void ExportMap()
     const char *filename = map_save("Export Selection");
 
     if (filename != NULL) {
-        g_strLastFolder = g_path_get_dirname(filename);
+        g_strLastMapFolder = g_path_get_dirname(filename);
         Map_SaveSelected(filename);
     }
 }
@@ -2034,7 +2045,7 @@ void SaveRegion()
     const char *filename = map_save("Export Region");
 
     if (filename != NULL) {
-        g_strLastFolder = g_path_get_dirname(filename);
+        g_strLastMapFolder = g_path_get_dirname(filename);
         Map_SaveRegion(filename);
     }
 }
@@ -2288,7 +2299,8 @@ void DoFind()
 
 void Map_constructPreferences(PreferencesPage &page)
 {
-    page.appendCheckBox("", "Load last map on open", g_bLoadLastMap);
+    page.appendCheckBox("", "Load last map at startup", g_bLoadLastMap);
+    page.appendCheckBox("", "Add entity and brush number comments on map write", g_writeMapComments);
 }
 
 
@@ -2366,6 +2378,7 @@ void Map_Construct()
     GlobalPreferenceSystem().registerPreference("LastMap", make_property_string(g_strLastMap));
     GlobalPreferenceSystem().registerPreference("LoadLastMap", make_property_string(g_bLoadLastMap));
     GlobalPreferenceSystem().registerPreference("MapInfoDlg", make_property<WindowPosition_String>(g_posMapInfoWnd));
+       GlobalPreferenceSystem().registerPreference("WriteMapComments", make_property_string(g_writeMapComments));
 
     PreferencesDialog_addSettingsPreferences(makeCallbackF(Map_constructPreferences));