1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

-Added diectly editable expressions on node to VSEditor, closes #6392

-Added ability for LineEdit to expand to fit text
This commit is contained in:
Juan Linietsky
2016-09-06 20:34:24 -03:00
parent 181fdce1e9
commit 405f6af79c
5 changed files with 94 additions and 25 deletions

View File

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