diff --git a/plugins/entity/entity.cpp b/plugins/entity/entity.cpp index 6d8bfb16..c2352266 100644 --- a/plugins/entity/entity.cpp +++ b/plugins/entity/entity.cpp @@ -151,7 +151,7 @@ typedef MemberCaller1 C inline Entity* ScenePath_getEntity( const scene::Path& path ){ Entity* entity = Node_getEntity( path.top() ); - if ( entity == 0 ) { + if ( entity == 0 && path.size() > 1 ) { entity = Node_getEntity( path.parent() ); } return entity; diff --git a/radiant/entity.cpp b/radiant/entity.cpp index 297ab4b9..0099be66 100644 --- a/radiant/entity.cpp +++ b/radiant/entity.cpp @@ -199,26 +199,25 @@ void Entity_ungroupSelected(){ UndoableCommand undo( "ungroupSelectedEntities" ); - scene::Path world_path( makeReference( GlobalSceneGraph().root() ) ); - world_path.push( makeReference( Map_FindOrInsertWorldspawn( g_map ) ) ); - scene::Instance &instance = GlobalSelectionSystem().ultimateSelected(); scene::Path path = instance.path(); - if ( !Node_isEntity( path.top() ) ) { + scene::Node& world = Map_FindOrInsertWorldspawn( g_map ); + + if ( !Node_isEntity( path.top() ) && path.size() > 1 ) { path.pop(); } - if ( Node_getEntity( path.top() ) != 0 + if ( Node_isEntity( path.top() ) && node_is_group( path.top() ) ) { - if ( world_path.top().get_pointer() != path.top().get_pointer() ) { - parentBrushes( path.top(), world_path.top() ); + if ( &world != path.top().get_pointer() ) { + parentBrushes( path.top(), world ); Path_deleteTop( path ); } } } - +#if 0 class EntityFindSelected : public scene::Graph::Walker { public: @@ -280,8 +279,8 @@ void post( const scene::Path& path, scene::Instance& instance ) const { } } }; - -void Entity_regroupSelected(){ +/// moves selected primitives to entity, whose entityNode is selected or to worldspawn, if none +void Entity_moveSelectedPrimitives(){ if ( GlobalSelectionSystem().countSelected() < 1 ) { return; } @@ -301,6 +300,25 @@ void Entity_regroupSelected(){ GlobalSceneGraph().traverse( EntityGroupSelected( world_path ) ); } } +#else +/// moves selected primitives to entity, which is or its primitive is ultimateSelected() +void Entity_moveSelectedPrimitives(){ + if ( GlobalSelectionSystem().countSelected() < 2 ) { + globalErrorStream() << "Source and target entity primitives should be selected!\n"; + return; + } + + const scene::Path& path = GlobalSelectionSystem().ultimateSelected().path(); + scene::Node& node = ( !Node_isEntity( path.top() ) && path.size() > 1 )? path.parent() : path.top(); + + if ( Node_isEntity( node ) && node_is_group( node ) ) { + StringOutputStream command; + command << "movePrimitivesToEntity " << makeQuoted( Node_getEntity( node )->getEntityClass().name() ); + UndoableCommand undo( command.c_str() ); + Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), node ); + } +} +#endif @@ -717,14 +735,14 @@ void ToggleShowLightRadii(){ } void Entity_constructMenu( GtkMenu* menu ){ - create_menu_item_with_mnemonic( menu, "_Regroup", "RegroupSelection" ); + create_menu_item_with_mnemonic( menu, "_Move Primitives to Entity", "EntityMovePrimitives" ); create_menu_item_with_mnemonic( menu, "_Ungroup", "UngroupSelection" ); - create_menu_item_with_mnemonic( menu, "_Connect", "ConnectSelection" ); + create_menu_item_with_mnemonic( menu, "_Connect Entities", "EntitiesConnect" ); if ( g_pGameDescription->mGameType == "nexuiz" ) { - create_menu_item_with_mnemonic( menu, "_KillConnect", "KillConnectSelection" ); + create_menu_item_with_mnemonic( menu, "_KillConnect Entities", "EntitiesKillConnect" ); } - create_menu_item_with_mnemonic( menu, "_Select Color...", "EntityColor" ); - create_menu_item_with_mnemonic( menu, "_Normalize Color", "NormalizeColor" ); + create_menu_item_with_mnemonic( menu, "_Select Color...", "EntityColorSet" ); + create_menu_item_with_mnemonic( menu, "_Normalize Color", "EntityColorNormalize" ); } @@ -733,12 +751,12 @@ void Entity_constructMenu( GtkMenu* menu ){ #include "stringio.h" void Entity_Construct(){ - GlobalCommands_insert( "EntityColor", FreeCaller(), Accelerator( 'K' ) ); - GlobalCommands_insert( "NormalizeColor", FreeCaller() ); - GlobalCommands_insert( "ConnectSelection", FreeCaller(), Accelerator( 'K', (GdkModifierType)GDK_CONTROL_MASK ) ); + GlobalCommands_insert( "EntityColorSet", FreeCaller(), Accelerator( 'K' ) ); + GlobalCommands_insert( "EntityColorNormalize", FreeCaller() ); + GlobalCommands_insert( "EntitiesConnect", FreeCaller(), Accelerator( 'K', (GdkModifierType)GDK_CONTROL_MASK ) ); if ( g_pGameDescription->mGameType == "nexuiz" ) - GlobalCommands_insert( "KillConnectSelection", FreeCaller(), Accelerator( 'K', (GdkModifierType)( GDK_SHIFT_MASK ) ) ); - GlobalCommands_insert( "RegroupSelection", FreeCaller() ); + GlobalCommands_insert( "EntitiesKillConnect", FreeCaller(), Accelerator( 'K', (GdkModifierType)GDK_SHIFT_MASK ) ); + GlobalCommands_insert( "EntityMovePrimitives", FreeCaller(), Accelerator( 'M', (GdkModifierType)GDK_CONTROL_MASK ) ); GlobalCommands_insert( "UngroupSelection", FreeCaller() ); GlobalToggles_insert( "ShowLightRadiuses", FreeCaller(), ToggleItem::AddCallbackCaller( g_show_lightradii_item ) ); diff --git a/radiant/select.cpp b/radiant/select.cpp index 62e6b6a3..49cb816a 100644 --- a/radiant/select.cpp +++ b/radiant/select.cpp @@ -254,7 +254,7 @@ void post( const scene::Path& path, scene::Instance& instance ) const { // node should be removed if ( m_remove ) { - if ( Node_isEntity( path.parent() ) != 0 ) { + if ( Node_isEntity( path.parent() ) ) { m_removedChild = true; } diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 01e9f287..f6e49d00 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -864,23 +864,18 @@ void entitycreate_activated( GtkMenuItem* item, gpointer user_data ){ scene::Node* world_node = Map_FindWorldspawn( g_map ); const char* entity_name = gtk_label_get_text( GTK_LABEL( GTK_BIN( item )->child ) ); - if ( !( world_node && string_equal( entity_name, "worldspawn" ) ) ) { + if ( world_node && string_equal( entity_name, "worldspawn" ) ) { +// GlobalRadiant().m_pfnMessageBox( GTK_WIDGET( MainFrame_getWindow() ), "There's already a worldspawn in your map!", "Info", eMB_OK, eMB_ICONDEFAULT ); + Scene_EntitySetClassname_Selected( entity_name ); /* ungroupSelectedPrimitives */ + } + else { if( g_bCamEntityMenu ){ StringOutputStream command; command << "entityCreate -class " << entity_name; UndoableCommand undo( command.c_str() ); -#if 0 - Vector3 angles( Camera_getAngles( *g_pParentWnd->GetCamWnd() ) ); - Vector3 radangles( degrees_to_radians( angles[0] ), degrees_to_radians( angles[1] ), degrees_to_radians( angles[2] ) ); - Vector3 viewvector; - viewvector[0] = cos( radangles[1] ) * cos( radangles[0] ); - viewvector[1] = sin( radangles[1] ) * cos( radangles[0] ); - viewvector[2] = sin( radangles[0] ); -#else - Vector3 viewvector = -Camera_getViewVector( *g_pParentWnd->GetCamWnd() ); -#endif - float offset_for_multiple = ( GetSnapGridSize() < 8.f ? 8.f : GetSnapGridSize() ) * g_entityCreationOffset; + const Vector3 viewvector = -Camera_getViewVector( *g_pParentWnd->GetCamWnd() ); + const float offset_for_multiple = std::max( GetSnapGridSize(), 8.f ) * g_entityCreationOffset; Vector3 point = viewvector * ( 64.f + offset_for_multiple ) + Camera_getOrigin( *g_pParentWnd->GetCamWnd() ); vector3_snap( point, GetSnapGridSize() ); Entity_createFromSelection( entity_name, point ); @@ -890,14 +885,6 @@ void entitycreate_activated( GtkMenuItem* item, gpointer user_data ){ } ++g_entityCreationOffset; } - else { -// GlobalRadiant().m_pfnMessageBox( GTK_WIDGET( MainFrame_getWindow() ), "There's already a worldspawn in your map!" -// "", -// "Info", -// eMB_OK, -// eMB_ICONDEFAULT ); - Scene_EntitySetClassname_Selected( entity_name ); //ungroupSelectedPrimitives - } } gboolean entitycreate_rightClicked( GtkWidget* widget, GdkEvent* event, gpointer user_data ) {