]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/entity.cpp
Merge commit '4ee1a6ee1ae75d52984e54e689ef1e587b384bcb' into master-merge
[xonotic/netradiant.git] / radiant / entity.cpp
index 2952684df04ee93645c1fafdb4da6d8261f5f7c9..c555715cc2fccf995b03214518fa4fa83fe907e1 100644 (file)
 #include "select.h"
 #include "map.h"
 #include "preferences.h"
+#include "preferencesystem.h"
+#include "stringio.h"
 #include "gtkdlgs.h"
 #include "mainframe.h"
 #include "qe3.h"
 #include "commands.h"
 
+#include "brushmanip.h"
+#include "patchmanip.h"
+
 #include "uilib/uilib.h"
 
 struct entity_globals_t
@@ -66,9 +71,11 @@ public:
 EntitySetKeyValueSelected( const char* key, const char* value )
        : m_key( key ), m_value( value ){
 }
+
 bool pre( const scene::Path& path, scene::Instance& instance ) const {
        return true;
 }
+
 void post( const scene::Path& path, scene::Instance& instance ) const {
        Entity* entity = Node_getEntity( path.top() );
        if ( entity != 0
@@ -152,11 +159,14 @@ class EntityFindSelected : public scene::Graph::Walker
 public:
 mutable const scene::Path *groupPath;
 mutable scene::Instance *groupInstance;
+
 EntityFindSelected() : groupPath( 0 ), groupInstance( 0 ){
 }
+
 bool pre( const scene::Path& path, scene::Instance& instance ) const {
        return true;
 }
+
 void post( const scene::Path& path, scene::Instance& instance ) const {
        Entity* entity = Node_getEntity( path.top() );
        if ( entity != 0
@@ -177,9 +187,11 @@ NodeSmartReference group, worldspawn;
 public:
 EntityGroupSelected( const scene::Path &p ) : group( p.top().get() ), worldspawn( Map_FindOrInsertWorldspawn( g_map ) ){
 }
+
 bool pre( const scene::Path& path, scene::Instance& instance ) const {
        return true;
 }
+
 void post( const scene::Path& path, scene::Instance& instance ) const {
        Selectable *selectable = Instance_getSelectable( instance );
        if ( selectable && selectable->isSelected() ) {
@@ -231,7 +243,6 @@ void Entity_groupSelected(){
 }
 
 
-
 void Entity_connectSelected(){
        if ( GlobalSelectionSystem().countSelected() == 2 ) {
                GlobalEntityCreator().connectEntities(
@@ -298,7 +309,7 @@ void Entity_createFromSelection( const char* name, const Vector3& origin ){
 
        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" ) );
+                                  || ( GlobalSelectionSystem().countSelected() == 0 && string_equal_nocase( name, "func_static" ) && g_pGameDescription->mGameType == "doom3" );
 
        bool brushesSelected = Scene_countSelectedBrushes( GlobalSceneGraph() ) != 0;
 
@@ -388,6 +399,18 @@ void Entity_createFromSelection( const char* name, const Vector3& origin ){
                        Node_getEntity( node )->setKeyValue( "model", model );
                }
        }
+
+       if ( string_compare_nocase_n( name, "trigger_", 8 ) == 0 && brushesSelected ){
+               const char* shader = g_pGameDescription->getKeyValue( "shader_trigger" );
+               if ( shader && *shader ){
+                       Scene_PatchSetShader_Selected( GlobalSceneGraph(), shader );
+                       Scene_BrushSetShader_Selected( GlobalSceneGraph(), shader );
+               }
+               else{
+                       Scene_PatchSetShader_Selected( GlobalSceneGraph(), "textures/common/trigger" );
+                       Scene_BrushSetShader_Selected( GlobalSceneGraph(), "textures/common/trigger" );
+               }
+       }
 }
 
 #if 0
@@ -519,21 +542,32 @@ void Entity_setColour(){
        }
 }
 
-const char* misc_model_dialog( ui::Widget parent ){
-       StringOutputStream buffer( 1024 );
-
-       buffer << g_qeglobals.m_userGamePath.c_str() << "models/";
-
-       if ( !file_readable( buffer.c_str() ) ) {
-               // just go to fsmain
-               buffer.clear();
-               buffer << g_qeglobals.m_userGamePath.c_str() << "/";
+CopiedString g_strLastModelFolder = "";
+
+const char *getLastModelFolderPath(){
+       if ( g_strLastModelFolder.empty() ) {
+               GlobalPreferenceSystem().registerPreference( "LastModelFolder", make_property_string( g_strLastModelFolder ) );
+               if ( g_strLastModelFolder.empty() ) {
+                       StringOutputStream buffer( 1024 );
+                       buffer << g_qeglobals.m_userGamePath.c_str() << "models/";
+                       if ( !file_readable( buffer.c_str() ) ) {
+                               // just go to fsmain
+                               buffer.clear();
+                               buffer << g_qeglobals.m_userGamePath.c_str() << "/";
+                       }
+                       g_strLastModelFolder = buffer.c_str();
+               }
        }
+       return g_strLastModelFolder.c_str();
+}
+
+const char *misc_model_dialog( ui::Widget parent ){
+       const char *filename = parent.file_dialog( TRUE, "Choose Model", getLastModelFolderPath(), ModelLoader::Name() );
 
-       const char *filename = parent.file_dialog( TRUE, "Choose Model", buffer.c_str(), ModelLoader::Name() );
-       if ( filename != 0 ) {
+       if ( filename != NULL ) {
+               g_strLastModelFolder = g_path_get_dirname( filename );
                // use VFS to get the correct relative path
-               const charrelative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
+               const char *relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );
                if ( relative == filename ) {
                        globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
                }
@@ -562,26 +596,24 @@ void Entity_constructPage( PreferenceGroup& group ){
        PreferencesPage page( group.createPage( "Entities", "Entity Display Preferences" ) );
        Entity_constructPreferences( page );
 }
+
 void Entity_registerPreferencesPage(){
        PreferencesDialog_addDisplayPage( makeCallbackF(Entity_constructPage) );
 }
 
 
-
 void Entity_constructMenu( ui::Menu menu ){
        create_menu_item_with_mnemonic( menu, "_Regroup", "GroupSelection" );
        create_menu_item_with_mnemonic( menu, "_Ungroup", "UngroupSelection" );
        create_menu_item_with_mnemonic( menu, "_Connect", "ConnectSelection" );
-       create_menu_item_with_mnemonic( menu, "_KillConnect", "KillConnectSelection" );
+       if ( g_pGameDescription->mGameType == "nexuiz" ) {
+               create_menu_item_with_mnemonic( menu, "_KillConnect", "KillConnectSelection" );
+       }
        create_menu_item_with_mnemonic( menu, "_Select Color...", "EntityColor" );
        create_menu_item_with_mnemonic( menu, "_Normalize Color...", "NormalizeColor" );
 }
 
 
-
-#include "preferencesystem.h"
-#include "stringio.h"
-
 void Entity_Construct(){
        GlobalCommands_insert( "EntityColor", makeCallbackF(Entity_setColour), Accelerator( 'K' ) );
        GlobalCommands_insert( "NormalizeColor", makeCallbackF(Entity_normalizeColor) );