X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fmap.cpp;h=2f42496f8421db5f9abb2d5ac0c0aee7a60c63ae;hb=a3d27eedb7107d7dd964fcc9d25c6464e3280b98;hp=0c0fd5f73136a59472c32f7c4b7b9846b3d37979;hpb=f012273544dc1fb1a3fa710ee190677d3b0381e8;p=xonotic%2Fnetradiant.git diff --git a/radiant/map.cpp b/radiant/map.cpp index 0c0fd5f7..2f42496f 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -21,6 +21,8 @@ #include "map.h" +#include + #include "debugging/debugging.h" #include "imap.h" @@ -39,19 +41,12 @@ MapModules& ReferenceAPI_getMapModules(); #include "ifilesystem.h" #include "namespace.h" #include "moduleobserver.h" -#include "moduleobservers.h" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include "uilib/uilib.h" #include "scenelib.h" #include "transformlib.h" @@ -82,6 +77,7 @@ MapModules& ReferenceAPI_getMapModules(); #include "xywindow.h" #include "mainframe.h" #include "preferences.h" +#include "preferencesystem.h" #include "referencecache.h" #include "mru.h" #include "commands.h" @@ -156,7 +152,7 @@ void detach( const NameCallback& setName, const NameCallbackCallback& detachObse } void makeUnique( const char* name, const NameCallback& setName ) const { - char buffer[1024]; + auto buffer = u::buffer<1024>(); name_write( buffer, m_uniqueNames.make_unique( name_read( name ) ) ); setName( buffer ); } @@ -178,7 +174,7 @@ void mergeNames( const BasicNamespace& other ) const { name_t uniqueName( uniqueNames.make_unique( name_read( ( *i ).first.c_str() ) ) ); uniqueNames.insert( uniqueName ); - char buffer[1024]; + auto buffer = u::buffer<1024>(); name_write( buffer, uniqueName ); //globalOutputStream() << "renaming " << makeQuoted((*i).first.c_str()) << " to " << makeQuoted(buffer) << "\n"; @@ -406,29 +402,6 @@ float g_MinWorldCoord = -64 * 1024; void AddRegionBrushes( void ); void RemoveRegionBrushes( void ); -/* Map open/close observers */ - -ModuleObservers g_mapPathObservers; - -class MapFileObserver : public ModuleObserver -{ -void realise() { - // Restart VFS to apply new pak filtering based on mapname - // needed for daemon dpk vfs - VFS_Restart(); -} -void unrealise() { } -}; - -MapFileObserver g_mapFileObserver; - -void BindMapFileObservers(){ - g_mapPathObservers.attach( g_mapFileObserver ); -} - -void UnBindMapFileObservers(){ - g_mapPathObservers.detach( g_mapFileObserver ); -} /* @@ -448,7 +421,6 @@ void Map_Free(){ g_currentMap = 0; Brush_unlatchPreferences(); - g_mapPathObservers.unrealise(); } class EntityFindByClassname : public scene::Graph::Walker @@ -792,17 +764,17 @@ WindowPosition g_posMapInfoWnd( c_default_window_pos ); void DoMapInfo(){ ModalDialog dialog; - GtkEntry* brushes_entry; - GtkEntry* entities_entry; - GtkListStore* EntityBreakdownWalker; + ui::Entry brushes_entry{ui::null}; + ui::Entry entities_entry{ui::null}; + ui::ListStore EntityBreakdownWalker{ui::null}; - GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Map Info", G_CALLBACK( dialog_delete_callback ), &dialog ); + ui::Window window = MainFrame_getWindow().create_dialog_window("Map Info", G_CALLBACK(dialog_delete_callback ), &dialog ); window_set_position( window, g_posMapInfoWnd ); { - GtkVBox* vbox = create_dialog_vbox( 4, 4 ); - gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( vbox ) ); + auto vbox = create_dialog_vbox( 4, 4 ); + window.add(vbox); { GtkHBox* hbox = create_dialog_hbox( 4 ); @@ -813,36 +785,36 @@ void DoMapInfo(){ gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 ); { - GtkEntry* entry = GTK_ENTRY( gtk_entry_new() ); - gtk_widget_show( GTK_WIDGET( entry ) ); + auto entry = ui::Entry(ui::New); + entry.show(); gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), (GtkAttachOptions) ( 0 ), 0, 0 ); - gtk_entry_set_editable( entry, FALSE ); + gtk_editable_set_editable( GTK_EDITABLE(entry), FALSE ); brushes_entry = entry; } { - GtkEntry* entry = GTK_ENTRY( gtk_entry_new() ); - gtk_widget_show( GTK_WIDGET( entry ) ); + auto entry = ui::Entry(ui::New); + entry.show(); gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), (GtkAttachOptions) ( 0 ), 0, 0 ); - gtk_entry_set_editable( entry, FALSE ); + gtk_editable_set_editable( GTK_EDITABLE(entry), FALSE ); entities_entry = entry; } { - GtkWidget* label = gtk_label_new( "Total Brushes" ); - gtk_widget_show( label ); + ui::Widget label = ui::Label( "Total Brushes" ); + label.show(); gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1, (GtkAttachOptions) ( GTK_FILL ), (GtkAttachOptions) ( 0 ), 0, 0 ); gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 ); } { - GtkWidget* label = gtk_label_new( "Total Entities" ); - gtk_widget_show( label ); + ui::Widget label = ui::Label( "Total Entities" ); + label.show(); gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2, (GtkAttachOptions) ( GTK_FILL ), (GtkAttachOptions) ( 0 ), 0, 0 ); @@ -860,38 +832,38 @@ void DoMapInfo(){ } } { - GtkWidget* label = gtk_label_new( "Entity breakdown" ); - gtk_widget_show( label ); + ui::Widget label = ui::Label( "Entity breakdown" ); + label.show(); gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( label ), FALSE, TRUE, 0 ); gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 ); } { - GtkScrolledWindow* scr = create_scrolled_window( GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC, 4 ); + auto scr = create_scrolled_window( ui::Policy::NEVER, ui::Policy::AUTOMATIC, 4 ); gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( scr ), TRUE, TRUE, 0 ); { - GtkListStore* store = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING ); + ui::ListStore store = ui::ListStore(gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_STRING )); - GtkWidget* view = gtk_tree_view_new_with_model( GTK_TREE_MODEL( store ) ); + ui::Widget view = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( store ) )); gtk_tree_view_set_headers_clickable( GTK_TREE_VIEW( view ), TRUE ); { - GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Entity", renderer, "text", 0, 0 ); + auto renderer = ui::CellRendererText(ui::New); + GtkTreeViewColumn* column = ui::TreeViewColumn( "Entity", renderer, {{"text", 0}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); gtk_tree_view_column_set_sort_column_id( column, 0 ); } { - GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); - GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes( "Count", renderer, "text", 1, 0 ); + auto renderer = ui::CellRendererText(ui::New); + GtkTreeViewColumn* column = ui::TreeViewColumn( "Count", renderer, {{"text", 1}} ); gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column ); gtk_tree_view_column_set_sort_column_id( column, 1 ); } - gtk_widget_show( view ); + view.show(); - gtk_container_add( GTK_CONTAINER( scr ), view ); + scr.add(view); EntityBreakdownWalker = store; } @@ -906,7 +878,7 @@ void DoMapInfo(){ for ( EntityBreakdown::iterator i = entitymap.begin(); i != entitymap.end(); ++i ) { - char tmp[16]; + auto tmp = u::buffer<16>(); sprintf( tmp, "%u", Unsigned( ( *i ).second ) ); GtkTreeIter iter; gtk_list_store_append( GTK_LIST_STORE( EntityBreakdownWalker ), &iter ); @@ -914,13 +886,13 @@ void DoMapInfo(){ } } - g_object_unref( G_OBJECT( EntityBreakdownWalker ) ); + EntityBreakdownWalker.unref(); - char tmp[16]; + auto tmp = u::buffer<16>(); sprintf( tmp, "%u", Unsigned( g_brushCount.get() ) ); - gtk_entry_set_text( GTK_ENTRY( brushes_entry ), tmp ); + brushes_entry.text(tmp); sprintf( tmp, "%u", Unsigned( g_entityCount.get() ) ); - gtk_entry_set_text( GTK_ENTRY( entities_entry ), tmp ); + entities_entry.text(tmp); modal_dialog_show( window, dialog ); @@ -947,6 +919,8 @@ ScopeTimer( const char* message ) } }; +CopiedString g_strLastFolder = ""; + /* ================ Map_LoadFile @@ -957,6 +931,9 @@ void Map_LoadFile( const char *filename ){ globalOutputStream() << "Loading map from " << filename << "\n"; ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Loading Map" ); + MRU_AddFile( filename ); + g_strLastFolder = g_path_get_dirname( filename ); + { ScopeTimer timer( "map load" ); @@ -973,7 +950,6 @@ void Map_LoadFile( const char *filename ){ } Brush_toggleFormat( i ); g_map.m_name = filename; - g_mapPathObservers.realise(); Map_UpdateTitle( g_map ); g_map.m_resource = GlobalReferenceCache().capture( g_map.m_name.c_str() ); if ( format ) { @@ -1004,6 +980,10 @@ void Map_LoadFile( const char *filename ){ Map_StartPosition(); g_currentMap = &g_map; + + // restart VFS to apply new pak filtering based on mapname + // needed for daemon DPK VFS + VFS_Restart(); } class Excluder @@ -1205,15 +1185,16 @@ void Map_RenameAbsolute( const char* absolute ){ g_map.m_resource->detach( g_map ); GlobalReferenceCache().release( g_map.m_name.c_str() ); - g_mapPathObservers.unrealise(); g_map.m_resource = resource; g_map.m_name = absolute; - g_mapPathObservers.realise(); Map_UpdateTitle( g_map ); g_map.m_resource->attach( g_map ); + // refresh VFS to apply new pak filtering based on mapname + // needed for daemon DPK VFS + VFS_Refresh(); } void Map_Rename( const char* filename ){ @@ -1248,7 +1229,6 @@ void Map_New(){ //globalOutputStream() << "Map_New\n"; g_map.m_name = "unnamed.map"; - g_mapPathObservers.realise(); Map_UpdateTitle( g_map ); { @@ -1262,6 +1242,10 @@ void Map_New(){ FocusViews( g_vector3_identity, 0 ); g_currentMap = &g_map; + + // restart VFS to apply new pak filtering based on mapname + // needed for daemon DPK VFS + VFS_Restart(); } extern void ConstructRegionBrushes( scene::Node * brushes[6], const Vector3 ®ion_mins, const Vector3 ®ion_maxs ); @@ -1284,7 +1268,7 @@ void ConstructRegionStartpoint( scene::Node* startpoint, const Vector3& region_m } // write the info_playerstart - char sTmp[1024]; + auto sTmp = u::buffer<1024>(); sprintf( sTmp, "%d %d %d", (int)vOrig[0], (int)vOrig[1], (int)vOrig[2] ); Node_getEntity( *startpoint )->setKeyValue( "origin", sTmp ); sprintf( sTmp, "%d", (int)Camera_getAngles( *g_pParentWnd->GetCamWnd() )[CAMERA_YAW] ); @@ -1509,6 +1493,8 @@ void Map_RegionBrush( void ){ bool Map_ImportFile( const char* filename ){ ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Loading Map" ); + g_strLastFolder = g_path_get_dirname( filename ); + bool success = false; if ( extension_equal( path_get_extension( filename ), "bsp" ) ) { @@ -1612,7 +1598,13 @@ tryDecompile: */ bool Map_SaveFile( const char* filename ){ ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Saving Map" ); - return MapResource_saveFile( MapFormat_forFile( filename ), GlobalSceneGraph().root(), Map_Traverse, filename ); + bool success = MapResource_saveFile( MapFormat_forFile( filename ), GlobalSceneGraph().root(), Map_Traverse, filename ); + if ( success ) { + // refresh VFS to apply new pak filtering based on mapname + // needed for daemon DPK VFS + VFS_Refresh(); + } + return success; } // @@ -1805,16 +1797,26 @@ const char* getMapsPath(){ return g_mapsPath.c_str(); } +const char* getLastFolderPath(){ + if (g_strLastFolder.empty()) { + GlobalPreferenceSystem().registerPreference( "LastFolder", CopiedStringImportStringCaller( g_strLastFolder ), CopiedStringExportStringCaller( g_strLastFolder ) ); + if (g_strLastFolder.empty()) { + g_strLastFolder = g_qeglobals.m_userGamePath; + } + } + return g_strLastFolder.c_str(); +} + const char* map_open( const char* title ){ - return file_dialog( GTK_WIDGET( MainFrame_getWindow() ), TRUE, title, getMapsPath(), MapFormat::Name(), true, false, false ); + return MainFrame_getWindow().file_dialog( TRUE, title, getLastFolderPath(), MapFormat::Name(), true, false, false ); } const char* map_import( const char* title ){ - return file_dialog( GTK_WIDGET( MainFrame_getWindow() ), TRUE, title, getMapsPath(), MapFormat::Name(), false, true, false ); + return MainFrame_getWindow().file_dialog( TRUE, title, getLastFolderPath(), MapFormat::Name(), false, true, false ); } const char* map_save( const char* title ){ - return file_dialog( GTK_WIDGET( MainFrame_getWindow() ), FALSE, title, getMapsPath(), MapFormat::Name(), false, false, true ); + return MainFrame_getWindow().file_dialog( FALSE, title, getLastFolderPath(), MapFormat::Name(), false, false, true ); } void OpenMap(){ @@ -1824,7 +1826,7 @@ void OpenMap(){ const char* filename = map_open( "Open Map" ); - if ( filename != 0 ) { + if ( filename != NULL ) { MRU_AddFile( filename ); Map_RegionOff(); Map_Free(); @@ -1835,7 +1837,7 @@ void OpenMap(){ void ImportMap(){ const char* filename = map_import( "Import Map" ); - if ( filename != 0 ) { + if ( filename != NULL ) { UndoableCommand undo( "mapImport" ); Map_ImportFile( filename ); } @@ -1844,7 +1846,8 @@ void ImportMap(){ bool Map_SaveAs(){ const char* filename = map_save( "Save Map" ); - if ( filename != 0 ) { + if ( filename != NULL ) { + g_strLastFolder = g_path_get_dirname( filename ); MRU_AddFile( filename ); Map_Rename( filename ); return Map_Save(); @@ -1868,7 +1871,8 @@ void SaveMap(){ void ExportMap(){ const char* filename = map_save( "Export Selection" ); - if ( filename != 0 ) { + if ( filename != NULL ) { + g_strLastFolder = g_path_get_dirname( filename ); Map_SaveSelected( filename ); } } @@ -1876,7 +1880,8 @@ void ExportMap(){ void SaveRegion(){ const char* filename = map_save( "Export Region" ); - if ( filename != 0 ) { + if ( filename != NULL ) { + g_strLastFolder = g_path_get_dirname( filename ); Map_SaveRegion( filename ); } } @@ -2032,37 +2037,37 @@ static void GetSelectionIndex( int *ent, int *brush ){ void DoFind(){ ModalDialog dialog; - GtkEntry* entity; - GtkEntry* brush; + ui::Entry entity{ui::null}; + ui::Entry brush{ui::null}; - GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Find Brush", G_CALLBACK( dialog_delete_callback ), &dialog ); + ui::Window window = MainFrame_getWindow().create_dialog_window("Find Brush", G_CALLBACK(dialog_delete_callback ), &dialog ); - GtkAccelGroup* accel = gtk_accel_group_new(); - gtk_window_add_accel_group( window, accel ); + auto accel = ui::AccelGroup(ui::New); + window.add_accel_group( accel ); { - GtkVBox* vbox = create_dialog_vbox( 4, 4 ); - gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( vbox ) ); + auto vbox = create_dialog_vbox( 4, 4 ); + window.add(vbox); { GtkTable* table = create_dialog_table( 2, 2, 4, 4 ); gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 ); { - GtkWidget* label = gtk_label_new( "Entity number" ); - gtk_widget_show( label ); + ui::Widget label = ui::Label( "Entity number" ); + label.show(); gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1, (GtkAttachOptions) ( 0 ), (GtkAttachOptions) ( 0 ), 0, 0 ); } { - GtkWidget* label = gtk_label_new( "Brush number" ); - gtk_widget_show( label ); + ui::Widget label = ui::Label( "Brush number" ); + label.show(); gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2, (GtkAttachOptions) ( 0 ), (GtkAttachOptions) ( 0 ), 0, 0 ); } { - GtkEntry* entry = GTK_ENTRY( gtk_entry_new() ); - gtk_widget_show( GTK_WIDGET( entry ) ); + auto entry = ui::Entry(ui::New); + entry.show(); gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), (GtkAttachOptions) ( 0 ), 0, 0 ); @@ -2070,8 +2075,8 @@ void DoFind(){ entity = entry; } { - GtkEntry* entry = GTK_ENTRY( gtk_entry_new() ); - gtk_widget_show( GTK_WIDGET( entry ) ); + auto entry = ui::Entry(ui::New); + entry.show(); gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2, (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), (GtkAttachOptions) ( 0 ), 0, 0 ); @@ -2083,28 +2088,28 @@ void DoFind(){ GtkHBox* hbox = create_dialog_hbox( 4 ); gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox ), TRUE, TRUE, 0 ); { - GtkButton* button = create_dialog_button( "Find", G_CALLBACK( dialog_button_ok ), &dialog ); + auto button = create_dialog_button( "Find", G_CALLBACK( dialog_button_ok ), &dialog ); gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 ); - widget_make_default( GTK_WIDGET( button ) ); - gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 ); + widget_make_default( button ); + gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 ); } { GtkButton* button = create_dialog_button( "Close", G_CALLBACK( dialog_button_cancel ), &dialog ); gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 ); - gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 ); + gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 ); } } } // Initialize dialog - char buf[16]; + auto buf = u::buffer<16>(); int ent, br; GetSelectionIndex( &ent, &br ); sprintf( buf, "%i", ent ); - gtk_entry_set_text( entity, buf ); + entity.text(buf); sprintf( buf, "%i", br ); - gtk_entry_set_text( brush, buf ); + brush.text(buf); if ( modal_dialog_show( window, dialog ) == eIDOK ) { const char *entstr = gtk_entry_get_text( entity ); @@ -2171,8 +2176,6 @@ void unrealise(){ MapModuleObserver g_MapModuleObserver; -#include "preferencesystem.h" - CopiedString g_strLastMap; bool g_bLoadLastMap = false;