mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 15:35:23 +00:00
Add ability to add pathgrids.
This commit is contained in:
parent
1781aaaa27
commit
b86250036c
@ -8,9 +8,11 @@
|
||||
#include <QAbstractItemModel>
|
||||
#include <QAbstractProxyModel>
|
||||
|
||||
#include "idcollection.hpp"
|
||||
#include "idtable.hpp"
|
||||
#include "idtree.hpp"
|
||||
#include "nestedtablewrapper.hpp"
|
||||
#include "pathgrid.hpp"
|
||||
|
||||
CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelIndex& index,
|
||||
const QVariant& new_, QUndoCommand* parent)
|
||||
@ -235,6 +237,35 @@ void CSMWorld::CloneCommand::undo()
|
||||
mModel.removeRow (mModel.getModelIndex (mId, 0).row());
|
||||
}
|
||||
|
||||
CSMWorld::CreatePathgridCommand::CreatePathgridCommand(IdTable& model, const std::string& id, QUndoCommand *parent)
|
||||
: CreateCommand(model, id, parent)
|
||||
{
|
||||
setType(UniversalId::Type_Pathgrid);
|
||||
}
|
||||
|
||||
void CSMWorld::CreatePathgridCommand::redo()
|
||||
{
|
||||
CreateCommand::redo();
|
||||
|
||||
Record<Pathgrid> record = static_cast<const Record<Pathgrid>& >(mModel.getRecord(mId));
|
||||
record.get().blank();
|
||||
record.get().mCell = mId;
|
||||
|
||||
if (!mId.empty() && mId[0]=='#')
|
||||
{
|
||||
int x, y;
|
||||
char ignore;
|
||||
|
||||
std::istringstream stream (mId);
|
||||
if (stream >> ignore >> x >> y)
|
||||
{
|
||||
record.get().mData.mX = x;
|
||||
record.get().mData.mY = y;
|
||||
}
|
||||
}
|
||||
|
||||
mModel.setRecord(mId, record, mType);
|
||||
}
|
||||
|
||||
CSMWorld::UpdateCellCommand::UpdateCellCommand (IdTable& model, int row, QUndoCommand *parent)
|
||||
: QUndoCommand (parent), mModel (model), mRow (row)
|
||||
|
@ -153,6 +153,15 @@ namespace CSMWorld
|
||||
virtual void undo();
|
||||
};
|
||||
|
||||
class CreatePathgridCommand : public CreateCommand
|
||||
{
|
||||
public:
|
||||
|
||||
CreatePathgridCommand(IdTable& model, const std::string& id, QUndoCommand *parent = 0);
|
||||
|
||||
virtual void redo();
|
||||
};
|
||||
|
||||
/// \brief Update cell ID according to x/y-coordinates
|
||||
///
|
||||
/// \note The new value will be calculated in the first call to redo instead of the
|
||||
|
@ -241,6 +241,10 @@ namespace CSVRender
|
||||
|
||||
void Pathgrid::applyPoint(CSMWorld::CommandMacro& commands, const osg::Vec3d& worldPos)
|
||||
{
|
||||
|
||||
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
|
||||
CSMWorld::UniversalId::Type_Pathgrids));
|
||||
|
||||
const CSMWorld::Pathgrid* source = getPathgridSource();
|
||||
if (source)
|
||||
{
|
||||
@ -250,9 +254,6 @@ namespace CSVRender
|
||||
int posY = clampToCell(static_cast<int>(localCoords.y()));
|
||||
int posZ = clampToCell(static_cast<int>(localCoords.z()));
|
||||
|
||||
CSMWorld::IdTree* model = dynamic_cast<CSMWorld::IdTree*>(mData.getTableModel(
|
||||
CSMWorld::UniversalId::Type_Pathgrids));
|
||||
|
||||
int recordIndex = mPathgridCollection.getIndex (mId);
|
||||
int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridPoints);
|
||||
|
||||
@ -269,14 +270,15 @@ namespace CSVRender
|
||||
int row = static_cast<int>(source->mPoints.size());
|
||||
|
||||
// Add node
|
||||
commands.push (new CSMWorld::AddNestedCommand(*model, mId, row, parentColumn));
|
||||
commands.push (new CSMWorld::ModifyCommand(*model, model->index(row, posXColumn, parent), posX));
|
||||
commands.push (new CSMWorld::ModifyCommand(*model, model->index(row, posYColumn, parent), posY));
|
||||
commands.push (new CSMWorld::ModifyCommand(*model, model->index(row, posZColumn, parent), posZ));
|
||||
commands.push(new CSMWorld::AddNestedCommand(*model, mId, row, parentColumn));
|
||||
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posXColumn, parent), posX));
|
||||
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posYColumn, parent), posY));
|
||||
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posZColumn, parent), posZ));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create pathgrid TODO
|
||||
CSMWorld::CreatePathgridCommand* createCmd = new CSMWorld::CreatePathgridCommand(*model, mId);
|
||||
commands.push(createCmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user