Debian Codegraph @

contrib/ufoaiplug/ufoai.cpp

raw symbols SCIP
1 /*
2 This file is part of GtkRadiant.
3
4 GtkRadiant is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 GtkRadiant is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GtkRadiant; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "ufoai.h"
20 #include "ufoai_level.h"
21 #include "ufoai_gtk.h"
22 #include "ufoai_filters.h"
23
24 #include "debugging/debugging.h"
25
26 #include "iplugin.h"
27
28 #include "string/string.h"
29 #include "modulesystem/singletonmodule.h"
30
31 #include <gtk/gtk.h>
32
33 #include "ifilter.h"
34 #include "ibrush.h"
35 #include "iundo.h" // declaration of undo system
36 #include "ientity.h" // declaration of entity system
37 #include "iscenegraph.h" // declaration of datastructure of the map
38 #include "scenelib.h" // declaration of datastructure of the map
39 #include "qerplugin.h" // declaration to use other interfaces as a plugin
40 #include "ieclass.h"
41
42 #define CMD_ABOUT "About..."
43
44 class UFOAIPluginDependencies :
45 public GlobalRadiantModuleRef, // basic class for all other module refs
46 public GlobalUndoModuleRef, // used to say radiant that something has changed and to undo that
47 public GlobalSceneGraphModuleRef, // necessary to handle data in the mapfile (change, retrieve data)
48 public GlobalEntityModuleRef, // to access and modify the entities
49 public GlobalEntityClassManagerModuleRef
50 {
51 public:
52 UFOAIPluginDependencies( void ) :
53 GlobalEntityModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entities" ) ),
54 GlobalEntityClassManagerModuleRef( GlobalRadiant().getRequiredGameDescriptionKeyValue( "entityclass" ) ){
55 }
56 };
57
58 namespace UFOAI
59 {
60 ui::Window g_mainwnd{ui::null};
61
62 const char* init( void* hApp, void* pMainWidget ){
63 g_mainwnd = ui::Window::from(pMainWidget);
64 return "Initializing GTKRadiant UFOAI plugin";
65 }
66 const char* getName(){
67 return PLUGIN_NAME;
68 }
69 const char* getCommandList(){
70 /*GlobalRadiant().getGameName()*/
71 return CMD_ABOUT ";-;Worldspawn reset;Worldspawn;Perform check;-;Level 1;Level 2;Level 3;Level 4;Level 5;Level 6;Level 7;Level 8;-;StepOn;ActorClip;WeaponClip;Nodraw";
72 }
73 const char* getCommandTitleList(){
74 return "";
75 }
76 void dispatch( const char* command, float* vMin, float* vMax, bool bSingleBrush ){
77 char const *message = NULL;
78 if ( string_equal( command, CMD_ABOUT ) ) {
79 const char *label_text =
80 PLUGIN_NAME " " PLUGIN_VERSION " for "
81 RADIANT_NAME " " RADIANT_VERSION "\n\n"
82 "Written by Martin Gerhardy (tlh2000/mattn)\n"
83 "for the UFO:AI project (http://ufoai.org)\n\n"
84 "Built against "
85 RADIANT_NAME " " RADIANT_VERSION_STRING "\n"
86 __DATE__;
87
88 GlobalRadiant().m_pfnMessageBox( g_mainwnd,
89 label_text, "About" PLUGIN_NAME,
90 eMB_OK, eMB_ICONDEFAULT );
91 }
92 else if ( string_equal( command, "Level 1" ) ) {
93 filter_level( CONTENTS_LEVEL1 );
94 }
95 else if ( string_equal( command, "Level 2" ) ) {
96 filter_level( CONTENTS_LEVEL2 );
97 }
98 else if ( string_equal( command, "Level 3" ) ) {
99 filter_level( CONTENTS_LEVEL3 );
100 }
101 else if ( string_equal( command, "Worldspawn" ) ) {
102 assign_default_values_to_worldspawn( false, &message );
103 }
104 else if ( string_equal( command, "Worldspawn reset" ) ) {
105 assign_default_values_to_worldspawn( true, &message );
106 }
107 else if ( string_equal( command, "Perform check" ) ) {
108 check_map_values( &message );
109 }
110 else if ( string_equal( command, "Level 4" ) ) {
111 filter_level( CONTENTS_LEVEL4 );
112 }
113 else if ( string_equal( command, "Level 5" ) ) {
114 filter_level( CONTENTS_LEVEL5 );
115 }
116 else if ( string_equal( command, "Level 6" ) ) {
117 filter_level( CONTENTS_LEVEL6 );
118 }
119 else if ( string_equal( command, "Level 7" ) ) {
120 filter_level( CONTENTS_LEVEL7 );
121 }
122 else if ( string_equal( command, "Level 8" ) ) {
123 filter_level( CONTENTS_LEVEL8 );
124 }
125 else if ( string_equal( command, "StepOn" ) ) {
126 filter_stepon();
127 }
128 else if ( string_equal( command, "ActorClip" ) ) {
129 filter_actorclip();
130 }
131 else if ( string_equal( command, "WeaponClip" ) ) {
132 filter_weaponclip();
133 }
134 else if ( string_equal( command, "NoDraw" ) ) {
135 filter_nodraw();
136 }
137
138 if ( message != NULL ) {
139 GlobalRadiant().m_pfnMessageBox( g_mainwnd,
140 message, "Note",
141 eMB_OK, eMB_ICONDEFAULT );
142 }
143 SceneChangeNotify();
144 }
145 } // namespace
146
147
148 class UFOAIModule : public TypeSystemRef
149 {
150 _QERPluginTable m_plugin;
151 public:
152 typedef _QERPluginTable Type;
153 STRING_CONSTANT( Name, "UFO:AI" );
154
155 UFOAIModule(){
156 m_plugin.m_pfnQERPlug_Init = &UFOAI::init;
157 m_plugin.m_pfnQERPlug_GetName = &UFOAI::getName;
158 m_plugin.m_pfnQERPlug_GetCommandList = &UFOAI::getCommandList;
159 m_plugin.m_pfnQERPlug_GetCommandTitleList = &UFOAI::getCommandTitleList;
160 m_plugin.m_pfnQERPlug_Dispatch = &UFOAI::dispatch;
161 }
162 _QERPluginTable* getTable(){
163 return &m_plugin;
164 }
165 };
166
167 typedef SingletonModule<UFOAIModule, UFOAIPluginDependencies> SingletonUFOAIModule;
168
169 SingletonUFOAIModule g_UFOAIModule;
170
171
172 class UFOAIToolbarDependencies : public ModuleRef<_QERPluginTable>
173 {
174 public:
175 UFOAIToolbarDependencies() : ModuleRef<_QERPluginTable>( "UFO:AI" ){
176 }
177 };
178
179 class UFOAIToolbarModule : public TypeSystemRef
180 {
181 _QERPlugToolbarTable m_table;
182 public:
183 typedef _QERPlugToolbarTable Type;
184 STRING_CONSTANT( Name, "UFO:AI" );
185
186 UFOAIToolbarModule(){
187 if ( !strcmp( GlobalRadiant().getGameDescriptionKeyValue( "name" ), "UFO:Alien Invasion" ) ) {
188 m_table.m_pfnToolbarButtonCount = ToolbarButtonCount;
189 m_table.m_pfnGetToolbarButton = GetToolbarButton;
190 }
191 else
192 {
193 m_table.m_pfnToolbarButtonCount = ToolbarNoButtons;
194 m_table.m_pfnGetToolbarButton = GetToolbarNoButton;
195 }
196 }
197 _QERPlugToolbarTable* getTable(){
198 return &m_table;
199 }
200 };
201
202 typedef SingletonModule<UFOAIToolbarModule, UFOAIToolbarDependencies> SingletonUFOAIToolbarModule;
203
204 SingletonUFOAIToolbarModule g_UFOAIToolbarModule;
205
206
207 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
208 initialiseModule( server );
209
210 g_UFOAIModule.selfRegister();
211 g_UFOAIToolbarModule.selfRegister();
212 }