Merge pull request #45096 from Chaosus/vs_assign_default_value_3.2

[3.2] Auto-assign default value for variable in visual script on type changing
This commit is contained in:
Rémi Verschelde 2021-01-11 10:39:39 +01:00 committed by GitHub
commit 5bbbcd09cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -251,6 +251,19 @@ protected:
undo_redo->create_action(TTR("Set Variable Type")); undo_redo->create_action(TTR("Set Variable Type"));
undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc);
undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d); undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d);
// Setting the default value.
Variant::Type type = (Variant::Type)(int)p_value;
if (type != Variant::NIL) {
Variant default_value;
Variant::CallError ce;
default_value = Variant::construct(type, NULL, 0, ce);
if (ce.error == Variant::CallError::CALL_OK) {
undo_redo->add_do_method(script.ptr(), "set_variable_default_value", var, default_value);
undo_redo->add_undo_method(script.ptr(), "set_variable_default_value", var, dc["value"]);
}
}
undo_redo->add_do_method(this, "_var_changed"); undo_redo->add_do_method(this, "_var_changed");
undo_redo->add_undo_method(this, "_var_changed"); undo_redo->add_undo_method(this, "_var_changed");
undo_redo->commit_action(); undo_redo->commit_action();