]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/map.cpp
Merge commit 'f472e6f0e8066e62cf3e159287bb07de97d2e59d' into master-merge
[xonotic/netradiant.git] / radiant / map.cpp
index a5ac53f899e63e2a27e863482a12091851efd4ce..86fd37d42c721f5664248da01bf62b4b55b3adae 100644 (file)
@@ -1321,7 +1321,17 @@ void ConstructRegionStartpoint( scene::Node* startpoint, const Vector3& region_m
 
    ===========================================================
  */
-bool region_active;
+bool region_active = false;
+
+ConstReferenceCaller<bool, void(const Callback<void(bool)> &), PropertyImpl<bool>::Export> g_region_caller( region_active );
+
+ToggleItem g_region_item( g_region_caller );
+
+/*void Map_ToggleRegion(){
+       region_active = !region_active;
+       g_region_item.update();
+}*/
+
 Vector3 region_mins( g_MinWorldCoord, g_MinWorldCoord, g_MinWorldCoord );
 Vector3 region_maxs( g_MaxWorldCoord, g_MaxWorldCoord, g_MaxWorldCoord );
 
@@ -1448,6 +1458,7 @@ void Scene_Exclude_Region( bool exclude ){
  */
 void Map_RegionOff(){
        region_active = false;
+       g_region_item.update();
 
        region_maxs[0] = g_MaxWorldCoord - 64;
        region_mins[0] = g_MinWorldCoord + 64;
@@ -1461,6 +1472,7 @@ void Map_RegionOff(){
 
 void Map_ApplyRegion( void ){
        region_active = true;
+       g_region_item.update();
 
        Scene_Exclude_Region( false );
 }
@@ -1477,6 +1489,7 @@ void Map_RegionSelectedBrushes( void ){
        if ( GlobalSelectionSystem().countSelected() != 0
                 && GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive ) {
                region_active = true;
+               g_region_item.update();
                Select_GetBounds( region_mins, region_maxs );
 
                Scene_Exclude_Selected( false );
@@ -1681,21 +1694,19 @@ bool Map_SaveSelected( const char* filename ){
        return MapResource_saveFile( MapFormat_forFile( filename ), GlobalSceneGraph().root(), Map_Traverse_Selected, filename );
 }
 
-
 class ParentSelectedBrushesToEntityWalker : public scene::Graph::Walker
 {
-scene::Node& m_parent;
+       scene::Node& m_parent;
+       mutable bool m_emptyOldParent;
+
 public:
-ParentSelectedBrushesToEntityWalker( scene::Node& parent ) : m_parent( parent ){
+ParentSelectedBrushesToEntityWalker( scene::Node& parent ) : m_parent( parent ), m_emptyOldParent( false ){
 }
 
 bool pre( const scene::Path& path, scene::Instance& instance ) const {
-       if ( path.top().get_pointer() != &m_parent
-                && Node_isPrimitive( path.top() ) ) {
+       if ( path.top().get_pointer() != &m_parent && ( Node_isPrimitive( path.top() ) || m_emptyOldParent ) ) {
                Selectable* selectable = Instance_getSelectable( instance );
-               if ( selectable != 0
-                        && selectable->isSelected()
-                        && path.size() > 1 ) {
+               if ( selectable && selectable->isSelected() && path.size() > 1 ) {
                        return false;
                }
        }
@@ -1703,20 +1714,33 @@ bool pre( const scene::Path& path, scene::Instance& instance ) const {
 }
 
 void post( const scene::Path& path, scene::Instance& instance ) const {
-       if ( path.top().get_pointer() != &m_parent
-                && Node_isPrimitive( path.top() ) ) {
+       if ( path.top().get_pointer() == &m_parent )
+               return;
+
+       if ( Node_isPrimitive( path.top() ) ){
+               m_emptyOldParent = false;
                Selectable* selectable = Instance_getSelectable( instance );
-               if ( selectable != 0
-                        && selectable->isSelected()
-                        && path.size() > 1 ) {
+
+               if ( selectable && selectable->isSelected() && path.size() > 1 ){
                        scene::Node& parent = path.parent();
-                       if ( &parent != &m_parent ) {
+                       if ( &parent != &m_parent ){
                                NodeSmartReference node( path.top().get() );
-                               Node_getTraversable( parent )->erase( node );
+                               scene::Traversable* traversable_parent = Node_getTraversable( parent );
+                               traversable_parent->erase( node );
                                Node_getTraversable( m_parent )->insert( node );
+                               if ( traversable_parent->empty() )
+                                       m_emptyOldParent = true;
                        }
                }
        }
+       else if ( m_emptyOldParent ){
+               m_emptyOldParent = false;
+               // delete empty entities
+               Entity* entity = Node_getEntity( path.top() );
+               if ( entity != 0 && path.top().get_pointer() != Map_FindWorldspawn( g_map )     && Node_getTraversable( path.top() )->empty() ) {
+                       Path_deleteTop( path );
+               }
+       }
 }
 };
 
@@ -1938,6 +1962,7 @@ void SaveMap(){
        }
        else if ( Map_Modified( g_map ) ) {
                Map_Save();
+               MRU_AddFile( g_map.m_name.c_str() );    //add on saving, but not opening via cmd line: spoils the list
        }
 }
 
@@ -2257,7 +2282,8 @@ void Map_Construct(){
        GlobalCommands_insert( "RegionOff", makeCallbackF(RegionOff) );
        GlobalCommands_insert( "RegionSetXY", makeCallbackF(RegionXY) );
        GlobalCommands_insert( "RegionSetBrush", makeCallbackF(RegionBrush) );
-       GlobalCommands_insert( "RegionSetSelection", makeCallbackF(RegionSelected), Accelerator( 'R', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       //GlobalCommands_insert( "RegionSetSelection", makeCallbackF(RegionSelected), Accelerator( 'R', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalToggles_insert( "RegionSetSelection", makeCallbackF(RegionSelected), ToggleItem::AddCallbackCaller( g_region_item ), Accelerator( 'R', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
 
        GlobalPreferenceSystem().registerPreference( "LastMap", make_property_string( g_strLastMap ) );
        GlobalPreferenceSystem().registerPreference( "LoadLastMap", make_property_string( g_bLoadLastMap ) );