]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/ufoai/plugin.cpp
uncrustify! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / contrib / ufoai / plugin.cpp
1 /*
2    Copyright (C) 1999-2007 id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
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
22 #include "plugin.h"
23 #include "ufoai_filters.h"
24
25 #define CMD_SEP "-"
26 #define CMD_ABOUT "About..."
27 // =============================================================================
28 // Globals
29
30 // function tables
31 _QERFuncTable_1 g_FuncTable;
32 _QERQglTable g_QglTable;
33 _QERFileSystemTable g_FileSystemTable;
34 _QEREntityTable g_EntityTable;
35 _QERAppDataTable g_DataTable;
36
37 // the gtk widget
38 void *g_pMainWidget;
39
40 // =============================================================================
41 // plugin implementation
42
43 #define PLUGIN_NAME "UFO:AI plugin"
44 #define PLUGIN_VERSION "0.1"
45
46 //backwards for some reason
47 static const char *PLUGIN_COMMANDS = CMD_ABOUT ";" CMD_SEP;
48 static const char *PLUGIN_ABOUT = _( "UFO: Alien Invasion plugin " PLUGIN_VERSION "\nby Martin Gerhardy" );
49
50 #define NUM_TOOLBAR_BUTTONS FILTER_MAX
51 typedef struct toolbar_button_info_s
52 {
53         const char *image;
54         const char *text;
55         const char *tip;
56         void ( *func )();
57         IToolbarButton::EType type;
58 } toolbar_button_info_t;
59
60 static const toolbar_button_info_t toolbar_buttons[NUM_TOOLBAR_BUTTONS] =
61 {
62         {
63                 "ufoai_actorclip.bmp",
64                 _( "Filter actorclip" ),
65                 _( "Actorclip" ),
66                 DoActorClipFiltering,
67                 IToolbarButton::eToggleButton
68         },
69         {
70                 "ufoai_weaponclip.bmp",
71                 _( "Filter weaponclip" ),
72                 _( "Weaponclip" ),
73                 DoWeaponClipFiltering,
74                 IToolbarButton::eToggleButton
75         },
76         {
77                 "ufoai_nodraw.bmp",
78                 _( "Filter nodraw" ),
79                 _( "NoDraw" ),
80                 DoNoDrawFiltering,
81                 IToolbarButton::eToggleButton
82         },
83         {
84                 "ufoai_stepon.bmp",
85                 _( "Filter stepon" ),
86                 _( "Stepon" ),
87                 DoSteponFiltering,
88                 IToolbarButton::eToggleButton
89         },
90         {
91                 "ufoai_level1.bmp",
92                 _( "Filter level1" ),
93                 _( "Level 1" ),
94                 DoLevel1Filtering,
95                 IToolbarButton::eToggleButton
96         },
97         {
98                 "ufoai_level2.bmp",
99                 _( "Filter level2" ),
100                 _( "Level 2" ),
101                 DoLevel2Filtering,
102                 IToolbarButton::eToggleButton
103         },
104         {
105                 "ufoai_level3.bmp",
106                 _( "Filter level3" ),
107                 _( "Level 3" ),
108                 DoLevel3Filtering,
109                 IToolbarButton::eToggleButton
110         },
111         {
112                 "ufoai_level4.bmp",
113                 _( "Filter level4" ),
114                 _( "Level 4" ),
115                 DoLevel4Filtering,
116                 IToolbarButton::eToggleButton
117         },
118         {
119                 "ufoai_level5.bmp",
120                 _( "Filter level5" ),
121                 _( "Level 5" ),
122                 DoLevel5Filtering,
123                 IToolbarButton::eToggleButton
124         },
125         {
126                 "ufoai_level6.bmp",
127                 _( "Filter level6" ),
128                 _( "Level 6" ),
129                 DoLevel6Filtering,
130                 IToolbarButton::eToggleButton
131         },
132         {
133                 "ufoai_level7.bmp",
134                 _( "Filter level7" ),
135                 _( "Level 7" ),
136                 DoLevel7Filtering,
137                 IToolbarButton::eToggleButton
138         },
139         {
140                 "ufoai_level8.bmp",
141                 _( "Filter level8" ),
142                 _( "Level 8" ),
143                 DoLevel8Filtering,
144                 IToolbarButton::eToggleButton
145         },
146 };
147
148 class UFOAIButton : public IToolbarButton
149 {
150 public:
151 const toolbar_button_info_s *bi;
152 virtual const char* getImage() const {
153         return bi->image;
154 }
155 virtual const char* getText() const {
156         return bi->text;
157 }
158 virtual const char* getTooltip() const {
159         return bi->tip;
160 }
161 virtual void activate() const {
162         bi->func();
163         return ;
164 }
165 virtual EType getType() const {
166         return bi->type;
167 }
168 };
169
170 UFOAIButton g_ufoaibuttons[NUM_TOOLBAR_BUTTONS];
171
172 unsigned int ToolbarButtonCount( void ){
173         return NUM_TOOLBAR_BUTTONS;
174 }
175
176 const IToolbarButton* GetToolbarButton( unsigned int index ){
177         g_ufoaibuttons[index].bi = &toolbar_buttons[index];
178         return &g_ufoaibuttons[index];
179 }
180
181 extern "C" const char* QERPlug_Init( void *hApp, void* pMainWidget ){
182         g_pMainWidget = pMainWidget;
183
184         UFOAIFilterInit();
185
186         return PLUGIN_NAME;
187 }
188
189 extern "C" const char* QERPlug_GetName( void ){
190         return (char *) PLUGIN_NAME;
191 }
192
193 extern "C" const char* QERPlug_GetCommandList( void ){
194         return (char *) PLUGIN_COMMANDS;
195 }
196
197 extern "C" void QERPlug_Dispatch( const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush ){
198         if ( !strcmp( p, CMD_ABOUT ) ) {
199                 g_FuncTable.m_pfnMessageBox( NULL, PLUGIN_ABOUT, _( "About" ), MB_OK, NULL );
200         }
201         else {
202                 Sys_Printf( "Message: %s\n", p );
203         }
204 }
205
206 // =============================================================================
207 // SYNAPSE
208
209 CSynapseServer* g_pSynapseServer = NULL;
210 CSynapseClientUFOAI g_SynapseClient;
211
212 #if __GNUC__ >= 4
213 #pragma GCC visibility push(default)
214 #endif
215 extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ){
216 #if __GNUC__ >= 4
217 #pragma GCC visibility pop
218 #endif
219         if ( strcmp( version, SYNAPSE_VERSION ) ) {
220                 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
221                 return NULL;
222         }
223         g_pSynapseServer = pServer;
224         g_pSynapseServer->IncRef();
225         Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
226
227         g_SynapseClient.AddAPI( TOOLBAR_MAJOR, UFOAI_MINOR, sizeof( _QERPlugToolbarTable ) );
228         g_SynapseClient.AddAPI( PLUGIN_MAJOR, UFOAI_MINOR, sizeof( _QERPluginTable ) );
229
230         g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );
231         g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );
232         g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable );
233         // get worldspawn
234         g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( g_EntityTable ), SYN_REQUIRE, &g_EntityTable );
235         // selected brushes
236         g_SynapseClient.AddAPI( DATA_MAJOR, NULL, sizeof( g_DataTable ), SYN_REQUIRE, &g_DataTable );
237
238         return &g_SynapseClient;
239 }
240
241 bool CSynapseClientUFOAI::RequestAPI( APIDescriptor_t *pAPI ){
242         if ( !strcmp( pAPI->major_name, PLUGIN_MAJOR ) ) {
243                 _QERPluginTable* pTable = static_cast<_QERPluginTable*>( pAPI->mpTable );
244
245                 pTable->m_pfnQERPlug_Init = QERPlug_Init;
246                 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
247                 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
248                 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
249                 return true;
250         }
251         else if ( !strcmp( pAPI->major_name, TOOLBAR_MAJOR ) ) {
252                 _QERPlugToolbarTable* pTable = static_cast<_QERPlugToolbarTable*>( pAPI->mpTable );
253
254                 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
255                 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
256                 return true;
257         }
258
259         Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
260         return false;
261 }
262
263 #include "version.h"
264
265 const char* CSynapseClientUFOAI::GetInfo(){
266         return PLUGIN_NAME " plugin built " __DATE__ " " RADIANT_VERSION;
267 }
268
269 const char* CSynapseClientUFOAI::GetName(){
270         return PLUGIN_NAME;
271 }