diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-09-06 20:34:24 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-09-06 20:34:24 -0300 |
commit | 405f6af79c32c575768f53661127cfd6aa4230f4 (patch) | |
tree | b6f145742a46aed20a01a1a76972813038d7362c /modules/visual_script | |
parent | 181fdce1e9c0b31f3a4ff14e25b2e0fec7108da0 (diff) |
-Added diectly editable expressions on node to VSEditor, closes #6392
-Added ability for LineEdit to expand to fit text
Diffstat (limited to 'modules/visual_script')
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 41 | ||||
-rw-r--r-- | modules/visual_script/visual_script_editor.h | 1 | ||||
-rw-r--r-- | modules/visual_script/visual_script_expression.cpp | 2 |
3 files changed, 39 insertions, 5 deletions
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 14708799af..acdcec7ae5 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -503,13 +503,21 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } - Label *text = memnew( Label ); - text->set_text(node->get_text()); - gnode->add_child(text); if (node->cast_to<VisualScriptExpression>()) { - text->add_font_override("font",get_font("source","EditorFonts")); + + LineEdit *line_edit = memnew( LineEdit ); + line_edit->set_text(node->get_text()); + line_edit->set_expand_to_text_length(true); + line_edit->add_font_override("font",get_font("source","EditorFonts")); + gnode->add_child(line_edit); + line_edit->connect("text_changed",this,"_expression_text_changed",varray(E->get())); + } else { + Label *text = memnew( Label ); + text->set_text(node->get_text()); + gnode->add_child(text); } + if (node->cast_to<VisualScriptComment>()) { Ref<VisualScriptComment> vsc=node; gnode->set_comment(true); @@ -1201,6 +1209,30 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } } +void VisualScriptEditor::_expression_text_changed(const String& p_text,int p_id) { + + Ref<VisualScriptExpression> vse = script->get_node(edited_func,p_id); + if (!vse.is_valid()) + return; + + + updating_graph=true; + + undo_redo->create_action(TTR("Change Expression"),UndoRedo::MERGE_ENDS); + undo_redo->add_do_property(vse.ptr(),"expression",p_text); + undo_redo->add_undo_property(vse.ptr(),"expression",vse->get("expression")); + undo_redo->add_do_method(this,"_update_graph",p_id); + undo_redo->add_undo_method(this,"_update_graph",p_id); + undo_redo->commit_action(); + + Node *node = graph->get_node(itos(p_id)); + if (node->cast_to<Control>()) + node->cast_to<Control>()->set_size(Vector2(1,1)); //shrink if text is smaller + + updating_graph=false; + +} + void VisualScriptEditor::_available_node_doubleclicked() { TreeItem *item = nodes->get_selected(); @@ -3224,6 +3256,7 @@ void VisualScriptEditor::_bind_methods() { ObjectTypeDB::bind_method("_button_resource_previewed",&VisualScriptEditor::_button_resource_previewed); ObjectTypeDB::bind_method("_port_action_menu",&VisualScriptEditor::_port_action_menu); ObjectTypeDB::bind_method("_selected_connect_node_method_or_setget",&VisualScriptEditor::_selected_connect_node_method_or_setget); + ObjectTypeDB::bind_method("_expression_text_changed",&VisualScriptEditor::_expression_text_changed); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 5191ed540a..483ae1644c 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -168,6 +168,7 @@ class VisualScriptEditor : public ScriptEditorBase { void _member_button(Object *p_item, int p_column, int p_button); + void _expression_text_changed(const String& p_text,int p_id); String revert_on_drag; diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index f486cf1ab1..cc3b5f2174 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -120,7 +120,7 @@ void VisualScriptExpression::_get_property_list( List<PropertyInfo> *p_list) con argt+=","+Variant::get_type_name(Variant::Type(i)); } - p_list->push_back(PropertyInfo(Variant::STRING,"expression")); + p_list->push_back(PropertyInfo(Variant::STRING,"expression",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR)); p_list->push_back(PropertyInfo(Variant::INT,"out_type",PROPERTY_HINT_ENUM,argt)); p_list->push_back(PropertyInfo(Variant::INT,"input_count",PROPERTY_HINT_RANGE,"0,64,1")); p_list->push_back(PropertyInfo(Variant::BOOL,"sequenced")); |