summaryrefslogtreecommitdiff
path: root/tools/editor/editor_plugin.cpp
blob: 0d162cbe5679351cea1662703fc4251ea36f756e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*************************************************************************/
/*  editor_plugin.cpp                                                    */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                    http://www.godotengine.org                         */
/*************************************************************************/
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur.                 */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/
#include "editor_plugin.h"
#include "scene/3d/camera.h"
#include "plugins/canvas_item_editor_plugin.h"
#include "plugins/spatial_editor_plugin.h"
#include "tools/editor/editor_node.h"
#include "tools/editor/editor_settings.h"

void EditorPlugin::add_custom_type(const String& p_type, const String& p_base,const Ref<Script>& p_script, const Ref<Texture>& p_icon) {

	EditorNode::get_editor_data().add_custom_type(p_type,p_base,p_script,p_icon);
}

void EditorPlugin::remove_custom_type(const String& p_type){

	EditorNode::get_editor_data().remove_custom_type(p_type);
}


ToolButton * EditorPlugin::add_control_to_bottom_panel(Control *p_control, const String &p_title) {

	return EditorNode::get_singleton()->add_bottom_panel_item(p_title,p_control);
}

void EditorPlugin::add_control_to_dock(DockSlot p_slot,Control *p_control) {

	ERR_FAIL_NULL(p_control);
	EditorNode::get_singleton()->add_control_to_dock(EditorNode::DockSlot(p_slot),p_control);

}

void EditorPlugin::remove_control_from_docks(Control *p_control) {

	ERR_FAIL_NULL(p_control);
	EditorNode::get_singleton()->remove_control_from_dock(p_control);

}

void EditorPlugin::remove_control_from_bottom_panel(Control *p_control) {

	ERR_FAIL_NULL(p_control);
	EditorNode::get_singleton()->remove_bottom_panel_item(p_control);

}

void EditorPlugin::add_control_to_container(CustomControlContainer p_location,Control *p_control) {

	switch(p_location) {

		case CONTAINER_TOOLBAR: {

			EditorNode::get_menu_hb()->add_child(p_control);
		} break;

		case CONTAINER_SPATIAL_EDITOR_MENU: {

			SpatialEditor::get_singleton()->add_control_to_menu_panel(p_control);

		} break;
		case CONTAINER_SPATIAL_EDITOR_SIDE: {

			SpatialEditor::get_singleton()->get_palette_split()->add_child(p_control);
			SpatialEditor::get_singleton()->get_palette_split()->move_child(p_control,0);

		} break;
		case CONTAINER_SPATIAL_EDITOR_BOTTOM: {

			SpatialEditor::get_singleton()->get_shader_split()->add_child(p_control);

		} break;
		case CONTAINER_CANVAS_EDITOR_MENU: {

			CanvasItemEditor::get_singleton()->add_control_to_menu_panel(p_control);

		} break;
		case CONTAINER_CANVAS_EDITOR_SIDE: {

			CanvasItemEditor::get_singleton()->get_palette_split()->add_child(p_control);
			CanvasItemEditor::get_singleton()->get_palette_split()->move_child(p_control,0);

		} break;
		case CONTAINER_CANVAS_EDITOR_BOTTOM: {

			CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(p_control);

		} break;
		case CONTAINER_PROPERTY_EDITOR_BOTTOM: {

			EditorNode::get_singleton()->get_property_editor_vb()->add_child(p_control);

		} break;


	}
}

Ref<SpatialEditorGizmo> EditorPlugin::create_spatial_gizmo(Spatial* p_spatial) {
	//??
	if (get_script_instance() && get_script_instance()->has_method("create_spatial_gizmo")) {
		return get_script_instance()->call("create_spatial_gizmo",p_spatial);
	}

	return Ref<SpatialEditorGizmo>();
}

bool EditorPlugin::forward_input_event(const InputEvent& p_event) {

	if (get_script_instance() && get_script_instance()->has_method("forward_input_event")) {
		return get_script_instance()->call("forward_input_event",p_event);
	}
	return false;
}
bool EditorPlugin::forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) {

	if (get_script_instance() && get_script_instance()->has_method("forward_spatial_input_event")) {
		return get_script_instance()->call("forward_spatial_input_event",p_camera,p_event);
	}

	return false;
}
String EditorPlugin::get_name() const {

	if (get_script_instance() && get_script_instance()->has_method("get_name")) {
		return get_script_instance()->call("get_name");
	}

	return String();

}
bool EditorPlugin::has_main_screen() const {

	if (get_script_instance() && get_script_instance()->has_method("has_main_screen")) {
		return get_script_instance()->call("has_main_screen");
	}

	return false;

}
void EditorPlugin::make_visible(bool p_visible) {

	if (get_script_instance() && get_script_instance()->has_method("make_visible")) {
		get_script_instance()->call("make_visible",p_visible);
	}
}


void EditorPlugin::edit(Object *p_object) {

	if (get_script_instance() && get_script_instance()->has_method("edit")) {
		get_script_instance()->call("edit",p_object);
	}

}

bool EditorPlugin::handles(Object *p_object) const {

	if (get_script_instance() && get_script_instance()->has_method("handles")) {
		return get_script_instance()->call("handles",p_object);
	}

	return false;
}
Dictionary EditorPlugin::get_state() const {

	if (get_script_instance() && get_script_instance()->has_method("get_state")) {
		return get_script_instance()->call("get_state");
	}

	return Dictionary();
}

void EditorPlugin::set_state(const Dictionary& p_state) {

	if (get_script_instance() && get_script_instance()->has_method("set_state")) {
		get_script_instance()->call("set_state",p_state);
	}
}

void EditorPlugin::clear() {

	if (get_script_instance() && get_script_instance()->has_method("clear")) {
		get_script_instance()->call("clear");
	}

}

void EditorPlugin::save_external_data() {} // if editor references external resources/scenes, save them
void EditorPlugin::apply_changes() {

	if (get_script_instance() && get_script_instance()->has_method("apply_changes")) {
		get_script_instance()->call("apply_changes");
	}


} // if changes are pending in editor, apply them
void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) {

	if (get_script_instance() && get_script_instance()->has_method("get_breakpoints")) {
		StringArray arr = get_script_instance()->call("get_breakpoints");
		for(int i=0;i<arr.size();i++)
			p_breakpoints->push_back(arr[i]);
	}

}
bool EditorPlugin::get_remove_list(List<Node*> *p_list) {

	return false;
}

void EditorPlugin::restore_global_state() {}
void EditorPlugin::save_global_state() {}

void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {

}

void EditorPlugin::get_window_layout(Ref<ConfigFile> p_layout){

}

EditorSelection* EditorPlugin::get_selection() {
	return EditorNode::get_singleton()->get_editor_selection();
}


EditorSettings *EditorPlugin::get_editor_settings() {
	return EditorSettings::get_singleton();
}

void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) {

	EditorNode::get_singleton()->add_editor_import_plugin(p_editor_import);
}

void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin>& p_editor_import){

	EditorNode::get_singleton()->remove_editor_import_plugin(p_editor_import);

}

void EditorPlugin::add_export_plugin(const Ref<EditorExportPlugin>& p_editor_export){

	EditorImportExport::get_singleton()->add_export_plugin(p_editor_export);
}
void EditorPlugin::remove_export_plugin(const Ref<EditorExportPlugin>& p_editor_export){

	EditorImportExport::get_singleton()->remove_export_plugin(p_editor_export);

}

Control *EditorPlugin::get_base_control() {

	return EditorNode::get_singleton()->get_gui_base();
}


void EditorPlugin::_bind_methods() {

	ObjectTypeDB::bind_method(_MD("add_control_to_container","container","control:Control"),&EditorPlugin::add_control_to_container);
	ObjectTypeDB::bind_method(_MD("add_control_to_bottom_panel:ToolButton","control:Control","title"),&EditorPlugin::add_control_to_bottom_panel);
	ObjectTypeDB::bind_method(_MD("add_control_to_dock","slot","control:Control"),&EditorPlugin::add_control_to_dock);
	ObjectTypeDB::bind_method(_MD("remove_control_from_docks","control:Control"),&EditorPlugin::remove_control_from_docks);
	ObjectTypeDB::bind_method(_MD("remove_control_from_bottom_panel","control:Control"),&EditorPlugin::remove_control_from_bottom_panel);
	ObjectTypeDB::bind_method(_MD("add_custom_type","type","base","script:Script","icon:Texture"),&EditorPlugin::add_custom_type);
	ObjectTypeDB::bind_method(_MD("remove_custom_type","type"),&EditorPlugin::remove_custom_type);

	ObjectTypeDB::bind_method(_MD("add_import_plugin","plugin:EditorImportPlugin"),&EditorPlugin::add_import_plugin);
	ObjectTypeDB::bind_method(_MD("remove_import_plugin","plugin:EditorImportPlugin"),&EditorPlugin::remove_import_plugin);

	ObjectTypeDB::bind_method(_MD("add_export_plugin","plugin:EditorExportPlugin"),&EditorPlugin::add_export_plugin);
	ObjectTypeDB::bind_method(_MD("remove_export_plugin","plugin:EditorExportPlugin"),&EditorPlugin::remove_export_plugin);


	ObjectTypeDB::bind_method(_MD("get_base_control:Control"),&EditorPlugin::get_base_control);
	ObjectTypeDB::bind_method(_MD("get_undo_redo:UndoRedo"),&EditorPlugin::_get_undo_redo);
	ObjectTypeDB::bind_method(_MD("get_selection:EditorSelection"),&EditorPlugin::get_selection);
	ObjectTypeDB::bind_method(_MD("get_editor_settings:EditorSettings"),&EditorPlugin::get_editor_settings);

	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"forward_input_event",PropertyInfo(Variant::INPUT_EVENT,"event")));
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"forward_spatial_input_event",PropertyInfo(Variant::OBJECT,"camera",PROPERTY_HINT_RESOURCE_TYPE,"Camera"),PropertyInfo(Variant::INPUT_EVENT,"event")));
	MethodInfo gizmo = MethodInfo(Variant::OBJECT,"create_spatial_gizmo",PropertyInfo(Variant::OBJECT,"for_spatial:Spatial"));
	gizmo.return_val.hint=PROPERTY_HINT_RESOURCE_TYPE;
	gizmo.return_val.hint_string="EditorSpatialGizmo";
	ObjectTypeDB::add_virtual_method(get_type_static(),gizmo);
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::STRING,"get_name"));
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"has_main_screen"));
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("make_visible",PropertyInfo(Variant::BOOL,"visible")));
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("edit",PropertyInfo(Variant::OBJECT,"object")));
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"handles",PropertyInfo(Variant::OBJECT,"object")));
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::DICTIONARY,"get_state"));
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("set_state",PropertyInfo(Variant::DICTIONARY,"state")));
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("clear"));
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("apply_changes"));
	ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::STRING_ARRAY,"get_breakpoints"));

	BIND_CONSTANT( CONTAINER_TOOLBAR );
	BIND_CONSTANT( CONTAINER_SPATIAL_EDITOR_MENU );
	BIND_CONSTANT( CONTAINER_SPATIAL_EDITOR_SIDE );
	BIND_CONSTANT( CONTAINER_SPATIAL_EDITOR_BOTTOM );
	BIND_CONSTANT( CONTAINER_CANVAS_EDITOR_MENU );
	BIND_CONSTANT( CONTAINER_CANVAS_EDITOR_SIDE );
	BIND_CONSTANT( CONTAINER_PROPERTY_EDITOR_BOTTOM );


	BIND_CONSTANT( DOCK_SLOT_LEFT_UL );
	BIND_CONSTANT( DOCK_SLOT_LEFT_BL );
	BIND_CONSTANT( DOCK_SLOT_LEFT_UR );
	BIND_CONSTANT( DOCK_SLOT_LEFT_BR );
	BIND_CONSTANT( DOCK_SLOT_RIGHT_UL );
	BIND_CONSTANT( DOCK_SLOT_RIGHT_BL );
	BIND_CONSTANT( DOCK_SLOT_RIGHT_UR );
	BIND_CONSTANT( DOCK_SLOT_RIGHT_BR );
	BIND_CONSTANT( DOCK_SLOT_MAX );

}

EditorPlugin::EditorPlugin()
{
	undo_redo=NULL;
}


EditorPlugin::~EditorPlugin()
{
}



EditorPluginCreateFunc EditorPlugins::creation_funcs[MAX_CREATE_FUNCS];

int EditorPlugins::creation_func_count=0;