| 1 | /* |
| 2 | BobToolz plugin for GtkRadiant |
| 3 | Copyright (C) 2001 Gordon Biggans |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | |
| 22 | #include "str.h" |
| 23 | #include "qerplugin.h" |
| 24 | #include "mathlib.h" |
| 25 | #include "string/string.h" |
| 26 | #include "itoolbar.h" |
| 27 | |
| 28 | #include "funchandlers.h" |
| 29 | #include "DBobView.h" |
| 30 | #include "DVisDrawer.h" |
| 31 | #include "DTrainDrawer.h" |
| 32 | #include "DTreePlanter.h" |
| 33 | |
| 34 | #include "dialogs/dialogs-gtk.h" |
| 35 | #include "../../libs/cmdlib.h" |
| 36 | |
| 37 | #define PLUGIN_NAME "bobToolz" |
| 38 | |
| 39 | void BobToolz_construct(){ |
| 40 | } |
| 41 | |
| 42 | void BobToolz_destroy(){ |
| 43 | if ( g_PathView ) { |
| 44 | delete g_PathView; |
| 45 | g_PathView = NULL; |
| 46 | } |
| 47 | if ( g_VisView ) { |
| 48 | delete g_VisView; |
| 49 | g_VisView = NULL; |
| 50 | } |
| 51 | if ( g_TrainView ) { |
| 52 | delete g_TrainView; |
| 53 | g_TrainView = NULL; |
| 54 | } |
| 55 | if ( g_TreePlanter ) { |
| 56 | delete g_TreePlanter; |
| 57 | g_TreePlanter = NULL; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // commands in the menu |
| 62 | static const char* PLUGIN_COMMANDS = "About...,-,Reset Textures...,PitOMatic,-,Vis Viewer,Brush Cleanup,Polygon Builder,Caulk Selection,-,Tree Planter,Drop Entity,Plot Splines,-,Merge Patches,Split patches,Split patches cols,Split patches rows,Turn edge"; |
| 63 | |
| 64 | // globals |
| 65 | static ui::Window main_window{ui::null}; |
| 66 | |
| 67 | extern "C" const char* QERPlug_Init( void* hApp, void* pMainWidget ) { |
| 68 | main_window = ui::Window::from(pMainWidget); |
| 69 | |
| 70 | return PLUGIN_NAME " for " RADIANT_NAME; |
| 71 | } |
| 72 | |
| 73 | extern "C" const char* QERPlug_GetName() { |
| 74 | return PLUGIN_NAME; |
| 75 | } |
| 76 | |
| 77 | extern "C" const char* QERPlug_GetCommandList() { |
| 78 | return PLUGIN_COMMANDS; |
| 79 | } |
| 80 | |
| 81 | extern "C" void QERPlug_Dispatch( const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush ) { |
| 82 | LoadLists(); |
| 83 | |
| 84 | if ( string_equal_nocase( p, "brush cleanup" ) ) { |
| 85 | DoFixBrushes(); |
| 86 | } |
| 87 | else if ( string_equal_nocase( p, "polygon builder" ) ) { |
| 88 | DoPolygonsTB(); |
| 89 | } |
| 90 | else if ( string_equal_nocase( p, "caulk selection" ) ) { |
| 91 | DoCaulkSelection(); |
| 92 | } |
| 93 | else if ( string_equal_nocase( p, "tree planter" ) ) { |
| 94 | DoTreePlanter(); |
| 95 | } |
| 96 | else if ( string_equal_nocase( p, "plot splines" ) ) { |
| 97 | DoTrainPathPlot(); |
| 98 | } |
| 99 | else if ( string_equal_nocase( p, "drop entity" ) ) { |
| 100 | DoDropEnts(); |
| 101 | } |
| 102 | else if ( string_equal_nocase( p, "merge patches" ) ) { |
| 103 | DoMergePatches(); |
| 104 | } |
| 105 | else if ( string_equal_nocase( p, "split patches" ) ) { |
| 106 | DoSplitPatch(); |
| 107 | } |
| 108 | else if ( string_equal_nocase( p, "split patches rows" ) ) { |
| 109 | DoSplitPatchRows(); |
| 110 | } |
| 111 | else if ( string_equal_nocase( p, "split patches cols" ) ) { |
| 112 | DoSplitPatchCols(); |
| 113 | } |
| 114 | else if ( string_equal_nocase( p, "turn edge" ) ) { |
| 115 | DoFlipTerrain(); |
| 116 | } |
| 117 | else if ( string_equal_nocase( p, "reset textures..." ) ) { |
| 118 | DoResetTextures( main_window ); |
| 119 | } |
| 120 | else if ( string_equal_nocase( p, "pitomatic" ) ) { |
| 121 | DoPitBuilder(); |
| 122 | } |
| 123 | else if ( string_equal_nocase( p, "vis viewer" ) ) { |
| 124 | DoVisAnalyse(); |
| 125 | } |
| 126 | else if ( string_equal_nocase( p, "stair builder..." ) ) { |
| 127 | DoBuildStairs(); |
| 128 | } |
| 129 | else if ( string_equal_nocase( p, "door builder..." ) ) { |
| 130 | DoBuildDoors(); |
| 131 | } |
| 132 | else if ( string_equal_nocase( p, "intersect..." ) ) { |
| 133 | DoIntersect(); |
| 134 | } |
| 135 | else if ( string_equal_nocase( p, "make chain..." ) ) { |
| 136 | DoMakeChain(); |
| 137 | } |
| 138 | else if ( string_equal_nocase( p, "path plotter..." ) ) { |
| 139 | DoPathPlotter( main_window ); |
| 140 | } |
| 141 | else if ( string_equal_nocase( p, "about..." ) ) { |
| 142 | static const char *label_text = |
| 143 | PLUGIN_NAME " for " |
| 144 | RADIANT_NAME " " RADIANT_VERSION "\n\n" |
| 145 | "by digibob <[email protected]>\n" |
| 146 | "https://www.splashdamage.com\n\n" |
| 147 | "Additional Contributors:\n" |
| 148 | "Arnout van Meer <[email protected]>\n" |
| 149 | "Mars Mattel\n\n" |
| 150 | "Built against " |
| 151 | RADIANT_NAME " " RADIANT_VERSION_STRING "\n" |
| 152 | __DATE__; |
| 153 | |
| 154 | GlobalRadiant().m_pfnMessageBox( main_window, label_text, |
| 155 | "About " PLUGIN_NAME, |
| 156 | eMB_OK, |
| 157 | eMB_ICONDEFAULT ); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | const char* QERPlug_GetCommandTitleList(){ |
| 162 | return ""; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | const int NUM_TOOLBARBUTTONS = 13; |
| 167 | |
| 168 | std::size_t ToolbarButtonCount( void ) { |
| 169 | return NUM_TOOLBARBUTTONS; |
| 170 | } |
| 171 | |
| 172 | class CBobtoolzToolbarButton : public IToolbarButton |
| 173 | { |
| 174 | public: |
| 175 | virtual const char* getImage() const { |
| 176 | switch ( mIndex ) { |
| 177 | case 0: return "bobtoolz_cleanup.png"; |
| 178 | case 1: return "bobtoolz_poly.png"; |
| 179 | // case 2: return "bobtoolz_caulk.png"; |
| 180 | case 2: return ""; |
| 181 | case 3: return "bobtoolz_treeplanter.png"; |
| 182 | case 4: return "bobtoolz_trainpathplot.png"; |
| 183 | case 5: return "bobtoolz_dropent.png"; |
| 184 | case 6: return ""; |
| 185 | case 7: return "bobtoolz_merge.png"; |
| 186 | case 8: return "bobtoolz_split.png"; |
| 187 | case 9: return "bobtoolz_splitrow.png"; |
| 188 | case 10: return "bobtoolz_splitcol.png"; |
| 189 | case 11: return ""; |
| 190 | case 12: return "bobtoolz_turnedge.png"; |
| 191 | } |
| 192 | return NULL; |
| 193 | } |
| 194 | virtual EType getType() const { |
| 195 | switch ( mIndex ) { |
| 196 | case 2: return eSpace; |
| 197 | case 3: return eToggleButton; |
| 198 | case 6: return eSpace; |
| 199 | case 11: return eSpace; |
| 200 | default: return eButton; |
| 201 | } |
| 202 | } |
| 203 | virtual const char* getText() const { |
| 204 | switch ( mIndex ) { |
| 205 | case 0: return "Cleanup"; |
| 206 | case 1: return "Polygons"; |
| 207 | // case 2: return "Caulk"; |
| 208 | case 3: return "Tree Planter"; |
| 209 | case 4: return "Plot Splines"; |
| 210 | case 5: return "Drop Entity"; |
| 211 | case 7: return "Merge 2 Patches"; |
| 212 | case 8: return "Split Patch"; |
| 213 | case 9: return "Split Patch Rows"; |
| 214 | case 10: return "Split Patch Columns"; |
| 215 | case 12: return "Flip Terrain"; |
| 216 | } |
| 217 | return NULL; |
| 218 | } |
| 219 | virtual const char* getTooltip() const { |
| 220 | switch ( mIndex ) { |
| 221 | case 0: return "Brush Cleanup"; |
| 222 | case 1: return "Polygons"; |
| 223 | // case 2: return "Caulk selection"; |
| 224 | case 3: return "Tree Planter"; |
| 225 | case 4: return "Plot Splines"; |
| 226 | case 5: return "Drop Entity"; |
| 227 | case 7: return "Merge 2 Patches"; |
| 228 | case 8: return "Split Patch"; |
| 229 | case 9: return "Split Patch Rows"; |
| 230 | case 10: return "Split Patch Columns"; |
| 231 | case 12: return "Flip Terrain (Turn Edge)"; |
| 232 | } |
| 233 | return NULL; |
| 234 | } |
| 235 | |
| 236 | virtual void activate() const { |
| 237 | LoadLists(); |
| 238 | |
| 239 | switch ( mIndex ) { |
| 240 | case 0: DoFixBrushes(); break; |
| 241 | case 1: DoPolygonsTB(); break; |
| 242 | // case 2: DoCaulkSelection(); break; |
| 243 | case 3: DoTreePlanter(); break; |
| 244 | case 4: DoTrainPathPlot(); break; |
| 245 | case 5: DoDropEnts(); break; |
| 246 | case 7: DoMergePatches(); break; |
| 247 | case 8: DoSplitPatch(); break; |
| 248 | case 9: DoSplitPatchRows(); break; |
| 249 | case 10: DoSplitPatchCols(); break; |
| 250 | case 12: DoFlipTerrain(); break; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | std::size_t mIndex; |
| 255 | }; |
| 256 | |
| 257 | CBobtoolzToolbarButton g_bobtoolzToolbarButtons[NUM_TOOLBARBUTTONS]; |
| 258 | |
| 259 | const IToolbarButton* GetToolbarButton( std::size_t index ){ |
| 260 | g_bobtoolzToolbarButtons[index].mIndex = index; |
| 261 | return &g_bobtoolzToolbarButtons[index]; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | #include "modulesystem/singletonmodule.h" |
| 266 | |
| 267 | #include "iscenegraph.h" |
| 268 | #include "irender.h" |
| 269 | #include "iundo.h" |
| 270 | #include "ishaders.h" |
| 271 | #include "ipatch.h" |
| 272 | #include "ibrush.h" |
| 273 | #include "ientity.h" |
| 274 | #include "ieclass.h" |
| 275 | #include "iglrender.h" |
| 276 | #include "iplugin.h" |
| 277 | |
| 278 | class BobToolzPluginDependencies : |
| 279 | public GlobalRadiantModuleRef, |
| 280 | public GlobalUndoModuleRef, |
| 281 | public GlobalSceneGraphModuleRef, |
| 282 | public GlobalSelectionModuleRef, |
| 283 | public GlobalEntityModuleRef, |
| 284 | public GlobalEntityClassManagerModuleRef, |
| 285 | public GlobalShadersModuleRef, |
| 286 | public GlobalShaderCacheModuleRef, |
| 287 | public GlobalBrushModuleRef, |
| 288 | public GlobalPatchModuleRef, |
| 289 | public GlobalOpenGLModuleRef, |
| 290 | public GlobalOpenGLStateLibraryModuleRef |
| 291 | { |
| 292 | public: |
| 293 | BobToolzPluginDependencies() : |
| 294 | GlobalEntityModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entities" ) ), |
| 295 | GlobalEntityClassManagerModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entityclass" ) ), |
| 296 | GlobalShadersModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "shaders" ) ), |
| 297 | GlobalBrushModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "brushtypes" ) ), |
| 298 | GlobalPatchModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "patchtypes" ) ){ |
| 299 | } |
| 300 | }; |
| 301 | |
| 302 | class BobToolzPluginModule : public TypeSystemRef |
| 303 | { |
| 304 | _QERPluginTable m_plugin; |
| 305 | public: |
| 306 | typedef _QERPluginTable Type; |
| 307 | STRING_CONSTANT( Name, "bobToolz" ); |
| 308 | |
| 309 | BobToolzPluginModule(){ |
| 310 | m_plugin.m_pfnQERPlug_Init = QERPlug_Init; |
| 311 | m_plugin.m_pfnQERPlug_GetName = QERPlug_GetName; |
| 312 | m_plugin.m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList; |
| 313 | m_plugin.m_pfnQERPlug_GetCommandTitleList = QERPlug_GetCommandTitleList; |
| 314 | m_plugin.m_pfnQERPlug_Dispatch = QERPlug_Dispatch; |
| 315 | |
| 316 | BobToolz_construct(); |
| 317 | } |
| 318 | ~BobToolzPluginModule(){ |
| 319 | BobToolz_destroy(); |
| 320 | } |
| 321 | _QERPluginTable* getTable(){ |
| 322 | return &m_plugin; |
| 323 | } |
| 324 | }; |
| 325 | |
| 326 | typedef SingletonModule<BobToolzPluginModule, BobToolzPluginDependencies> SingletonBobToolzPluginModule; |
| 327 | |
| 328 | SingletonBobToolzPluginModule g_BobToolzPluginModule; |
| 329 | |
| 330 | |
| 331 | class BobToolzToolbarDependencies : |
| 332 | public ModuleRef<_QERPluginTable> |
| 333 | { |
| 334 | public: |
| 335 | BobToolzToolbarDependencies() : |
| 336 | ModuleRef<_QERPluginTable>( "bobToolz" ){ |
| 337 | } |
| 338 | }; |
| 339 | |
| 340 | class BobToolzToolbarModule : public TypeSystemRef |
| 341 | { |
| 342 | _QERPlugToolbarTable m_table; |
| 343 | public: |
| 344 | typedef _QERPlugToolbarTable Type; |
| 345 | STRING_CONSTANT( Name, "bobToolz" ); |
| 346 | |
| 347 | BobToolzToolbarModule(){ |
| 348 | m_table.m_pfnToolbarButtonCount = ToolbarButtonCount; |
| 349 | m_table.m_pfnGetToolbarButton = GetToolbarButton; |
| 350 | } |
| 351 | _QERPlugToolbarTable* getTable(){ |
| 352 | return &m_table; |
| 353 | } |
| 354 | }; |
| 355 | |
| 356 | typedef SingletonModule<BobToolzToolbarModule, BobToolzToolbarDependencies> SingletonBobToolzToolbarModule; |
| 357 | |
| 358 | SingletonBobToolzToolbarModule g_BobToolzToolbarModule; |
| 359 | |
| 360 | |
| 361 | extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){ |
| 362 | initialiseModule( server ); |
| 363 | |
| 364 | g_BobToolzPluginModule.selfRegister(); |
| 365 | g_BobToolzToolbarModule.selfRegister(); |
| 366 | } |