diff --git a/mapeditor/icons/brush-3.png b/mapeditor/icons/brush-3.png new file mode 100644 index 000000000..19800c069 Binary files /dev/null and b/mapeditor/icons/brush-3.png differ diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index b8408b0f5..4bdbcc98e 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -839,6 +839,22 @@ void MainWindow::on_toolArea_clicked(bool checked) ui->tabWidget->setCurrentIndex(0); } +void MainWindow::on_toolLasso_clicked(bool checked) +{ + ui->toolBrush->setChecked(false); + ui->toolBrush2->setChecked(false); + ui->toolBrush4->setChecked(false); + ui->toolArea->setChecked(false); + //ui->toolLasso->setChecked(false); + + if(checked) + ui->mapView->selectionTool = MapView::SelectionTool::Lasso; + else + ui->mapView->selectionTool = MapView::SelectionTool::None; + + ui->tabWidget->setCurrentIndex(0); +} + void MainWindow::on_actionErase_triggered() { on_toolErase_clicked(); diff --git a/mapeditor/mainwindow.h b/mapeditor/mainwindow.h index ccd410aa8..d367525bd 100644 --- a/mapeditor/mainwindow.h +++ b/mapeditor/mainwindow.h @@ -87,6 +87,8 @@ private slots: void on_toolBrush2_clicked(bool checked); void on_toolBrush4_clicked(bool checked); + + void on_toolLasso_clicked(bool checked); void on_inspectorWidget_itemChanged(QTableWidgetItem *item); diff --git a/mapeditor/mainwindow.ui b/mapeditor/mainwindow.ui index 766114052..6e7522956 100644 --- a/mapeditor/mainwindow.ui +++ b/mapeditor/mainwindow.ui @@ -642,7 +642,7 @@ - false + true @@ -663,7 +663,11 @@ - O + + + + + icons:brush-3.pngicons:brush-3.png true diff --git a/mapeditor/mapview.cpp b/mapeditor/mapview.cpp index e24a990cb..6d91481ae 100644 --- a/mapeditor/mapview.cpp +++ b/mapeditor/mapview.cpp @@ -155,6 +155,14 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent) } sc->selectionTerrainView.draw(); break; + + case MapView::SelectionTool::Lasso: + if(mouseEvent->buttons() == Qt::LeftButton) + { + sc->selectionTerrainView.select(tile); + sc->selectionTerrainView.draw(); + } + break; case MapView::SelectionTool::None: if(mouseEvent->buttons() & Qt::RightButton) @@ -247,6 +255,7 @@ void MapView::mousePressEvent(QMouseEvent *event) break; case MapView::SelectionTool::Area: + case MapView::SelectionTool::Lasso: if(event->button() == Qt::RightButton) break; @@ -329,6 +338,55 @@ void MapView::mouseReleaseEvent(QMouseEvent *event) switch(selectionTool) { + case MapView::SelectionTool::Lasso: { + if(event->button() == Qt::RightButton) + break; + + //key: y position of tile + //value.first: x position of left tile + //value.second: x postiion of right tile + std::map> selectionRangeMapX, selectionRangeMapY; + for(auto & t : sc->selectionTerrainView.selection()) + { + auto pairIter = selectionRangeMapX.find(t.y); + if(pairIter == selectionRangeMapX.end()) + selectionRangeMapX[t.y] = std::make_pair(t.x, t.x); + else + { + pairIter->second.first = std::min(pairIter->second.first, t.x); + pairIter->second.second = std::max(pairIter->second.second, t.x); + } + + pairIter = selectionRangeMapY.find(t.x); + if(pairIter == selectionRangeMapY.end()) + selectionRangeMapY[t.x] = std::make_pair(t.y, t.y); + else + { + pairIter->second.first = std::min(pairIter->second.first, t.y); + pairIter->second.second = std::max(pairIter->second.second, t.y); + } + } + + std::set selectionByX, selectionByY; + std::vector finalSelection; + for(auto & selectionRange : selectionRangeMapX) + { + for(int i = selectionRange.second.first; i < selectionRange.second.second; ++i) + selectionByX.insert(int3(i, selectionRange.first, sc->level)); + } + for(auto & selectionRange : selectionRangeMapY) + { + for(int i = selectionRange.second.first; i < selectionRange.second.second; ++i) + selectionByY.insert(int3(selectionRange.first, i, sc->level)); + } + std::set_intersection(selectionByX.begin(), selectionByX.end(), selectionByY.begin(), selectionByY.end(), std::back_inserter(finalSelection)); + for(auto & lassoTile : finalSelection) + sc->selectionTerrainView.select(lassoTile); + + sc->selectionTerrainView.draw(); + break; + } + case MapView::SelectionTool::None: if(event->button() == Qt::RightButton) break;