diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index 77d850861..0ce0bcd9b 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -1,7 +1,7 @@ #include "terraintexturemode.hpp" -#include "editmode.hpp" #include +#include #include #include @@ -16,14 +16,11 @@ #include #include +#include + #include "../widget/modebutton.hpp" #include "../widget/scenetoolbar.hpp" -#include "pagedworldspacewidget.hpp" -#include "mask.hpp" -#include "object.hpp" // Something small needed regarding pointers from here () -#include "worldspacewidget.hpp" - #include "../../model/doc/document.hpp" #include "../../model/world/columnbase.hpp" #include "../../model/world/commandmacro.hpp" @@ -36,8 +33,11 @@ #include "../../model/world/tablemimedata.hpp" #include "../../model/world/universalid.hpp" - -#include +#include "editmode.hpp" +#include "pagedworldspacewidget.hpp" +#include "mask.hpp" +#include "object.hpp" // Something small needed regarding pointers from here () +#include "worldspacewidget.hpp" CSVRender::BrushSizeControls::BrushSizeControls(const QString &title, QWidget *parent) @@ -68,7 +68,10 @@ CSVRender::TextureBrushButton::TextureBrushButton (const QIcon & icon, const QSt } CSVRender::TextureBrushWindow::TextureBrushWindow(WorldspaceWidget *worldspaceWidget, QWidget *parent) - : QFrame(parent, Qt::Popup), mWorldspaceWidget (worldspaceWidget) + : QFrame(parent, Qt::Popup), + mWorldspaceWidget (worldspaceWidget), + mBrushSize(0), + mBrushShape(0) { mBrushTextureLabel = "Brush: " + mBrushTexture; selectedBrush = new QLabel(QString::fromUtf8(mBrushTextureLabel.c_str()), this); @@ -116,7 +119,7 @@ CSVRender::TextureBrushWindow::TextureBrushWindow(WorldspaceWidget *worldspaceWi connect(sizeSliders->brushSizeSlider, SIGNAL(valueChanged(int)), parent, SLOT(setBrushSize(int))); - connect(parent, SIGNAL(passBrushTexture(std::string)), this, SLOT(getBrushTexture(std::string))); + connect(parent, SIGNAL(passBrushTexture(std::string)), this, SLOT(setBrushTexture(std::string))); } void CSVRender::TextureBrushWindow::configureButtonInitialSettings(TextureBrushButton *button) @@ -129,7 +132,7 @@ void CSVRender::TextureBrushWindow::configureButtonInitialSettings(TextureBrushB button->setCheckable(true); } -void CSVRender::TextureBrushWindow::getBrushTexture(std::string brushTexture) +void CSVRender::TextureBrushWindow::setBrushTexture(std::string brushTexture) { mBrushTexture = brushTexture; mBrushTextureLabel = "Brush:" + mBrushTexture; @@ -152,8 +155,11 @@ void CSVRender::TextureBrushWindow::setBrushShape() } CSVRender::TerrainTextureMode::TerrainTextureMode (WorldspaceWidget *worldspaceWidget, QWidget *parent) -: EditMode (worldspaceWidget, QIcon {":scenetoolbar/editing-terrain-texture"}, Mask_Terrain | Mask_Reference, "Terrain texture editing", parent) -, textureBrushWindow(new TextureBrushWindow(worldspaceWidget, this)) +: EditMode (worldspaceWidget, QIcon {":scenetoolbar/editing-terrain-texture"}, Mask_Terrain | Mask_Reference, "Terrain texture editing", parent), + textureBrushWindow(new TextureBrushWindow(worldspaceWidget, this)), + mBrushTexture("#0"), + mBrushSize(0), + mBrushShape(0) { connect(parent, SIGNAL(passEvent(QDragEnterEvent*)), this, SLOT(handleDragEnterEvent(QDragEnterEvent*))); connect(parent, SIGNAL(passEvent(QDropEvent*)), this, SLOT(handleDropEvent(QDropEvent*))); @@ -245,13 +251,12 @@ void CSVRender::TerrainTextureMode::handleDropEvent (QDropEvent *event) { void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitResult& hit) { mCellId = getWorldspaceWidget().getCellId (hit.worldPos); - std::string hash = "#"; - std::string space = " "; - std::size_t hashlocation = mCellId.find(hash); - std::size_t spacelocation = mCellId.find(space); - std::string slicedX = mCellId.substr (hashlocation+1, spacelocation-hashlocation); - std::string slicedY = mCellId.substr (spacelocation+1); - CSMWorld::CellCoordinates mCoordinates(stoi(slicedX), stoi(slicedY)); + + std::istringstream streamCoord (mCellId); + char ignore; + int cellX = 0; + int cellY = 0; + streamCoord >> ignore >> cellX >> cellY; CSMDoc::Document& document = getWorldspaceWidget().getDocument(); CSMWorld::IdTable& landTable = dynamic_cast ( @@ -263,10 +268,10 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe CSMWorld::LandTexturesColumn::DataType mPointer = landTable.data(landTable.getModelIndex(mCellId, textureColumn)).value(); CSMWorld::LandTexturesColumn::DataType mNew(mPointer); - int xInCell ((hit.worldPos.x() - (stoi(slicedX)* cellSize)) * landTextureSize / cellSize); - int yInCell ((hit.worldPos.y() - (stoi(slicedY)* cellSize)) * landTextureSize / cellSize); + int xInCell ((hit.worldPos.x() - (cellX* cellSize)) * landTextureSize / cellSize); + int yInCell ((hit.worldPos.y() - (cellY* cellSize)) * landTextureSize / cellSize); - hashlocation = mBrushTexture.find(hash); + std::size_t hashlocation = mBrushTexture.find("#"); std::string mBrushTextureInt = mBrushTexture.substr (hashlocation+1); int brushInt = stoi(mBrushTexture.substr (hashlocation+1))+1; // All indices are offset by +1 @@ -307,11 +312,9 @@ void CSVRender::TerrainTextureMode::editTerrainTextureGrid(const WorldspaceHitRe CSMWorld::CommandMacro macro (document.getUndoStack(), "Edit texture records"); QModelIndex index(landTable.getModelIndex (mCellId, landTable.findColumnIndex (CSMWorld::Columns::ColumnId_LandTexturesIndex))); - - CSMWorld::TouchLandCommand* ltexTouch = new CSMWorld::TouchLandCommand(landTable, ltexTable, mCellId); - CSMWorld::ModifyCommand* ltexModify = new CSMWorld::ModifyCommand(landTable, index, changedLand); - macro.push (ltexTouch); - macro.push (ltexModify); + + macro.push (new CSMWorld::TouchLandCommand(landTable, ltexTable, mCellId)); + macro.push (new CSMWorld::ModifyCommand(landTable, index, changedLand)); } void CSVRender::TerrainTextureMode::dragMoveEvent (QDragMoveEvent *event) { diff --git a/apps/opencs/view/render/terraintexturemode.hpp b/apps/opencs/view/render/terraintexturemode.hpp index 6b6eb6c63..7e991a8f0 100644 --- a/apps/opencs/view/render/terraintexturemode.hpp +++ b/apps/opencs/view/render/terraintexturemode.hpp @@ -64,16 +64,14 @@ namespace CSVRender private: QLabel *selectedBrush; QGroupBox *horizontalGroupBox; - int mButtonSize; - int mBrushSize = 0; - int mBrushShape = 0; - int mIconSize; WorldspaceWidget *mWorldspaceWidget; + int mBrushSize; + int mBrushShape; std::string mBrushTexture; std::string mBrushTextureLabel; public slots: - void getBrushTexture(std::string brushTexture); + void setBrushTexture(std::string brushTexture); void setBrushShape(); void setBrushSize(int brushSize); @@ -113,9 +111,9 @@ namespace CSVRender private: TextureBrushWindow *textureBrushWindow; std::string mCellId; - std::string mBrushTexture = "#0"; - int mBrushSize = 0; - int mBrushShape = 0; + std::string mBrushTexture; + int mBrushSize; + int mBrushShape; const int cellSize {ESM::Land::REAL_SIZE}; const int landSize {ESM::Land::LAND_SIZE};