]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/preferences.cpp
readme: update target related help
[xonotic/netradiant.git] / radiant / preferences.cpp
index 6ad88df4dc4b0b543343eafce843ccf0a484326b..14a39f71c3e1293bdf4d276bc5eb085109390401 100644 (file)
@@ -81,7 +81,7 @@ void Mouse_constructPage( PreferenceGroup& group ){
        Mouse_constructPreferences( page );
 }
 void Mouse_registerPreferencesPage(){
-       PreferencesDialog_addInterfacePage( FreeCaller1<PreferenceGroup&, Mouse_constructPage>() );
+       PreferencesDialog_addInterfacePage( makeCallbackF(Mouse_constructPage) );
 }
 
 
@@ -121,7 +121,7 @@ CGameDescription::CGameDescription( xmlDocPtr pDoc, const CopiedString& gameFile
 
        {
                StringOutputStream path( 256 );
-               path << AppPath_get() << gameFile.c_str() << "/";
+               path << DataPath_get() << "gamepacks/" << gameFile.c_str() << "/";
                mGameToolsPath = path.c_str();
        }
 
@@ -216,18 +216,22 @@ bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filen
 }
 
 
+struct LogConsole {
+       static void Export(const Callback<void(bool)> &returnz) {
+               returnz(g_Console_enableLogging);
+       }
 
-void LogConsole_importString( const char* string ){
-       g_Console_enableLogging = string_equal( string, "true" );
-       Sys_LogFile( g_Console_enableLogging );
-}
-typedef FreeCaller1<const char*, LogConsole_importString> LogConsoleImportStringCaller;
+       static void Import(bool value) {
+               g_Console_enableLogging = value;
+               Sys_LogFile(g_Console_enableLogging);
+       }
+};
 
 
 void RegisterGlobalPreferences( PreferenceSystem& preferences ){
-       preferences.registerPreference( "gamefile", CopiedStringImportStringCaller( g_GamesDialog.m_sGameFile ), CopiedStringExportStringCaller( g_GamesDialog.m_sGameFile ) );
-       preferences.registerPreference( "gamePrompt", BoolImportStringCaller( g_GamesDialog.m_bGamePrompt ), BoolExportStringCaller( g_GamesDialog.m_bGamePrompt ) );
-       preferences.registerPreference( "log console", LogConsoleImportStringCaller(), BoolExportStringCaller( g_Console_enableLogging ) );
+       preferences.registerPreference( "gamefile", make_property_string( g_GamesDialog.m_sGameFile ) );
+       preferences.registerPreference( "gamePrompt", make_property_string( g_GamesDialog.m_bGamePrompt ) );
+       preferences.registerPreference( "log console", make_property_string<LogConsole>() );
 }
 
 
@@ -280,7 +284,7 @@ void CGameDialog::GameFileImport( int value ){
        m_sGameFile = ( *iGame )->mGameFile;
 }
 
-void CGameDialog::GameFileExport( const IntImportCallback& importCallback ) const {
+void CGameDialog::GameFileExport( const Callback<void(int)> & importCallback ) const {
        // use m_sGameFile to set value
        std::list<CGameDescription *>::const_iterator iGame;
        int i = 0;
@@ -295,13 +299,15 @@ void CGameDialog::GameFileExport( const IntImportCallback& importCallback ) cons
        importCallback( m_nComboSelect );
 }
 
-void CGameDialog_GameFileImport( CGameDialog& self, int value ){
-       self.GameFileImport( value );
-}
+struct CGameDialog_GameFile {
+       static void Export(const CGameDialog &self, const Callback<void(int)> &returnz) {
+               self.GameFileExport(returnz);
+       }
 
-void CGameDialog_GameFileExport( CGameDialog& self, const IntImportCallback& importCallback ){
-       self.GameFileExport( importCallback );
-}
+       static void Import(CGameDialog &self, int value) {
+               self.GameFileImport(value);
+       }
+};
 
 void CGameDialog::CreateGlobalFrame( PreferencesPage& page ){
        std::vector<const char*> games;
@@ -313,8 +319,7 @@ void CGameDialog::CreateGlobalFrame( PreferencesPage& page ){
        page.appendCombo(
                "Select the game",
                StringArrayRange( &( *games.begin() ), &( *games.end() ) ),
-               ReferenceCaller1<CGameDialog, int, CGameDialog_GameFileImport>( *this ),
-               ReferenceCaller1<CGameDialog, const IntImportCallback&, CGameDialog_GameFileExport>( *this )
+               make_property<CGameDialog_GameFile>(*this)
                );
        page.appendCheckBox( "Startup", "Show Global Preferences", m_bGamePrompt );
 }
@@ -334,36 +339,9 @@ ui::Window CGameDialog::BuildDialog(){
        return create_simple_modal_dialog_window( "Global Preferences", m_modal, frame );
 }
 
-class LoadGameFile
-{
-std::list<CGameDescription*>& mGames;
-const char* mPath;
-public:
-LoadGameFile( std::list<CGameDescription*>& games, const char* path ) : mGames( games ), mPath( path ){
-}
-void operator()( const char* name ) const {
-       if ( !extension_equal( path_get_extension( name ), "game" ) ) {
-               return;
-       }
-       StringOutputStream strPath( 256 );
-       strPath << mPath << name;
-       globalOutputStream() << strPath.c_str() << '\n';
-
-       xmlDocPtr pDoc = xmlParseFile( strPath.c_str() );
-       if ( pDoc ) {
-               mGames.push_front( new CGameDescription( pDoc, name ) );
-               xmlFreeDoc( pDoc );
-       }
-       else
-       {
-               globalErrorStream() << "XML parser failed on '" << strPath.c_str() << "'\n";
-       }
-}
-};
-
 void CGameDialog::ScanForGames(){
        StringOutputStream strGamesPath( 256 );
-       strGamesPath << AppPath_get() << "games/";
+       strGamesPath << DataPath_get() << "gamepacks/games/";
        const char *path = strGamesPath.c_str();
 
        globalOutputStream() << "Scanning for game description files: " << path << '\n';
@@ -377,7 +355,22 @@ void CGameDialog::ScanForGames(){
           (if that's really needed)
         */
 
-       Directory_forEach( path, LoadGameFile( mGames, path ) );
+       Directory_forEach(path, [&](const char *name) {
+               if (!extension_equal(path_get_extension(name), "game")) {
+                       return;
+               }
+               StringOutputStream strPath(256);
+               strPath << path << name;
+               globalOutputStream() << strPath.c_str() << '\n';
+
+               xmlDocPtr pDoc = xmlParseFile(strPath.c_str());
+               if (pDoc) {
+                       mGames.push_front(new CGameDescription(pDoc, name));
+                       xmlFreeDoc(pDoc);
+               } else {
+                       globalErrorStream() << "XML parser failed on '" << strPath.c_str() << "'\n";
+               }
+       });
 }
 
 CGameDescription* CGameDialog::GameDescriptionForComboItem(){
@@ -482,8 +475,8 @@ CGameDialog g_GamesDialog;
 
 static void OnButtonClean( ui::Widget widget, gpointer data ){
        // make sure this is what the user wants
-       if ( g_Preferences.GetWidget().alert( "This will close Radiant and clean the corresponding registry entries.\n"
-                                                                                                                                 "Next time you start Radiant it will be good as new. Do you wish to continue?",
+       if ( ui::alert( g_Preferences.GetWidget(), "This will close " RADIANT_NAME " and clean the corresponding registry entries.\n"
+                                                                                                                                 "Next time you start " RADIANT_NAME " it will be good as new. Do you wish to continue?",
                                                 "Reset Registry", ui::alert_type::YESNO, ui::alert_icon::Asterisk ) == ui::alert_response::YES ) {
                PrefsDlg *dlg = (PrefsDlg*)data;
                dlg->EndModal( eIDCANCEL );
@@ -542,7 +535,7 @@ void PrefsDlg::showPrefPage( ui::Widget prefpage ){
        return;
 }
 
-static void treeSelection( GtkTreeSelection* selection, gpointer data ){
+static void treeSelection( ui::TreeSelection selection, gpointer data ){
        PrefsDlg *dlg = (PrefsDlg*)data;
 
        GtkTreeModel* model;
@@ -680,10 +673,10 @@ PreferencesPage createPage( const char* treeName, const char* frameName ){
 };
 
 ui::Window PrefsDlg::BuildDialog(){
-       PreferencesDialog_addInterfacePreferences( FreeCaller1<PreferencesPage&, Interface_constructPreferences>() );
+       PreferencesDialog_addInterfacePreferences( makeCallbackF(Interface_constructPreferences) );
        Mouse_registerPreferencesPage();
 
-       ui::Window dialog = ui::Window(create_floating_window( "NetRadiant Preferences", m_parent ));
+       ui::Window dialog = ui::Window(create_floating_window( RADIANT_NAME " Preferences", m_parent ));
 
        {
                auto mainvbox = ui::VBox( FALSE, 5 );
@@ -723,7 +716,7 @@ ui::Window PrefsDlg::BuildDialog(){
                                gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( sc_win ), GTK_SHADOW_IN );
 
                                // prefs pages notebook
-                               m_notebook = ui::Widget(gtk_notebook_new());
+                               m_notebook = ui::Widget::from(gtk_notebook_new());
                                // hide the notebook tabs since its not supposed to look like a notebook
                                gtk_notebook_set_show_tabs( GTK_NOTEBOOK( m_notebook ), FALSE );
                                hbox.pack_start( m_notebook, TRUE, TRUE, 0 );
@@ -731,19 +724,19 @@ ui::Window PrefsDlg::BuildDialog(){
 
 
                                {
-                                       auto store = ui::TreeStore(gtk_tree_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
+                                       auto store = ui::TreeStore::from(gtk_tree_store_new( 2, G_TYPE_STRING, G_TYPE_POINTER ));
 
-                                       auto view = ui::TreeView(ui::TreeModel(store));
-                                       gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( view ), FALSE );
+                                       auto view = ui::TreeView(ui::TreeModel::from(store._handle));
+                                       gtk_tree_view_set_headers_visible(view, FALSE );
 
                                        {
                                                auto renderer = ui::CellRendererText(ui::New);
-                                               GtkTreeViewColumn* column = ui::TreeViewColumn( "Preferences", renderer, {{"text", 0}} );
-                                               gtk_tree_view_append_column( GTK_TREE_VIEW( view ), column );
+                        auto column = ui::TreeViewColumn( "Preferences", renderer, {{"text", 0}} );
+                                               gtk_tree_view_append_column(view, column );
                                        }
 
                                        {
-                                               auto selection = ui::TreeSelection(gtk_tree_view_get_selection( GTK_TREE_VIEW( view ) ));
+                                               auto selection = ui::TreeSelection::from(gtk_tree_view_get_selection(view));
                                                selection.connect( "changed", G_CALLBACK( treeSelection ), this );
                                        }
 
@@ -765,7 +758,7 @@ ui::Window PrefsDlg::BuildDialog(){
                                                                PreferencesPage preferencesPage( *this, getVBox( global ) );
                                                                Global_constructPreferences( preferencesPage );
                                                        }
-                                                       GtkTreeIter group = PreferenceTree_appendPage( store, 0, "Global", global );
+                            auto group = PreferenceTree_appendPage( store, 0, "Global", global );
                                                        {
                                                                auto game = PreferencePages_addPage( m_notebook, "Game" );
                                                                PreferencesPage preferencesPage( *this, getVBox( game ) );
@@ -782,7 +775,7 @@ ui::Window PrefsDlg::BuildDialog(){
                                                                PreferencesPageCallbacks_constructPage( g_interfacePreferences, preferencesPage );
                                                        }
 
-                                                       GtkTreeIter group = PreferenceTree_appendPage( store, 0, "Interface", interfacePage );
+                            auto group = PreferenceTree_appendPage( store, 0, "Interface", interfacePage );
                                                        PreferenceTreeGroup preferenceGroup( *this, m_notebook, store, group );
 
                                                        PreferenceGroupCallbacks_constructGroup( g_interfaceCallbacks, preferenceGroup );
@@ -794,7 +787,7 @@ ui::Window PrefsDlg::BuildDialog(){
                                                                PreferencesPage preferencesPage( *this, getVBox( display ) );
                                                                PreferencesPageCallbacks_constructPage( g_displayPreferences, preferencesPage );
                                                        }
-                                                       GtkTreeIter group = PreferenceTree_appendPage( store, 0, "Display", display );
+                            auto group = PreferenceTree_appendPage( store, 0, "Display", display );
                                                        PreferenceTreeGroup preferenceGroup( *this, m_notebook, store, group );
 
                                                        PreferenceGroupCallbacks_constructGroup( g_displayCallbacks, preferenceGroup );
@@ -807,14 +800,14 @@ ui::Window PrefsDlg::BuildDialog(){
                                                                PreferencesPageCallbacks_constructPage( g_settingsPreferences, preferencesPage );
                                                        }
 
-                                                       GtkTreeIter group = PreferenceTree_appendPage( store, 0, "Settings", settings );
+                            auto group = PreferenceTree_appendPage( store, 0, "Settings", settings );
                                                        PreferenceTreeGroup preferenceGroup( *this, m_notebook, store, group );
 
                                                        PreferenceGroupCallbacks_constructGroup( g_settingsCallbacks, preferenceGroup );
                                                }
                                        }
 
-                                       gtk_tree_view_expand_all( GTK_TREE_VIEW( view ) );
+                                       gtk_tree_view_expand_all(view );
 
                                        g_object_unref( G_OBJECT( store ) );
                                }
@@ -920,45 +913,42 @@ void PreferencesDialog_showDialog(){
                        {
                                message << ( *i ) << '\n';
                        }
-                       MainFrame_getWindow().alert( message.c_str() );
+                       ui::alert( MainFrame_getWindow(), message.c_str() );
                        g_restart_required.clear();
                }
        }
 }
 
+struct GameName {
+       static void Export(const Callback<void(const char *)> &returnz) {
+               returnz(gamename_get());
+       }
 
+       static void Import(const char *value) {
+               gamename_set(value);
+       }
+};
 
+struct GameMode {
+       static void Export(const Callback<void(const char *)> &returnz) {
+               returnz(gamemode_get());
+       }
 
-
-void GameName_importString( const char* value ){
-       gamename_set( value );
-}
-typedef FreeCaller1<const char*, GameName_importString> GameNameImportStringCaller;
-void GameName_exportString( const StringImportCallback& importer ){
-       importer( gamename_get() );
-}
-typedef FreeCaller1<const StringImportCallback&, GameName_exportString> GameNameExportStringCaller;
-
-void GameMode_importString( const char* value ){
-       gamemode_set( value );
-}
-typedef FreeCaller1<const char*, GameMode_importString> GameModeImportStringCaller;
-void GameMode_exportString( const StringImportCallback& importer ){
-       importer( gamemode_get() );
-}
-typedef FreeCaller1<const StringImportCallback&, GameMode_exportString> GameModeExportStringCaller;
-
+       static void Import(const char *value) {
+               gamemode_set(value);
+       }
+};
 
 void RegisterPreferences( PreferenceSystem& preferences ){
 #if GDEF_OS_WINDOWS
-       preferences.registerPreference( "UseCustomShaderEditor", BoolImportStringCaller( g_TextEditor_useWin32Editor ), BoolExportStringCaller( g_TextEditor_useWin32Editor ) );
+       preferences.registerPreference( "UseCustomShaderEditor", make_property_string( g_TextEditor_useWin32Editor ) );
 #else
-       preferences.registerPreference( "UseCustomShaderEditor", BoolImportStringCaller( g_TextEditor_useCustomEditor ), BoolExportStringCaller( g_TextEditor_useCustomEditor ) );
-       preferences.registerPreference( "CustomShaderEditorCommand", CopiedStringImportStringCaller( g_TextEditor_editorCommand ), CopiedStringExportStringCaller( g_TextEditor_editorCommand ) );
+       preferences.registerPreference( "UseCustomShaderEditor", make_property_string( g_TextEditor_useCustomEditor ) );
+       preferences.registerPreference( "CustomShaderEditorCommand", make_property_string( g_TextEditor_editorCommand ) );
 #endif
 
-       preferences.registerPreference( "GameName", GameNameImportStringCaller(), GameNameExportStringCaller() );
-       preferences.registerPreference( "GameMode", GameModeImportStringCaller(), GameModeExportStringCaller() );
+       preferences.registerPreference( "GameName", make_property<GameName>() );
+       preferences.registerPreference( "GameMode", make_property<GameMode>() );
 }
 
 void Preferences_Init(){