visual_script_editor.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*************************************************************************/
  2. /* visual_script_editor.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 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. #ifndef VISUALSCRIPT_EDITOR_H
  30. #define VISUALSCRIPT_EDITOR_H
  31. #include "editor/plugins/script_editor_plugin.h"
  32. #include "visual_script.h"
  33. #include "editor/property_editor.h"
  34. #include "scene/gui/graph_edit.h"
  35. #include "editor/create_dialog.h"
  36. #include "editor/property_selector.h"
  37. class VisualScriptEditorSignalEdit;
  38. class VisualScriptEditorVariableEdit;
  39. #ifdef TOOLS_ENABLED
  40. class VisualScriptEditor : public ScriptEditorBase {
  41. GDCLASS(VisualScriptEditor,ScriptEditorBase)
  42. enum {
  43. TYPE_SEQUENCE=1000,
  44. INDEX_BASE_SEQUENCE=1024
  45. };
  46. enum {
  47. EDIT_DELETE_NODES,
  48. EDIT_TOGGLE_BREAKPOINT,
  49. EDIT_FIND_NODE_TYPE,
  50. EDIT_COPY_NODES,
  51. EDIT_CUT_NODES,
  52. EDIT_PASTE_NODES,
  53. };
  54. enum PortAction {
  55. CREATE_CALL,
  56. CREATE_SET,
  57. CREATE_GET,
  58. CREATE_COND,
  59. CREATE_SEQUENCE,
  60. CREATE_SWITCH,
  61. CREATE_ITERATOR,
  62. CREATE_WHILE,
  63. CREATE_RETURN,
  64. };
  65. MenuButton *edit_menu;
  66. Ref<VisualScript> script;
  67. Button *base_type_select;
  68. HSplitContainer *main_hsplit;
  69. VSplitContainer *left_vsplit;
  70. GraphEdit *graph;
  71. LineEdit *node_filter;
  72. TextureRect *node_filter_icon;
  73. VisualScriptEditorSignalEdit *signal_editor;
  74. AcceptDialog *edit_signal_dialog;
  75. PropertyEditor *edit_signal_edit;
  76. PropertySelector *method_select;
  77. PropertySelector *new_connect_node_select;
  78. VisualScriptEditorVariableEdit *variable_editor;
  79. AcceptDialog *edit_variable_dialog;
  80. PropertyEditor *edit_variable_edit;
  81. CustomPropertyEditor *default_value_edit;
  82. UndoRedo *undo_redo;
  83. Tree *members;
  84. Tree *nodes;
  85. Label *hint_text;
  86. Timer *hint_text_timer;
  87. Label *select_func_text;
  88. bool updating_graph;
  89. void _show_hint(const String& p_hint);
  90. void _hide_timer();
  91. CreateDialog *select_base_type;
  92. struct VirtualInMenu {
  93. String name;
  94. Variant::Type ret;
  95. bool ret_variant;
  96. Vector< Pair<Variant::Type,String> > args;
  97. };
  98. Map<int,VirtualInMenu> virtuals_in_menu;
  99. PopupMenu *new_function_menu;
  100. StringName edited_func;
  101. void _update_graph_connections();
  102. void _update_graph(int p_only_id=-1);
  103. bool updating_members;
  104. void _update_members();
  105. StringName selected;
  106. String _validate_name(const String& p_name) const;
  107. struct Clipboard {
  108. Map<int,Ref<VisualScriptNode> > nodes;
  109. Map<int,Vector2 > nodes_positions;
  110. Set<VisualScript::SequenceConnection> sequence_connections;
  111. Set<VisualScript::DataConnection> data_connections;
  112. };
  113. static Clipboard *clipboard;
  114. PopupMenu *port_action_popup;
  115. PortAction port_action;
  116. int port_action_node;
  117. int port_action_output;
  118. Vector2 port_action_pos;
  119. int port_action_new_node;
  120. void _port_action_menu(int p_option);
  121. void _selected_connect_node_method_or_setget(const String& p_text);
  122. int error_line;
  123. void _node_selected(Node* p_node);
  124. void _center_on_node(int p_id);
  125. void _node_filter_changed(const String& p_text);
  126. void _change_base_type_callback();
  127. void _change_base_type();
  128. void _member_selected();
  129. void _member_edited();
  130. void _override_pressed(int p_id);
  131. void _begin_node_move();
  132. void _end_node_move();
  133. void _move_node(String func,int p_id,const Vector2& p_to);
  134. void _node_moved(Vector2 p_from,Vector2 p_to, int p_id);
  135. void _remove_node(int p_id);
  136. void _graph_connected(const String& p_from,int p_from_slot,const String& p_to,int p_to_slot);
  137. void _graph_disconnected(const String& p_from,int p_from_slot,const String& p_to,int p_to_slot);
  138. void _graph_connect_to_empty(const String& p_from,int p_from_slot,const Vector2& p_release_pos);
  139. void _node_ports_changed(const String& p_func,int p_id);
  140. void _available_node_doubleclicked();
  141. void _update_available_nodes();
  142. void _member_button(Object *p_item, int p_column, int p_button);
  143. void _expression_text_changed(const String& p_text,int p_id);
  144. String revert_on_drag;
  145. void _input(const InputEvent& p_event);
  146. void _on_nodes_delete();
  147. void _on_nodes_duplicate();
  148. Variant get_drag_data_fw(const Point2& p_point,Control* p_from);
  149. bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const;
  150. void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from);
  151. int editing_id;
  152. int editing_input;
  153. void _default_value_changed();
  154. void _default_value_edited(Node * p_button,int p_id,int p_input_port);
  155. void _menu_option(int p_what);
  156. void _graph_ofs_changed(const Vector2& p_ofs);
  157. void _comment_node_resized(const Vector2& p_new_size,int p_node);
  158. int selecting_method_id;
  159. void _selected_method(const String& p_method);
  160. void _draw_color_over_button(Object* obj,Color p_color);
  161. void _button_resource_previewed(const String& p_path,const Ref<Texture>& p_preview,Variant p_ud);
  162. VisualScriptNode::TypeGuess _guess_output_type(int p_port_action_node,int p_port_action_output,Set<int> &visited_nodes);
  163. protected:
  164. void _notification(int p_what);
  165. static void _bind_methods();
  166. public:
  167. virtual void apply_code();
  168. virtual Ref<Script> get_edited_script() const;
  169. virtual Vector<String> get_functions();
  170. virtual void set_edited_script(const Ref<Script>& p_script);
  171. virtual void reload_text();
  172. virtual String get_name();
  173. virtual Ref<Texture> get_icon();
  174. virtual bool is_unsaved();
  175. virtual Variant get_edit_state();
  176. virtual void set_edit_state(const Variant& p_state);
  177. virtual void goto_line(int p_line,bool p_with_error=false);
  178. virtual void trim_trailing_whitespace();
  179. virtual void ensure_focus();
  180. virtual void tag_saved_version();
  181. virtual void reload(bool p_soft);
  182. virtual void get_breakpoints(List<int> *p_breakpoints);
  183. virtual bool goto_method(const String& p_method);
  184. virtual void add_callback(const String& p_function,PoolStringArray p_args);
  185. virtual void update_settings();
  186. virtual void set_debugger_active(bool p_active);
  187. virtual void set_tooltip_request_func(String p_method,Object* p_obj);
  188. virtual Control *get_edit_menu();
  189. virtual bool can_lose_focus_on_node_selection() { return false; }
  190. static void register_editor();
  191. static void free_clipboard();
  192. VisualScriptEditor();
  193. ~VisualScriptEditor();
  194. };
  195. #endif
  196. #endif // VISUALSCRIPT_EDITOR_H