* replace reGroup command with simpler to use Move Primitives to Entity one (select primitives to move, select target entity primitive, go)

fix crashes in Entity_ungroupSelected, Entity_connectSelected
rename entity commands uniformly for simpler search in the list
This commit is contained in:
Garux 2018-05-24 18:21:38 +03:00
parent 6f8a0668a3
commit 17a7e2f413
4 changed files with 47 additions and 42 deletions

View File

@ -151,7 +151,7 @@ typedef MemberCaller1<ConnectEntities, const char*, &ConnectEntities::connect> 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;

View File

@ -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<Entity_setColour>(), Accelerator( 'K' ) );
GlobalCommands_insert( "NormalizeColor", FreeCaller<Entity_normalizeColor>() );
GlobalCommands_insert( "ConnectSelection", FreeCaller<Entity_connectSelected>(), Accelerator( 'K', (GdkModifierType)GDK_CONTROL_MASK ) );
GlobalCommands_insert( "EntityColorSet", FreeCaller<Entity_setColour>(), Accelerator( 'K' ) );
GlobalCommands_insert( "EntityColorNormalize", FreeCaller<Entity_normalizeColor>() );
GlobalCommands_insert( "EntitiesConnect", FreeCaller<Entity_connectSelected>(), Accelerator( 'K', (GdkModifierType)GDK_CONTROL_MASK ) );
if ( g_pGameDescription->mGameType == "nexuiz" )
GlobalCommands_insert( "KillConnectSelection", FreeCaller<Entity_killconnectSelected>(), Accelerator( 'K', (GdkModifierType)( GDK_SHIFT_MASK ) ) );
GlobalCommands_insert( "RegroupSelection", FreeCaller<Entity_regroupSelected>() );
GlobalCommands_insert( "EntitiesKillConnect", FreeCaller<Entity_killconnectSelected>(), Accelerator( 'K', (GdkModifierType)GDK_SHIFT_MASK ) );
GlobalCommands_insert( "EntityMovePrimitives", FreeCaller<Entity_moveSelectedPrimitives>(), Accelerator( 'M', (GdkModifierType)GDK_CONTROL_MASK ) );
GlobalCommands_insert( "UngroupSelection", FreeCaller<Entity_ungroupSelected>() );
GlobalToggles_insert( "ShowLightRadiuses", FreeCaller<ToggleShowLightRadii>(), ToggleItem::AddCallbackCaller( g_show_lightradii_item ) );

View File

@ -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;
}

View File

@ -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 ) {