From b6b75beb29025135f78180c14a6178631b2cb86a Mon Sep 17 00:00:00 2001 From: nordsoft Date: Tue, 24 Oct 2023 23:58:26 +0200 Subject: [PATCH] Fixes for map editor 1) fix owner serialization for hero placeholder 2) fix roads/rivers layout 3) fix lasso --- lib/gameState/CGameStateCampaign.cpp | 3 ++- lib/mapObjects/CGHeroInstance.cpp | 2 ++ mapeditor/inspector/inspector.cpp | 4 +++ mapeditor/mainwindow.ui | 12 +++++++-- mapeditor/mapview.cpp | 37 +++++++++++++++++++++++++--- 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/lib/gameState/CGameStateCampaign.cpp b/lib/gameState/CGameStateCampaign.cpp index 443aedf9f..462204cb7 100644 --- a/lib/gameState/CGameStateCampaign.cpp +++ b/lib/gameState/CGameStateCampaign.cpp @@ -336,7 +336,8 @@ void CGameStateCampaign::replaceHeroesPlaceholders(const std::vectorid = campaignHeroReplacement.heroPlaceholderId; - heroToPlace->tempOwner = heroPlaceholder->tempOwner; + if(heroPlaceholder->tempOwner.isValidPlayer()) + heroToPlace->tempOwner = heroPlaceholder->tempOwner; heroToPlace->pos = heroPlaceholder->pos; heroToPlace->type = VLC->heroh->objects[heroToPlace->subID]; heroToPlace->appearance = VLC->objtypeh->getHandlerFor(Obj::HERO, heroToPlace->type->heroClass->getIndex())->getTemplates().front(); diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index dc22f4ae5..5c8952beb 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -42,6 +42,8 @@ VCMI_LIB_NAMESPACE_BEGIN void CGHeroPlaceholder::serializeJsonOptions(JsonSerializeFormat & handler) { + serializeJsonOwner(handler); + bool isHeroType = heroType.has_value(); handler.serializeBool("placeholderType", isHeroType, false); diff --git a/mapeditor/inspector/inspector.cpp b/mapeditor/inspector/inspector.cpp index 61a96bb83..b0b1e6261 100644 --- a/mapeditor/inspector/inspector.cpp +++ b/mapeditor/inspector/inspector.cpp @@ -123,6 +123,8 @@ void Initializer::initialize(CGHeroPlaceholder * o) { if(!o) return; + o->tempOwner = defaultPlayer; + if(!o->powerRank.has_value() && !o->heroType.has_value()) o->powerRank = 0; @@ -274,6 +276,8 @@ void Inspector::updateProperties(CGHeroPlaceholder * o) { if(!o) return; + addProperty("Owner", o->tempOwner, false); + bool type = false; if(o->heroType.has_value()) type = true; diff --git a/mapeditor/mainwindow.ui b/mapeditor/mainwindow.ui index 226dd3b39..bedb9c465 100644 --- a/mapeditor/mainwindow.ui +++ b/mapeditor/mainwindow.ui @@ -953,7 +953,11 @@ 0 - + + + 1 + + @@ -989,7 +993,11 @@ 0 - + + + 1 + + diff --git a/mapeditor/mapview.cpp b/mapeditor/mapview.cpp index 9171fd7e3..52cb9f373 100644 --- a/mapeditor/mapview.cpp +++ b/mapeditor/mapview.cpp @@ -89,8 +89,6 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent) if(tile == tilePrev) //do not redraw return; - tilePrev = tile; - emit currentCoordinates(tile.x, tile.y); switch(selectionTool) @@ -208,7 +206,21 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent) case MapView::SelectionTool::Lasso: if(mouseEvent->buttons() == Qt::LeftButton) { - sc->selectionTerrainView.select(tile); + for(auto i = tilePrev; i != tile;) + { + int length = std::numeric_limits::max(); + int3 dir; + for(auto & d : int3::getDirs()) + { + if(tile.dist2dSQ(i + d) < length) + { + dir = d; + length = tile.dist2dSQ(i + d); + } + } + i += dir; + sc->selectionTerrainView.select(i); + } sc->selectionTerrainView.draw(); } break; @@ -235,6 +247,8 @@ void MapView::mouseMoveEvent(QMouseEvent *mouseEvent) sc->selectionObjectsView.draw(); break; } + + tilePrev = tile; } void MapView::mousePressEvent(QMouseEvent *event) @@ -459,6 +473,23 @@ void MapView::mouseReleaseEvent(QMouseEvent *event) case MapView::SelectionTool::Lasso: { if(event->button() == Qt::RightButton) break; + + //connect with initial tile + for(auto i = tilePrev; i != tileStart;) + { + int length = std::numeric_limits::max(); + int3 dir; + for(auto & d : int3::getDirs()) + { + if(tileStart.dist2dSQ(i + d) < length) + { + dir = d; + length = tileStart.dist2dSQ(i + d); + } + } + i += dir; + sc->selectionTerrainView.select(i); + } //key: y position of tile //value.first: x position of left tile