| 1 | /* |
| 2 | Copyright (C) 2006, Thomas Nitschke. |
| 3 | All Rights Reserved. |
| 4 | |
| 5 | This file is part of GtkRadiant. |
| 6 | |
| 7 | GtkRadiant is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | GtkRadiant is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with GtkRadiant; if not, write to the Free Software |
| 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | #include "plugin.h" |
| 22 | |
| 23 | #include "iplugin.h" |
| 24 | #include "qerplugin.h" |
| 25 | |
| 26 | #include <gtk/gtk.h> |
| 27 | |
| 28 | #include "debugging/debugging.h" |
| 29 | #include "string/string.h" |
| 30 | #include "modulesystem/singletonmodule.h" |
| 31 | #include "stream/textfilestream.h" |
| 32 | #include "stream/stringstream.h" |
| 33 | #include "gtkutil/messagebox.h" |
| 34 | #include "gtkutil/filechooser.h" |
| 35 | |
| 36 | #include "ibrush.h" |
| 37 | #include "iscenegraph.h" |
| 38 | #include "iselection.h" |
| 39 | #include "ifilesystem.h" |
| 40 | #include "ifiletypes.h" |
| 41 | |
| 42 | #include "support.h" |
| 43 | |
| 44 | #include "typesystem.h" |
| 45 | |
| 46 | #define CMD_ABOUT "About..." |
| 47 | |
| 48 | void CreateWindow( ui::Window main_window ); |
| 49 | void DestroyWindow( void ); |
| 50 | bool IsWindowOpen( void ); |
| 51 | |
| 52 | ui::Widget g_pRadiantWnd{ui::null}; |
| 53 | |
| 54 | namespace BrushExport |
| 55 | { |
| 56 | ui::Window g_mainwnd{ui::null}; |
| 57 | |
| 58 | const char* init( void* hApp, void* pMainWidget ){ |
| 59 | g_mainwnd = ui::Window::from(pMainWidget); |
| 60 | g_pRadiantWnd = ui::Window::from(pMainWidget); |
| 61 | ASSERT_TRUE( g_mainwnd ); |
| 62 | return ""; |
| 63 | } |
| 64 | const char* getName(){ |
| 65 | return "Brush export Plugin"; |
| 66 | } |
| 67 | const char* getCommandList(){ |
| 68 | return CMD_ABOUT ";-;Export selected as Wavefront Object"; |
| 69 | } |
| 70 | const char* getCommandTitleList(){ |
| 71 | return ""; |
| 72 | } |
| 73 | |
| 74 | void dispatch( const char* command, float* vMin, float* vMax, bool bSingleBrush ){ |
| 75 | if ( string_equal( command, CMD_ABOUT ) ) { |
| 76 | const char *label_text = |
| 77 | PLUGIN_NAME " " PLUGIN_VERSION " for " |
| 78 | RADIANT_NAME " " RADIANT_VERSION "\n\n" |
| 79 | "Written by namespace <[email protected]>\n\n" |
| 80 | // 20200404 dead link |
| 81 | // "http://www.codecreator.net" |
| 82 | "Built against " |
| 83 | RADIANT_NAME " " RADIANT_VERSION_STRING "\n" |
| 84 | __DATE__; |
| 85 | |
| 86 | GlobalRadiant().m_pfnMessageBox( g_mainwnd, label_text, |
| 87 | "About " PLUGIN_NAME, |
| 88 | eMB_OK, |
| 89 | eMB_ICONDEFAULT ); |
| 90 | } |
| 91 | else if ( string_equal( command, "Export selected as Wavefront Object" ) ) { |
| 92 | if ( IsWindowOpen() ) { |
| 93 | DestroyWindow(); |
| 94 | } |
| 95 | CreateWindow( g_mainwnd ); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | class BrushExportDependencies : |
| 101 | public GlobalRadiantModuleRef, |
| 102 | public GlobalFiletypesModuleRef, |
| 103 | public GlobalBrushModuleRef, |
| 104 | public GlobalFileSystemModuleRef, |
| 105 | public GlobalSceneGraphModuleRef, |
| 106 | public GlobalSelectionModuleRef |
| 107 | { |
| 108 | public: |
| 109 | BrushExportDependencies( void ) |
| 110 | : GlobalBrushModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "brushtypes" ) ) |
| 111 | {} |
| 112 | }; |
| 113 | |
| 114 | class BrushExportModule : public TypeSystemRef |
| 115 | { |
| 116 | _QERPluginTable m_plugin; |
| 117 | public: |
| 118 | typedef _QERPluginTable Type; |
| 119 | STRING_CONSTANT( Name, PLUGIN_NAME ); |
| 120 | |
| 121 | BrushExportModule(){ |
| 122 | m_plugin.m_pfnQERPlug_Init = &BrushExport::init; |
| 123 | m_plugin.m_pfnQERPlug_GetName = &BrushExport::getName; |
| 124 | m_plugin.m_pfnQERPlug_GetCommandList = &BrushExport::getCommandList; |
| 125 | m_plugin.m_pfnQERPlug_GetCommandTitleList = &BrushExport::getCommandTitleList; |
| 126 | m_plugin.m_pfnQERPlug_Dispatch = &BrushExport::dispatch; |
| 127 | } |
| 128 | _QERPluginTable* getTable(){ |
| 129 | return &m_plugin; |
| 130 | } |
| 131 | }; |
| 132 | |
| 133 | typedef SingletonModule<BrushExportModule, BrushExportDependencies> SingletonBrushExportModule; |
| 134 | SingletonBrushExportModule g_BrushExportModule; |
| 135 | |
| 136 | extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){ |
| 137 | initialiseModule( server ); |
| 138 | g_BrushExportModule.selfRegister(); |
| 139 | } |