mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
Only allow selection of cells in view
This commit is contained in:
parent
dc8de6c6e6
commit
39ab449431
4 changed files with 48 additions and 4 deletions
|
@ -113,6 +113,13 @@ int CSMWorld::CellCoordinates::vertexSelectionToInCellCoords(int pos)
|
|||
return static_cast<int>(pos - std::floor(static_cast<float>(pos) / (landSize - 1)) * (landSize - 1));
|
||||
}
|
||||
|
||||
std::string CSMWorld::CellCoordinates::textureGlobalToCellId(std::pair<int, int> textureGlobal)
|
||||
{
|
||||
int x = std::floor(static_cast<float>(textureGlobal.first) / landTextureSize);
|
||||
int y = std::floor(static_cast<float>(textureGlobal.second) / landTextureSize);
|
||||
return generateId(x, y);
|
||||
}
|
||||
|
||||
std::string CSMWorld::CellCoordinates::vertexGlobalToCellId(std::pair<int, int> vertexGlobal)
|
||||
{
|
||||
int x = std::floor(static_cast<float>(vertexGlobal.first) / (landSize - 1));
|
||||
|
|
|
@ -63,6 +63,8 @@ namespace CSMWorld
|
|||
///Converts local cell's heightmap coordinates from the global vertex coordinate
|
||||
static int vertexSelectionToInCellCoords(int);
|
||||
|
||||
static std::string textureGlobalToCellId(std::pair<int, int>);
|
||||
|
||||
///Converts global vertex coordinates to cell id
|
||||
static std::string vertexGlobalToCellId(std::pair<int, int>);
|
||||
};
|
||||
|
|
|
@ -493,6 +493,21 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe
|
|||
}
|
||||
}
|
||||
|
||||
bool CSVRender::TerrainTextureMode::isInCellSelection(const int& globalSelectionX, const int& globalSelectionY)
|
||||
{
|
||||
if (CSVRender::PagedWorldspaceWidget *paged = dynamic_cast<CSVRender::PagedWorldspaceWidget *> (&getWorldspaceWidget()))
|
||||
{
|
||||
CSMWorld::CellSelection selection = paged->getCellSelection();
|
||||
if (selection.has (CSMWorld::CellCoordinates::fromId(
|
||||
CSMWorld::CellCoordinates::textureGlobalToCellId(std::make_pair(globalSelectionX, globalSelectionY))).first))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CSVRender::TerrainTextureMode::selectTerrainTextures(const std::pair<int, int>& texCoords, unsigned char selectMode, bool dragOperation)
|
||||
{
|
||||
int r = mBrushSize / 2;
|
||||
|
@ -500,7 +515,7 @@ void CSVRender::TerrainTextureMode::selectTerrainTextures(const std::pair<int, i
|
|||
|
||||
if (mBrushShape == 0)
|
||||
{
|
||||
selections.emplace_back(texCoords);
|
||||
if (isInCellSelection(texCoords.first, texCoords.second)) selections.emplace_back(texCoords);
|
||||
}
|
||||
|
||||
if (mBrushShape == 1)
|
||||
|
@ -509,7 +524,12 @@ void CSVRender::TerrainTextureMode::selectTerrainTextures(const std::pair<int, i
|
|||
{
|
||||
for (int j = -r; j <= r; j++)
|
||||
{
|
||||
selections.emplace_back(i + texCoords.first, j + texCoords.second);
|
||||
int x = i + texCoords.first;
|
||||
int y = j + texCoords.second;
|
||||
if (isInCellSelection(x, y))
|
||||
{
|
||||
selections.emplace_back(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -522,7 +542,14 @@ void CSVRender::TerrainTextureMode::selectTerrainTextures(const std::pair<int, i
|
|||
{
|
||||
osg::Vec2f coords(i,j);
|
||||
if (std::round(coords.length()) < r)
|
||||
selections.emplace_back(i + texCoords.first, j + texCoords.second);
|
||||
{
|
||||
int x = i + texCoords.first;
|
||||
int y = j + texCoords.second;
|
||||
if (isInCellSelection(x, y))
|
||||
{
|
||||
selections.emplace_back(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -533,7 +560,12 @@ void CSVRender::TerrainTextureMode::selectTerrainTextures(const std::pair<int, i
|
|||
{
|
||||
for(auto const& value: mCustomBrushShape)
|
||||
{
|
||||
selections.emplace_back(texCoords.first + value.first, texCoords.second + value.second);
|
||||
int x = texCoords.first + value.first;
|
||||
int y = texCoords.second + value.second;
|
||||
if (isInCellSelection(x, y))
|
||||
{
|
||||
selections.emplace_back(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,9 @@ namespace CSVRender
|
|||
/// \brief Handle brush mechanics, maths regarding worldspace hit etc.
|
||||
void editTerrainTextureGrid (const WorldspaceHitResult& hit);
|
||||
|
||||
/// \brief Check if global selection coordinate belongs to cell in view
|
||||
bool isInCellSelection(const int& globalSelectionX, const int& globalSelectionY);
|
||||
|
||||
/// \brief Handle brush mechanics for texture selection
|
||||
void selectTerrainTextures (const std::pair<int, int>& texCoords, unsigned char selectMode, bool dragOperation);
|
||||
|
||||
|
|
Loading…
Reference in a new issue