From 682bd1b4a3cc7c762cfbaba29cca3e15c761c39a Mon Sep 17 00:00:00 2001 From: nordsoft Date: Thu, 8 Sep 2022 04:48:54 +0400 Subject: [PATCH] Start working with appearance --- mapeditor/inspector.cpp | 8 +++++++- mapeditor/mainwindow.cpp | 15 ++++++++++++++- mapeditor/mainwindow.h | 2 +- mapeditor/mapcontroller.cpp | 7 ++++++- mapeditor/mapview.cpp | 12 +++++++----- mapeditor/mapview.h | 2 +- 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/mapeditor/inspector.cpp b/mapeditor/inspector.cpp index bb7f98075..61a762bae 100644 --- a/mapeditor/inspector.cpp +++ b/mapeditor/inspector.cpp @@ -74,8 +74,14 @@ void Initializer::initialize(CGTownInstance * o) { if(!o) return; - o->builtBuildings.insert(BuildingID::FORT); + const std::vector castleLevels{"village", "fort", "citadel", "castle", "capitol"}; + int lvl = vstd::find_pos(castleLevels, o->appearance.stringID); o->builtBuildings.insert(BuildingID::DEFAULT); + if(lvl > -1) o->builtBuildings.insert(BuildingID::TAVERN); + if(lvl > 0) o->builtBuildings.insert(BuildingID::FORT); + if(lvl > 1) o->builtBuildings.insert(BuildingID::CITADEL); + if(lvl > 2) o->builtBuildings.insert(BuildingID::CASTLE); + if(lvl > 3) o->builtBuildings.insert(BuildingID::CAPITOL); for(auto spell : VLC->spellh->objects) //add all regular spells to town { diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 5392dccac..45b223477 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -133,6 +133,8 @@ MainWindow::MainWindow(QWidget *parent) : //loading objects loadObjectsTree(); + + ui->tabWidget->setCurrentIndex(0); show(); } @@ -624,6 +626,8 @@ void MainWindow::on_toolBrush_clicked(bool 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) @@ -638,6 +642,8 @@ void MainWindow::on_toolBrush2_clicked(bool checked) ui->mapView->selectionTool = MapView::SelectionTool::Brush2; else ui->mapView->selectionTool = MapView::SelectionTool::None; + + ui->tabWidget->setCurrentIndex(0); } @@ -653,6 +659,8 @@ void MainWindow::on_toolBrush4_clicked(bool 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) @@ -667,6 +675,8 @@ void MainWindow::on_toolArea_clicked(bool checked) ui->mapView->selectionTool = MapView::SelectionTool::Area; else ui->mapView->selectionTool = MapView::SelectionTool::None; + + ui->tabWidget->setCurrentIndex(0); } void MainWindow::on_actionErase_triggered() @@ -680,6 +690,7 @@ void MainWindow::on_toolErase_clicked() { controller.commitObjectErase(mapLevel); } + ui->tabWidget->setCurrentIndex(0); } void MainWindow::preparePreview(const QModelIndex &index, bool createNew) @@ -760,8 +771,10 @@ void MainWindow::on_actionFill_triggered() controller.commitObstacleFill(mapLevel); } -void MainWindow::loadInspector(CGObjectInstance * obj) +void MainWindow::loadInspector(CGObjectInstance * obj, bool switchTab) { + if(switchTab) + ui->tabWidget->setCurrentIndex(1); Inspector inspector(controller.map(), obj, ui->inspectorWidget); inspector.updateProperties(); } diff --git a/mapeditor/mainwindow.h b/mapeditor/mainwindow.h index 2c137909a..a3f80d30d 100644 --- a/mapeditor/mainwindow.h +++ b/mapeditor/mainwindow.h @@ -90,7 +90,7 @@ private slots: public slots: void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected); - void loadInspector(CGObjectInstance * obj); + void loadInspector(CGObjectInstance * obj, bool switchTab); void mapChanged(); void enableUndo(bool enable); void enableRedo(bool enable); diff --git a/mapeditor/mapcontroller.cpp b/mapeditor/mapcontroller.cpp index ef7a7f807..543020fea 100644 --- a/mapeditor/mapcontroller.cpp +++ b/mapeditor/mapcontroller.cpp @@ -258,7 +258,12 @@ void MapController::commitObstacleFill(int level) void MapController::commitObjectChange(int level) { - //for(auto * o : _scenes[level]->selectionObjectsView.getSelection()) + if(_scenes[level]->selectionObjectsView.getSelection().size() == 1) + { + auto * obj = *_scenes[level]->selectionObjectsView.getSelection().begin(); + if(auto * town = dynamic_cast(obj)) + town->updateAppearance(); + } //_mapHandler->invalidate(o); _scenes[level]->objectsView.draw(); _scenes[level]->selectionObjectsView.draw(); diff --git a/mapeditor/mapview.cpp b/mapeditor/mapview.cpp index 0dbdde285..a6448eb75 100644 --- a/mapeditor/mapview.cpp +++ b/mapeditor/mapview.cpp @@ -303,6 +303,7 @@ void MapView::mouseReleaseEvent(QMouseEvent *event) if(event->button() == Qt::RightButton) break; //switch position + bool tab = false; if(sc->selectionObjectsView.selectionMode == 2 && !sc->selectionObjectsView.shift.isNull()) { controller->commitObjectShiftOrCreate(sc->level); @@ -312,12 +313,13 @@ void MapView::mouseReleaseEvent(QMouseEvent *event) sc->selectionObjectsView.selectionMode = 0; sc->selectionObjectsView.shift = QPoint(0, 0); sc->selectionObjectsView.draw(); + tab = true; //check if we have only one object - auto selection = sc->selectionObjectsView.getSelection(); - if(selection.size() == 1) - { - emit openObjectProperties(*selection.begin()); - } + } + auto selection = sc->selectionObjectsView.getSelection(); + if(selection.size() == 1) + { + emit openObjectProperties(*selection.begin(), tab); } break; } diff --git a/mapeditor/mapview.h b/mapeditor/mapview.h index eecc75559..a7d241313 100644 --- a/mapeditor/mapview.h +++ b/mapeditor/mapview.h @@ -93,7 +93,7 @@ public slots: void cameraChanged(const QPointF & pos); signals: - void openObjectProperties(CGObjectInstance *); + void openObjectProperties(CGObjectInstance *, bool switchTab); //void viewportChanged(const QRectF & rect); protected: