From 9677203215fa4ebf5d8c9abd3bef76bda7c15323 Mon Sep 17 00:00:00 2001 From: Nelsson Huotari Date: Sun, 3 Nov 2019 22:07:04 +0200 Subject: [PATCH] Don't allow vertex selection outside visible cells --- apps/opencs/view/render/terrainshapemode.cpp | 21 ++++++++++++++++---- apps/opencs/view/render/terrainshapemode.hpp | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/apps/opencs/view/render/terrainshapemode.cpp b/apps/opencs/view/render/terrainshapemode.cpp index 4d456a9af..af97e4d8f 100644 --- a/apps/opencs/view/render/terrainshapemode.cpp +++ b/apps/opencs/view/render/terrainshapemode.cpp @@ -1027,6 +1027,17 @@ bool CSVRender::TerrainShapeMode::limitAlteredHeights(const CSMWorld::CellCoordi return steepnessIsWithinLimits; } +bool CSVRender::TerrainShapeMode::isInCellSelection(int globalSelectionX, int globalSelectionY) +{ + if (CSVRender::PagedWorldspaceWidget *paged = dynamic_cast (&getWorldspaceWidget())) + { + std::pair vertexCoords = std::make_pair(globalSelectionX, globalSelectionY); + std::string cellId = CSMWorld::CellCoordinates::vertexGlobalToCellId(vertexCoords); + return paged->getCellSelection().has(CSMWorld::CellCoordinates::fromId(cellId).first) && isLandLoaded(cellId); + } + return false; +} + void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair& vertexCoords, unsigned char selectMode, bool dragOperation) { int r = mBrushSize / 2; @@ -1034,7 +1045,7 @@ void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair& if (mBrushShape == CSVWidget::BrushShape_Point) { - selections.emplace_back(vertexCoords); + if (isInCellSelection(vertexCoords.first, vertexCoords.second)) selections.emplace_back(vertexCoords.first, vertexCoords.second); } if (mBrushShape == CSVWidget::BrushShape_Square) @@ -1043,7 +1054,7 @@ void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair& { for(int j = vertexCoords.second - r; j <= vertexCoords.second + r; ++j) { - selections.emplace_back(std::make_pair(i, j)); + if (isInCellSelection(i, j)) selections.emplace_back(i, j); } } } @@ -1057,7 +1068,7 @@ void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair& int distanceX = abs(i - vertexCoords.first); int distanceY = abs(j - vertexCoords.second); int distance = std::round(sqrt(pow(distanceX, 2)+pow(distanceY, 2))); - if (distance <= r) selections.emplace_back(std::make_pair(i, j)); + if (isInCellSelection(i, j) && distance <= r) selections.emplace_back(i, j); } } } @@ -1068,7 +1079,9 @@ void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair& { for(auto const& value: mCustomBrushShape) { - selections.emplace_back(std::make_pair(vertexCoords.first + value.first, vertexCoords.second + value.second)); + std::pair localVertexCoords (vertexCoords.first + value.first, vertexCoords.second + value.second); + std::string cellId (CSMWorld::CellCoordinates::vertexGlobalToCellId(localVertexCoords)); + if (isInCellSelection(localVertexCoords.first, localVertexCoords.second)) selections.emplace_back(localVertexCoords); } } } diff --git a/apps/opencs/view/render/terrainshapemode.hpp b/apps/opencs/view/render/terrainshapemode.hpp index 00218a63e..605827c9e 100644 --- a/apps/opencs/view/render/terrainshapemode.hpp +++ b/apps/opencs/view/render/terrainshapemode.hpp @@ -131,6 +131,9 @@ namespace CSVRender /// Check that the edit doesn't break save format limits, fix if necessary, return true if slope steepness is within limits bool limitAlteredHeights(const CSMWorld::CellCoordinates& cellCoords, bool reverseMode = false); + /// Check if global selection coordinate belongs to cell in view + bool isInCellSelection(int globalSelectionX, int globalSelectionY); + /// Handle brush mechanics for terrain shape selection void selectTerrainShapes (const std::pair& vertexCoords, unsigned char selectMode, bool dragOperation);