visual_script_editor.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*************************************************************************/
  2. /* visual_script_editor.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. #ifndef VISUALSCRIPT_EDITOR_H
  31. #define VISUALSCRIPT_EDITOR_H
  32. #include "editor/create_dialog.h"
  33. #include "editor/plugins/script_editor_plugin.h"
  34. #include "editor/property_editor.h"
  35. #include "scene/gui/graph_edit.h"
  36. #include "visual_script.h"
  37. #include "visual_script_property_selector.h"
  38. class VisualScriptEditorSignalEdit;
  39. class VisualScriptEditorVariableEdit;
  40. #ifdef TOOLS_ENABLED
  41. class VisualScriptEditor : public ScriptEditorBase {
  42. GDCLASS(VisualScriptEditor, ScriptEditorBase)
  43. enum {
  44. TYPE_SEQUENCE = 1000,
  45. INDEX_BASE_SEQUENCE = 1024
  46. };
  47. enum {
  48. EDIT_DELETE_NODES,
  49. EDIT_TOGGLE_BREAKPOINT,
  50. EDIT_FIND_NODE_TYPE,
  51. EDIT_COPY_NODES,
  52. EDIT_CUT_NODES,
  53. EDIT_PASTE_NODES,
  54. };
  55. enum PortAction {
  56. CREATE_CALL_SET_GET,
  57. CREATE_ACTION,
  58. };
  59. enum MemberAction {
  60. MEMBER_EDIT,
  61. MEMBER_REMOVE
  62. };
  63. enum MemberType {
  64. MEMBER_FUNCTION,
  65. MEMBER_VARIABLE,
  66. MEMBER_SIGNAL
  67. };
  68. VSplitContainer *left_vsplit;
  69. MenuButton *edit_menu;
  70. Ref<VisualScript> script;
  71. Button *base_type_select;
  72. GraphEdit *graph;
  73. LineEdit *node_filter;
  74. TextureRect *node_filter_icon;
  75. VisualScriptEditorSignalEdit *signal_editor;
  76. AcceptDialog *edit_signal_dialog;
  77. EditorInspector *edit_signal_edit;
  78. VisualScriptPropertySelector *method_select;
  79. VisualScriptPropertySelector *new_connect_node_select;
  80. VisualScriptPropertySelector *new_virtual_method_select;
  81. VisualScriptEditorVariableEdit *variable_editor;
  82. AcceptDialog *edit_variable_dialog;
  83. EditorInspector *edit_variable_edit;
  84. CustomPropertyEditor *default_value_edit;
  85. UndoRedo *undo_redo;
  86. Tree *members;
  87. Tree *nodes;
  88. Label *hint_text;
  89. Timer *hint_text_timer;
  90. Label *select_func_text;
  91. bool updating_graph;
  92. void _show_hint(const String &p_hint);
  93. void _hide_timer();
  94. CreateDialog *select_base_type;
  95. struct VirtualInMenu {
  96. String name;
  97. Variant::Type ret;
  98. bool ret_variant;
  99. Vector<Pair<Variant::Type, String> > args;
  100. };
  101. HashMap<StringName, Ref<StyleBox> > node_styles;
  102. StringName edited_func;
  103. void _update_graph_connections();
  104. void _update_graph(int p_only_id = -1);
  105. bool updating_members;
  106. void _update_members();
  107. StringName selected;
  108. String _validate_name(const String &p_name) const;
  109. struct Clipboard {
  110. Map<int, Ref<VisualScriptNode> > nodes;
  111. Map<int, Vector2> nodes_positions;
  112. Set<VisualScript::SequenceConnection> sequence_connections;
  113. Set<VisualScript::DataConnection> data_connections;
  114. };
  115. static Clipboard *clipboard;
  116. PopupMenu *member_popup;
  117. MemberType member_type;
  118. String member_name;
  119. PortAction port_action;
  120. int port_action_node;
  121. int port_action_output;
  122. Vector2 port_action_pos;
  123. int port_action_new_node;
  124. void _port_action_menu(int p_option);
  125. void new_node(Ref<VisualScriptNode> vnode, Vector2 ofs);
  126. void connect_data(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode, int new_id);
  127. void _selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting = true);
  128. void connect_seq(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode_new, int new_id);
  129. void _cancel_connect_node();
  130. void _create_new_node(const String &p_text, const String &p_category, const Vector2 &p_point);
  131. void _selected_new_virtual_method(const String &p_text, const String &p_category, const bool p_connecting);
  132. int error_line;
  133. void _node_selected(Node *p_node);
  134. void _center_on_node(int p_id);
  135. void _node_filter_changed(const String &p_text);
  136. void _change_base_type_callback();
  137. void _change_base_type();
  138. void _member_selected();
  139. void _member_edited();
  140. void _begin_node_move();
  141. void _end_node_move();
  142. void _move_node(String func, int p_id, const Vector2 &p_to);
  143. void _node_moved(Vector2 p_from, Vector2 p_to, int p_id);
  144. void _remove_node(int p_id);
  145. void _graph_connected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot);
  146. void _graph_disconnected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot);
  147. void _graph_connect_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_pos);
  148. void _node_ports_changed(const String &p_func, int p_id);
  149. void _available_node_doubleclicked();
  150. void _update_available_nodes();
  151. void _member_button(Object *p_item, int p_column, int p_button);
  152. void _expression_text_changed(const String &p_text, int p_id);
  153. String revert_on_drag;
  154. void _input(const Ref<InputEvent> &p_event);
  155. void _generic_search();
  156. void _members_gui_input(const Ref<InputEvent> &p_event);
  157. void _on_nodes_delete();
  158. void _on_nodes_duplicate();
  159. Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
  160. bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
  161. void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
  162. int editing_id;
  163. int editing_input;
  164. void _default_value_changed();
  165. void _default_value_edited(Node *p_button, int p_id, int p_input_port);
  166. void _menu_option(int p_what);
  167. void _graph_ofs_changed(const Vector2 &p_ofs);
  168. void _comment_node_resized(const Vector2 &p_new_size, int p_node);
  169. int selecting_method_id;
  170. void _selected_method(const String &p_method, const String &p_type, const bool p_connecting);
  171. void _draw_color_over_button(Object *obj, Color p_color);
  172. void _button_resource_previewed(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, Variant p_ud);
  173. VisualScriptNode::TypeGuess _guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &visited_nodes);
  174. void _member_rmb_selected(const Vector2 &p_pos);
  175. void _member_option(int p_option);
  176. protected:
  177. void _notification(int p_what);
  178. static void _bind_methods();
  179. public:
  180. virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter);
  181. virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter);
  182. virtual void apply_code();
  183. virtual RES get_edited_resource() const;
  184. virtual void set_edited_resource(const RES &p_res);
  185. virtual Vector<String> get_functions();
  186. virtual void reload_text();
  187. virtual String get_name();
  188. virtual Ref<Texture> get_icon();
  189. virtual bool is_unsaved();
  190. virtual Variant get_edit_state();
  191. virtual void set_edit_state(const Variant &p_state);
  192. virtual void goto_line(int p_line, bool p_with_error = false);
  193. virtual void trim_trailing_whitespace();
  194. virtual void convert_indent_to_spaces();
  195. virtual void convert_indent_to_tabs();
  196. virtual void ensure_focus();
  197. virtual void tag_saved_version();
  198. virtual void reload(bool p_soft);
  199. virtual void get_breakpoints(List<int> *p_breakpoints);
  200. virtual void add_callback(const String &p_function, PoolStringArray p_args);
  201. virtual void update_settings();
  202. virtual bool show_members_overview();
  203. virtual void set_debugger_active(bool p_active);
  204. virtual void set_tooltip_request_func(String p_method, Object *p_obj);
  205. virtual Control *get_edit_menu();
  206. virtual void clear_edit_menu();
  207. virtual bool can_lose_focus_on_node_selection() { return false; }
  208. static void register_editor();
  209. static void free_clipboard();
  210. VisualScriptEditor();
  211. ~VisualScriptEditor();
  212. };
  213. // Singleton
  214. class _VisualScriptEditor : public Object {
  215. GDCLASS(_VisualScriptEditor, Object);
  216. friend class VisualScriptLanguage;
  217. protected:
  218. static void _bind_methods();
  219. static _VisualScriptEditor *singleton;
  220. static Map<String, RefPtr> custom_nodes;
  221. static Ref<VisualScriptNode> create_node_custom(const String &p_name);
  222. public:
  223. static _VisualScriptEditor *get_singleton() { return singleton; }
  224. void add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script);
  225. void remove_custom_node(const String &p_name, const String &p_category);
  226. _VisualScriptEditor();
  227. ~_VisualScriptEditor();
  228. };
  229. #endif
  230. #endif // VISUALSCRIPT_EDITOR_H