From 0678e842b2f2e86cdeacfb00131105449b046c0b Mon Sep 17 00:00:00 2001 From: Garux Date: Fri, 28 Oct 2022 21:00:55 +0300 Subject: [PATCH] improve Surface Inspector consistency was showing shader of last selected brush, texdef of 1st now shows properties of single primitive at 1st tries to show last selected primitive to be responsible to selection prefers brushes over patches as general rule --- radiant/brushmanip.cpp | 15 +++++++++++++++ radiant/brushmanip.h | 1 + radiant/patchmanip.cpp | 14 ++++++++++++++ radiant/patchmanip.h | 1 + radiant/surfacedialog.cpp | 18 ++++++------------ 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/radiant/brushmanip.cpp b/radiant/brushmanip.cpp index 1dbc39d2..89be318a 100644 --- a/radiant/brushmanip.cpp +++ b/radiant/brushmanip.cpp @@ -908,6 +908,21 @@ void Scene_BrushGetTexdef_Selected( scene::Graph& graph, TextureProjection& proj Scene_ForEachSelectedBrush_ForEachFace( graph, FaceGetTexdef( projection ) ); } +bool Scene_BrushGetShaderTexdef_Selected( scene::Graph& graph, CopiedString& shader, TextureProjection& projection ){ + BrushInstance *brush = nullptr; + if ( GlobalSelectionSystem().countSelected() == 0 + || !( brush = Instance_getBrush( GlobalSelectionSystem().ultimateSelected() ) ) ) { + Scene_forEachSelectedBrush( [&brush]( BrushInstance& b ){ if( !brush ) brush = &b; } ); + } + if( brush && !brush->getBrush().empty() ){ + Face *face = brush->getBrush().begin()->get(); + shader = face->GetShader(); + face->GetTexdef( projection ); + return true; + } + return false; +} + void Scene_BrushGetTexdef_Component_Selected( scene::Graph& graph, TextureProjection& projection ){ #if 1 if ( !g_SelectedFaceInstances.empty() ) { diff --git a/radiant/brushmanip.h b/radiant/brushmanip.h index 91fbdcbc..222ed58e 100644 --- a/radiant/brushmanip.h +++ b/radiant/brushmanip.h @@ -51,6 +51,7 @@ void Scene_BrushSetTexdef_Component_Selected( scene::Graph& graph, const Texture void Scene_BrushSetTexdef_Selected( scene::Graph& graph, const float* hShift, const float* vShift, const float* hScale, const float* vScale, const float* rotation ); void Scene_BrushSetTexdef_Component_Selected( scene::Graph& graph, const float* hShift, const float* vShift, const float* hScale, const float* vScale, const float* rotation ); void Scene_BrushGetTexdef_Selected( scene::Graph& graph, TextureProjection& projection ); +bool Scene_BrushGetShaderTexdef_Selected( scene::Graph& graph, CopiedString& shader, TextureProjection& projection ); void Scene_BrushGetTexdef_Component_Selected( scene::Graph& graph, TextureProjection& projection ); void Scene_BrushSetFlags_Selected( scene::Graph& graph, const ContentsFlagsValue& flags ); void Scene_BrushSetFlags_Component_Selected( scene::Graph& graph, const ContentsFlagsValue& flags ); diff --git a/radiant/patchmanip.cpp b/radiant/patchmanip.cpp index 87bcfee8..7b577354 100644 --- a/radiant/patchmanip.cpp +++ b/radiant/patchmanip.cpp @@ -1133,6 +1133,20 @@ void Scene_PatchGetTexdef_Selected( scene::Graph& graph, TextureProjection &proj } } +bool Scene_PatchGetShaderTexdef_Selected( scene::Graph& graph, CopiedString& name, TextureProjection &projection ){ + Patch* patch = nullptr; + if ( !( patch = Scene_GetUltimateSelectedVisiblePatch() ) ) + Scene_forEachSelectedPatch( [&patch]( PatchInstance& p ){ if( !patch ) patch = &p.getPatch(); } ); + if( patch ){ + name = patch->GetShader(); + PatchTexdefConstructor c( patch ); + if( c.valid() ) + projection.m_brushprimit_texdef = c.m_bp; + return true; + } + return false; +} + void Patch_SetTexdef( const float* hShift, const float* vShift, const float* hScale, const float* vScale, const float* rotation ){ Scene_forEachVisibleSelectedPatch( [hShift, vShift, hScale, vScale, rotation]( Patch& patch ){ PatchTexdefConstructor c( &patch ); diff --git a/radiant/patchmanip.h b/radiant/patchmanip.h index 39953086..70de3341 100644 --- a/radiant/patchmanip.h +++ b/radiant/patchmanip.h @@ -39,6 +39,7 @@ void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ); void Scene_PatchGetTexdef_Selected( scene::Graph& graph, class TextureProjection &projection ); +bool Scene_PatchGetShaderTexdef_Selected( scene::Graph& graph, CopiedString& name, TextureProjection &projection ); void Patch_SetTexdef( const float* hShift, const float* vShift, const float* hScale, const float* vScale, const float* rotation ); void Scene_PatchCapTexture_Selected( scene::Graph& graph ); diff --git a/radiant/surfacedialog.cpp b/radiant/surfacedialog.cpp index 1419d79c..3f8c2055 100644 --- a/radiant/surfacedialog.cpp +++ b/radiant/surfacedialog.cpp @@ -251,7 +251,7 @@ void SurfaceInspector_SetCurrent_FromSelected(){ CopiedString name; Scene_BrushGetShader_Component_Selected( GlobalSceneGraph(), name ); - if ( string_not_empty( name.c_str() ) ) { + if ( !name.empty() ) { SurfaceInspector_SetSelectedShader( name.c_str() ); } @@ -263,18 +263,12 @@ void SurfaceInspector_SetCurrent_FromSelected(){ { TextureProjection projection; CopiedString name; - Scene_BrushGetShader_Selected( GlobalSceneGraph(), name ); - if ( string_empty( name.c_str() ) ) { - s_patch_mode = true; - Scene_PatchGetShader_Selected( GlobalSceneGraph(), name ); - Scene_PatchGetTexdef_Selected( GlobalSceneGraph(), projection ); - } - else{ - s_patch_mode = false; - Scene_BrushGetTexdef_Selected( GlobalSceneGraph(), projection ); - } + s_patch_mode = false; + if( !Scene_BrushGetShaderTexdef_Selected( GlobalSceneGraph(), name, projection ) ) + if( Scene_PatchGetShaderTexdef_Selected( GlobalSceneGraph(), name, projection ) ) + s_patch_mode = true; SurfaceInspector_SetSelectedTexdef( projection ); - if ( string_not_empty( name.c_str() ) ) { + if ( !name.empty() ) { SurfaceInspector_SetSelectedShader( name.c_str() ); }