editor_plugin.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*************************************************************************/
  2. /* editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "editor_plugin.h"
  30. #include "plugins/canvas_item_editor_plugin.h"
  31. #include "plugins/spatial_editor_plugin.h"
  32. void EditorPlugin::add_custom_type(const String& p_type, const String& p_base,const Ref<Script>& p_script, const Ref<Texture>& p_icon) {
  33. EditorNode::get_editor_data().add_custom_type(p_type,p_base,p_script,p_icon);
  34. }
  35. void EditorPlugin::remove_custom_type(const String& p_type){
  36. EditorNode::get_editor_data().remove_custom_type(p_type);
  37. }
  38. void EditorPlugin::add_custom_control(CustomControlContainer p_location,Control *p_control) {
  39. switch(p_location) {
  40. case CONTAINER_TOOLBAR: {
  41. EditorNode::get_menu_hb()->add_child(p_control);
  42. } break;
  43. case CONTAINER_SPATIAL_EDITOR_MENU: {
  44. SpatialEditor::get_singleton()->add_control_to_menu_panel(p_control);
  45. } break;
  46. case CONTAINER_SPATIAL_EDITOR_SIDE: {
  47. SpatialEditor::get_singleton()->get_palette_split()->add_child(p_control);
  48. SpatialEditor::get_singleton()->get_palette_split()->move_child(p_control,0);
  49. } break;
  50. case CONTAINER_SPATIAL_EDITOR_BOTTOM: {
  51. SpatialEditor::get_singleton()->get_shader_split()->add_child(p_control);
  52. } break;
  53. case CONTAINER_CANVAS_EDITOR_MENU: {
  54. CanvasItemEditor::get_singleton()->add_control_to_menu_panel(p_control);
  55. } break;
  56. case CONTAINER_CANVAS_EDITOR_SIDE: {
  57. } break;
  58. }
  59. }
  60. bool EditorPlugin::create_spatial_gizmo(Spatial* p_spatial) {
  61. //??
  62. return false;
  63. }
  64. bool EditorPlugin::forward_input_event(const InputEvent& p_event) {
  65. if (get_script_instance() && get_script_instance()->has_method("forward_input_event")) {
  66. return get_script_instance()->call("forward_input_event",p_event);
  67. }
  68. return false;
  69. }
  70. bool EditorPlugin::forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) {
  71. if (get_script_instance() && get_script_instance()->has_method("forward_spatial_input_event")) {
  72. return get_script_instance()->call("forward_spatial_input_event",p_camera,p_event);
  73. }
  74. return false;
  75. }
  76. String EditorPlugin::get_name() const {
  77. if (get_script_instance() && get_script_instance()->has_method("get_name")) {
  78. return get_script_instance()->call("get_name");
  79. }
  80. return String();
  81. }
  82. bool EditorPlugin::has_main_screen() const {
  83. if (get_script_instance() && get_script_instance()->has_method("has_main_screen")) {
  84. return get_script_instance()->call("has_main_screen");
  85. }
  86. return false;
  87. }
  88. void EditorPlugin::make_visible(bool p_visible) {
  89. if (get_script_instance() && get_script_instance()->has_method("make_visible")) {
  90. get_script_instance()->call("make_visible",p_visible);
  91. }
  92. }
  93. void EditorPlugin::edit(Object *p_object) {
  94. if (get_script_instance() && get_script_instance()->has_method("edit")) {
  95. get_script_instance()->call("edit",p_object);
  96. }
  97. }
  98. bool EditorPlugin::handles(Object *p_object) const {
  99. if (get_script_instance() && get_script_instance()->has_method("handles")) {
  100. return get_script_instance()->call("handles",p_object);
  101. }
  102. return false;
  103. }
  104. Dictionary EditorPlugin::get_state() const {
  105. if (get_script_instance() && get_script_instance()->has_method("get_state")) {
  106. return get_script_instance()->call("get_state");
  107. }
  108. return Dictionary();
  109. }
  110. void EditorPlugin::set_state(const Dictionary& p_state) {
  111. if (get_script_instance() && get_script_instance()->has_method("set_state")) {
  112. get_script_instance()->call("set_state",p_state);
  113. }
  114. }
  115. void EditorPlugin::clear() {
  116. if (get_script_instance() && get_script_instance()->has_method("clear")) {
  117. get_script_instance()->call("clear");
  118. }
  119. }
  120. void EditorPlugin::save_external_data() {} // if editor references external resources/scenes, save them
  121. void EditorPlugin::apply_changes() {
  122. if (get_script_instance() && get_script_instance()->has_method("apply_changes")) {
  123. get_script_instance()->call("apply_changes");
  124. }
  125. } // if changes are pending in editor, apply them
  126. void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) {
  127. if (get_script_instance() && get_script_instance()->has_method("get_breakpoints")) {
  128. StringArray arr = get_script_instance()->call("get_breakpoints");
  129. for(int i=0;i<arr.size();i++)
  130. p_breakpoints->push_back(arr[i]);
  131. }
  132. }
  133. bool EditorPlugin::get_remove_list(List<Node*> *p_list) {
  134. return false;
  135. }
  136. void EditorPlugin::restore_global_state() {}
  137. void EditorPlugin::save_global_state() {}
  138. void EditorPlugin::_bind_methods() {
  139. ObjectTypeDB::bind_method(_MD("get_undo_redo"),&EditorPlugin::_get_undo_redo);
  140. ObjectTypeDB::bind_method(_MD("add_custom_control","container","control"),&EditorPlugin::add_custom_control);
  141. ObjectTypeDB::bind_method(_MD("add_custom_type","type","base","script:Script","icon:Texture"),&EditorPlugin::add_custom_type);
  142. ObjectTypeDB::bind_method(_MD("remove_custom_type","type"),&EditorPlugin::remove_custom_type);
  143. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"forward_input_event",PropertyInfo(Variant::INPUT_EVENT,"event")));
  144. 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")));
  145. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::STRING,"get_name"));
  146. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"has_main_screen"));
  147. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("make_visible",PropertyInfo(Variant::BOOL,"visible")));
  148. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("edit",PropertyInfo(Variant::OBJECT,"object")));
  149. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::BOOL,"handles",PropertyInfo(Variant::OBJECT,"object")));
  150. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::DICTIONARY,"get_state"));
  151. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("set_state",PropertyInfo(Variant::DICTIONARY,"state")));
  152. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("clear"));
  153. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo("apply_changes"));
  154. ObjectTypeDB::add_virtual_method(get_type_static(),MethodInfo(Variant::STRING_ARRAY,"get_breakpoints"));
  155. BIND_CONSTANT( CONTAINER_TOOLBAR );
  156. BIND_CONSTANT( CONTAINER_SPATIAL_EDITOR_MENU );
  157. BIND_CONSTANT( CONTAINER_SPATIAL_EDITOR_SIDE );
  158. BIND_CONSTANT( CONTAINER_SPATIAL_EDITOR_BOTTOM );
  159. BIND_CONSTANT( CONTAINER_CANVAS_EDITOR_MENU );
  160. BIND_CONSTANT( CONTAINER_CANVAS_EDITOR_SIDE );
  161. }
  162. EditorPlugin::EditorPlugin()
  163. {
  164. undo_redo=NULL;
  165. }
  166. EditorPlugin::~EditorPlugin()
  167. {
  168. }
  169. EditorPluginCreateFunc EditorPlugins::creation_funcs[MAX_CREATE_FUNCS];
  170. int EditorPlugins::creation_func_count=0;