diff --git a/mapeditor/icons/brush-0.png b/mapeditor/icons/brush-0.png new file mode 100644 index 000000000..2aa81a4e7 Binary files /dev/null and b/mapeditor/icons/brush-0.png differ diff --git a/mapeditor/icons/brush-6.png b/mapeditor/icons/brush-6.png new file mode 100644 index 000000000..76c926b39 Binary files /dev/null and b/mapeditor/icons/brush-6.png differ diff --git a/mapeditor/icons/brush-7.png b/mapeditor/icons/brush-7.png new file mode 100644 index 000000000..0b075bd33 Binary files /dev/null and b/mapeditor/icons/brush-7.png differ diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 37ae34e81..7d82c7714 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -833,99 +833,12 @@ void MainWindow::changeBrushState(int idx) } -void MainWindow::on_toolBrush_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::Brush; - else - ui->mapView->selectionTool = MapView::SelectionTool::None; - - ui->tabWidget->setCurrentIndex(0); -} - -void MainWindow::on_toolBrush2_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::Brush2; - else - ui->mapView->selectionTool = MapView::SelectionTool::None; - - ui->tabWidget->setCurrentIndex(0); -} - - -void MainWindow::on_toolBrush4_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::Brush4; - else - ui->mapView->selectionTool = MapView::SelectionTool::None; - - ui->tabWidget->setCurrentIndex(0); -} - -void MainWindow::on_toolArea_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::Area; - else - ui->mapView->selectionTool = MapView::SelectionTool::None; - - 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(); -} - -void MainWindow::on_toolErase_clicked() { if(controller.map()) { controller.commitObjectErase(mapLevel); } - ui->tabWidget->setCurrentIndex(0); } void MainWindow::preparePreview(const QModelIndex &index) @@ -949,11 +862,7 @@ void MainWindow::preparePreview(const QModelIndex &index) void MainWindow::treeViewSelected(const QModelIndex & index, const QModelIndex & deselected) { - ui->toolBrush->setChecked(false); - ui->toolBrush2->setChecked(false); - ui->toolBrush4->setChecked(false); - ui->toolArea->setChecked(false); - ui->toolLasso->setChecked(false); + ui->toolSelect->setChecked(true); ui->mapView->selectionTool = MapView::SelectionTool::None; preparePreview(index); @@ -1114,7 +1023,6 @@ void MainWindow::onSelectionMade(int level, bool anythingSelected) if (level == mapLevel) { ui->actionErase->setEnabled(anythingSelected); - ui->toolErase->setEnabled(anythingSelected); } } void MainWindow::displayStatus(const QString& message, int timeout /* = 2000 */) @@ -1346,3 +1254,83 @@ void MainWindow::on_actionZoom_reset_triggered() ui->mapView->centerOn(center); } + +void MainWindow::on_toolLine_toggled(bool checked) +{ + if(checked) + { + ui->mapView->selectionTool = MapView::SelectionTool::Line; + ui->tabWidget->setCurrentIndex(0); + } +} + + +void MainWindow::on_toolBrush2_toggled(bool checked) +{ + if(checked) + { + ui->mapView->selectionTool = MapView::SelectionTool::Brush2; + ui->tabWidget->setCurrentIndex(0); + } +} + + +void MainWindow::on_toolBrush_toggled(bool checked) +{ + if(checked) + { + ui->mapView->selectionTool = MapView::SelectionTool::Brush; + ui->tabWidget->setCurrentIndex(0); + } +} + + +void MainWindow::on_toolBrush4_toggled(bool checked) +{ + if(checked) + { + ui->mapView->selectionTool = MapView::SelectionTool::Brush4; + ui->tabWidget->setCurrentIndex(0); + } +} + + +void MainWindow::on_toolLasso_toggled(bool checked) +{ + if(checked) + { + ui->mapView->selectionTool = MapView::SelectionTool::Lasso; + ui->tabWidget->setCurrentIndex(0); + } +} + + +void MainWindow::on_toolArea_toggled(bool checked) +{ + if(checked) + { + ui->mapView->selectionTool = MapView::SelectionTool::Area; + ui->tabWidget->setCurrentIndex(0); + } +} + + +void MainWindow::on_toolFill_toggled(bool checked) +{ + if(checked) + { + ui->mapView->selectionTool = MapView::SelectionTool::Fill; + ui->tabWidget->setCurrentIndex(0); + } +} + + +void MainWindow::on_toolSelect_toggled(bool checked) +{ + if(checked) + { + ui->mapView->selectionTool = MapView::SelectionTool::None; + ui->tabWidget->setCurrentIndex(0); + } +} + diff --git a/mapeditor/mainwindow.h b/mapeditor/mainwindow.h index 3d127b857..919267557 100644 --- a/mapeditor/mainwindow.h +++ b/mapeditor/mainwindow.h @@ -76,28 +76,16 @@ private slots: void on_actionGrid_triggered(bool checked); - void on_toolBrush_clicked(bool checked); - - void on_toolArea_clicked(bool checked); - void terrainButtonClicked(TerrainId terrain); void roadOrRiverButtonClicked(ui8 type, bool isRoad); void currentCoordinatesChanged(int x, int y); - void on_toolErase_clicked(); - void on_terrainFilterCombo_currentIndexChanged(int index); void on_filter_textChanged(const QString &arg1); void on_actionFill_triggered(); - void on_toolBrush2_clicked(bool checked); - - void on_toolBrush4_clicked(bool checked); - - void on_toolLasso_clicked(bool checked); - void on_inspectorWidget_itemChanged(QTableWidgetItem *item); void on_actionMapSettings_triggered(); @@ -134,6 +122,22 @@ private slots: void on_actionZoom_reset_triggered(); + void on_toolLine_toggled(bool checked); + + void on_toolBrush2_toggled(bool checked); + + void on_toolBrush_toggled(bool checked); + + void on_toolBrush4_toggled(bool checked); + + void on_toolLasso_toggled(bool checked); + + void on_toolArea_toggled(bool checked); + + void on_toolFill_toggled(bool checked); + + void on_toolSelect_toggled(bool checked); + public slots: void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected); diff --git a/mapeditor/mainwindow.ui b/mapeditor/mainwindow.ui index 518464262..226dd3b39 100644 --- a/mapeditor/mainwindow.ui +++ b/mapeditor/mainwindow.ui @@ -442,12 +442,6 @@ 0 - - - 128 - 192 - - QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable @@ -478,289 +472,361 @@ - 0 + 3 - 0 + 3 - 0 + 3 - 0 + 3 - - - - 0 - 0 - + + + 0 - - - 16777215 - 16777215 - + + + + + 0 + 0 + + + + + 40 + 40 + + + + + 40 + 40 + + + + + + + + icons:brush-1.pngicons:brush-1.png + + + + 16 + 16 + + + + true + + + true + + + false + + + + + + + true + + + + 0 + 0 + + + + + 40 + 40 + + + + + 40 + 40 + + + + + + + + icons:brush-2.pngicons:brush-2.png + + + + 16 + 16 + + + + true + + + true + + + false + + + + + + + true + + + + 0 + 0 + + + + + 40 + 40 + + + + + 40 + 40 + + + + + + + + icons:brush-4.pngicons:brush-4.png + + + + 16 + 16 + + + + true + + + true + + + false + + + + + + + true + + + + 0 + 0 + + + + + 40 + 40 + + + + + 40 + 40 + + + + + + + + icons:brush-3.pngicons:brush-3.png + + + true + + + true + + + false + + + + + + + + + 0 - - Brush - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 40 - 40 - - - - - 40 - 40 - - - - - - - - icons:brush-1.pngicons:brush-1.png - - - - 16 - 16 - - - - true - - - false - - - - - - - true - - - - 0 - 0 - - - - - 40 - 40 - - - - - 40 - 40 - - - - - - - - icons:brush-2.pngicons:brush-2.png - - - - 16 - 16 - - - - true - - - false - - - - - - - true - - - - 0 - 0 - - - - - 40 - 40 - - - - - 40 - 40 - - - - - - - - icons:brush-4.pngicons:brush-4.png - - - - 16 - 16 - - - - true - - - false - - - - - - - - 0 - 0 - - - - - 40 - 40 - - - - - 40 - 40 - - - - - - - - icons:brush-5.pngicons:brush-5.png - - - true - - - false - - - - - - - true - - - - 0 - 0 - - - - - 40 - 40 - - - - - 40 - 40 - - - - - - - - icons:brush-3.pngicons:brush-3.png - - - true - - - false - - - - - - - false - - - - 0 - 0 - - - - - 40 - 40 - - - - - 40 - 40 - - - - - - - - icons:edit-clear.pngicons:edit-clear.png - - - false - - - false - - - - - + + + + + 0 + 0 + + + + + 40 + 40 + + + + + 40 + 40 + + + + + + + + icons:brush-7.pngicons:brush-7.png + + + true + + + true + + + + + + + + 0 + 0 + + + + + 40 + 40 + + + + + 40 + 40 + + + + + + + + icons:brush-5.pngicons:brush-5.png + + + true + + + true + + + false + + + + + + + + 0 + 0 + + + + + 40 + 40 + + + + + 40 + 40 + + + + + + + + icons:brush-6.pngicons:brush-6.png + + + true + + + true + + + + + + + true + + + + 0 + 0 + + + + + 40 + 40 + + + + + 40 + 40 + + + + + + + + icons:brush-0.pngicons:brush-0.png + + + true + + + true + + + true + + + false + + + + @@ -818,7 +884,7 @@ 0 0 256 - 90 + 120 @@ -861,7 +927,7 @@ 0 0 256 - 90 + 120 @@ -897,7 +963,7 @@ 0 0 256 - 90 + 120 diff --git a/mapeditor/mapview.cpp b/mapeditor/mapview.cpp index 5013d206c..9171fd7e3 100644 --- a/mapeditor/mapview.cpp +++ b/mapeditor/mapview.cpp @@ -151,6 +151,60 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent) sc->selectionTerrainView.draw(); break; + case MapView::SelectionTool::Line: + { + assert(tile.z == tileStart.z); + const auto diff = tile - tileStart; + if(diff == int3{}) + break; + + const int edge = std::max(abs(diff.x), abs(diff.y)); + int distMin = std::numeric_limits::max(); + int3 dir; + + for(auto & d : int3::getDirs()) + { + if(tile.dist2d(d * edge + tileStart) < distMin) + { + distMin = tile.dist2d(d * edge + tileStart); + dir = d; + } + } + + assert(dir != int3{}); + + if(mouseEvent->buttons() == Qt::LeftButton) + { + for(auto & ts : temporaryTiles) + sc->selectionTerrainView.erase(ts); + + for(auto ts = tileStart; ts.dist2d(tileStart) < edge; ts += dir) + { + if(!controller->map()->isInTheMap(ts)) + break; + if(!sc->selectionTerrainView.selection().count(ts)) + temporaryTiles.insert(ts); + sc->selectionTerrainView.select(ts); + } + } + if(mouseEvent->buttons() == Qt::RightButton) + { + for(auto & ts : temporaryTiles) + sc->selectionTerrainView.select(ts); + + for(auto ts = tileStart; ts.dist2d(tileStart) < edge; ts += dir) + { + if(!controller->map()->isInTheMap(ts)) + break; + if(sc->selectionTerrainView.selection().count(ts)) + temporaryTiles.insert(ts); + sc->selectionTerrainView.erase(ts); + } + } + sc->selectionTerrainView.draw(); + break; + } + case MapView::SelectionTool::Lasso: if(mouseEvent->buttons() == Qt::LeftButton) { @@ -205,6 +259,7 @@ void MapView::mousePressEvent(QMouseEvent *event) switch(selectionTool) { case MapView::SelectionTool::Brush: + case MapView::SelectionTool::Line: sc->selectionObjectsView.clear(); sc->selectionObjectsView.draw(); @@ -262,6 +317,55 @@ void MapView::mousePressEvent(QMouseEvent *event) sc->selectionObjectsView.clear(); sc->selectionObjectsView.draw(); break; + + case MapView::SelectionTool::Fill: + { + if(event->button() != Qt::RightButton && event->button() != Qt::LeftButton) + break; + + std::vector queue; + queue.push_back(tileStart); + + const std::array dirs{ int3{1, 0, 0}, int3{-1, 0, 0}, int3{0, 1, 0}, int3{0, -1, 0} }; + + while(!queue.empty()) + { + auto tile = queue.back(); + queue.pop_back(); + if(event->button() == Qt::LeftButton) + sc->selectionTerrainView.select(tile); + else + sc->selectionTerrainView.erase(tile); + for(auto & d : dirs) + { + auto tilen = tile + d; + if(!controller->map()->isInTheMap(tilen)) + continue; + if(event->button() == Qt::LeftButton) + { + if(controller->map()->getTile(tile).roadType + && controller->map()->getTile(tile).roadType != controller->map()->getTile(tilen).roadType) + continue; + else if(controller->map()->getTile(tile).riverType + && controller->map()->getTile(tile).riverType != controller->map()->getTile(tilen).riverType) + continue; + else if(controller->map()->getTile(tile).terType != controller->map()->getTile(tilen).terType) + continue; + } + if(event->button() == Qt::LeftButton && sc->selectionTerrainView.selection().count(tilen)) + continue; + if(event->button() == Qt::RightButton && !sc->selectionTerrainView.selection().count(tilen)) + continue; + queue.push_back(tilen); + } + } + + + sc->selectionTerrainView.draw(); + sc->selectionObjectsView.clear(); + sc->selectionObjectsView.draw(); + break; + } case MapView::SelectionTool::None: sc->selectionTerrainView.clear(); @@ -401,6 +505,10 @@ void MapView::mouseReleaseEvent(QMouseEvent *event) break; } + case MapView::SelectionTool::Line: + temporaryTiles.clear(); + break; + case MapView::SelectionTool::None: if(event->button() == Qt::RightButton) break; diff --git a/mapeditor/mapview.h b/mapeditor/mapview.h index f9a83f133..c99785647 100644 --- a/mapeditor/mapview.h +++ b/mapeditor/mapview.h @@ -89,7 +89,7 @@ class MapView : public QGraphicsView public: enum class SelectionTool { - None, Brush, Brush2, Brush4, Area, Lasso + None, Brush, Brush2, Brush4, Area, Lasso, Line, Fill }; public: @@ -124,6 +124,8 @@ private: int3 tileStart; int3 tilePrev; bool pressedOnSelected; + + std::set temporaryTiles; }; class MinimapView : public QGraphicsView