Skip to content

Commit

Permalink
feat: copy position anywhere (#93)
Browse files Browse the repository at this point in the history
Make it possible to copy position even in empty tiles, useful for when you are scripting an area.
  • Loading branch information
phacUFPE authored Aug 10, 2024
1 parent 56c7efb commit 449e901
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions source/map_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1999,18 +1999,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));
}
}

Expand Down Expand Up @@ -2522,7 +2526,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());
Expand Down

0 comments on commit 449e901

Please sign in to comment.