From 16a7a99b56e00aae20522ad8ace6687c3ebb2d30 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Mon, 8 Jan 2024 00:16:18 +0100 Subject: [PATCH] Add "Duplicate" item to event right click --- .../Editor/Events/EventBlock/event_block.gd | 4 +-- .../EventBlock/event_right_click_menu.gd | 4 ++- .../VisualEditor/timeline_editor_visual.gd | 30 ++++++++++++------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/addons/dialogic/Editor/Events/EventBlock/event_block.gd b/addons/dialogic/Editor/Events/EventBlock/event_block.gd index d34b22296..3fb64c0d5 100644 --- a/addons/dialogic/Editor/Events/EventBlock/event_block.gd +++ b/addons/dialogic/Editor/Events/EventBlock/event_block.gd @@ -440,6 +440,6 @@ func _on_EventNode_gui_input(event:InputEvent) -> void: popup.current_event = self popup.popup_on_parent(Rect2(get_global_mouse_position(),Vector2())) if resource.help_page_path == "": - popup.set_item_disabled(0, true) + popup.set_item_disabled(2, true) else: - popup.set_item_disabled(0, false) + popup.set_item_disabled(2, false) diff --git a/addons/dialogic/Editor/Events/EventBlock/event_right_click_menu.gd b/addons/dialogic/Editor/Events/EventBlock/event_right_click_menu.gd index 6b10fa039..a2b42b9ec 100644 --- a/addons/dialogic/Editor/Events/EventBlock/event_right_click_menu.gd +++ b/addons/dialogic/Editor/Events/EventBlock/event_right_click_menu.gd @@ -5,6 +5,8 @@ var current_event : Node = null func _ready(): clear() + add_icon_item(get_theme_icon("Duplicate", "EditorIcons"), "Duplicate") + add_separator() add_icon_item(get_theme_icon("Help", "EditorIcons"), "Documentation") add_icon_item(get_theme_icon("CodeHighlighter", "EditorIcons"), "Open Code") add_separator() @@ -12,7 +14,7 @@ func _ready(): add_icon_item(get_theme_icon("ArrowDown", "EditorIcons"), "Move down") add_separator() add_icon_item(get_theme_icon("Remove", "EditorIcons"), "Delete") - + var menu_background := StyleBoxFlat.new() menu_background.bg_color = get_parent().get_theme_color("base_color", "Editor") add_theme_stylebox_override('panel', menu_background) diff --git a/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd b/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd index 3f705b709..2b9583f62 100644 --- a/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd +++ b/addons/dialogic/Editor/TimelineEditor/VisualEditor/timeline_editor_visual.gd @@ -888,18 +888,22 @@ func indent_events() -> void: func _on_event_popup_menu_index_pressed(index:int) -> void: var item :Control = %EventPopupMenu.current_event if index == 0: + if not item in selected_items: + selected_items = [item] + duplicate_selected() + elif index == 2: if not item.resource.help_page_path.is_empty(): OS.shell_open(item.resource.help_page_path) - elif index == 1: + elif index == 3: find_parent('EditorView').plugin_reference.get_editor_interface().set_main_screen_editor('Script') find_parent('EditorView').plugin_reference.get_editor_interface().edit_script(item.resource.get_script(), 1, 1) - elif index == 3 or index == 4: - if index == 3: + elif index == 5 or index == 6: + if index == 5: offset_blocks_by_index(selected_items, -1) else: offset_blocks_by_index(selected_items, +1) - elif index == 6: + elif index == 8: var events_indexed := get_events_indexed([item]) TimelineUndoRedo.create_action("[D] Deleting 1 event.") TimelineUndoRedo.add_do_method(delete_events_indexed.bind(events_indexed)) @@ -939,6 +943,16 @@ func _on_right_sidebar_resized(): #################### SHORTCUTS ################################################# ################################################################################ +func duplicate_selected() -> void: + if len(selected_items) > 0: + var events := get_events_indexed(selected_items).values() + var at_index: int = selected_items[-1].get_index()+1 + TimelineUndoRedo.create_action("[D] Duplicate "+str(len(events))+" event(s).") + TimelineUndoRedo.add_do_method(add_events_at_index.bind(events, at_index)) + TimelineUndoRedo.add_undo_method(delete_events_at_index.bind(at_index, len(events))) + TimelineUndoRedo.commit_action() + + func _input(event:InputEvent) -> void: # we protect this with is_visible_in_tree to not # invoke a shortcut by accident @@ -1063,13 +1077,7 @@ func _input(event:InputEvent) -> void: get_viewport().set_input_as_handled() "Ctrl+D": - if len(selected_items) > 0: - var events := get_events_indexed(selected_items).values() - var at_index :int= selected_items[-1].get_index() - TimelineUndoRedo.create_action("[D] Duplicate "+str(len(events))+" event(s).") - TimelineUndoRedo.add_do_method(add_events_at_index.bind(events, at_index)) - TimelineUndoRedo.add_undo_method(delete_events_at_index.bind(at_index, len(events))) - TimelineUndoRedo.commit_action() + duplicate_selected() get_viewport().set_input_as_handled() "Alt+Up", "Option+Up":