mirror of
https://github.com/godotengine/godot-visual-script.git
synced 2026-01-05 22:10:23 +03: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:
@@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user