editor_plugin.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*************************************************************************/
  2. /* editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "editor_plugin.h"
  31. #include "editor/editor_node.h"
  32. #include "editor/editor_settings.h"
  33. #include "editor_resource_preview.h"
  34. #include "main/main.h"
  35. #include "plugins/canvas_item_editor_plugin.h"
  36. #include "plugins/spatial_editor_plugin.h"
  37. #include "scene/3d/camera.h"
  38. #include "scene/gui/popup_menu.h"
  39. #include "servers/visual_server.h"
  40. Array EditorInterface::_make_mesh_previews(const Array &p_meshes, int p_preview_size) {
  41. Vector<Ref<Mesh> > meshes;
  42. for (int i = 0; i < p_meshes.size(); i++) {
  43. meshes.push_back(p_meshes[i]);
  44. }
  45. Vector<Ref<Texture> > textures = make_mesh_previews(meshes, p_preview_size);
  46. Array ret;
  47. for (int i = 0; i < textures.size(); i++) {
  48. ret.push_back(textures[i]);
  49. }
  50. return ret;
  51. }
  52. Vector<Ref<Texture> > EditorInterface::make_mesh_previews(const Vector<Ref<Mesh> > &p_meshes, int p_preview_size) {
  53. int size = p_preview_size;
  54. RID scenario = VS::get_singleton()->scenario_create();
  55. RID viewport = VS::get_singleton()->viewport_create();
  56. VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ALWAYS);
  57. VS::get_singleton()->viewport_set_vflip(viewport, true);
  58. VS::get_singleton()->viewport_set_scenario(viewport, scenario);
  59. VS::get_singleton()->viewport_set_size(viewport, size, size);
  60. VS::get_singleton()->viewport_set_transparent_background(viewport, true);
  61. VS::get_singleton()->viewport_set_active(viewport, true);
  62. RID viewport_texture = VS::get_singleton()->viewport_get_texture(viewport);
  63. RID camera = VS::get_singleton()->camera_create();
  64. VS::get_singleton()->viewport_attach_camera(viewport, camera);
  65. VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3)));
  66. //VS::get_singleton()->camera_set_perspective(camera,45,0.1,10);
  67. VS::get_singleton()->camera_set_orthogonal(camera, 1.0, 0.01, 1000.0);
  68. RID light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL);
  69. RID light_instance = VS::get_singleton()->instance_create2(light, scenario);
  70. VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0)));
  71. RID light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL);
  72. VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7));
  73. //VS::get_singleton()->light_set_color(light2, VS::LIGHT_COLOR_SPECULAR, Color(0.0, 0.0, 0.0));
  74. RID light_instance2 = VS::get_singleton()->instance_create2(light2, scenario);
  75. VS::get_singleton()->instance_set_transform(light_instance2, Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1)));
  76. //sphere = VS::get_singleton()->mesh_create();
  77. RID mesh_instance = VS::get_singleton()->instance_create();
  78. VS::get_singleton()->instance_set_scenario(mesh_instance, scenario);
  79. EditorProgress ep("mlib", TTR("Creating Mesh Previews"), p_meshes.size());
  80. Vector<Ref<Texture> > textures;
  81. for (int i = 0; i < p_meshes.size(); i++) {
  82. Ref<Mesh> mesh = p_meshes[i];
  83. if (!mesh.is_valid()) {
  84. textures.push_back(Ref<Texture>());
  85. continue;
  86. }
  87. Rect3 aabb = mesh->get_aabb();
  88. print_line("aabb: " + aabb);
  89. Vector3 ofs = aabb.position + aabb.size * 0.5;
  90. aabb.position -= ofs;
  91. Transform xform;
  92. xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.25);
  93. xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.25) * xform.basis;
  94. Rect3 rot_aabb = xform.xform(aabb);
  95. print_line("rot_aabb: " + rot_aabb);
  96. float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5;
  97. if (m == 0) {
  98. textures.push_back(Ref<Texture>());
  99. continue;
  100. }
  101. m = 1.0 / m;
  102. m *= 0.5;
  103. print_line("scale: " + rtos(m));
  104. xform.basis.scale(Vector3(m, m, m));
  105. xform.origin = -xform.basis.xform(ofs); //-ofs*m;
  106. xform.origin.z -= rot_aabb.size.z * 2;
  107. RID inst = VS::get_singleton()->instance_create2(mesh->get_rid(), scenario);
  108. VS::get_singleton()->instance_set_transform(inst, xform);
  109. ep.step(TTR("Thumbnail.."), i);
  110. Main::iteration();
  111. Main::iteration();
  112. Ref<Image> img = VS::get_singleton()->texture_get_data(viewport_texture);
  113. ERR_CONTINUE(!img.is_valid() || img->empty());
  114. Ref<ImageTexture> it(memnew(ImageTexture));
  115. it->create_from_image(img);
  116. //print_line("loaded image, size: "+rtos(m)+" dist: "+rtos(dist)+" empty?"+itos(img.empty())+" w: "+itos(it->get_width())+" h: "+itos(it->get_height()));
  117. VS::get_singleton()->free(inst);
  118. textures.push_back(it);
  119. }
  120. VS::get_singleton()->free(mesh_instance);
  121. VS::get_singleton()->free(viewport);
  122. VS::get_singleton()->free(light);
  123. VS::get_singleton()->free(light_instance);
  124. VS::get_singleton()->free(light2);
  125. VS::get_singleton()->free(light_instance2);
  126. VS::get_singleton()->free(camera);
  127. VS::get_singleton()->free(scenario);
  128. return textures;
  129. }
  130. Control *EditorInterface::get_editor_viewport() {
  131. return EditorNode::get_singleton()->get_viewport();
  132. }
  133. void EditorInterface::edit_resource(const Ref<Resource> &p_resource) {
  134. EditorNode::get_singleton()->edit_resource(p_resource);
  135. }
  136. void EditorInterface::open_scene_from_path(const String &scene_path) {
  137. if (EditorNode::get_singleton()->is_changing_scene()) {
  138. return;
  139. }
  140. EditorNode::get_singleton()->open_request(scene_path);
  141. }
  142. void EditorInterface::reload_scene_from_path(const String &scene_path) {
  143. if (EditorNode::get_singleton()->is_changing_scene()) {
  144. return;
  145. }
  146. EditorNode::get_singleton()->reload_scene(scene_path);
  147. }
  148. Node *EditorInterface::get_edited_scene_root() {
  149. return EditorNode::get_singleton()->get_edited_scene();
  150. }
  151. Array EditorInterface::get_open_scenes() const {
  152. Array ret;
  153. Vector<EditorData::EditedScene> scenes = EditorNode::get_singleton()->get_editor_data().get_edited_scenes();
  154. int scns_amount = scenes.size();
  155. for (int idx_scn = 0; idx_scn < scns_amount; idx_scn++) {
  156. if (scenes[idx_scn].root == NULL)
  157. continue;
  158. ret.push_back(scenes[idx_scn].root->get_filename());
  159. }
  160. return ret;
  161. }
  162. ScriptEditor *EditorInterface::get_script_editor() {
  163. return ScriptEditor::get_singleton();
  164. }
  165. void EditorInterface::inspect_object(Object *p_obj, const String &p_for_property) {
  166. EditorNode::get_singleton()->push_item(p_obj, p_for_property);
  167. }
  168. EditorFileSystem *EditorInterface::get_resource_file_system() {
  169. return EditorFileSystem::get_singleton();
  170. }
  171. EditorSelection *EditorInterface::get_selection() {
  172. return EditorNode::get_singleton()->get_editor_selection();
  173. }
  174. EditorSettings *EditorInterface::get_editor_settings() {
  175. return EditorSettings::get_singleton();
  176. }
  177. EditorResourcePreview *EditorInterface::get_resource_previewer() {
  178. return EditorResourcePreview::get_singleton();
  179. }
  180. Control *EditorInterface::get_base_control() {
  181. return EditorNode::get_singleton()->get_gui_base();
  182. }
  183. Error EditorInterface::save_scene() {
  184. if (!get_edited_scene_root())
  185. return ERR_CANT_CREATE;
  186. if (get_edited_scene_root()->get_filename() == String())
  187. return ERR_CANT_CREATE;
  188. save_scene_as(get_edited_scene_root()->get_filename());
  189. return OK;
  190. }
  191. void EditorInterface::save_scene_as(const String &p_scene, bool p_with_preview) {
  192. EditorNode::get_singleton()->save_scene_to_path(p_scene, p_with_preview);
  193. }
  194. EditorInterface *EditorInterface::singleton = NULL;
  195. void EditorInterface::_bind_methods() {
  196. ClassDB::bind_method(D_METHOD("inspect_object", "object", "for_property"), &EditorInterface::inspect_object, DEFVAL(String()));
  197. ClassDB::bind_method(D_METHOD("get_selection"), &EditorInterface::get_selection);
  198. ClassDB::bind_method(D_METHOD("get_editor_settings"), &EditorInterface::get_editor_settings);
  199. ClassDB::bind_method(D_METHOD("get_script_editor"), &EditorInterface::get_script_editor);
  200. ClassDB::bind_method(D_METHOD("get_base_control"), &EditorInterface::get_base_control);
  201. ClassDB::bind_method(D_METHOD("edit_resource", "resource"), &EditorInterface::edit_resource);
  202. ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath"), &EditorInterface::open_scene_from_path);
  203. ClassDB::bind_method(D_METHOD("reload_scene_from_path", "scene_filepath"), &EditorInterface::reload_scene_from_path);
  204. ClassDB::bind_method(D_METHOD("get_open_scenes"), &EditorInterface::get_open_scenes);
  205. ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &EditorInterface::get_edited_scene_root);
  206. ClassDB::bind_method(D_METHOD("get_resource_previewer"), &EditorInterface::get_resource_previewer);
  207. ClassDB::bind_method(D_METHOD("get_resource_filesystem"), &EditorInterface::get_resource_file_system);
  208. ClassDB::bind_method(D_METHOD("get_editor_viewport"), &EditorInterface::get_editor_viewport);
  209. ClassDB::bind_method(D_METHOD("make_mesh_previews", "meshes", "preview_size"), &EditorInterface::_make_mesh_previews);
  210. ClassDB::bind_method(D_METHOD("save_scene"), &EditorInterface::save_scene);
  211. ClassDB::bind_method(D_METHOD("save_scene_as", "path", "with_preview"), &EditorInterface::save_scene_as, DEFVAL(true));
  212. }
  213. EditorInterface::EditorInterface() {
  214. singleton = this;
  215. }
  216. ///////////////////////////////////////////
  217. void EditorPlugin::add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture> &p_icon) {
  218. EditorNode::get_editor_data().add_custom_type(p_type, p_base, p_script, p_icon);
  219. }
  220. void EditorPlugin::remove_custom_type(const String &p_type) {
  221. EditorNode::get_editor_data().remove_custom_type(p_type);
  222. }
  223. ToolButton *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const String &p_title) {
  224. return EditorNode::get_singleton()->add_bottom_panel_item(p_title, p_control);
  225. }
  226. void EditorPlugin::add_control_to_dock(DockSlot p_slot, Control *p_control) {
  227. ERR_FAIL_NULL(p_control);
  228. EditorNode::get_singleton()->add_control_to_dock(EditorNode::DockSlot(p_slot), p_control);
  229. }
  230. void EditorPlugin::remove_control_from_docks(Control *p_control) {
  231. ERR_FAIL_NULL(p_control);
  232. EditorNode::get_singleton()->remove_control_from_dock(p_control);
  233. }
  234. void EditorPlugin::remove_control_from_bottom_panel(Control *p_control) {
  235. ERR_FAIL_NULL(p_control);
  236. EditorNode::get_singleton()->remove_bottom_panel_item(p_control);
  237. }
  238. void EditorPlugin::add_control_to_container(CustomControlContainer p_location, Control *p_control) {
  239. switch (p_location) {
  240. case CONTAINER_TOOLBAR: {
  241. EditorNode::get_menu_hb()->add_child(p_control);
  242. } break;
  243. case CONTAINER_SPATIAL_EDITOR_MENU: {
  244. SpatialEditor::get_singleton()->add_control_to_menu_panel(p_control);
  245. } break;
  246. case CONTAINER_SPATIAL_EDITOR_SIDE: {
  247. SpatialEditor::get_singleton()->get_palette_split()->add_child(p_control);
  248. SpatialEditor::get_singleton()->get_palette_split()->move_child(p_control, 0);
  249. } break;
  250. case CONTAINER_SPATIAL_EDITOR_BOTTOM: {
  251. SpatialEditor::get_singleton()->get_shader_split()->add_child(p_control);
  252. } break;
  253. case CONTAINER_CANVAS_EDITOR_MENU: {
  254. CanvasItemEditor::get_singleton()->add_control_to_menu_panel(p_control);
  255. } break;
  256. case CONTAINER_CANVAS_EDITOR_SIDE: {
  257. CanvasItemEditor::get_singleton()->get_palette_split()->add_child(p_control);
  258. CanvasItemEditor::get_singleton()->get_palette_split()->move_child(p_control, 0);
  259. } break;
  260. case CONTAINER_CANVAS_EDITOR_BOTTOM: {
  261. CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(p_control);
  262. } break;
  263. case CONTAINER_PROPERTY_EDITOR_BOTTOM: {
  264. EditorNode::get_singleton()->get_property_editor_vb()->add_child(p_control);
  265. } break;
  266. }
  267. }
  268. void EditorPlugin::add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud) {
  269. //EditorNode::get_singleton()->add_tool_menu_item(p_name, p_handler, p_callback, p_ud);
  270. }
  271. void EditorPlugin::add_tool_submenu_item(const String &p_name, Object *p_submenu) {
  272. ERR_FAIL_NULL(p_submenu);
  273. PopupMenu *submenu = Object::cast_to<PopupMenu>(p_submenu);
  274. ERR_FAIL_NULL(submenu);
  275. //EditorNode::get_singleton()->add_tool_submenu_item(p_name, submenu);
  276. }
  277. void EditorPlugin::remove_tool_menu_item(const String &p_name) {
  278. //EditorNode::get_singleton()->remove_tool_menu_item(p_name);
  279. }
  280. void EditorPlugin::set_input_event_forwarding_always_enabled() {
  281. input_event_forwarding_always_enabled = true;
  282. EditorPluginList *always_input_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding();
  283. always_input_forwarding_list->add_plugin(this);
  284. }
  285. void EditorPlugin::notify_scene_changed(const Node *scn_root) {
  286. if (scn_root == NULL) return;
  287. emit_signal("scene_changed", scn_root);
  288. }
  289. void EditorPlugin::notify_main_screen_changed(const String &screen_name) {
  290. if (screen_name == last_main_screen_name)
  291. return;
  292. emit_signal("main_screen_changed", screen_name);
  293. last_main_screen_name = screen_name;
  294. }
  295. void EditorPlugin::notify_scene_closed(const String &scene_filepath) {
  296. emit_signal("scene_closed", scene_filepath);
  297. }
  298. Ref<SpatialEditorGizmo> EditorPlugin::create_spatial_gizmo(Spatial *p_spatial) {
  299. //??
  300. if (get_script_instance() && get_script_instance()->has_method("create_spatial_gizmo")) {
  301. return get_script_instance()->call("create_spatial_gizmo", p_spatial);
  302. }
  303. return Ref<SpatialEditorGizmo>();
  304. }
  305. bool EditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) {
  306. if (get_script_instance() && get_script_instance()->has_method("forward_canvas_gui_input")) {
  307. return get_script_instance()->call("forward_canvas_gui_input", p_event);
  308. }
  309. return false;
  310. }
  311. void EditorPlugin::forward_draw_over_canvas(Control *p_canvas) {
  312. if (get_script_instance() && get_script_instance()->has_method("forward_draw_over_canvas")) {
  313. get_script_instance()->call("forward_draw_over_canvas", p_canvas);
  314. }
  315. }
  316. void EditorPlugin::update_canvas() {
  317. CanvasItemEditor::get_singleton()->get_viewport_control()->update();
  318. }
  319. bool EditorPlugin::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) {
  320. if (get_script_instance() && get_script_instance()->has_method("forward_spatial_gui_input")) {
  321. return get_script_instance()->call("forward_spatial_gui_input", p_camera, p_event);
  322. }
  323. return false;
  324. }
  325. String EditorPlugin::get_name() const {
  326. if (get_script_instance() && get_script_instance()->has_method("get_plugin_name")) {
  327. return get_script_instance()->call("get_plugin_name");
  328. }
  329. return String();
  330. }
  331. bool EditorPlugin::has_main_screen() const {
  332. if (get_script_instance() && get_script_instance()->has_method("has_main_screen")) {
  333. return get_script_instance()->call("has_main_screen");
  334. }
  335. return false;
  336. }
  337. void EditorPlugin::make_visible(bool p_visible) {
  338. if (get_script_instance() && get_script_instance()->has_method("make_visible")) {
  339. get_script_instance()->call("make_visible", p_visible);
  340. }
  341. }
  342. void EditorPlugin::edit(Object *p_object) {
  343. if (get_script_instance() && get_script_instance()->has_method("edit")) {
  344. get_script_instance()->call("edit", p_object);
  345. }
  346. }
  347. bool EditorPlugin::handles(Object *p_object) const {
  348. if (get_script_instance() && get_script_instance()->has_method("handles")) {
  349. return get_script_instance()->call("handles", p_object);
  350. }
  351. return false;
  352. }
  353. Dictionary EditorPlugin::get_state() const {
  354. if (get_script_instance() && get_script_instance()->has_method("get_state")) {
  355. return get_script_instance()->call("get_state");
  356. }
  357. return Dictionary();
  358. }
  359. void EditorPlugin::set_state(const Dictionary &p_state) {
  360. if (get_script_instance() && get_script_instance()->has_method("set_state")) {
  361. get_script_instance()->call("set_state", p_state);
  362. }
  363. }
  364. void EditorPlugin::clear() {
  365. if (get_script_instance() && get_script_instance()->has_method("clear")) {
  366. get_script_instance()->call("clear");
  367. }
  368. }
  369. // if editor references external resources/scenes, save them
  370. void EditorPlugin::save_external_data() {
  371. if (get_script_instance() && get_script_instance()->has_method("save_external_data")) {
  372. get_script_instance()->call("save_external_data");
  373. }
  374. }
  375. // if changes are pending in editor, apply them
  376. void EditorPlugin::apply_changes() {
  377. if (get_script_instance() && get_script_instance()->has_method("apply_changes")) {
  378. get_script_instance()->call("apply_changes");
  379. }
  380. }
  381. void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) {
  382. if (get_script_instance() && get_script_instance()->has_method("get_breakpoints")) {
  383. PoolStringArray arr = get_script_instance()->call("get_breakpoints");
  384. for (int i = 0; i < arr.size(); i++)
  385. p_breakpoints->push_back(arr[i]);
  386. }
  387. }
  388. bool EditorPlugin::get_remove_list(List<Node *> *p_list) {
  389. return false;
  390. }
  391. void EditorPlugin::restore_global_state() {}
  392. void EditorPlugin::save_global_state() {}
  393. void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin> &p_importer) {
  394. ResourceFormatImporter::get_singleton()->add_importer(p_importer);
  395. EditorFileSystem::get_singleton()->scan();
  396. }
  397. void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin> &p_importer) {
  398. ResourceFormatImporter::get_singleton()->remove_importer(p_importer);
  399. EditorFileSystem::get_singleton()->scan();
  400. }
  401. void EditorPlugin::add_export_plugin(const Ref<EditorExportPlugin> &p_exporter) {
  402. EditorExport::get_singleton()->add_export_plugin(p_exporter);
  403. }
  404. void EditorPlugin::remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter) {
  405. EditorExport::get_singleton()->remove_export_plugin(p_exporter);
  406. }
  407. void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
  408. if (get_script_instance() && get_script_instance()->has_method("set_window_layout")) {
  409. get_script_instance()->call("set_window_layout", p_layout);
  410. }
  411. }
  412. void EditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
  413. if (get_script_instance() && get_script_instance()->has_method("get_window_layout")) {
  414. get_script_instance()->call("get_window_layout", p_layout);
  415. }
  416. }
  417. void EditorPlugin::queue_save_layout() const {
  418. EditorNode::get_singleton()->save_layout();
  419. }
  420. void EditorPlugin::make_bottom_panel_item_visible(Control *p_item) {
  421. EditorNode::get_singleton()->make_bottom_panel_item_visible(p_item);
  422. }
  423. void EditorPlugin::hide_bottom_panel() {
  424. EditorNode::get_singleton()->hide_bottom_panel();
  425. }
  426. EditorInterface *EditorPlugin::get_editor_interface() {
  427. return EditorInterface::get_singleton();
  428. }
  429. void EditorPlugin::_bind_methods() {
  430. ClassDB::bind_method(D_METHOD("add_control_to_container", "container", "control"), &EditorPlugin::add_control_to_container);
  431. ClassDB::bind_method(D_METHOD("add_control_to_bottom_panel", "control", "title"), &EditorPlugin::add_control_to_bottom_panel);
  432. ClassDB::bind_method(D_METHOD("add_control_to_dock", "slot", "control"), &EditorPlugin::add_control_to_dock);
  433. ClassDB::bind_method(D_METHOD("remove_control_from_docks", "control"), &EditorPlugin::remove_control_from_docks);
  434. ClassDB::bind_method(D_METHOD("remove_control_from_bottom_panel", "control"), &EditorPlugin::remove_control_from_bottom_panel);
  435. //ClassDB::bind_method(D_METHOD("add_tool_menu_item", "name", "handler", "callback", "ud"),&EditorPlugin::add_tool_menu_item,DEFVAL(Variant()));
  436. ClassDB::bind_method(D_METHOD("add_tool_submenu_item", "name", "submenu"), &EditorPlugin::add_tool_submenu_item);
  437. //ClassDB::bind_method(D_METHOD("remove_tool_menu_item", "name"),&EditorPlugin::remove_tool_menu_item);
  438. ClassDB::bind_method(D_METHOD("add_custom_type", "type", "base", "script", "icon"), &EditorPlugin::add_custom_type);
  439. ClassDB::bind_method(D_METHOD("remove_custom_type", "type"), &EditorPlugin::remove_custom_type);
  440. ClassDB::bind_method(D_METHOD("update_canvas"), &EditorPlugin::update_canvas);
  441. ClassDB::bind_method(D_METHOD("make_bottom_panel_item_visible", "item"), &EditorPlugin::make_bottom_panel_item_visible);
  442. ClassDB::bind_method(D_METHOD("hide_bottom_panel"), &EditorPlugin::hide_bottom_panel);
  443. ClassDB::bind_method(D_METHOD("get_undo_redo"), &EditorPlugin::_get_undo_redo);
  444. ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout);
  445. ClassDB::bind_method(D_METHOD("add_import_plugin", "importer"), &EditorPlugin::add_import_plugin);
  446. ClassDB::bind_method(D_METHOD("remove_import_plugin", "importer"), &EditorPlugin::remove_import_plugin);
  447. ClassDB::bind_method(D_METHOD("add_export_plugin", "exporter"), &EditorPlugin::add_export_plugin);
  448. ClassDB::bind_method(D_METHOD("remove_export_plugin", "exporter"), &EditorPlugin::remove_export_plugin);
  449. ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled);
  450. ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorPlugin::get_editor_interface);
  451. ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_canvas_gui_input", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
  452. ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_draw_over_canvas", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "canvas", PROPERTY_HINT_RESOURCE_TYPE, "Control")));
  453. ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
  454. MethodInfo gizmo = MethodInfo(Variant::OBJECT, "create_spatial_gizmo", PropertyInfo(Variant::OBJECT, "for_spatial", PROPERTY_HINT_RESOURCE_TYPE, "Spatial"));
  455. gizmo.return_val.hint = PROPERTY_HINT_RESOURCE_TYPE;
  456. gizmo.return_val.hint_string = "EditorSpatialGizmo";
  457. ClassDB::add_virtual_method(get_class_static(), gizmo);
  458. ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_plugin_name"));
  459. ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "has_main_screen"));
  460. ClassDB::add_virtual_method(get_class_static(), MethodInfo("make_visible", PropertyInfo(Variant::BOOL, "visible")));
  461. ClassDB::add_virtual_method(get_class_static(), MethodInfo("edit", PropertyInfo(Variant::OBJECT, "object")));
  462. ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "handles", PropertyInfo(Variant::OBJECT, "object")));
  463. ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::DICTIONARY, "get_state"));
  464. ClassDB::add_virtual_method(get_class_static(), MethodInfo("set_state", PropertyInfo(Variant::DICTIONARY, "state")));
  465. ClassDB::add_virtual_method(get_class_static(), MethodInfo("clear"));
  466. ClassDB::add_virtual_method(get_class_static(), MethodInfo("save_external_data"));
  467. ClassDB::add_virtual_method(get_class_static(), MethodInfo("apply_changes"));
  468. ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::POOL_STRING_ARRAY, "get_breakpoints"));
  469. ClassDB::add_virtual_method(get_class_static(), MethodInfo("set_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile")));
  470. ClassDB::add_virtual_method(get_class_static(), MethodInfo("get_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile")));
  471. ADD_SIGNAL(MethodInfo("scene_changed", PropertyInfo(Variant::OBJECT, "scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
  472. ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "filepath")));
  473. ADD_SIGNAL(MethodInfo("main_screen_changed", PropertyInfo(Variant::STRING, "screen_name")));
  474. BIND_ENUM_CONSTANT(CONTAINER_TOOLBAR);
  475. BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_MENU);
  476. BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_SIDE);
  477. BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_BOTTOM);
  478. BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_MENU);
  479. BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_SIDE);
  480. BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_BOTTOM);
  481. BIND_ENUM_CONSTANT(CONTAINER_PROPERTY_EDITOR_BOTTOM);
  482. BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_UL);
  483. BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_BL);
  484. BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_UR);
  485. BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_BR);
  486. BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UL);
  487. BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BL);
  488. BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UR);
  489. BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BR);
  490. BIND_ENUM_CONSTANT(DOCK_SLOT_MAX);
  491. }
  492. EditorPlugin::EditorPlugin() {
  493. undo_redo = NULL;
  494. input_event_forwarding_always_enabled = false;
  495. last_main_screen_name = "";
  496. }
  497. EditorPlugin::~EditorPlugin() {
  498. }
  499. EditorPluginCreateFunc EditorPlugins::creation_funcs[MAX_CREATE_FUNCS];
  500. int EditorPlugins::creation_func_count = 0;