diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index e607e50f8..68fc87934 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -598,6 +598,10 @@ void MainWindow::on_actionGrid_triggered(bool checked) } } +void MainWindow::changeBrushState(int idx) +{ + +} void MainWindow::on_toolBrush_clicked(bool checked) { @@ -608,15 +612,39 @@ void MainWindow::on_toolBrush_clicked(bool checked) ui->toolLasso->setChecked(false); if(checked) - { ui->mapView->selectionTool = MapView::SelectionTool::Brush; - } else - { ui->mapView->selectionTool = MapView::SelectionTool::None; - } } +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; +} + + +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; +} void MainWindow::on_toolArea_clicked(bool checked) { @@ -627,13 +655,9 @@ void MainWindow::on_toolArea_clicked(bool checked) ui->toolLasso->setChecked(false); if(checked) - { ui->mapView->selectionTool = MapView::SelectionTool::Area; - } else - { ui->mapView->selectionTool = MapView::SelectionTool::None; - } } diff --git a/mapeditor/mainwindow.h b/mapeditor/mainwindow.h index 9190a9aa1..dc31dadef 100644 --- a/mapeditor/mainwindow.h +++ b/mapeditor/mainwindow.h @@ -72,6 +72,10 @@ private slots: void on_actionFill_triggered(); + void on_toolBrush2_clicked(bool checked); + + void on_toolBrush4_clicked(bool checked); + public slots: void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected); @@ -81,6 +85,8 @@ private: void addGroupIntoCatalog(const std::string & groupName, bool staticOnly); void addGroupIntoCatalog(const std::string & groupName, bool staticOnly, int ID); + void changeBrushState(int idx); + private: Ui::MainWindow *ui; ObjectBrowser * objectBrowser = nullptr; diff --git a/mapeditor/mainwindow.ui b/mapeditor/mainwindow.ui index 839b4b5aa..0894cdbfe 100644 --- a/mapeditor/mainwindow.ui +++ b/mapeditor/mainwindow.ui @@ -399,7 +399,7 @@ - false + true @@ -433,7 +433,7 @@ - false + true diff --git a/mapeditor/mapview.cpp b/mapeditor/mapview.cpp index ffbde8722..5bd4588a3 100644 --- a/mapeditor/mapview.cpp +++ b/mapeditor/mapview.cpp @@ -44,8 +44,41 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent) sc->selectionTerrainView.draw(); break; + case MapView::SelectionTool::Brush2: + { + std::array extra{ int3{0, 0, 0}, int3{1, 0, 0}, int3{0, 1, 0}, int3{1, 1, 0} }; + for(auto & e : extra) + { + if(mouseEvent->buttons() & Qt::RightButton) + sc->selectionTerrainView.erase(tile + e); + else if(mouseEvent->buttons() == Qt::LeftButton) + sc->selectionTerrainView.select(tile + e); + } + } + sc->selectionTerrainView.draw(); + break; + + case MapView::SelectionTool::Brush4: + { + std::array extra{ + int3{-1, -1, 0}, int3{0, -1, 0}, int3{1, -1, 0}, int3{2, -1, 0}, + int3{-1, 0, 0}, int3{0, 0, 0}, int3{1, 0, 0}, int3{2, 0, 0}, + int3{-1, 1, 0}, int3{0, 1, 0}, int3{1, 1, 0}, int3{2, 1, 0}, + int3{-1, 2, 0}, int3{0, 2, 0}, int3{1, 2, 0}, int3{2, 2, 0} + }; + for(auto & e : extra) + { + if(mouseEvent->buttons() & Qt::RightButton) + sc->selectionTerrainView.erase(tile + e); + else if(mouseEvent->buttons() == Qt::LeftButton) + sc->selectionTerrainView.select(tile + e); + } + } + sc->selectionTerrainView.draw(); + break; + case MapView::SelectionTool::Area: - if(mouseEvent->buttons() & Qt::RightButton) + if(mouseEvent->buttons() & Qt::RightButton || !mouseEvent->buttons() & Qt::LeftButton) break; sc->selectionTerrainView.clear(); @@ -106,6 +139,43 @@ void MapView::mousePressEvent(QMouseEvent *event) sc->selectionTerrainView.draw(); break; + case MapView::SelectionTool::Brush2: + sc->selectionObjectsView.clear(); + sc->selectionObjectsView.draw(); + { + std::array extra{ int3{0, 0, 0}, int3{1, 0, 0}, int3{0, 1, 0}, int3{1, 1, 0} }; + for(auto & e : extra) + { + if(event->button() == Qt::RightButton) + sc->selectionTerrainView.erase(tileStart + e); + else if(event->button() == Qt::LeftButton) + sc->selectionTerrainView.select(tileStart + e); + } + } + sc->selectionTerrainView.draw(); + break; + + case MapView::SelectionTool::Brush4: + sc->selectionObjectsView.clear(); + sc->selectionObjectsView.draw(); + { + std::array extra{ + int3{-1, -1, 0}, int3{0, -1, 0}, int3{1, -1, 0}, int3{2, -1, 0}, + int3{-1, 0, 0}, int3{0, 0, 0}, int3{1, 0, 0}, int3{2, 0, 0}, + int3{-1, 1, 0}, int3{0, 1, 0}, int3{1, 1, 0}, int3{2, 1, 0}, + int3{-1, 2, 0}, int3{0, 2, 0}, int3{1, 2, 0}, int3{2, 2, 0} + }; + for(auto & e : extra) + { + if(event->button() == Qt::RightButton) + sc->selectionTerrainView.erase(tileStart + e); + else if(event->button() == Qt::LeftButton) + sc->selectionTerrainView.select(tileStart + e); + } + } + sc->selectionTerrainView.draw(); + break; + case MapView::SelectionTool::Area: if(event->button() == Qt::RightButton) break; @@ -361,6 +431,9 @@ void SelectionTerrainView::draw() void SelectionTerrainView::select(const int3 & tile) { + if(!main->getMap() || !main->getMap()->isInTheMap(tile)) + return; + if(!area.count(tile)) { area.insert(tile); @@ -371,6 +444,9 @@ void SelectionTerrainView::select(const int3 & tile) void SelectionTerrainView::erase(const int3 & tile) { + if(!main->getMap() || !main->getMap()->isInTheMap(tile)) + return; + if(area.count(tile)) { area.erase(tile); @@ -601,7 +677,7 @@ void SelectionObjectsView::draw() CGObjectInstance * SelectionObjectsView::selectObjectAt(int x, int y) { - if(!main->getMap() || !main->getMapHandler()) + if(!main->getMap() || !main->getMapHandler() || !main->getMap()->isInTheMap(int3(x, y, scene->level))) return nullptr; auto & objects = main->getMapHandler()->getObjects(x, y, scene->level);