]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/shaderplug/shaderplug.cpp
q3map2/games: bikeshedding
[xonotic/netradiant.git] / contrib / shaderplug / shaderplug.cpp
index 75171bd8370d889b2e078fa19a5550563d401fe8..06c378a5ec956bc2cffd0e7a2268ed2b421f18e4 100644 (file)
@@ -41,6 +41,8 @@
 
 #include "generic/callback.h"
 
+#define CMD_ABOUT "About..."
+
 namespace {
 const char SHADERTAG_FILE[] = "shadertags.xml";
 }
@@ -57,7 +59,7 @@ ShaderPlugPluginDependencies() :
 
 namespace Shaderplug
 {
-ui::Window g_window{ui::null};
+ui::Window main_window{ui::null};
 
 std::vector<const char*> archives;
 std::set<std::string> shaders;
@@ -67,26 +69,38 @@ XmlTagBuilder TagBuilder;
 void CreateTagFile();
 
 const char* init( void* hApp, void* pMainWidget ){
-       g_window = ui::Window(GTK_WINDOW( pMainWidget ));
+       main_window = ui::Window::from(pMainWidget);
        return "";
 }
+
 const char* getName(){
-       return "ShaderPlug";
+       return PLUGIN_NAME;
 }
+
 const char* getCommandList(){
-       return "About;Create tag file";
+       return CMD_ABOUT ";-;Create tag file";
 }
+
 const char* getCommandTitleList(){
        return "";
 }
+
 void dispatch( const char* command, float* vMin, float* vMax, bool bSingleBrush ){
-       if ( string_equal( command, "About" ) ) {
-               GlobalRadiant().m_pfnMessageBox( g_window, "Shaderplug (1.0)\n\n"
-                                                                                                                                "by Shaderman (shaderman@gmx.net)",
-                                                                                "About",
+       if ( string_equal( command, CMD_ABOUT ) ) {
+               const char *label_text =
+                       PLUGIN_NAME " " PLUGIN_VERSION " for "
+                       RADIANT_NAME " " RADIANT_VERSION "\n\n"
+                       "Written by Shaderman <shaderman@gmx.net>\n\n"
+                       "Built against "
+                       RADIANT_NAME " " RADIANT_VERSION_STRING "\n"
+                       __DATE__;
+
+               GlobalRadiant().m_pfnMessageBox( main_window, label_text,
+                                                                                "About " PLUGIN_NAME,
                                                                                 eMB_OK,
                                                                                 eMB_ICONDEFAULT );
        }
+
        if ( string_equal( command, "Create tag file" ) ) {
                CreateTagFile();
        }
@@ -96,8 +110,6 @@ void loadArchiveFile( const char* filename ){
        archives.push_back( filename );
 }
 
-typedef FreeCaller1<const char*, loadArchiveFile> LoadArchiveFileCaller;
-
 void LoadTextureFile( const char* filename ){
        std::string s_filename = filename;
 
@@ -116,10 +128,8 @@ void LoadTextureFile( const char* filename ){
        }
 }
 
-typedef FreeCaller1<const char*, LoadTextureFile> LoadTextureFileCaller;
-
 void GetTextures( const char* extension ){
-       GlobalFileSystem().forEachFile( "textures/", extension, LoadTextureFileCaller(), 0 );
+       GlobalFileSystem().forEachFile("textures/", extension, makeCallbackF(LoadTextureFile), 0);
 }
 
 void LoadShaderList( const char* filename ){
@@ -128,33 +138,31 @@ void LoadShaderList( const char* filename ){
        }
 }
 
-typedef FreeCaller1<const char*, LoadShaderList> LoadShaderListCaller;
-
 void GetAllShaders(){
-       GlobalShaderSystem().foreachShaderName( LoadShaderListCaller() );
+       GlobalShaderSystem().foreachShaderName(makeCallbackF(LoadShaderList));
 }
 
 void GetArchiveList(){
-       GlobalFileSystem().forEachArchive( LoadArchiveFileCaller() );
-       globalOutputStream() << "Shaderplug: " << (const Unsigned)Shaderplug::archives.size() << " archives found.\n";
+       GlobalFileSystem().forEachArchive(makeCallbackF(loadArchiveFile));
+       globalOutputStream() << PLUGIN_NAME ": " << (const Unsigned)Shaderplug::archives.size() << " archives found.\n";
 }
 
 void CreateTagFile(){
        const char* shader_type = GlobalRadiant().getGameDescriptionKeyValue( "shaders" );
 
        GetAllShaders();
-       globalOutputStream() << "Shaderplug: " << (const Unsigned)shaders.size() << " shaders found.\n";
+       globalOutputStream() << PLUGIN_NAME ": " << (const Unsigned)shaders.size() << " shaders found.\n";
 
        if ( string_equal( shader_type, "quake3" ) ) {
                GetTextures( "jpg" );
                GetTextures( "tga" );
                GetTextures( "png" );
 
-               globalOutputStream() << "Shaderplug: " << (const Unsigned)textures.size() << " textures found.\n";
+               globalOutputStream() << PLUGIN_NAME ":" << (const Unsigned)textures.size() << " textures found.\n";
        }
 
        if ( shaders.size() || textures.size() != 0 ) {
-               globalOutputStream() << "Shaderplug: Creating XML tag file.\n";
+               globalOutputStream() << PLUGIN_NAME ":Creating XML tag file.\n";
 
                TagBuilder.CreateXmlDocument();
 
@@ -178,26 +186,26 @@ void CreateTagFile(){
                char message[256];
                strcpy( message, "Tag file saved to\n" );
                strcat( message, tagFile );
-               strcat( message, "\nPlease restart Radiant now.\n" );
+               strcat( message, "\nPlease restart " RADIANT_NAME " now.\n" );
 
                if ( file_exists( tagFile ) ) {
-                       EMessageBoxReturn result = GlobalRadiant().m_pfnMessageBox( g_window ,
+                       EMessageBoxReturn result = GlobalRadiant().m_pfnMessageBox( main_window ,
                                                                                                                                                "WARNING! A tag file already exists! Overwrite it?", "Overwrite tag file?",
                                                                                                                                                eMB_NOYES,
                                                                                                                                                eMB_ICONWARNING );
 
                        if ( result == eIDYES ) {
                                TagBuilder.SaveXmlDoc( tagFile );
-                               GlobalRadiant().m_pfnMessageBox( g_window, message, "INFO", eMB_OK, eMB_ICONASTERISK );
+                               GlobalRadiant().m_pfnMessageBox( main_window, message, "INFO", eMB_OK, eMB_ICONASTERISK );
                        }
                }
                else {
                        TagBuilder.SaveXmlDoc( tagFile );
-                       GlobalRadiant().m_pfnMessageBox( g_window, message, "INFO", eMB_OK, eMB_ICONASTERISK );
+                       GlobalRadiant().m_pfnMessageBox( main_window, message, "INFO", eMB_OK, eMB_ICONASTERISK );
                }
        }
        else {
-               GlobalRadiant().m_pfnMessageBox( g_window,
+               GlobalRadiant().m_pfnMessageBox( main_window,
                                                                                 "No shaders or textures found. No XML tag file created!\n"
                                                                                 "",
                                                                                 "ERROR",
@@ -212,7 +220,7 @@ class ShaderPluginModule
 _QERPluginTable m_plugin;
 public:
 typedef _QERPluginTable Type;
-STRING_CONSTANT( Name, "ShaderPlug" );
+STRING_CONSTANT( Name, PLUGIN_NAME );
 
 ShaderPluginModule(){
        m_plugin.m_pfnQERPlug_Init = &Shaderplug::init;