Merge pull request #80860 from RandomShaper/harmonize_track_insert
Simplify right-click track insertion code
This commit is contained in:
commit
d66281c7b8
|
@ -4425,7 +4425,7 @@ AnimationTrackEditor::TrackIndices AnimationTrackEditor::_confirm_insert(InsertD
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float time = timeline->get_play_position();
|
float time = p_id.time == FLT_MAX ? timeline->get_play_position() : p_id.time;
|
||||||
Variant value;
|
Variant value;
|
||||||
|
|
||||||
switch (p_id.type) {
|
switch (p_id.type) {
|
||||||
|
@ -4433,7 +4433,9 @@ AnimationTrackEditor::TrackIndices AnimationTrackEditor::_confirm_insert(InsertD
|
||||||
case Animation::TYPE_ROTATION_3D:
|
case Animation::TYPE_ROTATION_3D:
|
||||||
case Animation::TYPE_SCALE_3D:
|
case Animation::TYPE_SCALE_3D:
|
||||||
case Animation::TYPE_BLEND_SHAPE:
|
case Animation::TYPE_BLEND_SHAPE:
|
||||||
case Animation::TYPE_VALUE: {
|
case Animation::TYPE_VALUE:
|
||||||
|
case Animation::TYPE_AUDIO:
|
||||||
|
case Animation::TYPE_ANIMATION: {
|
||||||
value = p_id.value;
|
value = p_id.value;
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
@ -4449,10 +4451,9 @@ AnimationTrackEditor::TrackIndices AnimationTrackEditor::_confirm_insert(InsertD
|
||||||
bezier_edit_icon->set_disabled(false);
|
bezier_edit_icon->set_disabled(false);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_ANIMATION: {
|
|
||||||
value = p_id.value;
|
|
||||||
} break;
|
|
||||||
default: {
|
default: {
|
||||||
|
// Other track types shouldn't use this code path.
|
||||||
|
DEV_ASSERT(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5185,87 +5186,68 @@ void AnimationTrackEditor::_insert_key_from_track(float p_ofs, int p_track) {
|
||||||
p_ofs += SECOND_DECIMAL;
|
p_ofs += SECOND_DECIMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
Node *node = root->get_node_or_null(animation->track_get_path(p_track));
|
||||||
|
if (!node) {
|
||||||
|
EditorNode::get_singleton()->show_warning(TTR("Track path is invalid, so can't add a key."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special handling for this one.
|
||||||
|
if (animation->track_get_type(p_track) == Animation::TYPE_METHOD) {
|
||||||
|
method_selector->select_method_from_instance(node);
|
||||||
|
|
||||||
|
insert_key_from_track_call_ofs = p_ofs;
|
||||||
|
insert_key_from_track_call_track = p_track;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InsertData id;
|
||||||
|
id.path = animation->track_get_path(p_track);
|
||||||
|
id.advance = false;
|
||||||
|
id.track_idx = p_track;
|
||||||
|
id.type = animation->track_get_type(p_track);
|
||||||
|
// TRANSLATORS: This describes the target of new animation track, will be inserted into another string.
|
||||||
|
id.query = vformat(TTR("node '%s'"), node->get_name());
|
||||||
|
id.time = p_ofs;
|
||||||
|
// id.value is filled in each case handled below.
|
||||||
|
|
||||||
switch (animation->track_get_type(p_track)) {
|
switch (animation->track_get_type(p_track)) {
|
||||||
case Animation::TYPE_POSITION_3D: {
|
case Animation::TYPE_POSITION_3D: {
|
||||||
if (!root->has_node(animation->track_get_path(p_track))) {
|
Node3D *base = Object::cast_to<Node3D>(node);
|
||||||
EditorNode::get_singleton()->show_warning(TTR("Track path is invalid, so can't add a key."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Node3D *base = Object::cast_to<Node3D>(root->get_node(animation->track_get_path(p_track)));
|
|
||||||
|
|
||||||
if (!base) {
|
if (!base) {
|
||||||
EditorNode::get_singleton()->show_warning(TTR("Track is not of type Node3D, can't insert key"));
|
EditorNode::get_singleton()->show_warning(TTR("Track is not of type Node3D, can't insert key"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 pos = base->get_position();
|
id.value = base->get_position();
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Position Key"));
|
|
||||||
undo_redo->add_do_method(animation.ptr(), "position_track_insert_key", p_track, p_ofs, pos);
|
|
||||||
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
|
||||||
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", p_track, p_ofs);
|
|
||||||
undo_redo->commit_action();
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_ROTATION_3D: {
|
case Animation::TYPE_ROTATION_3D: {
|
||||||
if (!root->has_node(animation->track_get_path(p_track))) {
|
Node3D *base = Object::cast_to<Node3D>(node);
|
||||||
EditorNode::get_singleton()->show_warning(TTR("Track path is invalid, so can't add a key."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Node3D *base = Object::cast_to<Node3D>(root->get_node(animation->track_get_path(p_track)));
|
|
||||||
|
|
||||||
if (!base) {
|
if (!base) {
|
||||||
EditorNode::get_singleton()->show_warning(TTR("Track is not of type Node3D, can't insert key"));
|
EditorNode::get_singleton()->show_warning(TTR("Track is not of type Node3D, can't insert key"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion rot = base->get_transform().basis.operator Quaternion();
|
id.value = base->get_transform().basis.operator Quaternion();
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Rotation Key"));
|
|
||||||
undo_redo->add_do_method(animation.ptr(), "rotation_track_insert_key", p_track, p_ofs, rot);
|
|
||||||
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
|
||||||
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", p_track, p_ofs);
|
|
||||||
undo_redo->commit_action();
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_SCALE_3D: {
|
case Animation::TYPE_SCALE_3D: {
|
||||||
if (!root->has_node(animation->track_get_path(p_track))) {
|
Node3D *base = Object::cast_to<Node3D>(node);
|
||||||
EditorNode::get_singleton()->show_warning(TTR("Track path is invalid, so can't add a key."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Node3D *base = Object::cast_to<Node3D>(root->get_node(animation->track_get_path(p_track)));
|
|
||||||
|
|
||||||
if (!base) {
|
if (!base) {
|
||||||
EditorNode::get_singleton()->show_warning(TTR("Track is not of type Node3D, can't insert key"));
|
EditorNode::get_singleton()->show_warning(TTR("Track is not of type Node3D, can't insert key"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Scale Key"));
|
id.value = base->get_scale();
|
||||||
undo_redo->add_do_method(animation.ptr(), "scale_track_insert_key", p_track, p_ofs, base->get_scale());
|
|
||||||
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
|
||||||
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", p_track, p_ofs);
|
|
||||||
undo_redo->commit_action();
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_BLEND_SHAPE:
|
case Animation::TYPE_BLEND_SHAPE:
|
||||||
case Animation::TYPE_VALUE: {
|
case Animation::TYPE_VALUE: {
|
||||||
NodePath bp;
|
NodePath bp;
|
||||||
Variant value;
|
_find_hint_for_track(p_track, bp, &id.value);
|
||||||
_find_hint_for_track(p_track, bp, &value);
|
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Track Key"));
|
|
||||||
undo_redo->add_do_method(animation.ptr(), "track_insert_key", p_track, p_ofs, value);
|
|
||||||
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
|
||||||
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", p_track, p_ofs);
|
|
||||||
undo_redo->commit_action();
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_METHOD: {
|
case Animation::TYPE_METHOD: {
|
||||||
if (!root->has_node(animation->track_get_path(p_track))) {
|
|
||||||
EditorNode::get_singleton()->show_warning(TTR("Track path is invalid, so can't add a method key."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Node *base = root->get_node_or_null(animation->track_get_path(p_track));
|
Node *base = root->get_node_or_null(animation->track_get_path(p_track));
|
||||||
ERR_FAIL_NULL(base);
|
ERR_FAIL_NULL(base);
|
||||||
|
|
||||||
|
@ -5287,12 +5269,7 @@ void AnimationTrackEditor::_insert_key_from_track(float p_ofs, int p_track) {
|
||||||
arr[3] = 0.25;
|
arr[3] = 0.25;
|
||||||
arr[4] = 0;
|
arr[4] = 0;
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Track Key"));
|
id.value = arr;
|
||||||
undo_redo->add_do_method(animation.ptr(), "track_insert_key", p_track, p_ofs, arr);
|
|
||||||
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
|
||||||
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", p_track, p_ofs);
|
|
||||||
undo_redo->commit_action();
|
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_AUDIO: {
|
case Animation::TYPE_AUDIO: {
|
||||||
Dictionary ak;
|
Dictionary ak;
|
||||||
|
@ -5300,24 +5277,20 @@ void AnimationTrackEditor::_insert_key_from_track(float p_ofs, int p_track) {
|
||||||
ak["start_offset"] = 0;
|
ak["start_offset"] = 0;
|
||||||
ak["end_offset"] = 0;
|
ak["end_offset"] = 0;
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Track Key"));
|
id.value = ak;
|
||||||
undo_redo->add_do_method(animation.ptr(), "track_insert_key", p_track, p_ofs, ak);
|
|
||||||
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
|
||||||
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", p_track, p_ofs);
|
|
||||||
undo_redo->commit_action();
|
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_ANIMATION: {
|
case Animation::TYPE_ANIMATION: {
|
||||||
StringName anim = "[stop]";
|
id.value = StringName("[stop]");
|
||||||
|
|
||||||
undo_redo->create_action(TTR("Add Track Key"));
|
|
||||||
undo_redo->add_do_method(animation.ptr(), "track_insert_key", p_track, p_ofs, anim);
|
|
||||||
undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
|
||||||
undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", p_track, p_ofs);
|
|
||||||
undo_redo->commit_action();
|
|
||||||
} break;
|
} break;
|
||||||
|
default: {
|
||||||
|
// All track types should be handled by now.
|
||||||
|
DEV_ASSERT(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_query_insert(id);
|
||||||
|
}
|
||||||
|
|
||||||
void AnimationTrackEditor::_add_method_key(const String &p_method) {
|
void AnimationTrackEditor::_add_method_key(const String &p_method) {
|
||||||
if (!root->has_node(animation->track_get_path(insert_key_from_track_call_track))) {
|
if (!root->has_node(animation->track_get_path(insert_key_from_track_call_track))) {
|
||||||
EditorNode::get_singleton()->show_warning(TTR("Track path is invalid, so can't add a method key."));
|
EditorNode::get_singleton()->show_warning(TTR("Track path is invalid, so can't add a method key."));
|
||||||
|
|
|
@ -464,6 +464,7 @@ class AnimationTrackEditor : public VBoxContainer {
|
||||||
Animation::TrackType type;
|
Animation::TrackType type;
|
||||||
NodePath path;
|
NodePath path;
|
||||||
int track_idx = 0;
|
int track_idx = 0;
|
||||||
|
float time = FLT_MAX; // Defaults to current timeline position.
|
||||||
Variant value;
|
Variant value;
|
||||||
String query;
|
String query;
|
||||||
bool advance = false;
|
bool advance = false;
|
||||||
|
|
Loading…
Reference in New Issue