Skip to content

Commit e0798f6

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

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed

editor/animation/animation_track_editor.cpp

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3244,51 +3244,13 @@ 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);
3247+
_try_select_at_ui_pos(pos, mb->is_command_or_control_pressed() || mb->is_shift_pressed(), false);
32543248
moving_selection_attempt = false;
32553249

3256-
menu->clear();
3257-
if (animation->track_get_type(track) == Animation::TYPE_METHOD) {
3258-
if (hovering_key_idx != -1) {
3259-
lookup_key_idx = hovering_key_idx;
3260-
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);
3261-
menu->add_separator();
3262-
}
3263-
}
3264-
menu->add_icon_item(get_editor_theme_icon(SNAME("Key")), TTR("Insert Key..."), MENU_KEY_INSERT);
3265-
if (selected || editor->is_selection_active()) {
3266-
menu->add_separator();
3267-
menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Duplicate Key(s)"), MENU_KEY_DUPLICATE);
3268-
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCut")), TTR("Cut Key(s)"), MENU_KEY_CUT);
3269-
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCopy")), TTR("Copy Key(s)"), MENU_KEY_COPY);
3270-
}
3271-
if (editor->is_key_clipboard_active()) {
3272-
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionPaste")), TTR("Paste Key(s)"), MENU_KEY_PASTE);
3273-
}
3274-
if (selected || editor->is_selection_active()) {
3275-
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
3276-
if (ape) {
3277-
AnimationPlayer *ap = ape->get_player();
3278-
if (ap && editor->can_add_reset_key() && animation != ap->get_animation(SceneStringName(RESET))) {
3279-
menu->add_separator();
3280-
menu->add_icon_item(get_editor_theme_icon(SNAME("MoveUp")), TTR("Send Key(s) to RESET"), MENU_KEY_ADD_RESET);
3281-
}
3282-
}
3283-
menu->add_separator();
3284-
menu->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Delete Key(s)"), MENU_KEY_DELETE);
3285-
}
3286-
menu->reset_size();
3287-
3288-
menu->set_position(get_screen_position() + get_local_mouse_position());
3289-
menu->popup();
3290-
32913250
insert_at_pos = offset + timeline->get_value();
3251+
Vector2 popup_pos = get_screen_position() + get_local_mouse_position();
3252+
// Use call_deferred to wait for the selected keys being updated.
3253+
callable_mp(this, &AnimationTrackEdit::_popup_key_context_menu).call_deferred(hovering_key_idx, popup_pos);
32923254
accept_event();
32933255
}
32943256
}
@@ -3615,6 +3577,49 @@ void AnimationTrackEdit::drop_data(const Point2 &p_point, const Variant &p_data)
36153577
}
36163578
}
36173579

3580+
void AnimationTrackEdit::_popup_key_context_menu(int p_hovering_key_idx, Vector2 p_popup_pos) {
3581+
if (!menu) {
3582+
menu = memnew(PopupMenu);
3583+
add_child(menu);
3584+
menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationTrackEdit::_menu_selected));
3585+
}
3586+
3587+
menu->clear();
3588+
if (animation->track_get_type(track) == Animation::TYPE_METHOD) {
3589+
if (p_hovering_key_idx != -1) {
3590+
lookup_key_idx = p_hovering_key_idx;
3591+
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);
3592+
menu->add_separator();
3593+
}
3594+
}
3595+
menu->add_icon_item(get_editor_theme_icon(SNAME("Key")), TTR("Insert Key..."), MENU_KEY_INSERT);
3596+
if (editor->is_selection_active()) {
3597+
menu->add_separator();
3598+
menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Duplicate Key(s)"), MENU_KEY_DUPLICATE);
3599+
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCut")), TTR("Cut Key(s)"), MENU_KEY_CUT);
3600+
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionCopy")), TTR("Copy Key(s)"), MENU_KEY_COPY);
3601+
}
3602+
if (editor->is_key_clipboard_active()) {
3603+
menu->add_icon_item(get_editor_theme_icon(SNAME("ActionPaste")), TTR("Paste Key(s)"), MENU_KEY_PASTE);
3604+
}
3605+
if (editor->is_selection_active()) {
3606+
AnimationPlayerEditor *ape = AnimationPlayerEditor::get_singleton();
3607+
if (ape) {
3608+
AnimationPlayer *ap = ape->get_player();
3609+
if (ap && editor->can_add_reset_key() && animation != ap->get_animation(SceneStringName(RESET))) {
3610+
menu->add_separator();
3611+
menu->add_icon_item(get_editor_theme_icon(SNAME("MoveUp")), TTR("Send Key(s) to RESET"), MENU_KEY_ADD_RESET);
3612+
}
3613+
}
3614+
menu->add_separator();
3615+
menu->add_icon_item(get_editor_theme_icon(SNAME("Remove")), TTR("Delete Key(s)"), MENU_KEY_DELETE);
3616+
}
3617+
menu->reset_size();
3618+
3619+
menu->set_position(p_popup_pos);
3620+
menu->popup();
3621+
}
3622+
36183623
void AnimationTrackEdit::_menu_selected(int p_index) {
36193624
switch (p_index) {
36203625
case MENU_CALL_MODE_CONTINUOUS:

editor/animation/animation_track_editor.h

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

485485
void _menu_selected(int p_index);
486+
void _popup_key_context_menu(int p_hovering_key_idx, Vector2 p_popup_pos);
486487

487488
void _path_submitted(const String &p_text);
488489
void _play_position_draw();

0 commit comments

Comments
 (0)