diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-06-24 00:07:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-24 00:07:13 +0200 |
commit | 297e7efa0af0765b3030dce726e54dde0b37f95c (patch) | |
tree | 834c0f9360720a5cc6a9e0eb5055b1513f8f5a24 /editor | |
parent | 30383a1cdc00d398349515b81a85fa1d3da7ae37 (diff) | |
parent | b3d772ed837c57d590c064f9de4e2ea89eb55001 (diff) |
Merge pull request #30011 from akien-mga/animation-invalid-key
Display invalid value keys in AnimationTrackEdit
Diffstat (limited to 'editor')
-rw-r--r-- | editor/animation_track_editor.cpp | 81 | ||||
-rw-r--r-- | editor/animation_track_editor.h | 14 | ||||
-rw-r--r-- | editor/icons/icon_key_valid.svg | 5 |
3 files changed, 51 insertions, 49 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 6e47fadb20..1bed5a9524 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -1203,7 +1203,9 @@ AnimationTimelineEdit::AnimationTimelineEdit() { //////////////////////////////////// void AnimationTrackEdit::_notification(int p_what) { + if (p_what == NOTIFICATION_DRAW) { + if (animation.is_null()) return; ERR_FAIL_INDEX(track, animation->get_track_count()); @@ -1240,20 +1242,15 @@ void AnimationTrackEdit::_notification(int p_what) { int ofs = in_group ? check->get_width() : 0; //not the best reference for margin but.. check_rect = Rect2(Point2(ofs, int(get_size().height - check->get_height()) / 2), check->get_size()); - draw_texture(check, check_rect.position); - ofs += check->get_width() + hsep; Ref<Texture> type_icon = type_icons[animation->track_get_type(track)]; - draw_texture(type_icon, Point2(ofs, int(get_size().height - type_icon->get_height()) / 2)); ofs += type_icon->get_width() + hsep; NodePath path = animation->track_get_path(track); - Node *node = NULL; - if (root && root->has_node(path)) { node = root->get_node(path); } @@ -1308,12 +1305,11 @@ void AnimationTrackEdit::_notification(int p_what) { draw_line(Point2(limit, 0), Point2(limit, get_size().height), linecolor, Math::round(EDSCALE)); } - // KEYFAMES // + // KEYFRAMES // draw_bg(limit, get_size().width - timeline->get_buttons_width()); { - float scale = timeline->get_zoom_scale(); int limit_end = get_size().width - timeline->get_buttons_width(); @@ -1342,6 +1338,7 @@ void AnimationTrackEdit::_notification(int p_what) { draw_fg(limit, get_size().width - timeline->get_buttons_width()); // BUTTONS // + { Ref<Texture> wrap_icon[2] = { @@ -1566,7 +1563,18 @@ void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool if (p_x < p_clip_left || p_x > p_clip_right) return; - Vector2 ofs(p_x - type_icon->get_width() / 2, int(get_size().height - type_icon->get_height()) / 2); + Ref<Texture> icon_to_draw = p_selected ? selected_icon : type_icon; + + // Override type icon for invalid value keys, unless selected. + if (!p_selected && animation->track_get_type(track) == Animation::TYPE_VALUE) { + const Variant &v = animation->track_get_key_value(track, p_index); + Variant::Type valid_type = Variant::NIL; + if (!_is_value_key_valid(v, valid_type)) { + icon_to_draw = get_icon("KeyInvalid", "EditorIcons"); + } + } + + Vector2 ofs(p_x - icon_to_draw->get_width() / 2, int(get_size().height - icon_to_draw->get_height()) / 2); if (animation->track_get_type(track) == Animation::TYPE_METHOD) { Ref<Font> font = get_font("font", "Label"); @@ -1590,16 +1598,13 @@ void AnimationTrackEdit::draw_key(int p_index, float p_pixels_sec, int p_x, bool } text += ")"; - int limit = MAX(0, p_clip_right - p_x - type_icon->get_width()); + int limit = MAX(0, p_clip_right - p_x - icon_to_draw->get_width()); if (limit > 0) { - draw_string(font, Vector2(p_x + type_icon->get_width(), int(get_size().height - font->get_height()) / 2 + font->get_ascent()), text, color, limit); + draw_string(font, Vector2(p_x + icon_to_draw->get_width(), int(get_size().height - font->get_height()) / 2 + font->get_ascent()), text, color, limit); } } - if (p_selected) { - draw_texture(selected_icon, ofs); - } else { - draw_texture(type_icon, ofs); - } + + draw_texture(icon_to_draw, ofs); } //helper @@ -1764,6 +1769,27 @@ void AnimationTrackEdit::_path_entered(const String &p_text) { undo_redo->commit_action(); } +bool AnimationTrackEdit::_is_value_key_valid(const Variant &p_key_value, Variant::Type &r_valid_type) const { + + RES res; + Vector<StringName> leftover_path; + Node *node = root->get_node_and_resource(animation->track_get_path(track), res, leftover_path); + + Object *obj = NULL; + if (res.is_valid()) { + obj = res.ptr(); + } else if (node) { + obj = node; + } + + bool prop_exists = false; + if (obj) { + r_valid_type = obj->get_static_property_type_indexed(leftover_path, &prop_exists); + } + + return (!prop_exists || Variant::can_convert(p_key_value.get_type(), r_valid_type)); +} + String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { if (check_rect.has_point(p_pos)) { @@ -1834,29 +1860,10 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { } break; case Animation::TYPE_VALUE: { - Variant v = animation->track_get_key_value(track, key_idx); - //text+="value: "+String(v)+"\n"; - - bool prop_exists = false; - Variant::Type valid_type = Variant::NIL; - Object *obj = NULL; - - RES res; - Vector<StringName> leftover_path; - Node *node = root->get_node_and_resource(animation->track_get_path(track), res, leftover_path); - - if (res.is_valid()) { - obj = res.ptr(); - } else if (node) { - obj = node; - } - - if (obj) { - valid_type = obj->get_static_property_type_indexed(leftover_path, &prop_exists); - } - + const Variant &v = animation->track_get_key_value(track, key_idx); text += "Type: " + Variant::get_type_name(v.get_type()) + "\n"; - if (prop_exists && !Variant::can_convert(v.get_type(), valid_type)) { + Variant::Type valid_type = Variant::NIL; + if (!_is_value_key_valid(v, valid_type)) { text += "Value: " + String(v) + " (Invalid, expected type: " + Variant::get_type_name(valid_type) + ")\n"; } else { text += "Value: " + String(v) + "\n"; diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index 1452d5519c..5f05c1de8c 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -31,6 +31,11 @@ #ifndef ANIMATION_TRACK_EDITOR_H #define ANIMATION_TRACK_EDITOR_H +#include "editor/editor_data.h" +#include "editor/editor_spin_slider.h" +#include "editor/property_editor.h" +#include "editor/property_selector.h" +#include "scene/animation/animation_cache.h" #include "scene/gui/control.h" #include "scene/gui/file_dialog.h" #include "scene/gui/menu_button.h" @@ -40,12 +45,6 @@ #include "scene/gui/tab_container.h" #include "scene/gui/texture_rect.h" #include "scene/gui/tool_button.h" - -#include "editor/property_selector.h" -#include "editor_data.h" -#include "editor_spin_slider.h" -#include "property_editor.h" -#include "scene/animation/animation_cache.h" #include "scene/resources/animation.h" #include "scene_tree_editor.h" @@ -175,8 +174,9 @@ class AnimationTrackEdit : public Control { void _path_entered(const String &p_text); void _play_position_draw(); - mutable int dropping_at; + bool _is_value_key_valid(const Variant &p_key_value, Variant::Type &r_valid_type) const; + mutable int dropping_at; float insert_at_pos; bool moving_selection_attempt; int select_single_attempt; diff --git a/editor/icons/icon_key_valid.svg b/editor/icons/icon_key_valid.svg deleted file mode 100644 index 4a3fab4754..0000000000 --- a/editor/icons/icon_key_valid.svg +++ /dev/null @@ -1,5 +0,0 @@ -<svg width="8" height="8" version="1.1" viewBox="0 0 8 8" xmlns="http://www.w3.org/2000/svg"> -<g transform="translate(0 -1044.4)"> -<rect transform="rotate(-45)" x="-741.53" y="741.08" width="6.1027" height="6.1027" ry=".76286" fill="#fff"/> -</g> -</svg> |