Skip to content

Commit 3602231

Browse files
committed
Fix "Send Key(s) to RESET" not appearing on first right-click in Animation Editor
1 parent a1eaac8 commit 3602231

File tree

2 files changed

+50
-42
lines changed

2 files changed

+50
-42
lines changed

editor/animation/animation_track_editor.cpp

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3244,50 +3244,12 @@ void AnimationTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
32443244
// Can do something with menu too! show insert key.
32453245
float offset = (pos.x - timeline->get_name_limit()) / timeline->get_zoom_scale();
32463246
if (!read_only) {
3247-
if (!menu) {
3248-
menu = memnew(PopupMenu);
3249-
add_child(menu);
3250-
menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationTrackEdit::_menu_selected));
3251-
}
3252-
3253-
bool selected = _try_select_at_ui_pos(pos, mb->is_command_or_control_pressed() || mb->is_shift_pressed(), false);
3254-
3255-
menu->clear();
3256-
if (animation->track_get_type(track) == Animation::TYPE_METHOD) {
3257-
if (hovering_key_idx != -1) {
3258-
lookup_key_idx = hovering_key_idx;
3259-
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);
3260-
menu->add_separator();
3261-
}
3262-
}
3263-
menu->add_icon_item(get_editor_theme_icon(SNAME("Key")), TTR("Insert Key..."), MENU_KEY_INSERT);
3264-
if (selected || editor->is_selection_active()) {
3265-
menu->add_separator();
3266-
menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Duplicate Key(s)"), MENU_KEY_DUPLICATE);
3267-
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCut")), TTR("Cut Key(s)"), MENU_KEY_CUT);
3268-
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCopy")), TTR("Copy Key(s)"), MENU_KEY_COPY);
3269-
}
3270-
if (editor->is_key_clipboard_active()) {
3271-
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionPaste")), TTR("Paste Key(s)"), MENU_KEY_PASTE);
3272-
}
3273-
if (selected || editor->is_selection_active()) {
3274-
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
3275-
if (ape) {
3276-
AnimationPlayer *ap = ape->get_player();
3277-
if (ap && editor->can_add_reset_key() && animation != ap->get_animation(SceneStringName(RESET))) {
3278-
menu->add_separator();
3279-
menu->add_icon_item(get_editor_theme_icon(SNAME("MoveUp")), TTR("Send Key(s) to RESET"), MENU_KEY_ADD_RESET);
3280-
}
3281-
}
3282-
menu->add_separator();
3283-
menu->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Delete Key(s)"), MENU_KEY_DELETE);
3284-
}
3285-
menu->reset_size();
3286-
3287-
menu->set_position(get_screen_position() + get_local_mouse_position());
3288-
menu->popup();
3247+
_try_select_at_ui_pos(pos, mb->is_command_or_control_pressed() || mb->is_shift_pressed(), false);
32893248

32903249
insert_at_pos = offset + timeline->get_value();
3250+
Vector2 popup_pos = get_screen_position() + get_local_mouse_position();
3251+
// Use call_deferred to wait for the selected keys being updated.
3252+
call_deferred("_popup_key_context_menu", hovering_key_idx, popup_pos);
32913253
accept_event();
32923254
}
32933255
}
@@ -3761,6 +3723,51 @@ void AnimationTrackEdit::_bind_methods() {
37613723
ADD_SIGNAL(MethodInfo("cut_request"));
37623724
ADD_SIGNAL(MethodInfo("paste_request", PropertyInfo(Variant::FLOAT, "offset"), PropertyInfo(Variant::BOOL, "is_offset_valid")));
37633725
ADD_SIGNAL(MethodInfo("delete_request"));
3726+
3727+
ClassDB::bind_method(D_METHOD("_popup_key_context_menu", "p_hovering_key_idx", "popup_pos"), &AnimationTrackEdit::_popup_key_context_menu);
3728+
}
3729+
3730+
void AnimationTrackEdit::_popup_key_context_menu(int p_hovering_key_idx, Vector2 p_popup_pos) {
3731+
if (!menu) {
3732+
menu = memnew(PopupMenu);
3733+
add_child(menu);
3734+
menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationTrackEdit::_menu_selected));
3735+
}
3736+
3737+
menu->clear();
3738+
if (animation->track_get_type(track) == Animation::TYPE_METHOD) {
3739+
if (p_hovering_key_idx != -1) {
3740+
lookup_key_idx = p_hovering_key_idx;
3741+
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);
3742+
menu->add_separator();
3743+
}
3744+
}
3745+
menu->add_icon_item(get_editor_theme_icon(SNAME("Key")), TTR("Insert Key..."), MENU_KEY_INSERT);
3746+
if (editor->is_selection_active()) {
3747+
menu->add_separator();
3748+
menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Duplicate Key(s)"), MENU_KEY_DUPLICATE);
3749+
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCut")), TTR("Cut Key(s)"), MENU_KEY_CUT);
3750+
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCopy")), TTR("Copy Key(s)"), MENU_KEY_COPY);
3751+
}
3752+
if (editor->is_key_clipboard_active()) {
3753+
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionPaste")), TTR("Paste Key(s)"), MENU_KEY_PASTE);
3754+
}
3755+
if (editor->is_selection_active()) {
3756+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
3757+
if (ape) {
3758+
AnimationPlayer *ap = ape->get_player();
3759+
if (ap && editor->can_add_reset_key() && animation != ap->get_animation(SceneStringName(RESET))) {
3760+
menu->add_separator();
3761+
menu->add_icon_item(get_editor_theme_icon(SNAME("MoveUp")), TTR("Send Key(s) to RESET"), MENU_KEY_ADD_RESET);
3762+
}
3763+
}
3764+
menu->add_separator();
3765+
menu->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Delete Key(s)"), MENU_KEY_DELETE);
3766+
}
3767+
menu->reset_size();
3768+
3769+
menu->set_position(p_popup_pos);
3770+
menu->popup();
37643771
}
37653772

37663773
AnimationTrackEdit::AnimationTrackEdit() {

editor/animation/animation_track_editor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ class AnimationTrackEdit : public Control {
481481
String path_cache;
482482

483483
void _menu_selected(int p_index);
484+
void _popup_key_context_menu(int p_hovering_key_idx, Vector2 p_popup_pos);
484485

485486
void _path_submitted(const String &p_text);
486487
void _play_position_draw();

0 commit comments

Comments
 (0)