Fixes in AnimationTrackEditor around bezier curves

- Undo add bezier track (#31695)
- Undo insert keys for several properties
- Insert keys for several properties using bezier curves (#31698)
- Insert keys for 2d rotation using bezier curve (#28429)
- Insert keys for existing bezier track (#31697)
- Auto-insert keys for bezier track (#31696)
- Number of tracks in insert keys confirmation message
This commit is contained in:
PouleyKetchoupp 2019-09-07 14:46:54 +02:00
parent 393a0152ea
commit 87bb1515af

View file

@ -3470,20 +3470,18 @@ void AnimationTrackEditor::_query_insert(const InsertData &p_id) {
if (p_id.track_idx == -1) { if (p_id.track_idx == -1) {
if (bool(EDITOR_DEF("editors/animation/confirm_insert_track", true))) { if (bool(EDITOR_DEF("editors/animation/confirm_insert_track", true))) {
//potential new key, does not exist //potential new key, does not exist
if (insert_data.size() == 1) int num_tracks = 0;
insert_confirm_text->set_text(vformat(TTR("Create NEW track for %s and insert key?"), p_id.query));
else
insert_confirm_text->set_text(vformat(TTR("Create %d NEW tracks and insert keys?"), insert_data.size()));
bool all_bezier = true; bool all_bezier = true;
for (int i = 0; i < insert_data.size(); i++) { for (int i = 0; i < insert_data.size(); i++) {
if (insert_data[i].type != Animation::TYPE_VALUE && insert_data[i].type != Animation::TYPE_BEZIER) { if (insert_data[i].type != Animation::TYPE_VALUE && insert_data[i].type != Animation::TYPE_BEZIER)
all_bezier = false; all_bezier = false;
}
if (insert_data[i].type != Animation::TYPE_VALUE) { if (insert_data[i].track_idx == -1)
++num_tracks;
if (insert_data[i].type != Animation::TYPE_VALUE)
continue; continue;
}
switch (insert_data[i].value.get_type()) { switch (insert_data[i].value.get_type()) {
case Variant::INT: case Variant::INT:
case Variant::REAL: case Variant::REAL:
@ -3500,6 +3498,11 @@ void AnimationTrackEditor::_query_insert(const InsertData &p_id) {
} }
} }
if (num_tracks == 1)
insert_confirm_text->set_text(vformat(TTR("Create NEW track for %s and insert key?"), p_id.query));
else
insert_confirm_text->set_text(vformat(TTR("Create %d NEW tracks and insert keys?"), num_tracks));
insert_confirm_bezier->set_visible(all_bezier); insert_confirm_bezier->set_visible(all_bezier);
insert_confirm->get_ok()->set_text(TTR("Create")); insert_confirm->get_ok()->set_text(TTR("Create"));
insert_confirm->popup_centered_minsize(); insert_confirm->popup_centered_minsize();
@ -3686,16 +3689,20 @@ void AnimationTrackEditor::insert_node_value_key(Node *p_node, const String &p_p
} else if (animation->track_get_type(i) == Animation::TYPE_BEZIER) { } else if (animation->track_get_type(i) == Animation::TYPE_BEZIER) {
Variant value; Variant value;
if (animation->track_get_path(i) == np) { String track_path = animation->track_get_path(i);
if (track_path == np) {
value = p_value; //all good value = p_value; //all good
} else { } else {
String tpath = animation->track_get_path(i); int sep = track_path.find_last(":");
if (NodePath(tpath.get_basename()) == np) { if (sep != -1) {
String subindex = tpath.get_extension(); String base_path = track_path.substr(0, sep);
value = p_value.get(subindex); if (base_path == np) {
} else { String value_name = track_path.substr(sep + 1);
value = p_value.get(value_name);
} else
continue;
} else
continue; continue;
}
} }
InsertData id; InsertData id;
@ -3955,25 +3962,20 @@ int AnimationTrackEditor::_confirm_insert(InsertData p_id, int p_last_track, boo
bool created = false; bool created = false;
if (p_id.track_idx < 0) { if (p_id.track_idx < 0) {
if (p_create_beziers && (p_id.value.get_type() == Variant::INT || if (p_create_beziers) {
p_id.value.get_type() == Variant::REAL || bool valid;
p_id.value.get_type() == Variant::VECTOR2 || Vector<String> subindices = _get_bezier_subindices_for_type(p_id.value.get_type(), &valid);
p_id.value.get_type() == Variant::VECTOR3 || if (valid) {
p_id.value.get_type() == Variant::QUAT || for (int i = 0; i < subindices.size(); i++) {
p_id.value.get_type() == Variant::COLOR || InsertData id = p_id;
p_id.value.get_type() == Variant::PLANE)) { id.type = Animation::TYPE_BEZIER;
id.value = p_id.value.get(subindices[i].substr(1, subindices[i].length()));
id.path = String(p_id.path) + subindices[i];
_confirm_insert(id, p_last_track + i);
}
Vector<String> subindices = _get_bezier_subindices_for_type(p_id.value.get_type()); return p_last_track + subindices.size();
for (int i = 0; i < subindices.size(); i++) {
InsertData id = p_id;
id.type = Animation::TYPE_BEZIER;
id.value = p_id.value.get(subindices[i].substr(1, subindices[i].length()));
id.path = String(p_id.path) + subindices[i];
_confirm_insert(id, p_last_track + i);
} }
return p_last_track + subindices.size() - 1;
} }
created = true; created = true;
undo_redo->create_action(TTR("Anim Insert Track & Key")); undo_redo->create_action(TTR("Anim Insert Track & Key"));
@ -4064,7 +4066,7 @@ int AnimationTrackEditor::_confirm_insert(InsertData p_id, int p_last_track, boo
// Just remove the track. // Just remove the track.
undo_redo->add_undo_method(this, "_clear_selection", false); undo_redo->add_undo_method(this, "_clear_selection", false);
undo_redo->add_undo_method(animation.ptr(), "remove_track", p_last_track); undo_redo->add_undo_method(animation.ptr(), "remove_track", animation->get_track_count());
p_last_track++; p_last_track++;
} else { } else {
@ -4590,7 +4592,7 @@ void AnimationTrackEditor::_new_track_property_selected(String p_name) {
for (int i = 0; i < subindices.size(); i++) { for (int i = 0; i < subindices.size(); i++) {
undo_redo->add_do_method(animation.ptr(), "add_track", adding_track_type); undo_redo->add_do_method(animation.ptr(), "add_track", adding_track_type);
undo_redo->add_do_method(animation.ptr(), "track_set_path", base_track + i, full_path + subindices[i]); undo_redo->add_do_method(animation.ptr(), "track_set_path", base_track + i, full_path + subindices[i]);
undo_redo->add_undo_method(animation.ptr(), "remove_track", base_track + i); undo_redo->add_undo_method(animation.ptr(), "remove_track", base_track);
} }
undo_redo->commit_action(); undo_redo->commit_action();
} }