Tool Mode for Visualscript

Add the ability to VisualScript to function in Tool mode aka the Editor itself similar to GDScript or Mono
This commit is contained in:
Swarnim Arun 2019-07-27 01:30:23 +05:30
parent e4ec59b6ae
commit 097f47f064
No known key found for this signature in database
GPG key ID: A110DB7473A8E5A9
4 changed files with 27 additions and 2 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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");

View file

@ -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();