From b65dc4150df2cda01b7852d2f24e9978a0a683c2 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Alves Cruz Date: Thu, 8 Aug 2024 23:32:17 -0300 Subject: [PATCH] feat: copy position anywhere --- source/map_display.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/source/map_display.cpp b/source/map_display.cpp index 1b735b7e..a6b63b16 100644 --- a/source/map_display.cpp +++ b/source/map_display.cpp @@ -1996,18 +1996,22 @@ void MapCanvas::OnDelete(wxCommandEvent &WXUNUSED(event)) { } void MapCanvas::OnCopyPosition(wxCommandEvent &WXUNUSED(event)) { - if (!editor.hasSelection()) { - return; + if (editor.hasSelection()) { + auto minPos = editor.getSelection().minPosition(); + auto maxPos = editor.getSelection().maxPosition(); + if (minPos != maxPos) { + posToClipboard(minPos.x, minPos.y, minPos.z, maxPos.x, maxPos.y, maxPos.z, g_settings.getInteger(Config::COPY_POSITION_FORMAT)); + return; + } } - Position minPos = editor.getSelection().minPosition(); - Position maxPos = editor.getSelection().maxPosition(); - if (minPos != maxPos) { - int format = g_settings.getInteger(Config::COPY_AREA_FORMAT); - posToClipboard(minPos.x, minPos.y, minPos.z, maxPos.x, maxPos.y, maxPos.z, format); - } else { - int format = g_settings.getInteger(Config::COPY_POSITION_FORMAT); - posToClipboard(minPos.x, minPos.y, minPos.z, format); + MapTab* tab = g_gui.GetCurrentMapTab(); + if (tab) { + MapCanvas* canvas = tab->GetCanvas(); + int x, y; + int z = canvas->GetFloor(); + canvas->MouseToMap(&x, &y); + posToClipboard(x, y, z, g_settings.getInteger(Config::COPY_POSITION_FORMAT)); } } @@ -2519,7 +2523,7 @@ void MapPopupMenu::Update() { copyItem->Enable(anything_selected); wxMenuItem* copyPositionItem = Append(MAP_POPUP_MENU_COPY_POSITION, "&Copy Position", "Copy the position as a lua table"); - copyPositionItem->Enable(anything_selected); + copyPositionItem->Enable(true); wxMenuItem* pasteItem = Append(MAP_POPUP_MENU_PASTE, "&Paste\tCTRL+V", "Paste items in the copybuffer here"); pasteItem->Enable(editor.copybuffer.canPaste());