summaryrefslogtreecommitdiff
path: root/modules/visual_script
diff options
context:
space:
mode:
authorSwarnim Arun <swarnimarun11@gmail.com>2019-07-27 01:30:23 +0530
committerSwarnim Arun <swarnimarun11@gmail.com>2019-09-21 18:42:27 +0530
commit097f47f064f05a38b1f41e03daf6c5e03a30cbc4 (patch)
tree7b2d429b837985897b201e7eb871a9361bf6b81a /modules/visual_script
parente4ec59b6ae7ba4da8a57d35a4763192fd84fa358 (diff)
Tool Mode for Visualscript
Add the ability to VisualScript to function in Tool mode aka the Editor itself similar to GDScript or Mono
Diffstat (limited to 'modules/visual_script')
-rw-r--r--modules/visual_script/visual_script.cpp15
-rw-r--r--modules/visual_script/visual_script.h3
-rw-r--r--modules/visual_script/visual_script_editor.cpp10
-rw-r--r--modules/visual_script/visual_script_editor.h1
4 files changed, 27 insertions, 2 deletions
diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp
index 4425565afa..4eaad3db31 100644
--- a/modules/visual_script/visual_script.cpp
+++ b/modules/visual_script/visual_script.cpp
@@ -579,6 +579,10 @@ void VisualScript::get_data_connection_list(const StringName &p_func, List<DataC
}
}
+void VisualScript::set_tool_enabled(bool p_enabled) {
+ is_tool_script = p_enabled;
+}
+
void VisualScript::add_variable(const StringName &p_name, const Variant &p_default_value, bool p_export) {
ERR_FAIL_COND(instances.size());
@@ -895,7 +899,7 @@ ScriptInstance *VisualScript::instance_create(Object *p_this) {
#ifdef TOOLS_ENABLED
- if (!ScriptServer::is_scripting_enabled()) {
+ if (!ScriptServer::is_scripting_enabled() && !is_tool_script) {
PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(VisualScriptLanguage::singleton, Ref<Script>((Script *)this), p_this));
placeholders.insert(sins);
@@ -959,7 +963,7 @@ Error VisualScript::reload(bool p_keep_state) {
bool VisualScript::is_tool() const {
- return false;
+ return is_tool_script;
}
bool VisualScript::is_valid() const {
@@ -1165,6 +1169,11 @@ void VisualScript::_set_data(const Dictionary &p_data) {
data_connect(name, data_connections[j + 0], data_connections[j + 1], data_connections[j + 2], data_connections[j + 3]);
}
}
+
+ if (d.has("is_tool_script"))
+ is_tool_script = d["is_tool_script"];
+ else
+ is_tool_script = false;
}
Dictionary VisualScript::_get_data() const {
@@ -1247,6 +1256,8 @@ Dictionary VisualScript::_get_data() const {
d["functions"] = funcs;
+ d["is_tool_script"] = is_tool_script;
+
return d;
}
diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h
index 098c28370d..14927c4363 100644
--- a/modules/visual_script/visual_script.h
+++ b/modules/visual_script/visual_script.h
@@ -247,6 +247,8 @@ private:
Map<Object *, VisualScriptInstance *> instances;
+ bool is_tool_script;
+
#ifdef TOOLS_ENABLED
Set<PlaceHolderScriptInstance *> placeholders;
//void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
@@ -273,6 +275,7 @@ public:
Vector2 get_function_scroll(const StringName &p_name) const;
void get_function_list(List<StringName> *r_functions) const;
int get_function_node_id(const StringName &p_name) const;
+ void set_tool_enabled(bool p_enabled);
void add_node(const StringName &p_func, int p_id, const Ref<VisualScriptNode> &p_node, const Point2 &p_pos = Point2());
void remove_node(const StringName &p_func, int p_id);
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp
index 603c5a7f3c..d9eae03799 100644
--- a/modules/visual_script/visual_script_editor.cpp
+++ b/modules/visual_script/visual_script_editor.cpp
@@ -2226,6 +2226,10 @@ void VisualScriptEditor::_change_base_type() {
select_base_type->popup_create(true, true);
}
+void VisualScriptEditor::_toggle_tool_script() {
+ script->set_tool_enabled(!script->is_tool());
+}
+
void VisualScriptEditor::clear_edit_menu() {
memdelete(edit_menu);
memdelete(left_vsplit);
@@ -3447,6 +3451,7 @@ void VisualScriptEditor::_bind_methods() {
ClassDB::bind_method("_update_members", &VisualScriptEditor::_update_members);
ClassDB::bind_method("_change_base_type", &VisualScriptEditor::_change_base_type);
ClassDB::bind_method("_change_base_type_callback", &VisualScriptEditor::_change_base_type_callback);
+ ClassDB::bind_method("_toggle_tool_script", &VisualScriptEditor::_toggle_tool_script);
ClassDB::bind_method("_node_selected", &VisualScriptEditor::_node_selected);
ClassDB::bind_method("_node_moved", &VisualScriptEditor::_node_moved);
ClassDB::bind_method("_move_node", &VisualScriptEditor::_move_node);
@@ -3532,6 +3537,11 @@ VisualScriptEditor::VisualScriptEditor() {
left_vb->set_v_size_flags(SIZE_EXPAND_FILL);
//left_vb->set_custom_minimum_size(Size2(230, 1) * EDSCALE);
+ CheckButton *tool_script_check = memnew(CheckButton);
+ tool_script_check->set_text(TTR("Make Tool:"));
+ left_vb->add_child(tool_script_check);
+ tool_script_check->connect("pressed", this, "_toggle_tool_script");
+
base_type_select = memnew(Button);
left_vb->add_margin_child(TTR("Base Type:"), base_type_select);
base_type_select->connect("pressed", this, "_change_base_type");
diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h
index 4f302d1d72..5df9b1a004 100644
--- a/modules/visual_script/visual_script_editor.h
+++ b/modules/visual_script/visual_script_editor.h
@@ -186,6 +186,7 @@ class VisualScriptEditor : public ScriptEditorBase {
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();