diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/animation_track_editor.cpp | 34 | ||||
-rw-r--r-- | editor/animation_track_editor.h | 1 | ||||
-rw-r--r-- | editor/editor_node.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 74 |
4 files changed, 81 insertions, 30 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 3233bd79d5..f33fd1d4dd 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -2003,7 +2003,6 @@ void AnimationTrackEdit::_notification(int p_what) { draw_texture(down_icon, Vector2(ofs, int(get_size().height - down_icon->get_height()) / 2)); update_mode_rect.size.x += down_icon->get_width(); } else if (animation->track_get_type(track) == Animation::TYPE_BEZIER) { - Ref<Texture2D> bezier_icon = get_theme_icon(SNAME("EditBezier"), SNAME("EditorIcons")); update_mode_rect.size.x += down_icon->get_width(); update_mode_rect = Rect2(); } else { @@ -3311,25 +3310,15 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim, bool p_re snap->set_disabled(false); snap_mode->set_disabled(false); - bezier_edit_icon->set_disabled(true); - imported_anim_warning->hide(); - bool import_warning_done = false; - bool bezier_done = false; for (int i = 0; i < animation->get_track_count(); i++) { if (animation->track_is_imported(i)) { imported_anim_warning->show(); - import_warning_done = true; - } - if (animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) { - bezier_edit_icon->set_disabled(false); - bezier_done = true; - } - if (import_warning_done && bezier_done) { break; } } + _check_bezier_exist(); } else { hscroll->hide(); edit->set_disabled(true); @@ -3343,6 +3332,24 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim, bool p_re } } +void AnimationTrackEditor::_check_bezier_exist() { + bool is_exist = false; + for (int i = 0; i < animation->get_track_count(); i++) { + if (animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) { + is_exist = true; + break; + } + } + if (is_exist) { + bezier_edit_icon->set_disabled(false); + } else { + if (bezier_edit->is_visible()) { + _cancel_bezier_edit(); + } + bezier_edit_icon->set_disabled(true); + } +} + Ref<Animation> AnimationTrackEditor::get_current_animation() const { return animation; } @@ -4490,6 +4497,8 @@ void AnimationTrackEditor::_animation_changed() { return; // All will be updated, don't bother with anything. } + _check_bezier_exist(); + if (key_edit) { if (key_edit->setting) { // If editing a key, just redraw the edited track, makes refresh less costly. @@ -4710,7 +4719,6 @@ void AnimationTrackEditor::_new_track_node_selected(NodePath p_path) { adding_track_path = path_to; prop_selector->set_type_filter(filter); prop_selector->select_property_from_instance(node); - bezier_edit_icon->set_disabled(false); } break; case Animation::TYPE_AUDIO: { if (!node->is_class("AudioStreamPlayer") && !node->is_class("AudioStreamPlayer2D") && !node->is_class("AudioStreamPlayer3D")) { diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index 2a59bda2a4..c733f397e3 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -399,6 +399,7 @@ class AnimationTrackEditor : public VBoxContainer { void _update_tracks(); void _redraw_tracks(); void _redraw_groups(); + void _check_bezier_exist(); void _name_limit_changed(); void _timeline_changed(float p_new_pos, bool p_drag, bool p_timeline_only); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 3adebb2f8e..1dce65cfab 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3685,7 +3685,7 @@ void EditorNode::_set_main_scene_state(Dictionary p_state, Node *p_for_scene) { Node *editor_node = SceneTreeDock::get_singleton()->get_tree_editor()->get_selected(); editor_node = editor_node == nullptr ? get_edited_scene() : editor_node; - if (Object::cast_to<Node2D>(editor_node) || Object::cast_to<Control>(editor_node)) { + if (Object::cast_to<CanvasItem>(editor_node)) { editor_select(EDITOR_2D); } else if (Object::cast_to<Node3D>(editor_node)) { editor_select(EDITOR_3D); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 6b4e7184d9..4fe3ca5a5c 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1820,30 +1820,72 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { color_position.x = row; color_position.y = col; - int begin = 0; - int end = 0; - bool valid = false; + int begin = -1; + int end = -1; + enum EXPRESSION_PATTERNS { + NOT_PARSED, + RGBA_PARAMETER, // Color(float,float,float) or Color(float,float,float,float) + COLOR_NAME, // Color.COLOR_NAME + } expression_pattern = NOT_PARSED; + for (int i = col; i < line.length(); i++) { if (line[i] == '(') { + if (expression_pattern == NOT_PARSED) { + begin = i; + expression_pattern = RGBA_PARAMETER; + } else { + // Method call or '(' appearing twice. + expression_pattern = NOT_PARSED; + + break; + } + } else if (expression_pattern == RGBA_PARAMETER && line[i] == ')' && end < 0) { + end = i + 1; + + break; + } else if (expression_pattern == NOT_PARSED && line[i] == '.') { begin = i; + expression_pattern = COLOR_NAME; + } else if (expression_pattern == COLOR_NAME && end < 0 && (line[i] == ' ' || line[i] == '\t')) { + // Including '.' and spaces. continue; - } else if (line[i] == ')') { - end = i + 1; - valid = true; + } else if (expression_pattern == COLOR_NAME && !(line[i] == '_' || ('A' <= line[i] && line[i] <= 'Z'))) { + end = i; + break; } } - if (valid) { - color_args = line.substr(begin, end - begin); - String stripped = color_args.replace(" ", "").replace("(", "").replace(")", ""); - PackedFloat64Array color = stripped.split_floats(","); - if (color.size() > 2) { - float alpha = color.size() > 3 ? color[3] : 1.0f; - color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha)); - } + + switch (expression_pattern) { + case RGBA_PARAMETER: { + color_args = line.substr(begin, end - begin); + String stripped = color_args.replace(" ", "").replace("\t", "").replace("(", "").replace(")", ""); + PackedFloat64Array color = stripped.split_floats(","); + if (color.size() > 2) { + float alpha = color.size() > 3 ? color[3] : 1.0f; + color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha)); + } + } break; + case COLOR_NAME: { + if (end < 0) { + end = line.length(); + } + color_args = line.substr(begin, end - begin); + const String color_name = color_args.replace(" ", "").replace("\t", "").replace(".", ""); + const int color_index = Color::find_named_color(color_name); + if (0 <= color_index) { + const Color color_constant = Color::get_named_color(color_index); + color_picker->set_pick_color(color_constant); + } else { + has_color = false; + } + } break; + default: + has_color = false; + break; + } + if (has_color) { color_panel->set_position(get_screen_position() + local_pos); - } else { - has_color = false; } } _make_context_menu(tx->has_selection(), has_color, foldable, open_docs, goto_definition, local_pos); |