]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/patchmanip.cpp
Merge commit '146d231d90b19e2a0edcabff1c4eb9ca44e053e7' into master-merge
[xonotic/netradiant.git] / radiant / patchmanip.cpp
index 644e122af4aa3dbb03ca423516be0eedb9ef7a79..dae11c60d5a70b03564a1ddbd0ff0ac9dd1aea5e 100644 (file)
@@ -225,27 +225,27 @@ void Scene_PatchDeform( scene::Graph& graph, const int deform )
 void Patch_thicken( Patch& patch, scene::Instance& instance, const float thickness, bool seams, const int axis ){
 
                // Create a new patch node
-               NodeSmartReference node(g_patchCreator->createPatch());
+               NodeSmartReference node( g_patchCreator->createPatch() );
                // Insert the node into worldspawn
-               Node_getTraversable(Map_FindOrInsertWorldspawn(g_map))->insert(node);
+               Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
 
                // Retrieve the contained patch from the node
-               Patch* targetPatch = Node_getPatch(node);
+               Patch* targetPatch = Node_getPatch( node );
 
                // Create the opposite patch with the given thickness = distance
                bool no12 = true;
                bool no34 = true;
-               targetPatch->createThickenedOpposite(patch, thickness, axis, no12, no34);
+               targetPatch->createThickenedOpposite( patch, thickness, axis, no12, no34 );
 
                // Now select the newly created patches
                {
-                       scene::Path patchpath(makeReference(GlobalSceneGraph().root()));
-                       patchpath.push(makeReference(*Map_GetWorldspawn(g_map)));
-                       patchpath.push(makeReference(node.get()));
-                       Instance_getSelectable(*GlobalSceneGraph().find(patchpath))->setSelected(true);
+                       scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
+                       patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
+                       patchpath.push( makeReference( node.get() ) );
+                       Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
                }
 
-               if (seams && thickness != 0.0f) {
+               if( seams && thickness != 0.0f){
                        int i = 0;
                        if ( no12 ){
                                i = 2;
@@ -255,31 +255,31 @@ void Patch_thicken( Patch& patch, scene::Instance& instance, const float thickne
                                iend = 2;
                        }
                        // Now create the four walls
-                       for ( ; i < iend; i++ ) {
+                       for ( ; i < iend; i++ ){
                                // Allocate new patch
-                               NodeSmartReference node = NodeSmartReference(g_patchCreator->createPatch());
+                               NodeSmartReference node = NodeSmartReference( g_patchCreator->createPatch() );
                                // Insert each node into worldspawn
-                               Node_getTraversable(Map_FindOrInsertWorldspawn(g_map))->insert(node);
+                               Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
 
                                // Retrieve the contained patch from the node
-                               Patch* wallPatch = Node_getPatch(node);
+                               Patch* wallPatch = Node_getPatch( node );
 
                                // Create the wall patch by passing i as wallIndex
-                               wallPatch->createThickenedWall( patch, *targetPatch, i);
+                               wallPatch->createThickenedWall( patch, *targetPatch, i );
 
                                if( ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[1] <= 0.00005 ) ||
                                        ( wallPatch->localAABB().extents[1] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ||
                                        ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ){
                                        //globalOutputStream() << "Thicken: Discarding degenerate patch.\n";
-                                       Node_getTraversable( Map_FindOrInsertWorldspawn(g_map) )->erase( node );
+                                       Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->erase( node );
                                }
                                else
                                // Now select the newly created patches
                                {
-                                       scene::Path patchpath(makeReference(GlobalSceneGraph().root()));
-                                       patchpath.push(makeReference(*Map_GetWorldspawn(g_map)));
-                                       patchpath.push(makeReference(node.get()));
-                                       Instance_getSelectable(*GlobalSceneGraph().find(patchpath))->setSelected(true);
+                                       scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
+                                       patchpath.push( makeReference( *Map_GetWorldspawn(g_map) ) );
+                                       patchpath.push( makeReference( node.get() ) );
+                                       Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
                                }
                        }
                }
@@ -378,6 +378,20 @@ void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
        }
 }
 
+class PatchSelectByShader
+{
+const char* m_name;
+public:
+inline PatchSelectByShader( const char* name )
+       : m_name( name ){
+}
+void operator()( PatchInstance& patch ) const {
+       if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
+               patch.setSelected( true );
+       }
+}
+};
+
 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
        Scene_forEachVisiblePatchInstance([&](PatchInstance &patch) {
                if (shader_equal(patch.getPatch().GetShader(), name)) {
@@ -387,20 +401,42 @@ void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
 }
 
 
+class PatchFindReplaceShader
+{
+const char* m_find;
+const char* m_replace;
+public:
+PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
+}
+void operator()( Patch& patch ) const {
+       if ( shader_equal( patch.GetShader(), m_find ) ) {
+               patch.SetShader( m_replace );
+       }
+}
+};
+
+namespace{
+bool DoingSearch( const char *repl ){
+       return ( repl == NULL || ( strcmp( "textures/", repl ) == 0 ) );
+}
+}
 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
-       Scene_forEachVisiblePatch([&](Patch &patch) {
-               if (shader_equal(patch.GetShader(), find)) {
-                       patch.SetShader(replace);
-               }
-       });
+       if( DoingSearch( replace ) ){
+               Scene_forEachVisiblePatchInstance( PatchSelectByShader( find ) );
+       }
+       else{
+               Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
+       }
 }
 
 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
-       Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
-               if (shader_equal(patch.GetShader(), find)) {
-                       patch.SetShader(replace);
-               }
-       });
+       if( DoingSearch( replace ) ){
+               //do nothing, because alternative is replacing to notex
+               //perhaps deselect ones with not matching shaders here?
+       }
+       else{
+               Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
+       }
 }
 
 
@@ -664,6 +700,8 @@ void Patch_Thicken(){
 
        DoPatchThickenDlg();
 }
+
+
 #include "ifilter.h"
 
 
@@ -699,13 +737,15 @@ bool filter( const Patch& patch ) const {
 
 
 filter_patch_all g_filter_patch_all;
-filter_patch_shader g_filter_patch_clip( "textures/common/clip" );
+filter_patch_flags g_filter_patch_clip( QER_CLIP );
+filter_patch_shader g_filter_patch_commonclip( "textures/common/clip" );
 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
-filter_patch_flags g_filter_patch_translucent( QER_TRANS );
+filter_patch_flags g_filter_patch_translucent( QER_TRANS | QER_ALPHATEST );
 
 void PatchFilters_construct(){
        add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
        add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
+       add_patch_filter( g_filter_patch_commonclip, EXCLUDE_CLIP );
        add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
        add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
 }
@@ -819,11 +859,11 @@ void Patch_constructMenu( ui::Menu menu ){
                if ( g_Layout_enableDetachableMenus.m_value ) {
                        menu_tearoff( menu_in_menu );
                }
-               create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn" );
                create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Columns", "PatchInsertAddColumn" );
+               create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn" );
                menu_separator( menu_in_menu );
-               create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow" );
                create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Rows", "PatchInsertAddRow" );
+               create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow" );
        }
        {
                auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Delete" );
@@ -1009,10 +1049,10 @@ void DoPatchDeformDlg(){
        gtk_window_add_accel_group( window, accel );
 
        {
-               GtkHBox* hbox = create_dialog_hbox( 4, 4 );
+               auto hbox = create_dialog_hbox( 4, 4 );
                gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
                {
-                       GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
+                       auto table = create_dialog_table( 2, 2, 4, 4 );
                        gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
                        {
                                GtkLabel* label = GTK_LABEL( gtk_label_new( "Max deform:" ) );
@@ -1035,7 +1075,7 @@ void DoPatchDeformDlg(){
                }
                {
                        auto vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
+                       hbox.pack_start( vbox, FALSE, FALSE, 0 );
                        {
                                auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
                                vbox.pack_start( button, FALSE, FALSE, 0 );