visual_script_editor.h 8.0 KB

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