static bool Entity_create (const std::string& name, const Vector3& origin) { EntityClass* entityClass = GlobalEntityClassManager().findOrInsert(name, true); bool revert = false; const bool isModel = (name == "misc_model"); const bool isSound = (name == "misc_sound"); const bool isParticle = (name == "misc_particle"); const bool isStartingPositionActor = (name == "info_player_start") || (name == "info_human_start") || (name == "info_alien_start") || (name == "info_civilian_start"); const bool isStartingPositionUGV = (name == "info_2x2_start"); const bool isStartingPosition = isStartingPositionActor || isStartingPositionUGV; const bool brushesSelected = map::countSelectedBrushes() != 0; if (!(entityClass->fixedsize || isModel) && !brushesSelected) { throw EntityCreationException(std::string("Unable to create entity \"") + name + "\", no brushes selected"); } UndoableCommand undo("entityCreate -class " + name); AABB workzone(AABB::createFromMinMax(GlobalSelectionSystem().getWorkZone().min, GlobalSelectionSystem().getWorkZone().max)); NodeSmartReference node(GlobalEntityCreator().createEntity(entityClass)); Node_getTraversable(GlobalSceneGraph().root())->insert(node); scene::Path entitypath(makeReference(GlobalSceneGraph().root())); entitypath.push(makeReference(node.get())); scene::Instance& instance = findInstance(entitypath); // set all mandatory fields to default values // some will be overwritten later Entity *entity = Node_getEntity(node); entity->addMandatoryKeyValues(); if (entityClass->fixedsize || (isModel && !brushesSelected)) { selection::algorithm::deleteSelection(); Transformable* transform = Instance_getTransformable(instance); if (transform != 0) { transform->setType(TRANSFORM_PRIMITIVE); if (isStartingPosition) { const int sizeX = (int) ((entityClass->maxs[0] - entityClass->mins[0]) / 2.0); const int sizeY = (int) ((entityClass->maxs[1] - entityClass->mins[1]) / 2.0); const int sizeZ = (int) ((entityClass->maxs[2] - entityClass->mins[2]) / 2.0); const int x = ((int) origin.x() / UNIT_SIZE) * UNIT_SIZE - sizeX; const int y = ((int) origin.y() / UNIT_SIZE) * UNIT_SIZE - sizeY; const int z = ((int) origin.z() / UNIT_HEIGHT) * UNIT_HEIGHT + sizeZ; const Vector3 vec(x, y, z); transform->setTranslation(vec); } else { transform->setTranslation(origin); } transform->freezeTransform(); } GlobalSelectionSystem().setSelectedAll(false); Instance_setSelected(instance, true); } else { // Add selected brushes as children of non-fixed entity Scene_parentSelectedBrushesToEntity(GlobalSceneGraph(), node); Scene_forEachChildSelectable(SelectableSetSelected(true), instance.path()); } // TODO tweaking: when right click dropping a light entity, ask for light value in a custom dialog box if (name == "light" || name == "light_spot") { ui::LightDialog dialog; dialog.show(); if (!dialog.isAborted()) { std::string intensity = dialog.getIntensity(); Vector3 color = dialog.getColor(); entity->setKeyValue("light", intensity); entity->setKeyValue("_color", color.toString()); } else revert = true; } if (isModel) { ui::ModelAndSkin modelAndSkin = ui::ModelSelector::chooseModel(); if (!modelAndSkin.model.empty()) { entity->setKeyValue("model", modelAndSkin.model); if (modelAndSkin.skin != -1) entity->setKeyValue("skin", string::toString(modelAndSkin.skin)); } else revert = true; } else if (isSound) { // Display the Sound Chooser to get a sound from the user ui::SoundChooser sChooser; std::string sound = sChooser.chooseSound(); if (!sound.empty()) entity->setKeyValue("noise", sound); else revert = true; } else if (isParticle) { ui::ParticleSelector pSelector; std::string particle = pSelector.chooseParticle(); if (!particle.empty()) entity->setKeyValue("particle", particle); else revert = true; } return revert; }
void Entity_createFromSelection( const char* name, const Vector3& origin ){ #if 0 if ( string_equal_nocase( name, "worldspawn" ) ) { ui::alert( MainFrame_getWindow( ), "Can't create an entity with worldspawn.", "info" ); return; } #endif EntityClass* entityClass = GlobalEntityClassManager().findOrInsert( name, true ); bool isModel = ( string_compare_nocase_n( name, "misc_", 5 ) == 0 && string_equal_nocase( name + string_length( name ) - 5, "model" ) ) // misc_*model (also misc_model) || string_equal_nocase( name, "model_static" ) || ( GlobalSelectionSystem().countSelected() == 0 && string_equal_nocase( name, "func_static" ) ); bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0; if ( !( entityClass->fixedsize || isModel ) && !brushesSelected ) { globalErrorStream() << "failed to create a group entity - no brushes are selected\n"; return; } AABB workzone( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) ); NodeSmartReference node( GlobalEntityCreator().createEntity( entityClass ) ); Node_getTraversable( GlobalSceneGraph().root() )->insert( node ); scene::Path entitypath( makeReference( GlobalSceneGraph().root() ) ); entitypath.push( makeReference( node.get() ) ); scene::Instance& instance = findInstance( entitypath ); if ( entityClass->fixedsize || ( isModel && !brushesSelected ) ) { Select_Delete(); Transformable* transform = Instance_getTransformable( instance ); if ( transform != 0 ) { transform->setType( TRANSFORM_PRIMITIVE ); transform->setTranslation( origin ); transform->freezeTransform(); } GlobalSelectionSystem().setSelectedAll( false ); Instance_setSelected( instance, true ); } else { if ( g_pGameDescription->mGameType == "doom3" ) { Node_getEntity( node )->setKeyValue( "model", Node_getEntity( node )->getKeyValue( "name" ) ); } Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), node ); Scene_forEachChildSelectable( SelectableSetSelected( true ), instance.path() ); } // tweaking: when right clic dropping a light entity, ask for light value in a custom dialog box // see SF bug 105383 if ( g_pGameDescription->mGameType == "hl" ) { // FIXME - Hydra: really we need a combined light AND color dialog for halflife. if ( string_equal_nocase( name, "light" ) || string_equal_nocase( name, "light_environment" ) || string_equal_nocase( name, "light_spot" ) ) { int intensity = g_iLastLightIntensity; if ( DoLightIntensityDlg( &intensity ) == eIDOK ) { g_iLastLightIntensity = intensity; char buf[30]; sprintf( buf, "255 255 255 %d", intensity ); Node_getEntity( node )->setKeyValue( "_light", buf ); } } } else if ( string_equal_nocase( name, "light" ) ) { if ( g_pGameDescription->mGameType != "doom3" ) { int intensity = g_iLastLightIntensity; if ( DoLightIntensityDlg( &intensity ) == eIDOK ) { g_iLastLightIntensity = intensity; char buf[10]; sprintf( buf, "%d", intensity ); Node_getEntity( node )->setKeyValue( "light", buf ); } } else if ( brushesSelected ) { // use workzone to set light position/size for doom3 lights, if there are brushes selected AABB bounds( Doom3Light_getBounds( workzone ) ); StringOutputStream key( 64 ); key << bounds.origin[0] << " " << bounds.origin[1] << " " << bounds.origin[2]; Node_getEntity( node )->setKeyValue( "origin", key.c_str() ); key.clear(); key << bounds.extents[0] << " " << bounds.extents[1] << " " << bounds.extents[2]; Node_getEntity( node )->setKeyValue( "light_radius", key.c_str() ); } } if ( isModel ) { const char* model = misc_model_dialog(MainFrame_getWindow()); if ( model != 0 ) { Node_getEntity( node )->setKeyValue( "model", model ); } } }
void Entity_createFromSelection(const char* name, const Vector3& origin) { #if 0 if(string_equal_nocase(name, "worldspawn")) { gtk_MessageBox(GTK_WIDGET(MainFrame_getWindow()), "Can't create an entity with worldspawn.", "info"); return; } #endif EntityClass* entityClass = GlobalEntityClassManager().findOrInsert(name, true); bool isModel = string_equal_nocase(name, "misc_model") || string_equal_nocase(name, "misc_gamemodel") || string_equal_nocase(name, "model_static") || (GlobalSelectionSystem().countSelected() == 0 && string_equal_nocase(name, "func_static")); if(!(entityClass->fixedsize || isModel) && Scene_countSelectedBrushes(GlobalSceneGraph()) == 0) { globalErrorStream() << "failed to create a group entity - no brushes are selected\n"; return; } NodeSmartReference node(GlobalEntityCreator().createEntity(entityClass)); Node_getTraversable(GlobalSceneGraph().root())->insert(node); scene::Path entitypath(makeReference(GlobalSceneGraph().root())); entitypath.push(makeReference(node.get())); scene::Instance& instance = findInstance(entitypath); if(entityClass->fixedsize) { Select_Delete(); Transformable* transform = Instance_getTransformable(instance); if(transform != 0) { transform->setType(TRANSFORM_PRIMITIVE); transform->setTranslation(origin); transform->freezeTransform(); } GlobalSelectionSystem().setSelectedAll(false); Instance_setSelected(instance, true); } else { Scene_parentSelectedBrushesToEntity(GlobalSceneGraph(), node); Scene_forEachChildSelectable(SelectableSetSelected(true), instance.path()); } // tweaking: when right clic dropping a light entity, ask for light value in a custom dialog box // see SF bug 105383 if (g_pGameDescription->mGameType == "hl") { // FIXME - Hydra: really we need a combined light AND color dialog for halflife. if (string_equal_nocase(name, "light") || string_equal_nocase(name, "light_environment") || string_equal_nocase(name, "light_spot")) { int intensity = g_iLastLightIntensity; if (DoLightIntensityDlg (&intensity) == eIDOK) { g_iLastLightIntensity = intensity; char buf[30]; sprintf( buf, "255 255 255 %d", intensity ); Node_getEntity(node)->setKeyValue("_light", buf); } } } else if(g_pGameDescription->mGameType != "doom3" && string_equal_nocase(name, "light")) { int intensity = g_iLastLightIntensity; if (DoLightIntensityDlg (&intensity) == eIDOK) { g_iLastLightIntensity = intensity; char buf[10]; sprintf( buf, "%d", intensity ); Node_getEntity(node)->setKeyValue("light", buf); } } if(isModel) { const char* model = misc_model_dialog(GTK_WIDGET(MainFrame_getWindow())); if(model != 0) { Node_getEntity(node)->setKeyValue("model", model); } } }
void Entity_createFromSelection( const char* name, const Vector3& origin ){ #if 0 if ( string_equal_nocase( name, "worldspawn" ) ) { gtk_MessageBox( GTK_WIDGET( MainFrame_getWindow() ), "Can't create an entity with worldspawn.", "info" ); 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 StringOutputStream command; command << "entityCreate -class " << name; UndoableCommand undo( command.c_str() ); EntityClass* entityClass = GlobalEntityClassManager().findOrInsert( name, true ); const bool isModel = entityClass->miscmodel_is || ( GlobalSelectionSystem().countSelected() == 0 && classname_equal( name, "func_static" ) && g_pGameDescription->mGameType == "doom3" ); const bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0; //is important to have retexturing here; if doing in the end, undo doesn't succeed; if ( string_compare_nocase_n( name, "trigger_", 8 ) == 0 && brushesSelected && !entityClass->fixedsize ){ //const char* shader = GetCommonShader( "trigger" ).c_str(); Scene_PatchSetShader_Selected( GlobalSceneGraph(), GetCommonShader( "trigger" ).c_str() ); Scene_BrushSetShader_Selected( GlobalSceneGraph(), GetCommonShader( "trigger" ).c_str() ); } if ( !( entityClass->fixedsize || isModel ) && !brushesSelected ) { globalErrorStream() << "failed to create a group entity - no brushes are selected\n"; return; } AABB workzone( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) ); NodeSmartReference node( GlobalEntityCreator().createEntity( entityClass ) ); Node_getTraversable( GlobalSceneGraph().root() )->insert( node ); scene::Path entitypath( makeReference( GlobalSceneGraph().root() ) ); entitypath.push( makeReference( node.get() ) ); scene::Instance& instance = findInstance( entitypath ); if ( entityClass->fixedsize || ( isModel && !brushesSelected ) ) { //Select_Delete(); Transformable* transform = Instance_getTransformable( instance ); if ( transform != 0 ) { transform->setType( TRANSFORM_PRIMITIVE ); transform->setTranslation( origin ); transform->freezeTransform(); } GlobalSelectionSystem().setSelectedAll( false ); Instance_setSelected( instance, true ); } else { if ( g_pGameDescription->mGameType == "doom3" ) { Node_getEntity( node )->setKeyValue( "model", Node_getEntity( node )->getKeyValue( "name" ) ); } Scene_parentSelectedBrushesToEntity( GlobalSceneGraph(), node ); Scene_forEachChildSelectable( SelectableSetSelected( true ), instance.path() ); } // tweaking: when right click dropping a light entity, ask for light value in a custom dialog box // see SF bug 105383 if ( g_pGameDescription->mGameType == "hl" ) { // FIXME - Hydra: really we need a combined light AND color dialog for halflife. if ( string_equal_nocase( name, "light" ) || string_equal_nocase( name, "light_environment" ) || string_equal_nocase( name, "light_spot" ) ) { int intensity = g_iLastLightIntensity; if ( DoLightIntensityDlg( &intensity ) == eIDOK ) { g_iLastLightIntensity = intensity; char buf[30]; sprintf( buf, "255 255 255 %d", intensity ); Node_getEntity( node )->setKeyValue( "_light", buf ); } } } else if ( string_equal_nocase( name, "light" ) ) { if ( g_pGameDescription->mGameType != "doom3" ) { int intensity = g_iLastLightIntensity; if ( DoLightIntensityDlg( &intensity ) == eIDOK ) { g_iLastLightIntensity = intensity; char buf[10]; sprintf( buf, "%d", intensity ); Node_getEntity( node )->setKeyValue( "light", buf ); } } else if ( brushesSelected ) { // use workzone to set light position/size for doom3 lights, if there are brushes selected AABB bounds( Doom3Light_getBounds( workzone ) ); StringOutputStream key( 64 ); key << bounds.origin[0] << " " << bounds.origin[1] << " " << bounds.origin[2]; Node_getEntity( node )->setKeyValue( "origin", key.c_str() ); key.clear(); key << bounds.extents[0] << " " << bounds.extents[1] << " " << bounds.extents[2]; Node_getEntity( node )->setKeyValue( "light_radius", key.c_str() ); } } if ( isModel ) { const char* model = misc_model_dialog( GTK_WIDGET( MainFrame_getWindow() ) ); if ( model != 0 ) { Node_getEntity( node )->setKeyValue( entityClass->miscmodel_key() , model ); } } }