]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/select.cpp
Merge branch 'NateEag-master-patch-12920' into 'master'
[xonotic/netradiant.git] / radiant / select.cpp
index bca6f2ccddb7f249e7538212b8bb050f812ef99c..8f25906d83df876c9b02f5ec047680b79015aa25 100644 (file)
@@ -405,7 +405,7 @@ bool pre( const scene::Path& path, scene::Instance& instance ) const {
        if ( m_depth == 2 ) { // entity depth
                // traverse and select children if any one is selected
                bool beselected = false;
-               if ( instance.childSelected() ) {
+               if ( instance.childSelected() || instance.isSelected() ) {
                        beselected = true;
                        if( path.top().get() != worldspawn ){
                                Instance_setSelected( instance, true );
@@ -452,9 +452,9 @@ void UpdateWorkzone_ForSelection(){
 
 // update the workzone to the current selection
 void UpdateWorkzone_ForSelectionChanged( const Selectable& selectable ){
-       if ( selectable.isSelected() ) {
+       //if ( selectable.isSelected() ) {
                UpdateWorkzone_ForSelection();
-       }
+       //}
 }
 
 void Select_SetShader( const char* shader ){
@@ -465,6 +465,13 @@ void Select_SetShader( const char* shader ){
        Scene_BrushSetShader_Component_Selected( GlobalSceneGraph(), shader );
 }
 
+void Select_SetShader_Undo( const char* shader ){
+       if ( GlobalSelectionSystem().countSelectedComponents() != 0 || GlobalSelectionSystem().countSelected() != 0 ) {
+               UndoableCommand undo( "textureNameSetSelected" );
+               Select_SetShader( shader );
+       }
+}
+
 void Select_SetTexdef( const TextureProjection& projection ){
        if ( GlobalSelectionSystem().Mode() != SelectionSystem::eComponent ) {
                Scene_BrushSetTexdef_Selected( GlobalSceneGraph(), projection );
@@ -1365,3 +1372,79 @@ void DoScaleDlg(){
 
        g_scale_dialog.window.show();
 }
+
+
+class EntityGetSelectedPropertyValuesWalker_nonEmpty : public scene::Graph::Walker
+{
+PropertyValues& m_propertyvalues;
+const char *m_prop;
+const NodeSmartReference worldspawn;
+public:
+EntityGetSelectedPropertyValuesWalker_nonEmpty( const char *prop, PropertyValues& propertyvalues )
+       : m_propertyvalues( propertyvalues ), m_prop( prop ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){
+}
+bool pre( const scene::Path& path, scene::Instance& instance ) const {
+       Entity* entity = Node_getEntity( path.top() );
+       if ( entity != 0 ){
+               if( path.top().get() != worldspawn ){
+                       Selectable* selectable = Instance_getSelectable( instance );
+                       if ( ( selectable != 0 && selectable->isSelected() ) || instance.childSelected() ) {
+                               const char* keyvalue = entity->getKeyValue( m_prop );
+                               if ( !string_empty( keyvalue ) && !propertyvalues_contain( m_propertyvalues, keyvalue ) ) {
+                                       m_propertyvalues.push_back( keyvalue );
+                               }
+                       }
+               }
+               return false;
+       }
+       return true;
+}
+};
+
+void Scene_EntityGetPropertyValues_nonEmpty( scene::Graph& graph, const char *prop, PropertyValues& propertyvalues ){
+       graph.traverse( EntityGetSelectedPropertyValuesWalker_nonEmpty( prop, propertyvalues ) );
+}
+
+#include "preferences.h"
+
+void Select_ConnectedEntities( bool targeting, bool targets, bool focus ){
+       PropertyValues target_propertyvalues;
+       PropertyValues targetname_propertyvalues;
+       const char *target_prop = "target";
+       const char *targetname_prop;
+       if ( g_pGameDescription->mGameType == "doom3" ) {
+               targetname_prop = "name";
+       }
+       else{
+               targetname_prop = "targetname";
+       }
+
+       if( targeting ){
+               Scene_EntityGetPropertyValues_nonEmpty( GlobalSceneGraph(), targetname_prop, targetname_propertyvalues );
+       }
+       if( targets ){
+               Scene_EntityGetPropertyValues_nonEmpty( GlobalSceneGraph(), target_prop, target_propertyvalues );
+       }
+
+       if( target_propertyvalues.empty() && targetname_propertyvalues.empty() ){
+               globalErrorStream() << "SelectConnectedEntities: nothing found\n";
+               return;
+       }
+
+       if( !targeting || !targets ){
+               GlobalSelectionSystem().setSelectedAll( false );
+       }
+       if ( targeting && !targetname_propertyvalues.empty() ) {
+               Scene_EntitySelectByPropertyValues( GlobalSceneGraph(), target_prop, targetname_propertyvalues );
+       }
+       if ( targets && !target_propertyvalues.empty() ) {
+               Scene_EntitySelectByPropertyValues( GlobalSceneGraph(), targetname_prop, target_propertyvalues );
+       }
+       if( focus ){
+               FocusAllViews();
+       }
+}
+
+void SelectConnectedEntities(){
+       Select_ConnectedEntities( true, true, false );
+}