From 8158cbf87c86269105830061a772afc6d5bfa4bd Mon Sep 17 00:00:00 2001 From: Sven Eberhardt Date: Wed, 22 Jun 2016 01:04:14 -0400 Subject: [PATCH] Qt Editor: Allow hotkey (F2) to duplicate selected objects. Also reset cursor pos to center of duplicated objects to ensure they're on screen when duplicating by hotkey. --- src/editor/C4ConsoleQtMainWindow.ui | 3 +++ src/editor/C4ConsoleQtState.cpp | 3 +++ src/editor/C4EditCursor.cpp | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/editor/C4ConsoleQtMainWindow.ui b/src/editor/C4ConsoleQtMainWindow.ui index c0254542e..107e2c8e4 100644 --- a/src/editor/C4ConsoleQtMainWindow.ui +++ b/src/editor/C4ConsoleQtMainWindow.ui @@ -993,6 +993,9 @@ IDS_MNU_DUPLICATE + + F2 + diff --git a/src/editor/C4ConsoleQtState.cpp b/src/editor/C4ConsoleQtState.cpp index be4bac66c..52ea6e40a 100644 --- a/src/editor/C4ConsoleQtState.cpp +++ b/src/editor/C4ConsoleQtState.cpp @@ -342,6 +342,9 @@ bool C4ConsoleQtMainWindow::HandleEditorKeyDown(QKeyEvent *event) case Qt::Key_Delete: ::Console.EditCursor.Delete(); return true; + case Qt::Key_F2: + ::Console.EditCursor.Duplicate(); + return true; } uint32_t shift = 0; if (event->modifiers() & Qt::AltModifier) shift |= MK_ALT; diff --git a/src/editor/C4EditCursor.cpp b/src/editor/C4EditCursor.cpp index deee5fe54..aa35c8eb2 100644 --- a/src/editor/C4EditCursor.cpp +++ b/src/editor/C4EditCursor.cpp @@ -726,13 +726,25 @@ void C4EditCursor::PerformDuplication(int32_t *object_numbers, int32_t object_co if (obj) obj->Call(PSF_EditCursorDeselection); } if (local_call) selection.clear(); + int64_t X_all = 0, Y_all = 0, n_selected = 0; for (C4Object *obj : ::Objects) if (obj->Number > prev_oei) { obj->Call(PSF_EditCursorSelection); - if (local_call) selection.push_back(C4VObj(obj)); - // TODO: Reset editor X/Y to center objects on cursor + if (local_call) + { + selection.push_back(C4VObj(obj)); + X_all += obj->GetX(); + Y_all += obj->GetY(); + ++n_selected; + } } + // Reset EditCursor pos to center of duplicated objects, so they will be dragged along with the cursor + if (n_selected) + { + X = X_all / n_selected; + Y = Y_all / n_selected; + } SetHold(true); OnSelectionChanged(); }