Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 47 additions & 42 deletions editor/animation/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3244,51 +3244,13 @@ void AnimationTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
// Can do something with menu too! show insert key.
float offset = (pos.x - timeline->get_name_limit()) / timeline->get_zoom_scale();
if (!read_only) {
if (!menu) {
menu = memnew(PopupMenu);
add_child(menu);
menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationTrackEdit::_menu_selected));
}

bool selected = _try_select_at_ui_pos(pos, mb->is_command_or_control_pressed() || mb->is_shift_pressed(), false);
_try_select_at_ui_pos(pos, mb->is_command_or_control_pressed() || mb->is_shift_pressed(), false);
moving_selection_attempt = false;

menu->clear();
if (animation->track_get_type(track) == Animation::TYPE_METHOD) {
if (hovering_key_idx != -1) {
lookup_key_idx = hovering_key_idx;
menu->add_icon_item(get_editor_theme_icon(SNAME("Help")), vformat("%s (%s)", TTR("Go to Definition"), animation->method_track_get_name(track, lookup_key_idx)), MENU_KEY_LOOKUP);
menu->add_separator();
}
}
menu->add_icon_item(get_editor_theme_icon(SNAME("Key")), TTR("Insert Key..."), MENU_KEY_INSERT);
if (selected || editor->is_selection_active()) {
menu->add_separator();
menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Duplicate Key(s)"), MENU_KEY_DUPLICATE);
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCut")), TTR("Cut Key(s)"), MENU_KEY_CUT);
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCopy")), TTR("Copy Key(s)"), MENU_KEY_COPY);
}
if (editor->is_key_clipboard_active()) {
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionPaste")), TTR("Paste Key(s)"), MENU_KEY_PASTE);
}
if (selected || editor->is_selection_active()) {
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
if (ape) {
AnimationPlayer *ap = ape->get_player();
if (ap && editor->can_add_reset_key() && animation != ap->get_animation(SceneStringName(RESET))) {
menu->add_separator();
menu->add_icon_item(get_editor_theme_icon(SNAME("MoveUp")), TTR("Send Key(s) to RESET"), MENU_KEY_ADD_RESET);
}
}
menu->add_separator();
menu->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Delete Key(s)"), MENU_KEY_DELETE);
}
menu->reset_size();

menu->set_position(get_screen_position() + get_local_mouse_position());
menu->popup();

insert_at_pos = offset + timeline->get_value();
Vector2 popup_pos = get_screen_position() + get_local_mouse_position();
// Use call_deferred to wait for the selected keys being updated.
callable_mp(this, &AnimationTrackEdit::_popup_key_context_menu).call_deferred(hovering_key_idx, popup_pos);
accept_event();
}
}
Expand Down Expand Up @@ -3615,6 +3577,49 @@ void AnimationTrackEdit::drop_data(const Point2 &p_point, const Variant &p_data)
}
}

void AnimationTrackEdit::_popup_key_context_menu(int p_hovering_key_idx, Vector2 p_popup_pos) {
if (!menu) {
menu = memnew(PopupMenu);
add_child(menu);
menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationTrackEdit::_menu_selected));
}

menu->clear();
if (animation->track_get_type(track) == Animation::TYPE_METHOD) {
if (p_hovering_key_idx != -1) {
lookup_key_idx = p_hovering_key_idx;
menu->add_icon_item(get_editor_theme_icon(SNAME("Help")), vformat("%s (%s)", TTR("Go to Definition"), animation->method_track_get_name(track, lookup_key_idx)), MENU_KEY_LOOKUP);
menu->add_separator();
}
}
menu->add_icon_item(get_editor_theme_icon(SNAME("Key")), TTR("Insert Key..."), MENU_KEY_INSERT);
if (editor->is_selection_active()) {
menu->add_separator();
menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Duplicate Key(s)"), MENU_KEY_DUPLICATE);
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCut")), TTR("Cut Key(s)"), MENU_KEY_CUT);
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCopy")), TTR("Copy Key(s)"), MENU_KEY_COPY);
}
if (editor->is_key_clipboard_active()) {
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionPaste")), TTR("Paste Key(s)"), MENU_KEY_PASTE);
}
if (editor->is_selection_active()) {
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
if (ape) {
AnimationPlayer *ap = ape->get_player();
if (ap && editor->can_add_reset_key() && animation != ap->get_animation(SceneStringName(RESET))) {
menu->add_separator();
menu->add_icon_item(get_editor_theme_icon(SNAME("MoveUp")), TTR("Send Key(s) to RESET"), MENU_KEY_ADD_RESET);
}
}
menu->add_separator();
menu->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Delete Key(s)"), MENU_KEY_DELETE);
}
menu->reset_size();

menu->set_position(p_popup_pos);
menu->popup();
}

void AnimationTrackEdit::_menu_selected(int p_index) {
switch (p_index) {
case MENU_CALL_MODE_CONTINUOUS:
Expand Down
1 change: 1 addition & 0 deletions editor/animation/animation_track_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ class AnimationTrackEdit : public Control {
String path_cache;

void _menu_selected(int p_index);
void _popup_key_context_menu(int p_hovering_key_idx, Vector2 p_popup_pos);

void _path_submitted(const String &p_text);
void _play_position_draw();
Expand Down
Loading