2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* visual_script_editor.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
2018-01-01 14:40:08 +01:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2017-03-05 15:47:28 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2017-03-05 15:47:28 +01:00
|
|
|
#ifndef VISUALSCRIPT_EDITOR_H
|
|
|
|
#define VISUALSCRIPT_EDITOR_H
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "editor/create_dialog.h"
|
2017-03-05 14:21:25 +01:00
|
|
|
#include "editor/plugins/script_editor_plugin.h"
|
|
|
|
#include "editor/property_editor.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/gui/graph_edit.h"
|
|
|
|
#include "visual_script.h"
|
2018-05-13 05:34:35 +02:00
|
|
|
#include "visual_script_property_selector.h"
|
2016-08-03 00:11:05 +02:00
|
|
|
class VisualScriptEditorSignalEdit;
|
|
|
|
class VisualScriptEditorVariableEdit;
|
|
|
|
|
2016-08-15 09:54:02 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
class VisualScriptEditor : public ScriptEditorBase {
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(VisualScriptEditor, ScriptEditorBase)
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
enum {
|
2017-03-05 16:44:50 +01:00
|
|
|
TYPE_SEQUENCE = 1000,
|
|
|
|
INDEX_BASE_SEQUENCE = 1024
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-08-07 00:00:54 +02:00
|
|
|
enum {
|
|
|
|
EDIT_DELETE_NODES,
|
2016-08-08 06:41:57 +02:00
|
|
|
EDIT_TOGGLE_BREAKPOINT,
|
|
|
|
EDIT_FIND_NODE_TYPE,
|
2016-08-25 22:45:20 +02:00
|
|
|
EDIT_COPY_NODES,
|
|
|
|
EDIT_CUT_NODES,
|
|
|
|
EDIT_PASTE_NODES,
|
2016-08-07 00:00:54 +02:00
|
|
|
};
|
|
|
|
|
2016-09-03 19:58:23 +02:00
|
|
|
enum PortAction {
|
|
|
|
|
2018-05-13 05:34:35 +02:00
|
|
|
CREATE_CALL_SET_GET,
|
|
|
|
CREATE_ACTION,
|
2016-09-03 19:58:23 +02:00
|
|
|
};
|
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
enum MemberAction {
|
|
|
|
MEMBER_EDIT,
|
|
|
|
MEMBER_REMOVE
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
enum MemberType {
|
|
|
|
MEMBER_FUNCTION,
|
|
|
|
MEMBER_VARIABLE,
|
|
|
|
MEMBER_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
VSplitContainer *left_vsplit;
|
2016-08-07 00:00:54 +02:00
|
|
|
MenuButton *edit_menu;
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
Ref<VisualScript> script;
|
|
|
|
|
|
|
|
Button *base_type_select;
|
|
|
|
|
|
|
|
GraphEdit *graph;
|
|
|
|
|
2016-08-04 03:06:39 +02:00
|
|
|
LineEdit *node_filter;
|
2017-01-12 22:27:27 +01:00
|
|
|
TextureRect *node_filter_icon;
|
2016-08-04 03:06:39 +02:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
VisualScriptEditorSignalEdit *signal_editor;
|
|
|
|
|
|
|
|
AcceptDialog *edit_signal_dialog;
|
|
|
|
PropertyEditor *edit_signal_edit;
|
|
|
|
|
2018-05-13 05:34:35 +02:00
|
|
|
VisualScriptPropertySelector *method_select;
|
|
|
|
VisualScriptPropertySelector *new_connect_node_select;
|
|
|
|
VisualScriptPropertySelector *new_virtual_method_select;
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
VisualScriptEditorVariableEdit *variable_editor;
|
|
|
|
|
|
|
|
AcceptDialog *edit_variable_dialog;
|
|
|
|
PropertyEditor *edit_variable_edit;
|
|
|
|
|
2016-08-04 03:06:39 +02:00
|
|
|
CustomPropertyEditor *default_value_edit;
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
UndoRedo *undo_redo;
|
|
|
|
|
|
|
|
Tree *members;
|
|
|
|
Tree *nodes;
|
|
|
|
|
2016-08-03 16:28:20 +02:00
|
|
|
Label *hint_text;
|
|
|
|
Timer *hint_text_timer;
|
|
|
|
|
|
|
|
Label *select_func_text;
|
|
|
|
|
2016-08-07 00:00:54 +02:00
|
|
|
bool updating_graph;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _show_hint(const String &p_hint);
|
2016-08-03 16:28:20 +02:00
|
|
|
void _hide_timer();
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
CreateDialog *select_base_type;
|
|
|
|
|
|
|
|
struct VirtualInMenu {
|
|
|
|
String name;
|
|
|
|
Variant::Type ret;
|
|
|
|
bool ret_variant;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector<Pair<Variant::Type, String> > args;
|
2016-08-03 00:11:05 +02:00
|
|
|
};
|
|
|
|
|
2018-07-02 20:08:35 +02:00
|
|
|
HashMap<StringName, Ref<StyleBox> > node_styles;
|
2016-08-03 00:11:05 +02:00
|
|
|
StringName edited_func;
|
|
|
|
|
|
|
|
void _update_graph_connections();
|
2017-03-05 16:44:50 +01:00
|
|
|
void _update_graph(int p_only_id = -1);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
bool updating_members;
|
|
|
|
|
|
|
|
void _update_members();
|
|
|
|
|
|
|
|
StringName selected;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String _validate_name(const String &p_name) const;
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2016-08-25 22:45:20 +02:00
|
|
|
struct Clipboard {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<int, Ref<VisualScriptNode> > nodes;
|
|
|
|
Map<int, Vector2> nodes_positions;
|
2016-08-25 22:45:20 +02:00
|
|
|
|
|
|
|
Set<VisualScript::SequenceConnection> sequence_connections;
|
|
|
|
Set<VisualScript::DataConnection> data_connections;
|
2016-08-31 22:58:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static Clipboard *clipboard;
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
PopupMenu *member_popup;
|
|
|
|
MemberType member_type;
|
|
|
|
String member_name;
|
2016-09-03 19:58:23 +02:00
|
|
|
|
2018-05-13 05:34:35 +02:00
|
|
|
bool seq_connect = false;
|
|
|
|
|
2016-09-03 19:58:23 +02:00
|
|
|
PortAction port_action;
|
|
|
|
int port_action_node;
|
|
|
|
int port_action_output;
|
|
|
|
Vector2 port_action_pos;
|
|
|
|
int port_action_new_node;
|
|
|
|
void _port_action_menu(int p_option);
|
2018-05-13 05:34:35 +02:00
|
|
|
|
|
|
|
void new_node(Ref<VisualScriptNode> vnode, Vector2 ofs);
|
|
|
|
|
|
|
|
void connect_data(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode, int new_id);
|
|
|
|
|
2018-07-25 20:49:41 +02:00
|
|
|
void _selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting = true);
|
2018-05-13 05:34:35 +02:00
|
|
|
void connect_seq(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode_new, int new_id);
|
|
|
|
|
|
|
|
void _cancel_connect_node();
|
|
|
|
void _create_new_node(const String &p_text, const String &p_category, const Vector2 &p_point);
|
2018-07-25 20:49:41 +02:00
|
|
|
void _selected_new_virtual_method(const String &p_text, const String &p_category, const bool p_connecting = true);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2016-08-07 00:00:54 +02:00
|
|
|
int error_line;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _node_selected(Node *p_node);
|
2016-08-07 00:00:54 +02:00
|
|
|
void _center_on_node(int p_id);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _node_filter_changed(const String &p_text);
|
2016-08-03 00:11:05 +02:00
|
|
|
void _change_base_type_callback();
|
|
|
|
void _change_base_type();
|
|
|
|
void _member_selected();
|
|
|
|
void _member_edited();
|
|
|
|
|
|
|
|
void _begin_node_move();
|
|
|
|
void _end_node_move();
|
2017-03-05 16:44:50 +01:00
|
|
|
void _move_node(String func, int p_id, const Vector2 &p_to);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _node_moved(Vector2 p_from, Vector2 p_to, int p_id);
|
2016-08-03 00:11:05 +02:00
|
|
|
void _remove_node(int p_id);
|
2017-03-05 16:44:50 +01:00
|
|
|
void _graph_connected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot);
|
|
|
|
void _graph_disconnected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot);
|
|
|
|
void _graph_connect_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_pos);
|
2016-08-24 00:29:07 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _node_ports_changed(const String &p_func, int p_id);
|
2016-08-03 00:11:05 +02:00
|
|
|
void _available_node_doubleclicked();
|
|
|
|
|
|
|
|
void _update_available_nodes();
|
|
|
|
|
|
|
|
void _member_button(Object *p_item, int p_column, int p_button);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _expression_text_changed(const String &p_text, int p_id);
|
2016-09-03 19:58:23 +02:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
String revert_on_drag;
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
void _input(const Ref<InputEvent> &p_event);
|
2018-07-25 17:25:03 +02:00
|
|
|
|
|
|
|
void _generic_search();
|
|
|
|
|
2018-01-05 20:45:54 +01:00
|
|
|
void _members_gui_input(const Ref<InputEvent> &p_event);
|
2016-08-03 00:11:05 +02:00
|
|
|
void _on_nodes_delete();
|
|
|
|
void _on_nodes_duplicate();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant get_drag_data_fw(const Point2 &p_point, Control *p_from);
|
|
|
|
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
|
|
|
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2016-08-04 03:06:39 +02:00
|
|
|
int editing_id;
|
|
|
|
int editing_input;
|
|
|
|
|
|
|
|
void _default_value_changed();
|
2017-03-05 16:44:50 +01:00
|
|
|
void _default_value_edited(Node *p_button, int p_id, int p_input_port);
|
2016-08-07 00:00:54 +02:00
|
|
|
|
|
|
|
void _menu_option(int p_what);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _graph_ofs_changed(const Vector2 &p_ofs);
|
|
|
|
void _comment_node_resized(const Vector2 &p_new_size, int p_node);
|
2016-08-24 00:29:07 +02:00
|
|
|
|
2016-08-26 22:34:25 +02:00
|
|
|
int selecting_method_id;
|
2018-05-13 05:34:35 +02:00
|
|
|
void _selected_method(const String &p_method, const String &p_type);
|
2016-08-26 22:34:25 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _draw_color_over_button(Object *obj, Color p_color);
|
|
|
|
void _button_resource_previewed(const String &p_path, const Ref<Texture> &p_preview, Variant p_ud);
|
2016-09-03 19:58:23 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNode::TypeGuess _guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &visited_nodes);
|
2016-08-24 00:29:07 +02:00
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
void _member_rmb_selected(const Vector2 &p_pos);
|
|
|
|
void _member_option(int p_option);
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
protected:
|
2016-08-04 03:06:39 +02:00
|
|
|
void _notification(int p_what);
|
2016-08-03 00:11:05 +02:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2018-04-02 13:41:44 +02:00
|
|
|
virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter);
|
|
|
|
virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter);
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
virtual void apply_code();
|
2018-05-28 17:52:28 +02:00
|
|
|
virtual RES get_edited_resource() const;
|
|
|
|
virtual void set_edited_resource(const RES &p_res);
|
2016-08-03 00:11:05 +02:00
|
|
|
virtual Vector<String> get_functions();
|
|
|
|
virtual void reload_text();
|
|
|
|
virtual String get_name();
|
|
|
|
virtual Ref<Texture> get_icon();
|
|
|
|
virtual bool is_unsaved();
|
|
|
|
virtual Variant get_edit_state();
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_edit_state(const Variant &p_state);
|
|
|
|
virtual void goto_line(int p_line, bool p_with_error = false);
|
2016-08-03 00:11:05 +02:00
|
|
|
virtual void trim_trailing_whitespace();
|
2017-04-17 15:46:00 +02:00
|
|
|
virtual void convert_indent_to_spaces();
|
|
|
|
virtual void convert_indent_to_tabs();
|
2016-08-03 00:11:05 +02:00
|
|
|
virtual void ensure_focus();
|
|
|
|
virtual void tag_saved_version();
|
|
|
|
virtual void reload(bool p_soft);
|
|
|
|
virtual void get_breakpoints(List<int> *p_breakpoints);
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void add_callback(const String &p_function, PoolStringArray p_args);
|
2016-08-03 00:11:05 +02:00
|
|
|
virtual void update_settings();
|
2017-05-28 16:20:38 +02:00
|
|
|
virtual bool show_members_overview();
|
2016-08-07 00:00:54 +02:00
|
|
|
virtual void set_debugger_active(bool p_active);
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_tooltip_request_func(String p_method, Object *p_obj);
|
2016-08-03 00:11:05 +02:00
|
|
|
virtual Control *get_edit_menu();
|
2017-07-01 02:30:17 +02:00
|
|
|
virtual void clear_edit_menu();
|
2016-08-25 22:45:20 +02:00
|
|
|
virtual bool can_lose_focus_on_node_selection() { return false; }
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
static void register_editor();
|
|
|
|
|
2016-08-31 22:58:51 +02:00
|
|
|
static void free_clipboard();
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
VisualScriptEditor();
|
|
|
|
~VisualScriptEditor();
|
|
|
|
};
|
2017-11-15 16:57:24 +01:00
|
|
|
|
|
|
|
// Singleton
|
|
|
|
class _VisualScriptEditor : public Object {
|
|
|
|
GDCLASS(_VisualScriptEditor, Object);
|
|
|
|
|
|
|
|
friend class VisualScriptLanguage;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
static _VisualScriptEditor *singleton;
|
|
|
|
|
|
|
|
static Map<String, RefPtr> custom_nodes;
|
|
|
|
static Ref<VisualScriptNode> create_node_custom(const String &p_name);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static _VisualScriptEditor *get_singleton() { return singleton; }
|
|
|
|
|
|
|
|
void add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script);
|
|
|
|
void remove_custom_node(const String &p_name, const String &p_category);
|
|
|
|
|
|
|
|
_VisualScriptEditor();
|
|
|
|
~_VisualScriptEditor();
|
|
|
|
};
|
2016-08-15 09:54:02 +02:00
|
|
|
#endif
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 15:47:28 +01:00
|
|
|
#endif // VISUALSCRIPT_EDITOR_H
|