Merge pull request #13371 from RayKoopa/mute_animation_tracks

Add feature to disable animation tracks
This commit is contained in:
Rémi Verschelde 2017-12-09 19:23:18 +01:00 committed by GitHub
commit ff11864901
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 5 deletions

View file

@ -1124,6 +1124,8 @@ void AnimationKeyEditor::_track_editor_draw() {
Ref<Texture> add_key_icon = get_icon("TrackAddKey", "EditorIcons");
Ref<Texture> add_key_icon_hl = get_icon("TrackAddKeyHl", "EditorIcons");
Ref<Texture> down_icon = get_icon("select_arrow", "Tree");
Ref<Texture> checked = get_icon("checked", "Tree");
Ref<Texture> unchecked = get_icon("unchecked", "Tree");
Ref<Texture> wrap_icon[2] = {
get_icon("InterpWrapClamp", "EditorIcons"),
@ -1170,6 +1172,7 @@ void AnimationKeyEditor::_track_editor_draw() {
v_scroll->set_page(fit);
}
int left_check_ofs = checked->get_width();
int settings_limit = size.width - right_separator_ofs;
int name_limit = settings_limit * name_column_ratio;
@ -1332,6 +1335,7 @@ void AnimationKeyEditor::_track_editor_draw() {
valid_type = obj->get_static_property_type_indexed(leftover_path, &prop_exists);
}
// Draw background color of the whole track
if (/*mouse_over.over!=MouseOver::OVER_NONE &&*/ idx == mouse_over.track) {
Color sepc = hover_color;
te->draw_rect(Rect2(ofs + Point2(0, y), Size2(size.width, h - 1)), sepc);
@ -1343,14 +1347,20 @@ void AnimationKeyEditor::_track_editor_draw() {
te->draw_rect(Rect2(ofs + Point2(0, y), Size2(size.width - 1, h - 1)), tc);
}
te->draw_texture(type_icon[animation->track_get_type(idx)], ofs + Point2(0, y + (h - type_icon[0]->get_height()) / 2).floor());
// Draw track enabled state check box
Ref<Texture> check_box = animation->track_is_enabled(idx) ? checked : unchecked;
te->draw_texture(check_box, ofs + Point2(0, y + (h - checked->get_height()) / 2).floor());
// Draw track type glyph and node path
te->draw_texture(type_icon[animation->track_get_type(idx)], ofs + Point2(left_check_ofs + sep, y + (h - type_icon[0]->get_height()) / 2).floor());
NodePath np = animation->track_get_path(idx);
Node *n = root ? root->get_node(np) : (Node *)NULL;
Color ncol = color;
if (n && editor_selection->is_selected(n))
ncol = track_select_color;
te->draw_string(font, Point2(ofs + Point2(type_icon[0]->get_width() + sep, y + font->get_ascent() + (sep / 2))).floor(), np, ncol, name_limit - (type_icon[0]->get_width() + sep) - 5);
te->draw_string(font, Point2(ofs + Point2(left_check_ofs + sep + type_icon[0]->get_width() + sep, y + font->get_ascent() + (sep / 2))).floor(), np, ncol, name_limit - (type_icon[0]->get_width() + sep) - 5);
// Draw separator line below track area
if (!obj)
te->draw_line(ofs + Point2(0, y + h / 2), ofs + Point2(name_limit, y + h / 2), invalid_path_color);
@ -1798,6 +1808,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input)
Ref<Texture> down_icon = get_icon("select_arrow", "Tree");
Ref<Texture> hsize_icon = get_icon("Hsize", "EditorIcons");
Ref<Texture> add_key_icon = get_icon("TrackAddKey", "EditorIcons");
Ref<Texture> check_icon = get_icon("checked", "Tree");
Ref<Texture> wrap_icon[2] = {
get_icon("InterpWrapClamp", "EditorIcons"),
@ -1832,6 +1843,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input)
v_scroll->set_page(fit);
}
int left_check_ofs = check_icon->get_width();
int settings_limit = size.width - right_separator_ofs;
int name_limit = settings_limit * name_column_ratio;
@ -2092,7 +2104,12 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input)
return;
}
if (mpos.x < name_limit - (type_icon[0]->get_width() / 2.0)) {
if (mpos.x < left_check_ofs) {
// Checkbox on the very left to enable/disable tracks.
animation->track_set_enabled(idx, !animation->track_is_enabled(idx));
} else if (mpos.x < name_limit - (type_icon[0]->get_width() / 2.0)) {
//name column
// area
@ -2103,7 +2120,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input)
return;
}
Rect2 area(ofs.x, ofs.y + ((int(mpos.y) / h) + 1) * h, name_limit, h);
Rect2 area(ofs.x + left_check_ofs + sep, ofs.y + ((int(mpos.y) / h) + 1) * h, name_limit - left_check_ofs - sep, h);
track_name->set_text(animation->track_get_path(idx));
track_name->set_position(te->get_global_position() + area.position);
track_name->set_size(area.size);

View file

@ -364,6 +364,9 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float
if (!nc) // no node cache for this track, skip it
continue;
if (!a->track_is_enabled(i))
continue; // do nothing if the track is disabled
if (a->track_get_key_count(i) == 0)
continue; // do nothing if track is empty

View file

@ -831,7 +831,7 @@ void AnimationTreePlayer::_process_animation(float p_delta) {
for (List<AnimationNode::TrackRef>::Element *E = anim_list->tref.front(); E; E = E->next()) {
AnimationNode::TrackRef &tr = E->get();
if (tr.track == NULL || tr.local_track < 0 || tr.weight < CMP_EPSILON)
if (tr.track == NULL || tr.local_track < 0 || tr.weight < CMP_EPSILON || !a->track_is_enabled(tr.local_track))
continue;
switch (a->track_get_type(tr.local_track)) {

View file

@ -77,6 +77,8 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) {
track_set_interpolation_loop_wrap(track, p_value);
else if (what == "imported")
track_set_imported(track, p_value);
else if (what == "enabled")
track_set_enabled(track, p_value);
else if (what == "keys" || what == "key_values") {
if (track_get_type(track) == TYPE_TRANSFORM) {
@ -247,6 +249,8 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = track_get_interpolation_loop_wrap(track);
else if (what == "imported")
r_ret = track_is_imported(track);
else if (what == "enabled")
r_ret = track_is_enabled(track);
else if (what == "keys") {
if (track_get_type(track) == TYPE_TRANSFORM) {
@ -391,6 +395,7 @@ void Animation::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::INT, "tracks/" + itos(i) + "/interp", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
p_list->push_back(PropertyInfo(Variant::BOOL, "tracks/" + itos(i) + "/loop_wrap", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
p_list->push_back(PropertyInfo(Variant::BOOL, "tracks/" + itos(i) + "/imported", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
p_list->push_back(PropertyInfo(Variant::BOOL, "tracks/" + itos(i) + "/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
p_list->push_back(PropertyInfo(Variant::ARRAY, "tracks/" + itos(i) + "/keys", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
}
}
@ -1575,6 +1580,19 @@ bool Animation::track_is_imported(int p_track) const {
return tracks[p_track]->imported;
}
void Animation::track_set_enabled(int p_track, bool p_enabled) {
ERR_FAIL_INDEX(p_track, tracks.size());
tracks[p_track]->enabled = p_enabled;
emit_changed();
}
bool Animation::track_is_enabled(int p_track) const {
ERR_FAIL_INDEX_V(p_track, tracks.size(), false);
return tracks[p_track]->enabled;
}
void Animation::track_move_down(int p_track) {
if (p_track > 0 && p_track < tracks.size()) {
@ -1603,6 +1621,7 @@ void Animation::copy_track(int src_track, Ref<Animation> p_to_animation) {
p_to_animation->track_set_path(dst_track, track_get_path(src_track));
p_to_animation->track_set_imported(dst_track, track_is_imported(src_track));
p_to_animation->track_set_enabled(dst_track, track_is_enabled(src_track));
p_to_animation->track_set_interpolation_type(dst_track, track_get_interpolation_type(src_track));
p_to_animation->track_set_interpolation_loop_wrap(dst_track, track_get_interpolation_loop_wrap(src_track));
for (int i = 0; i < track_get_key_count(src_track); i++) {
@ -1626,6 +1645,9 @@ void Animation::_bind_methods() {
ClassDB::bind_method(D_METHOD("track_set_imported", "idx", "imported"), &Animation::track_set_imported);
ClassDB::bind_method(D_METHOD("track_is_imported", "idx"), &Animation::track_is_imported);
ClassDB::bind_method(D_METHOD("track_set_enabled", "idx", "enabled"), &Animation::track_set_enabled);
ClassDB::bind_method(D_METHOD("track_is_enabled", "idx"), &Animation::track_is_enabled);
ClassDB::bind_method(D_METHOD("transform_track_insert_key", "idx", "time", "location", "rotation", "scale"), &Animation::transform_track_insert_key);
ClassDB::bind_method(D_METHOD("track_insert_key", "idx", "time", "key", "transition"), &Animation::track_insert_key, DEFVAL(1));
ClassDB::bind_method(D_METHOD("track_remove_key", "idx", "key_idx"), &Animation::track_remove_key);

View file

@ -67,10 +67,12 @@ private:
bool loop_wrap;
NodePath path; // path to something
bool imported;
bool enabled;
Track() {
interpolation = INTERPOLATION_LINEAR;
imported = false;
loop_wrap = true;
enabled = true;
}
virtual ~Track() {}
};
@ -239,6 +241,9 @@ public:
void track_set_imported(int p_track, bool p_imported);
bool track_is_imported(int p_track) const;
void track_set_enabled(int p_track, bool p_enabled);
bool track_is_enabled(int p_track) const;
int transform_track_insert_key(int p_track, float p_time, const Vector3 p_loc, const Quat &p_rot = Quat(), const Vector3 &p_scale = Vector3());
void track_insert_key(int p_track, float p_time, const Variant &p_key, float p_transition = 1);
void track_set_key_transition(int p_track, int p_key_idx, float p_transition);