* remove entity->ungroup command: change classname to worldspawn does equal job; 'create worldspawn' click ungroups selected primitives only

This commit is contained in:
Garux 2018-05-24 22:56:46 +03:00
parent 66197713a5
commit bf6e29d9c6
3 changed files with 39 additions and 41 deletions

View File

@ -85,9 +85,10 @@ class EntitySetClassnameSelected : public scene::Graph::Walker
{ {
const char* m_classname; const char* m_classname;
scene::Node* m_world; scene::Node* m_world;
const bool m_2world;
public: public:
EntitySetClassnameSelected( const char* classname ) EntitySetClassnameSelected( const char* classname )
: m_classname( classname ), m_world( Map_FindWorldspawn( g_map ) ){ : m_classname( classname ), m_world( Map_FindWorldspawn( g_map ) ), m_2world( m_world && string_equal( m_classname, "worldspawn" ) ){
} }
bool pre( const scene::Path& path, scene::Instance& instance ) const { bool pre( const scene::Path& path, scene::Instance& instance ) const {
return true; return true;
@ -96,7 +97,7 @@ void post( const scene::Path& path, scene::Instance& instance ) const {
Entity* entity = Node_getEntity( path.top() ); Entity* entity = Node_getEntity( path.top() );
if ( entity != 0 && ( instance.childSelected() || Instance_getSelectable( instance )->isSelected() ) ) { if ( entity != 0 && ( instance.childSelected() || Instance_getSelectable( instance )->isSelected() ) ) {
if( path.top().get_pointer() == m_world ){ /* do not want to convert whole worldspawn entity */ if( path.top().get_pointer() == m_world ){ /* do not want to convert whole worldspawn entity */
if( instance.childSelected() ){ /* create an entity from world brushes instead */ if( instance.childSelected() && !m_2world ){ /* create an entity from world brushes instead */
EntityClass* entityClass = GlobalEntityClassManager().findOrInsert( m_classname, true ); EntityClass* entityClass = GlobalEntityClassManager().findOrInsert( m_classname, true );
if( entityClass->fixedsize ) if( entityClass->fixedsize )
return; return;
@ -124,6 +125,13 @@ void post( const scene::Path& path, scene::Instance& instance ) const {
} }
return; return;
} }
else if( m_2world ){ /* ungroupSelectedEntities */ //condition is skipped with world = 0, so code next to this may create multiple worldspawns; todo handle this very special case?
if( node_is_group( path.top() ) ){
parentBrushes( path.top(), *m_world );
Path_deleteTop( path );
}
return;
}
EntityClass* eclass = GlobalEntityClassManager().findOrInsert( m_classname, node_is_group( path.top() ) ); EntityClass* eclass = GlobalEntityClassManager().findOrInsert( m_classname, node_is_group( path.top() ) );
NodeSmartReference node( GlobalEntityCreator().createEntity( eclass ) ); NodeSmartReference node( GlobalEntityCreator().createEntity( eclass ) );
@ -166,24 +174,18 @@ void Scene_EntitySetKeyValue_Selected( const char* key, const char* value ){
} }
void Scene_EntitySetClassname_Selected( const char* classname ){ void Scene_EntitySetClassname_Selected( const char* classname ){
if ( GlobalSelectionSystem().countSelected() < 1 ) { if ( GlobalSelectionSystem().countSelected() > 0 ) {
return;
}
if( string_equal( classname, "worldspawn" ) ){
UndoableCommand undo( "ungroupSelectedPrimitives" );
Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), Map_FindOrInsertWorldspawn( g_map ) ); //=no action, if no worldspawn (but one inserted)
//Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), *Map_FindWorldspawn( g_map )); = crash, if no worldspawn
}
else{
StringOutputStream command; StringOutputStream command;
if( string_equal( classname, "worldspawn" ) )
command << "ungroupSelectedEntities";
else
command << "entitySetClass -class " << classname; command << "entitySetClass -class " << classname;
UndoableCommand undo( command.c_str() ); UndoableCommand undo( command.c_str() );
GlobalSceneGraph().traverse( EntitySetClassnameSelected( classname ) ); GlobalSceneGraph().traverse( EntitySetClassnameSelected( classname ) );
} }
} }
#if 0
void Entity_ungroupSelected(){ void Entity_ungroupSelected(){
if ( GlobalSelectionSystem().countSelected() < 1 ) { if ( GlobalSelectionSystem().countSelected() < 1 ) {
return; return;
@ -208,6 +210,7 @@ void Entity_ungroupSelected(){
} }
} }
} }
#endif
#if 0 #if 0
class EntityFindSelected : public scene::Graph::Walker class EntityFindSelected : public scene::Graph::Walker
@ -375,8 +378,21 @@ void Entity_createFromSelection( const char* name, const Vector3& origin ){
gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), "Can't create an entity with worldspawn.", "info" ); gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), "Can't create an entity with worldspawn.", "info" );
return; return;
} }
#else
const scene::Node* world_node = Map_FindWorldspawn( g_map );
if ( world_node && string_equal( name, "worldspawn" ) ) {
// GlobalRadiant().m_pfnMessageBox( GTK_WIDGET( MainFrame_getWindow() ), "There's already a worldspawn in your map!", "Info", eMB_OK, eMB_ICONDEFAULT );
UndoableCommand undo( "ungroupSelectedPrimitives" );
Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), Map_FindOrInsertWorldspawn( g_map ) ); //=no action, if no worldspawn (but one inserted) (since insertion deselects everything)
//Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), *Map_FindWorldspawn( g_map ) ); = crash, if no worldspawn
return;
}
#endif #endif
StringOutputStream command;
command << "entityCreate -class " << name;
UndoableCommand undo( command.c_str() );
EntityClass* entityClass = GlobalEntityClassManager().findOrInsert( name, true ); EntityClass* entityClass = GlobalEntityClassManager().findOrInsert( name, true );
const bool isModel = entityClass->miscmodel_is const bool isModel = entityClass->miscmodel_is
@ -728,7 +744,6 @@ void ToggleShowLightRadii(){
void Entity_constructMenu( GtkMenu* menu ){ void Entity_constructMenu( GtkMenu* menu ){
create_menu_item_with_mnemonic( menu, "_Move Primitives to Entity", "EntityMovePrimitives" ); 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 Entities", "EntitiesConnect" ); create_menu_item_with_mnemonic( menu, "_Connect Entities", "EntitiesConnect" );
if ( g_pGameDescription->mGameType == "nexuiz" ) { if ( g_pGameDescription->mGameType == "nexuiz" ) {
create_menu_item_with_mnemonic( menu, "_KillConnect Entities", "EntitiesKillConnect" ); create_menu_item_with_mnemonic( menu, "_KillConnect Entities", "EntitiesKillConnect" );
@ -749,7 +764,6 @@ void Entity_Construct(){
if ( g_pGameDescription->mGameType == "nexuiz" ) if ( g_pGameDescription->mGameType == "nexuiz" )
GlobalCommands_insert( "EntitiesKillConnect", FreeCaller<Entity_killconnectSelected>(), Accelerator( 'K', (GdkModifierType)GDK_SHIFT_MASK ) ); 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( "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 ) ); GlobalToggles_insert( "ShowLightRadiuses", FreeCaller<ToggleShowLightRadii>(), ToggleItem::AddCallbackCaller( g_show_lightradii_item ) );

View File

@ -168,7 +168,6 @@ gboolean Trigger_button_press( GtkWidget *widget, GdkEventButton *event, gpointe
gboolean Func_Groups_button_press( GtkWidget *widget, GdkEventButton *event, gpointer data ){ gboolean Func_Groups_button_press( GtkWidget *widget, GdkEventButton *event, gpointer data ){
if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) { if ( event->button == 3 && event->type == GDK_BUTTON_PRESS ) {
UndoableCommand undo( "create func_group" );
Entity_createFromSelection( "func_group", g_vector3_identity ); Entity_createFromSelection( "func_group", g_vector3_identity );
ToggleActions = 0; ToggleActions = 0;
return TRUE; return TRUE;

View File

@ -861,19 +861,8 @@ void XYWnd::NewBrushDrag( int x, int y, bool square, bool cube ){
int g_entityCreationOffset = 0; int g_entityCreationOffset = 0;
void entitycreate_activated( GtkMenuItem* item, gpointer user_data ){ 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 ) ); const char* entity_name = gtk_label_get_text( GTK_LABEL( GTK_BIN( item )->child ) );
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 ){ if( g_bCamEntityMenu ){
StringOutputStream command;
command << "entityCreate -class " << entity_name;
UndoableCommand undo( command.c_str() );
const Vector3 viewvector = -Camera_getViewVector( *g_pParentWnd->GetCamWnd() ); const Vector3 viewvector = -Camera_getViewVector( *g_pParentWnd->GetCamWnd() );
const float offset_for_multiple = std::max( GetSnapGridSize(), 8.f ) * g_entityCreationOffset; 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 point = viewvector * ( 64.f + offset_for_multiple ) + Camera_getOrigin( *g_pParentWnd->GetCamWnd() );
@ -884,7 +873,6 @@ void entitycreate_activated( GtkMenuItem* item, gpointer user_data ){
g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name ); g_pParentWnd->ActiveXY()->OnEntityCreate( entity_name );
} }
++g_entityCreationOffset; ++g_entityCreationOffset;
}
} }
gboolean entitycreate_rightClicked( GtkWidget* widget, GdkEvent* event, gpointer user_data ) { gboolean entitycreate_rightClicked( GtkWidget* widget, GdkEvent* event, gpointer user_data ) {
@ -2494,9 +2482,6 @@ void XYWnd_MouseToPoint( XYWnd* xywnd, int x, int y, Vector3& point ){
} }
void XYWnd::OnEntityCreate( const char* item ){ void XYWnd::OnEntityCreate( const char* item ){
StringOutputStream command;
command << "entityCreate -class " << item;
UndoableCommand undo( command.c_str() );
Vector3 point; Vector3 point;
XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point ); XYWnd_MouseToPoint( this, m_entityCreate_x, m_entityCreate_y, point );