mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 07:09:42 +00:00
Better terrain texture ID handling
This commit is contained in:
parent
301c05662b
commit
fbb9800e89
1 changed files with 30 additions and 29 deletions
|
@ -142,60 +142,61 @@ void CSVWidget::TextureBrushWindow::configureButtonInitialSettings(QPushButton *
|
|||
|
||||
void CSVWidget::TextureBrushWindow::setBrushTexture(std::string brushTexture)
|
||||
{
|
||||
mBrushTexture = brushTexture;
|
||||
CSMWorld::IdTable& ltexTable = dynamic_cast<CSMWorld::IdTable&> (
|
||||
*mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_LandTextures));
|
||||
QUndoStack& undoStack = mDocument.getUndoStack();
|
||||
|
||||
CSMWorld::IdCollection<CSMWorld::LandTexture>& landtexturesCollection = mDocument.getData().getLandTextures();
|
||||
|
||||
int landTextureFilename = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Texture);
|
||||
int columnModification = landtexturesCollection.findColumnIndex(CSMWorld::Columns::ColumnId_Modification);
|
||||
int index = landtexturesCollection.searchId(mBrushTexture);
|
||||
|
||||
// Check if texture exists in current plugin
|
||||
if(landtexturesCollection.getData(index, columnModification).value<int>() == 0)
|
||||
int index = 0;
|
||||
int pluginInDragged = 0;
|
||||
CSMWorld::LandTexture::parseUniqueRecordId(brushTexture, pluginInDragged, index);
|
||||
std::string newBrushTextureId = CSMWorld::LandTexture::createUniqueRecordId(0, index);
|
||||
int rowInBase = landtexturesCollection.searchId(brushTexture);
|
||||
int rowInNew = landtexturesCollection.searchId(newBrushTextureId);
|
||||
|
||||
// Check if texture exists in current plugin, and clone if id found in base, otherwise reindex the texture
|
||||
// TO-DO: Handle case when texture is not found in neither base or plugin properly (finding new index is not enough)
|
||||
// TO-DO: Handle conflicting plugins properly
|
||||
if (rowInNew == -1)
|
||||
{
|
||||
CSMWorld::IdTable& ltexTable = dynamic_cast<CSMWorld::IdTable&> (
|
||||
*mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_LandTextures));
|
||||
|
||||
QUndoStack& undoStack = mDocument.getUndoStack();
|
||||
|
||||
QVariant textureFileNameVariant;
|
||||
textureFileNameVariant.setValue(landtexturesCollection.getData(index, landTextureFilename).value<QString>());
|
||||
|
||||
std::size_t hashlocation = mBrushTexture.find("#");
|
||||
std::string mBrushTexturePlugin = "L0#" + mBrushTexture.substr (hashlocation+1);
|
||||
int indexPlugin = landtexturesCollection.searchId(mBrushTexturePlugin);
|
||||
|
||||
// Reindex texture if needed
|
||||
if (indexPlugin != -1 && !landtexturesCollection.getRecord(indexPlugin).isDeleted())
|
||||
if (rowInBase == -1)
|
||||
{
|
||||
int counter=0;
|
||||
bool freeIndexFound = false;
|
||||
const int maxCounter = std::numeric_limits<uint16_t>::max() - 1;
|
||||
do {
|
||||
const size_t maxCounter = std::numeric_limits<uint16_t>::max() - 1;
|
||||
mBrushTexturePlugin = CSMWorld::LandTexture::createUniqueRecordId(0, counter);
|
||||
if (landtexturesCollection.searchId(mBrushTexturePlugin) != -1 && landtexturesCollection.getRecord(mBrushTexturePlugin).isDeleted() == 0) counter = (counter + 1) % maxCounter;
|
||||
newBrushTextureId = CSMWorld::LandTexture::createUniqueRecordId(0, counter);
|
||||
if (landtexturesCollection.searchId(brushTexture) != -1 &&
|
||||
landtexturesCollection.getRecord(brushTexture).isDeleted() == 0 &&
|
||||
landtexturesCollection.searchId(newBrushTextureId) != -1 &&
|
||||
landtexturesCollection.getRecord(newBrushTextureId).isDeleted() == 0)
|
||||
counter = (counter + 1) % maxCounter;
|
||||
else freeIndexFound = true;
|
||||
} while (freeIndexFound == false);
|
||||
} while (freeIndexFound == false || counter < maxCounter);
|
||||
}
|
||||
|
||||
undoStack.beginMacro ("Add land texture record");
|
||||
undoStack.push (new CSMWorld::CloneCommand (ltexTable, mBrushTexture, mBrushTexturePlugin, CSMWorld::UniversalId::Type_LandTexture));
|
||||
undoStack.push (new CSMWorld::CloneCommand (ltexTable, brushTexture, newBrushTextureId, CSMWorld::UniversalId::Type_LandTexture));
|
||||
undoStack.endMacro();
|
||||
mBrushTexture = mBrushTexturePlugin;
|
||||
emit passTextureId(mBrushTexture);
|
||||
}
|
||||
|
||||
if (index != -1 && !landtexturesCollection.getRecord(index).isDeleted())
|
||||
{
|
||||
mBrushTextureLabel = "Selected texture: " + mBrushTexture + " ";
|
||||
mBrushTextureLabel = "Selected texture: " + newBrushTextureId + " ";
|
||||
mSelectedBrush->setText(QString::fromStdString(mBrushTextureLabel) + landtexturesCollection.getData(index, landTextureFilename).value<QString>());
|
||||
} else
|
||||
{
|
||||
newBrushTextureId = "";
|
||||
mBrushTextureLabel = "No selected texture or invalid texture";
|
||||
mSelectedBrush->setText(QString::fromStdString(mBrushTextureLabel));
|
||||
}
|
||||
|
||||
emit passBrushShape(mBrushShape); // update icon
|
||||
mBrushTexture = newBrushTextureId;
|
||||
|
||||
emit passTextureId(mBrushTexture);
|
||||
emit passBrushShape(mBrushShape); // updates the icon tooltip
|
||||
}
|
||||
|
||||
void CSVWidget::TextureBrushWindow::setBrushSize(int brushSize)
|
||||
|
|
Loading…
Reference in a new issue