Make OpenSimplex and VisualScript modules not depend on the editor
This commit is contained in:
4612
modules/visual_script/editor/visual_script_editor.cpp
Normal file
4612
modules/visual_script/editor/visual_script_editor.cpp
Normal file
File diff suppressed because it is too large
Load Diff
370
modules/visual_script/editor/visual_script_editor.h
Normal file
370
modules/visual_script/editor/visual_script_editor.h
Normal file
@@ -0,0 +1,370 @@
|
||||
/*************************************************************************/
|
||||
/* visual_script_editor.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef VISUALSCRIPT_EDITOR_H
|
||||
#define VISUALSCRIPT_EDITOR_H
|
||||
|
||||
#include "../visual_script.h"
|
||||
#include "editor/create_dialog.h"
|
||||
#include "editor/plugins/script_editor_plugin.h"
|
||||
#include "editor/property_editor.h"
|
||||
#include "scene/gui/graph_edit.h"
|
||||
#include "visual_script_property_selector.h"
|
||||
|
||||
class VisualScriptEditorSignalEdit;
|
||||
class VisualScriptEditorVariableEdit;
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
||||
// TODO: Maybe this class should be refactored.
|
||||
// See https://github.com/godotengine/godot/issues/51913
|
||||
class VisualScriptEditor : public ScriptEditorBase {
|
||||
GDCLASS(VisualScriptEditor, ScriptEditorBase);
|
||||
|
||||
enum {
|
||||
TYPE_SEQUENCE = 1000,
|
||||
INDEX_BASE_SEQUENCE = 1024
|
||||
};
|
||||
|
||||
enum {
|
||||
EDIT_DELETE_NODES,
|
||||
EDIT_TOGGLE_BREAKPOINT,
|
||||
EDIT_FIND_NODE_TYPE,
|
||||
EDIT_COPY_NODES,
|
||||
EDIT_CUT_NODES,
|
||||
EDIT_PASTE_NODES,
|
||||
EDIT_CREATE_FUNCTION,
|
||||
REFRESH_GRAPH,
|
||||
};
|
||||
|
||||
enum PortAction {
|
||||
CREATE_CALL_SET_GET,
|
||||
CREATE_ACTION,
|
||||
};
|
||||
|
||||
enum MemberAction {
|
||||
MEMBER_EDIT,
|
||||
MEMBER_REMOVE
|
||||
};
|
||||
|
||||
enum MemberType {
|
||||
MEMBER_FUNCTION,
|
||||
MEMBER_VARIABLE,
|
||||
MEMBER_SIGNAL
|
||||
};
|
||||
|
||||
VBoxContainer *members_section;
|
||||
MenuButton *edit_menu;
|
||||
|
||||
Ref<VisualScript> script;
|
||||
|
||||
Button *base_type_select;
|
||||
|
||||
LineEdit *func_name_box;
|
||||
ScrollContainer *func_input_scroll;
|
||||
VBoxContainer *func_input_vbox;
|
||||
ConfirmationDialog *function_create_dialog;
|
||||
|
||||
GraphEdit *graph;
|
||||
HBoxContainer *status_bar;
|
||||
Button *toggle_scripts_button;
|
||||
|
||||
VisualScriptEditorSignalEdit *signal_editor;
|
||||
|
||||
AcceptDialog *edit_signal_dialog;
|
||||
EditorInspector *edit_signal_edit;
|
||||
|
||||
VisualScriptPropertySelector *method_select;
|
||||
VisualScriptPropertySelector *new_connect_node_select;
|
||||
VisualScriptPropertySelector *new_virtual_method_select;
|
||||
|
||||
VisualScriptEditorVariableEdit *variable_editor;
|
||||
|
||||
AcceptDialog *edit_variable_dialog;
|
||||
EditorInspector *edit_variable_edit;
|
||||
|
||||
CustomPropertyEditor *default_value_edit;
|
||||
|
||||
UndoRedo *undo_redo;
|
||||
|
||||
Tree *members;
|
||||
AcceptDialog *function_name_edit;
|
||||
LineEdit *function_name_box;
|
||||
|
||||
Label *hint_text;
|
||||
Timer *hint_text_timer;
|
||||
|
||||
Label *select_func_text;
|
||||
|
||||
bool updating_graph;
|
||||
|
||||
void _show_hint(const String &p_hint);
|
||||
void _hide_timer();
|
||||
|
||||
CreateDialog *select_base_type;
|
||||
|
||||
struct VirtualInMenu {
|
||||
String name;
|
||||
Variant::Type ret;
|
||||
bool ret_variant;
|
||||
Vector<Pair<Variant::Type, String>> args;
|
||||
};
|
||||
|
||||
Map<StringName, Color> node_colors;
|
||||
HashMap<StringName, Ref<StyleBox>> node_styles;
|
||||
|
||||
void _update_graph_connections();
|
||||
void _update_graph(int p_only_id = -1);
|
||||
|
||||
bool updating_members;
|
||||
|
||||
void _update_members();
|
||||
String _sanitized_variant_text(const StringName &property_name);
|
||||
|
||||
StringName selected;
|
||||
|
||||
String _validate_name(const String &p_name) const;
|
||||
|
||||
struct Clipboard {
|
||||
Map<int, Ref<VisualScriptNode>> nodes;
|
||||
Map<int, Vector2> nodes_positions;
|
||||
|
||||
Set<VisualScript::SequenceConnection> sequence_connections;
|
||||
Set<VisualScript::DataConnection> data_connections;
|
||||
};
|
||||
|
||||
static Clipboard *clipboard;
|
||||
|
||||
PopupMenu *member_popup;
|
||||
MemberType member_type;
|
||||
String member_name;
|
||||
|
||||
PortAction port_action;
|
||||
int port_action_node;
|
||||
int port_action_output;
|
||||
Vector2 port_action_pos;
|
||||
int port_action_new_node;
|
||||
|
||||
bool saved_pos_dirty;
|
||||
Vector2 saved_position;
|
||||
|
||||
Vector2 mouse_up_position;
|
||||
|
||||
void _port_action_menu(int p_option);
|
||||
|
||||
void connect_data(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode, int new_id);
|
||||
|
||||
NodePath drop_path;
|
||||
Node *drop_node = nullptr;
|
||||
Vector2 drop_position;
|
||||
void _selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting = true);
|
||||
void connect_seq(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode_new, int new_id);
|
||||
|
||||
void _cancel_connect_node();
|
||||
int _create_new_node_from_name(const String &p_text, const Vector2 &p_point);
|
||||
void _selected_new_virtual_method(const String &p_text, const String &p_category, const bool p_connecting);
|
||||
|
||||
int error_line;
|
||||
|
||||
void _node_selected(Node *p_node);
|
||||
void _center_on_node(int p_id);
|
||||
|
||||
void _node_filter_changed(const String &p_text);
|
||||
void _change_base_type_callback();
|
||||
void _change_base_type();
|
||||
void _toggle_tool_script();
|
||||
void _member_selected();
|
||||
void _member_edited();
|
||||
|
||||
void _begin_node_move();
|
||||
void _end_node_move();
|
||||
void _move_node(int p_id, const Vector2 &p_to);
|
||||
|
||||
void _get_ends(int p_node, const List<VisualScript::SequenceConnection> &p_seqs, const Set<int> &p_selected, Set<int> &r_end_nodes);
|
||||
|
||||
void _node_moved(Vector2 p_from, Vector2 p_to, int p_id);
|
||||
void _remove_node(int p_id);
|
||||
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);
|
||||
|
||||
void _node_ports_changed(int p_id);
|
||||
void _node_create();
|
||||
|
||||
void _update_available_nodes();
|
||||
|
||||
void _member_button(Object *p_item, int p_column, int p_button);
|
||||
|
||||
void _expression_text_changed(const String &p_text, int p_id);
|
||||
void _add_input_port(int p_id);
|
||||
void _add_output_port(int p_id);
|
||||
void _remove_input_port(int p_id, int p_port);
|
||||
void _remove_output_port(int p_id, int p_port);
|
||||
void _change_port_type(int p_select, int p_id, int p_port, bool is_input);
|
||||
void _update_node_size(int p_id);
|
||||
void _port_name_focus_out(const Node *p_name_box, int p_id, int p_port, bool is_input);
|
||||
|
||||
Vector2 _get_pos_in_graph(Vector2 p_point) const;
|
||||
Vector2 _get_available_pos(bool p_centered = true, Vector2 p_pos = Vector2()) const;
|
||||
|
||||
bool node_has_sequence_connections(int p_id);
|
||||
|
||||
void _generic_search(String p_base_type = "", Vector2 pos = Vector2(), bool node_centered = false);
|
||||
|
||||
virtual void input(const Ref<InputEvent> &p_event) override;
|
||||
void _graph_gui_input(const Ref<InputEvent> &p_event);
|
||||
void _members_gui_input(const Ref<InputEvent> &p_event);
|
||||
void _fn_name_box_input(const Ref<InputEvent> &p_event);
|
||||
void _rename_function(const String &p_name, const String &p_new_name);
|
||||
|
||||
void _create_function_dialog();
|
||||
void _create_function();
|
||||
void _add_func_input();
|
||||
void _remove_func_input(Node *p_node);
|
||||
void _deselect_input_names();
|
||||
void _add_node_dialog();
|
||||
void _node_item_selected();
|
||||
void _node_item_unselected();
|
||||
|
||||
void _on_nodes_copy();
|
||||
void _on_nodes_paste();
|
||||
void _on_nodes_delete();
|
||||
void _on_nodes_duplicate();
|
||||
|
||||
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);
|
||||
|
||||
int editing_id;
|
||||
int editing_input;
|
||||
|
||||
bool can_swap;
|
||||
int data_disconnect_node;
|
||||
int data_disconnect_port;
|
||||
|
||||
void _default_value_changed();
|
||||
void _default_value_edited(Node *p_button, int p_id, int p_input_port);
|
||||
|
||||
void _menu_option(int p_what);
|
||||
|
||||
void _graph_ofs_changed(const Vector2 &p_ofs);
|
||||
void _comment_node_resized(const Vector2 &p_new_size, int p_node);
|
||||
|
||||
void _draw_color_over_button(Object *obj, Color p_color);
|
||||
void _button_resource_previewed(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, Variant p_ud);
|
||||
|
||||
VisualScriptNode::TypeGuess _guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &p_visited_nodes);
|
||||
|
||||
void _member_rmb_selected(const Vector2 &p_pos);
|
||||
void _member_option(int p_option);
|
||||
|
||||
void _toggle_scripts_pressed();
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
|
||||
virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override;
|
||||
|
||||
virtual void apply_code() override;
|
||||
virtual RES get_edited_resource() const override;
|
||||
virtual void set_edited_resource(const RES &p_res) override;
|
||||
virtual void enable_editor() override;
|
||||
virtual Vector<String> get_functions() override;
|
||||
virtual void reload_text() override;
|
||||
virtual String get_name() override;
|
||||
virtual Ref<Texture2D> get_theme_icon() override;
|
||||
virtual bool is_unsaved() override;
|
||||
virtual Variant get_edit_state() override;
|
||||
virtual void set_edit_state(const Variant &p_state) override;
|
||||
virtual void goto_line(int p_line, bool p_with_error = false) override;
|
||||
virtual void set_executing_line(int p_line) override;
|
||||
virtual void clear_executing_line() override;
|
||||
virtual void trim_trailing_whitespace() override;
|
||||
virtual void insert_final_newline() override;
|
||||
virtual void convert_indent_to_spaces() override;
|
||||
virtual void convert_indent_to_tabs() override;
|
||||
virtual void ensure_focus() override;
|
||||
virtual void tag_saved_version() override;
|
||||
virtual void reload(bool p_soft) override;
|
||||
virtual Array get_breakpoints() override;
|
||||
virtual void set_breakpoint(int p_line, bool p_enable) override{};
|
||||
virtual void clear_breakpoints() override{};
|
||||
virtual void add_callback(const String &p_function, PackedStringArray p_args) override;
|
||||
virtual void update_settings() override;
|
||||
virtual bool show_members_overview() override;
|
||||
virtual void set_debugger_active(bool p_active) override;
|
||||
virtual void set_tooltip_request_func(String p_method, Object *p_obj) override;
|
||||
virtual Control *get_edit_menu() override;
|
||||
virtual void clear_edit_menu() override;
|
||||
virtual void set_find_replace_bar(FindReplaceBar *p_bar) override { p_bar->hide(); }; // Not needed here.
|
||||
virtual bool can_lose_focus_on_node_selection() override { return false; }
|
||||
virtual void validate() override;
|
||||
|
||||
virtual Control *get_base_editor() const override;
|
||||
|
||||
static void register_editor();
|
||||
|
||||
static void free_clipboard();
|
||||
|
||||
void update_toggle_scripts_button() override;
|
||||
|
||||
VisualScriptEditor();
|
||||
~VisualScriptEditor();
|
||||
};
|
||||
|
||||
// Singleton
|
||||
class VisualScriptCustomNodes : public Object {
|
||||
GDCLASS(VisualScriptCustomNodes, Object);
|
||||
|
||||
friend class VisualScriptLanguage;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
static VisualScriptCustomNodes *singleton;
|
||||
|
||||
static Map<String, REF> custom_nodes;
|
||||
static Ref<VisualScriptNode> create_node_custom(const String &p_name);
|
||||
|
||||
public:
|
||||
static VisualScriptCustomNodes *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);
|
||||
|
||||
VisualScriptCustomNodes();
|
||||
~VisualScriptCustomNodes();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif // VISUALSCRIPT_EDITOR_H
|
||||
733
modules/visual_script/editor/visual_script_property_selector.cpp
Normal file
733
modules/visual_script/editor/visual_script_property_selector.cpp
Normal file
@@ -0,0 +1,733 @@
|
||||
/*************************************************************************/
|
||||
/* visual_script_property_selector.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "visual_script_property_selector.h"
|
||||
|
||||
#include "../visual_script.h"
|
||||
#include "../visual_script_builtin_funcs.h"
|
||||
#include "../visual_script_flow_control.h"
|
||||
#include "../visual_script_func_nodes.h"
|
||||
#include "../visual_script_nodes.h"
|
||||
#include "core/os/keyboard.h"
|
||||
#include "editor/doc_tools.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_scale.h"
|
||||
#include "scene/main/node.h"
|
||||
#include "scene/main/window.h"
|
||||
|
||||
void VisualScriptPropertySelector::_text_changed(const String &p_newtext) {
|
||||
_update_search();
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
|
||||
Ref<InputEventKey> k = p_ie;
|
||||
|
||||
if (k.is_valid()) {
|
||||
switch (k->get_keycode()) {
|
||||
case KEY_UP:
|
||||
case KEY_DOWN:
|
||||
case KEY_PAGEUP:
|
||||
case KEY_PAGEDOWN: {
|
||||
search_options->gui_input(k);
|
||||
search_box->accept_event();
|
||||
|
||||
TreeItem *root = search_options->get_root();
|
||||
if (!root->get_first_child()) {
|
||||
break;
|
||||
}
|
||||
|
||||
TreeItem *current = search_options->get_selected();
|
||||
|
||||
TreeItem *item = search_options->get_next_selected(root);
|
||||
while (item) {
|
||||
item->deselect(0);
|
||||
item = search_options->get_next_selected(item);
|
||||
}
|
||||
|
||||
current->select(0);
|
||||
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::_update_search() {
|
||||
set_title(TTR("Search VisualScript"));
|
||||
|
||||
search_options->clear();
|
||||
help_bit->set_text("");
|
||||
|
||||
TreeItem *root = search_options->create_item();
|
||||
bool found = false;
|
||||
StringName base = base_type;
|
||||
List<StringName> base_list;
|
||||
while (base) {
|
||||
base_list.push_back(base);
|
||||
base = ClassDB::get_parent_class_nocheck(base);
|
||||
}
|
||||
|
||||
for (const StringName &E : base_list) {
|
||||
List<MethodInfo> methods;
|
||||
List<PropertyInfo> props;
|
||||
TreeItem *category = nullptr;
|
||||
Ref<Texture2D> type_icons[Variant::VARIANT_MAX] = {
|
||||
vbc->get_theme_icon(SNAME("Variant"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("bool"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("int"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("float"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("String"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Vector2"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Vector2i"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Rect2"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Rect2i"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Vector3"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Vector3i"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Transform2D"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Plane"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Quaternion"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("AABB"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Basis"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Transform3D"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Color"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("StringName"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("NodePath"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("RID"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("MiniObject"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Callable"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Signal"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Dictionary"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("Array"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("PackedByteArray"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("PackedInt32Array"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("PackedInt64Array"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("PackedFloat32Array"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("PackedFloat64Array"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("PackedStringArray"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("PackedVector2Array"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("PackedVector3Array"), SNAME("EditorIcons")),
|
||||
vbc->get_theme_icon(SNAME("PackedColorArray"), SNAME("EditorIcons"))
|
||||
};
|
||||
{
|
||||
String b = String(E);
|
||||
category = search_options->create_item(root);
|
||||
if (category) {
|
||||
category->set_text(0, b.replace_first("*", ""));
|
||||
category->set_selectable(0, false);
|
||||
Ref<Texture2D> icon;
|
||||
String rep = b.replace("*", "");
|
||||
icon = EditorNode::get_singleton()->get_class_icon(rep);
|
||||
category->set_icon(0, icon);
|
||||
}
|
||||
}
|
||||
if (properties || seq_connect) {
|
||||
if (instance) {
|
||||
instance->get_property_list(&props, true);
|
||||
} else {
|
||||
Object *obj = ObjectDB::get_instance(script);
|
||||
if (Object::cast_to<Script>(obj)) {
|
||||
Object::cast_to<Script>(obj)->get_script_property_list(&props);
|
||||
} else {
|
||||
ClassDB::get_property_list(E, &props, true);
|
||||
}
|
||||
}
|
||||
for (const PropertyInfo &F : props) {
|
||||
if (!(F.usage & PROPERTY_USAGE_EDITOR) && !(F.usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type_filter.size() && type_filter.find(F.type) == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// capitalize() also converts underscore to space, we'll match again both possible styles
|
||||
String get_text_raw = String(vformat(TTR("Get %s"), F.name));
|
||||
String get_text = get_text_raw.capitalize();
|
||||
String set_text_raw = String(vformat(TTR("Set %s"), F.name));
|
||||
String set_text = set_text_raw.capitalize();
|
||||
String input = search_box->get_text().capitalize();
|
||||
|
||||
if (input == String() || get_text_raw.findn(input) != -1 || get_text.findn(input) != -1) {
|
||||
TreeItem *item = search_options->create_item(category ? category : root);
|
||||
item->set_text(0, get_text);
|
||||
item->set_metadata(0, F.name);
|
||||
item->set_icon(0, type_icons[F.type]);
|
||||
item->set_metadata(1, "get");
|
||||
item->set_collapsed(true);
|
||||
item->set_selectable(0, true);
|
||||
item->set_selectable(1, false);
|
||||
item->set_selectable(2, false);
|
||||
item->set_metadata(2, connecting);
|
||||
}
|
||||
|
||||
if (input == String() || set_text_raw.findn(input) != -1 || set_text.findn(input) != -1) {
|
||||
TreeItem *item = search_options->create_item(category ? category : root);
|
||||
item->set_text(0, set_text);
|
||||
item->set_metadata(0, F.name);
|
||||
item->set_icon(0, type_icons[F.type]);
|
||||
item->set_metadata(1, "set");
|
||||
item->set_selectable(0, true);
|
||||
item->set_selectable(1, false);
|
||||
item->set_selectable(2, false);
|
||||
item->set_metadata(2, connecting);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
if (type != Variant::NIL) {
|
||||
Variant v;
|
||||
Callable::CallError ce;
|
||||
Variant::construct(type, v, nullptr, 0, ce);
|
||||
v.get_method_list(&methods);
|
||||
} else {
|
||||
Object *obj = ObjectDB::get_instance(script);
|
||||
if (Object::cast_to<Script>(obj)) {
|
||||
Object::cast_to<Script>(obj)->get_script_method_list(&methods);
|
||||
}
|
||||
|
||||
ClassDB::get_method_list(E, &methods, true, true);
|
||||
}
|
||||
}
|
||||
for (List<MethodInfo>::Element *M = methods.front(); M; M = M->next()) {
|
||||
String name = M->get().name.get_slice(":", 0);
|
||||
if (name.begins_with("_") && !(M->get().flags & METHOD_FLAG_VIRTUAL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (virtuals_only && !(M->get().flags & METHOD_FLAG_VIRTUAL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!virtuals_only && (M->get().flags & METHOD_FLAG_VIRTUAL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MethodInfo mi = M->get();
|
||||
String desc_arguments;
|
||||
if (mi.arguments.size() > 0) {
|
||||
desc_arguments = "(";
|
||||
for (int i = 0; i < mi.arguments.size(); i++) {
|
||||
if (i > 0) {
|
||||
desc_arguments += ", ";
|
||||
}
|
||||
if (mi.arguments[i].type == Variant::NIL) {
|
||||
desc_arguments += "var";
|
||||
} else if (mi.arguments[i].name.find(":") != -1) {
|
||||
desc_arguments += mi.arguments[i].name.get_slice(":", 1);
|
||||
mi.arguments[i].name = mi.arguments[i].name.get_slice(":", 0);
|
||||
} else {
|
||||
desc_arguments += Variant::get_type_name(mi.arguments[i].type);
|
||||
}
|
||||
}
|
||||
desc_arguments += ")";
|
||||
}
|
||||
String desc_raw = mi.name + desc_arguments;
|
||||
String desc = desc_raw.capitalize().replace("( ", "(");
|
||||
|
||||
if (search_box->get_text() != String() &&
|
||||
name.findn(search_box->get_text()) == -1 &&
|
||||
desc.findn(search_box->get_text()) == -1 &&
|
||||
desc_raw.findn(search_box->get_text()) == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TreeItem *item = search_options->create_item(category ? category : root);
|
||||
item->set_text(0, desc);
|
||||
item->set_icon(0, vbc->get_theme_icon(SNAME("MemberMethod"), SNAME("EditorIcons")));
|
||||
item->set_metadata(0, name);
|
||||
item->set_selectable(0, true);
|
||||
|
||||
item->set_metadata(1, "method");
|
||||
item->set_collapsed(true);
|
||||
item->set_selectable(1, false);
|
||||
|
||||
item->set_selectable(2, false);
|
||||
item->set_metadata(2, connecting);
|
||||
}
|
||||
|
||||
if (category && category->get_first_child() == nullptr) {
|
||||
memdelete(category); //old category was unused
|
||||
}
|
||||
}
|
||||
if (properties) {
|
||||
if (!seq_connect && !visual_script_generic) {
|
||||
get_visual_node_names("flow_control/type_cast", Set<String>(), found, root, search_box);
|
||||
get_visual_node_names("functions/built_in/print", Set<String>(), found, root, search_box);
|
||||
get_visual_node_names("functions/by_type/" + Variant::get_type_name(type), Set<String>(), found, root, search_box);
|
||||
get_visual_node_names("functions/deconstruct/" + Variant::get_type_name(type), Set<String>(), found, root, search_box);
|
||||
get_visual_node_names("operators/compare/", Set<String>(), found, root, search_box);
|
||||
if (type == Variant::INT) {
|
||||
get_visual_node_names("operators/bitwise/", Set<String>(), found, root, search_box);
|
||||
}
|
||||
if (type == Variant::BOOL) {
|
||||
get_visual_node_names("operators/logic/", Set<String>(), found, root, search_box);
|
||||
}
|
||||
if (type == Variant::BOOL || type == Variant::INT || type == Variant::FLOAT || type == Variant::VECTOR2 || type == Variant::VECTOR3) {
|
||||
get_visual_node_names("operators/math/", Set<String>(), found, root, search_box);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (seq_connect && !visual_script_generic) {
|
||||
String text = search_box->get_text();
|
||||
create_visualscript_item(String("VisualScriptCondition"), root, text, String("Condition"));
|
||||
create_visualscript_item(String("VisualScriptSwitch"), root, text, String("Switch"));
|
||||
create_visualscript_item(String("VisualScriptSequence"), root, text, String("Sequence"));
|
||||
create_visualscript_item(String("VisualScriptIterator"), root, text, String("Iterator"));
|
||||
create_visualscript_item(String("VisualScriptWhile"), root, text, String("While"));
|
||||
create_visualscript_item(String("VisualScriptReturn"), root, text, String("Return"));
|
||||
get_visual_node_names("flow_control/type_cast", Set<String>(), found, root, search_box);
|
||||
get_visual_node_names("functions/built_in/print", Set<String>(), found, root, search_box);
|
||||
}
|
||||
|
||||
if ((properties || seq_connect) && visual_script_generic) {
|
||||
get_visual_node_names("", Set<String>(), found, root, search_box);
|
||||
}
|
||||
|
||||
TreeItem *selected_item = search_options->search_item_text(search_box->get_text());
|
||||
if (!found && selected_item != nullptr) {
|
||||
selected_item->select(0);
|
||||
found = true;
|
||||
}
|
||||
|
||||
get_ok_button()->set_disabled(root->get_first_child() == nullptr);
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::create_visualscript_item(const String &name, TreeItem *const root, const String &search_input, const String &text) {
|
||||
if (search_input == String() || text.findn(search_input) != -1) {
|
||||
TreeItem *item = search_options->create_item(root);
|
||||
item->set_text(0, text);
|
||||
item->set_icon(0, vbc->get_theme_icon(SNAME("VisualScript"), SNAME("EditorIcons")));
|
||||
item->set_metadata(0, name);
|
||||
item->set_metadata(1, "action");
|
||||
item->set_selectable(0, true);
|
||||
item->set_collapsed(true);
|
||||
item->set_selectable(1, false);
|
||||
item->set_selectable(2, false);
|
||||
item->set_metadata(2, connecting);
|
||||
}
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::get_visual_node_names(const String &root_filter, const Set<String> &p_modifiers, bool &found, TreeItem *const root, LineEdit *const search_box) {
|
||||
Map<String, TreeItem *> path_cache;
|
||||
|
||||
List<String> fnodes;
|
||||
VisualScriptLanguage::singleton->get_registered_node_names(&fnodes);
|
||||
|
||||
for (const String &E : fnodes) {
|
||||
if (!E.begins_with(root_filter)) {
|
||||
continue;
|
||||
}
|
||||
Vector<String> path = E.split("/");
|
||||
|
||||
// check if the name has the filter
|
||||
bool in_filter = false;
|
||||
Vector<String> tx_filters = search_box->get_text().split(" ");
|
||||
for (int i = 0; i < tx_filters.size(); i++) {
|
||||
if (tx_filters[i] == "") {
|
||||
in_filter = true;
|
||||
} else {
|
||||
in_filter = false;
|
||||
}
|
||||
if (E.findn(tx_filters[i]) != -1) {
|
||||
in_filter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!in_filter) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bool in_modifier = p_modifiers.is_empty();
|
||||
for (Set<String>::Element *F = p_modifiers.front(); F && in_modifier; F = F->next()) {
|
||||
if (E.findn(F->get()) != -1) {
|
||||
in_modifier = true;
|
||||
}
|
||||
}
|
||||
if (!in_modifier) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TreeItem *item = search_options->create_item(root);
|
||||
Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(E);
|
||||
Ref<VisualScriptOperator> vnode_operator = vnode;
|
||||
String type_name;
|
||||
if (vnode_operator.is_valid()) {
|
||||
String type;
|
||||
if (path.size() >= 2) {
|
||||
type = path[1];
|
||||
}
|
||||
type_name = type.capitalize() + " ";
|
||||
}
|
||||
Ref<VisualScriptFunctionCall> vnode_function_call = vnode;
|
||||
if (vnode_function_call.is_valid()) {
|
||||
String basic_type = Variant::get_type_name(vnode_function_call->get_basic_type());
|
||||
type_name = basic_type.capitalize() + " ";
|
||||
}
|
||||
Ref<VisualScriptConstructor> vnode_constructor = vnode;
|
||||
if (vnode_constructor.is_valid()) {
|
||||
type_name = "Construct ";
|
||||
}
|
||||
Ref<VisualScriptDeconstruct> vnode_deconstruct = vnode;
|
||||
if (vnode_deconstruct.is_valid()) {
|
||||
type_name = "Deconstruct ";
|
||||
}
|
||||
Vector<String> desc = path[path.size() - 1].replace("(", " ").replace(")", " ").replace(",", " ").split(" ");
|
||||
for (int i = 0; i < desc.size(); i++) {
|
||||
desc.write[i] = desc[i].capitalize();
|
||||
if (desc[i].ends_with(",")) {
|
||||
desc.write[i] = desc[i].replace(",", ", ");
|
||||
}
|
||||
}
|
||||
|
||||
item->set_text(0, type_name + String("").join(desc));
|
||||
item->set_icon(0, vbc->get_theme_icon(SNAME("VisualScript"), SNAME("EditorIcons")));
|
||||
item->set_selectable(0, true);
|
||||
item->set_metadata(0, E);
|
||||
item->set_selectable(0, true);
|
||||
item->set_metadata(1, "visualscript");
|
||||
item->set_selectable(1, false);
|
||||
item->set_selectable(2, false);
|
||||
item->set_metadata(2, connecting);
|
||||
}
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::_confirmed() {
|
||||
TreeItem *ti = search_options->get_selected();
|
||||
if (!ti) {
|
||||
return;
|
||||
}
|
||||
emit_signal(SNAME("selected"), ti->get_metadata(0), ti->get_metadata(1), ti->get_metadata(2));
|
||||
set_visible(false);
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::_item_selected() {
|
||||
help_bit->set_text("");
|
||||
|
||||
TreeItem *item = search_options->get_selected();
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
String name = item->get_metadata(0);
|
||||
|
||||
String class_type;
|
||||
if (type != Variant::NIL) {
|
||||
class_type = Variant::get_type_name(type);
|
||||
|
||||
} else {
|
||||
class_type = base_type;
|
||||
}
|
||||
|
||||
DocTools *dd = EditorHelp::get_doc_data();
|
||||
String text;
|
||||
|
||||
String at_class = class_type;
|
||||
|
||||
while (at_class != String()) {
|
||||
Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(at_class);
|
||||
if (E) {
|
||||
for (int i = 0; i < E->get().properties.size(); i++) {
|
||||
if (E->get().properties[i].name == name) {
|
||||
text = DTR(E->get().properties[i].description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
at_class = ClassDB::get_parent_class_nocheck(at_class);
|
||||
}
|
||||
at_class = class_type;
|
||||
|
||||
while (at_class != String()) {
|
||||
Map<String, DocData::ClassDoc>::Element *C = dd->class_list.find(at_class);
|
||||
if (C) {
|
||||
for (int i = 0; i < C->get().methods.size(); i++) {
|
||||
if (C->get().methods[i].name == name) {
|
||||
text = DTR(C->get().methods[i].description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
at_class = ClassDB::get_parent_class_nocheck(at_class);
|
||||
}
|
||||
Vector<String> functions = name.rsplit("/", false);
|
||||
at_class = functions.size() > 3 ? functions[functions.size() - 2] : class_type;
|
||||
Map<String, DocData::ClassDoc>::Element *T = dd->class_list.find(at_class);
|
||||
if (T) {
|
||||
for (int i = 0; i < T->get().methods.size(); i++) {
|
||||
if (T->get().methods[i].name == functions[functions.size() - 1]) {
|
||||
text = DTR(T->get().methods[i].description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> *names = memnew(List<String>);
|
||||
VisualScriptLanguage::singleton->get_registered_node_names(names);
|
||||
if (names->find(name) != nullptr) {
|
||||
Ref<VisualScriptOperator> operator_node = VisualScriptLanguage::singleton->create_node_from_name(name);
|
||||
if (operator_node.is_valid()) {
|
||||
Map<String, DocData::ClassDoc>::Element *F = dd->class_list.find(operator_node->get_class_name());
|
||||
if (F) {
|
||||
text = Variant::get_operator_name(operator_node->get_operator());
|
||||
}
|
||||
}
|
||||
Ref<VisualScriptTypeCast> typecast_node = VisualScriptLanguage::singleton->create_node_from_name(name);
|
||||
if (typecast_node.is_valid()) {
|
||||
Map<String, DocData::ClassDoc>::Element *F = dd->class_list.find(typecast_node->get_class_name());
|
||||
if (F) {
|
||||
text = DTR(F->get().description);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<VisualScriptBuiltinFunc> builtin_node = VisualScriptLanguage::singleton->create_node_from_name(name);
|
||||
if (builtin_node.is_valid()) {
|
||||
Map<String, DocData::ClassDoc>::Element *F = dd->class_list.find(builtin_node->get_class_name());
|
||||
if (F) {
|
||||
for (int i = 0; i < F->get().constants.size(); i++) {
|
||||
if (F->get().constants[i].value.to_int() == int(builtin_node->get_func())) {
|
||||
text = DTR(F->get().constants[i].description);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memdelete(names);
|
||||
|
||||
if (text == String()) {
|
||||
return;
|
||||
}
|
||||
|
||||
help_bit->set_text(text);
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::_hide_requested() {
|
||||
_cancel_pressed(); // From AcceptDialog.
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::_notification(int p_what) {
|
||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||
connect("confirmed", callable_mp(this, &VisualScriptPropertySelector::_confirmed));
|
||||
}
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::select_method_from_base_type(const String &p_base, const String &p_current, const bool p_virtuals_only, const bool p_connecting, bool clear_text) {
|
||||
base_type = p_base;
|
||||
selected = p_current;
|
||||
type = Variant::NIL;
|
||||
properties = false;
|
||||
instance = nullptr;
|
||||
virtuals_only = p_virtuals_only;
|
||||
|
||||
show_window(.5f);
|
||||
if (clear_text) {
|
||||
search_box->set_text("");
|
||||
} else {
|
||||
search_box->select_all();
|
||||
}
|
||||
search_box->grab_focus();
|
||||
connecting = p_connecting;
|
||||
|
||||
_update_search();
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::set_type_filter(const Vector<Variant::Type> &p_type_filter) {
|
||||
type_filter = p_type_filter;
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::select_from_base_type(const String &p_base, const String &p_current, bool p_virtuals_only, bool p_seq_connect, const bool p_connecting, bool clear_text) {
|
||||
base_type = p_base;
|
||||
selected = p_current;
|
||||
type = Variant::NIL;
|
||||
properties = true;
|
||||
visual_script_generic = false;
|
||||
instance = nullptr;
|
||||
virtuals_only = p_virtuals_only;
|
||||
|
||||
show_window(.5f);
|
||||
if (clear_text) {
|
||||
search_box->set_text("");
|
||||
} else {
|
||||
search_box->select_all();
|
||||
}
|
||||
search_box->grab_focus();
|
||||
seq_connect = p_seq_connect;
|
||||
connecting = p_connecting;
|
||||
|
||||
_update_search();
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::select_from_script(const Ref<Script> &p_script, const String &p_current, const bool p_connecting, bool clear_text) {
|
||||
ERR_FAIL_COND(p_script.is_null());
|
||||
|
||||
base_type = p_script->get_instance_base_type();
|
||||
selected = p_current;
|
||||
type = Variant::NIL;
|
||||
script = p_script->get_instance_id();
|
||||
properties = true;
|
||||
visual_script_generic = false;
|
||||
instance = nullptr;
|
||||
virtuals_only = false;
|
||||
|
||||
show_window(.5f);
|
||||
if (clear_text) {
|
||||
search_box->set_text("");
|
||||
} else {
|
||||
search_box->select_all();
|
||||
}
|
||||
search_box->grab_focus();
|
||||
seq_connect = false;
|
||||
connecting = p_connecting;
|
||||
|
||||
_update_search();
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::select_from_basic_type(Variant::Type p_type, const String &p_current, const bool p_connecting, bool clear_text) {
|
||||
ERR_FAIL_COND(p_type == Variant::NIL);
|
||||
base_type = "";
|
||||
selected = p_current;
|
||||
type = p_type;
|
||||
properties = true;
|
||||
visual_script_generic = false;
|
||||
instance = nullptr;
|
||||
virtuals_only = false;
|
||||
|
||||
show_window(.5f);
|
||||
if (clear_text) {
|
||||
search_box->set_text("");
|
||||
} else {
|
||||
search_box->select_all();
|
||||
}
|
||||
search_box->grab_focus();
|
||||
seq_connect = false;
|
||||
connecting = p_connecting;
|
||||
|
||||
_update_search();
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::select_from_action(const String &p_type, const String &p_current, const bool p_connecting, bool clear_text) {
|
||||
base_type = p_type;
|
||||
selected = p_current;
|
||||
type = Variant::NIL;
|
||||
properties = false;
|
||||
visual_script_generic = false;
|
||||
instance = nullptr;
|
||||
virtuals_only = false;
|
||||
|
||||
show_window(.5f);
|
||||
if (clear_text) {
|
||||
search_box->set_text("");
|
||||
} else {
|
||||
search_box->select_all();
|
||||
}
|
||||
search_box->grab_focus();
|
||||
seq_connect = true;
|
||||
connecting = p_connecting;
|
||||
|
||||
_update_search();
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::select_from_instance(Object *p_instance, const String &p_current, const bool p_connecting, const String &p_basetype, bool clear_text) {
|
||||
base_type = p_basetype;
|
||||
selected = p_current;
|
||||
type = Variant::NIL;
|
||||
properties = true;
|
||||
visual_script_generic = false;
|
||||
instance = p_instance;
|
||||
virtuals_only = false;
|
||||
|
||||
show_window(.5f);
|
||||
if (clear_text) {
|
||||
search_box->set_text("");
|
||||
} else {
|
||||
search_box->select_all();
|
||||
}
|
||||
search_box->grab_focus();
|
||||
seq_connect = false;
|
||||
connecting = p_connecting;
|
||||
|
||||
_update_search();
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::select_from_visual_script(const String &p_base, const bool p_connecting, bool clear_text) {
|
||||
base_type = p_base;
|
||||
selected = "";
|
||||
type = Variant::NIL;
|
||||
properties = true;
|
||||
visual_script_generic = true;
|
||||
instance = nullptr;
|
||||
virtuals_only = false;
|
||||
show_window(.5f);
|
||||
if (clear_text) {
|
||||
search_box->set_text("");
|
||||
} else {
|
||||
search_box->select_all();
|
||||
}
|
||||
search_box->grab_focus();
|
||||
connecting = p_connecting;
|
||||
|
||||
_update_search();
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::show_window(float p_screen_ratio) {
|
||||
popup_centered_ratio(p_screen_ratio);
|
||||
}
|
||||
|
||||
void VisualScriptPropertySelector::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::STRING, "category"), PropertyInfo(Variant::BOOL, "connecting")));
|
||||
}
|
||||
|
||||
VisualScriptPropertySelector::VisualScriptPropertySelector() {
|
||||
vbc = memnew(VBoxContainer);
|
||||
add_child(vbc);
|
||||
//set_child_rect(vbc);
|
||||
search_box = memnew(LineEdit);
|
||||
vbc->add_margin_child(TTR("Search:"), search_box);
|
||||
search_box->connect("text_changed", callable_mp(this, &VisualScriptPropertySelector::_text_changed));
|
||||
search_box->connect("gui_input", callable_mp(this, &VisualScriptPropertySelector::_sbox_input));
|
||||
search_options = memnew(Tree);
|
||||
vbc->add_margin_child(TTR("Matches:"), search_options, true);
|
||||
get_ok_button()->set_text(TTR("Open"));
|
||||
get_ok_button()->set_disabled(true);
|
||||
register_text_enter(search_box);
|
||||
set_hide_on_ok(false);
|
||||
search_options->connect("item_activated", callable_mp(this, &VisualScriptPropertySelector::_confirmed));
|
||||
search_options->connect("cell_selected", callable_mp(this, &VisualScriptPropertySelector::_item_selected));
|
||||
search_options->set_hide_root(true);
|
||||
search_options->set_hide_folding(true);
|
||||
virtuals_only = false;
|
||||
seq_connect = false;
|
||||
help_bit = memnew(EditorHelpBit);
|
||||
vbc->add_margin_child(TTR("Description:"), help_bit);
|
||||
help_bit->connect("request_hide", callable_mp(this, &VisualScriptPropertySelector::_hide_requested));
|
||||
search_options->set_columns(3);
|
||||
search_options->set_column_expand(1, false);
|
||||
search_options->set_column_expand(2, false);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*************************************************************************/
|
||||
/* visual_script_property_selector.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef VISUALSCRIPT_PROPERTYSELECTOR_H
|
||||
#define VISUALSCRIPT_PROPERTYSELECTOR_H
|
||||
|
||||
#include "editor/editor_help.h"
|
||||
#include "editor/property_editor.h"
|
||||
#include "scene/gui/rich_text_label.h"
|
||||
|
||||
class VisualScriptPropertySelector : public ConfirmationDialog {
|
||||
GDCLASS(VisualScriptPropertySelector, ConfirmationDialog);
|
||||
|
||||
LineEdit *search_box;
|
||||
Tree *search_options;
|
||||
|
||||
void _text_changed(const String &p_newtext);
|
||||
void _sbox_input(const Ref<InputEvent> &p_ie);
|
||||
void _update_search();
|
||||
|
||||
void create_visualscript_item(const String &name, TreeItem *const root, const String &search_input, const String &text);
|
||||
void get_visual_node_names(const String &root_filter, const Set<String> &p_modifiers, bool &found, TreeItem *const root, LineEdit *const search_box);
|
||||
|
||||
void _confirmed();
|
||||
void _item_selected();
|
||||
void _hide_requested();
|
||||
|
||||
EditorHelpBit *help_bit;
|
||||
|
||||
bool properties;
|
||||
bool visual_script_generic;
|
||||
bool connecting;
|
||||
String selected;
|
||||
Variant::Type type;
|
||||
String base_type;
|
||||
ObjectID script;
|
||||
Object *instance;
|
||||
bool virtuals_only;
|
||||
bool seq_connect;
|
||||
VBoxContainer *vbc;
|
||||
|
||||
Vector<Variant::Type> type_filter;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void select_method_from_base_type(const String &p_base, const String &p_current = "", const bool p_virtuals_only = false, const bool p_connecting = true, bool clear_text = true);
|
||||
void select_from_base_type(const String &p_base, const String &p_current = "", bool p_virtuals_only = false, bool p_seq_connect = false, const bool p_connecting = true, bool clear_text = true);
|
||||
void select_from_script(const Ref<Script> &p_script, const String &p_current = "", const bool p_connecting = true, bool clear_text = true);
|
||||
void select_from_basic_type(Variant::Type p_type, const String &p_current = "", const bool p_connecting = true, bool clear_text = true);
|
||||
void select_from_action(const String &p_type, const String &p_current = "", const bool p_connecting = true, bool clear_text = true);
|
||||
void select_from_instance(Object *p_instance, const String &p_current = "", const bool p_connecting = true, const String &p_basetype = "", bool clear_text = true);
|
||||
void select_from_visual_script(const String &p_base, const bool p_connecting = true, bool clear_text = true);
|
||||
|
||||
void show_window(float p_screen_ratio);
|
||||
|
||||
void set_type_filter(const Vector<Variant::Type> &p_type_filter);
|
||||
|
||||
VisualScriptPropertySelector();
|
||||
};
|
||||
|
||||
#endif // VISUALSCRIPT_PROPERTYSELECTOR_H
|
||||
Reference in New Issue
Block a user