Cleanup. Also modify ltex index generation.

pull/1427/head
Kyle Cooley 7 years ago
parent 97d0fd756a
commit 99e90ef808

@ -278,6 +278,7 @@ void CSMPrefs::State::declare()
declareShortcut ("table-edit", "Edit Record", QKeySequence());
declareShortcut ("table-add", "Add Row/Record", QKeySequence(Qt::ShiftModifier | Qt::Key_A));
declareShortcut ("table-clone", "Clone Record", QKeySequence(Qt::ShiftModifier | Qt::Key_D));
declareShortcut ("touch-record", "Touch Record", QKeySequence());
declareShortcut ("table-revert", "Revert Record", QKeySequence());
declareShortcut ("table-remove", "Remove Row/Record", QKeySequence(Qt::Key_Delete));
declareShortcut ("table-moveup", "Move Record Up", QKeySequence());

@ -48,8 +48,6 @@ namespace CSMWorld
Land::parseUniqueRecordId(id, x, y);
record.mX = x;
record.mY = y;
// TODO check for uses of mId and remove them
record.mId = id;
}
template<>

@ -63,6 +63,13 @@ namespace CSMWorld
}
};
template<>
inline QVariant StringIdColumn<Land>::get(const Record<Land>& record) const
{
const Land& land = record.get();
return QString(Land::createUniqueRecordId(land.mX, land.mY).c_str());
}
template<>
inline QVariant StringIdColumn<LandTexture>::get(const Record<LandTexture>& record) const
{
@ -2483,7 +2490,7 @@ namespace CSMWorld
return -1;
}
virtual bool isEditable() const override
bool isEditable() const override
{
return false;
}

@ -333,6 +333,11 @@ namespace CSMWorld
{ ColumnId_TextureHandle, "Texture Handle" },
{ ColumnId_PluginIndex, "Plugin Index" },
{ ColumnId_TextureIndex, "Texture Index" },
{ ColumnId_LandMapLodIndex, "Land map height LOD" },
{ ColumnId_LandNormalsIndex, "Land normals" },
{ ColumnId_LandHeightsIndex, "Land heights" },
{ ColumnId_LandColoursIndex, "Land colors" },
{ ColumnId_LandTexturesIndex, "Land textures" },
{ ColumnId_UseValue1, "Use value 1" },
{ ColumnId_UseValue2, "Use value 2" },

@ -1,5 +1,6 @@
#include "idtable.hpp"
#include <cstdint>
#include <limits>
#include <stdexcept>
@ -379,11 +380,10 @@ CSMWorld::LandTextureIdTable::ImportResults CSMWorld::LandTextureIdTable::import
}
// Determine next index. Spread out the indices to reduce conflicts.
size_t MaxIndex = std::numeric_limits<uint16_t>::max();
size_t Prime = (1 << 19) - 1; // A mersenne prime
size_t K = 2154;
size_t MaxIndex = std::numeric_limits<uint16_t>::max() - 1;
size_t Prime = (1 << 13) - 1; // A mersenne prime
index = ((K * index) % Prime) % MaxIndex;
index = (index + Prime) % MaxIndex;
} while (true);
}

@ -8,8 +8,6 @@ namespace CSMWorld
void Land::load(ESM::ESMReader &esm, bool &isDeleted)
{
ESM::Land::load(esm, isDeleted);
mId = createUniqueRecordId(mX, mY);
}
std::string Land::createUniqueRecordId(int x, int y)

@ -12,8 +12,6 @@ namespace CSMWorld
/// \todo Add worldspace support to the Land record.
struct Land : public ESM::Land
{
std::string mId;
/// Loads the metadata and ID
void load (ESM::ESMReader &esm, bool &isDeleted);

@ -1,6 +1,6 @@
#include "landtexture.hpp"
#include <string>
#include <sstream>
#include <stdexcept>
#include <components/esm/esmreader.hpp>
@ -16,7 +16,9 @@ namespace CSMWorld
std::string LandTexture::createUniqueRecordId(int plugin, int index)
{
return 'L' + std::to_string(plugin) + '#' + std::to_string(index);
std::stringstream ss;
ss << 'L' << plugin << '#' << index;
return ss.str();
}
void LandTexture::parseUniqueRecordId(const std::string& id, int& plugin, int& index)

@ -2,6 +2,9 @@
#include <limits>
#include <QLabel>
#include <QSpinBox>
#include "../../model/world/commands.hpp"
#include "../../model/world/idtable.hpp"
#include "../../model/world/land.hpp"

@ -1,11 +1,11 @@
#ifndef CSV_WORLD_LANDCREATOR_H
#define CSV_WORLD_LANDCREATOR_H
#include <QLabel>
#include <QSpinBox>
#include "genericcreator.hpp"
class QLabel;
class QSpinBox;
namespace CSVWorld
{
class LandCreator : public GenericCreator

@ -3,9 +3,9 @@
#include <cstdint>
#include <limits>
#include <QIntValidator>
#include <QLabel>
#include <QLineEdit>
#include <QSpinBox>
#include "../../model/world/commands.hpp"
#include "../../model/world/idtable.hpp"
@ -30,14 +30,13 @@ namespace CSVWorld
QLabel* indexLabel = new QLabel("Index");
insertBeforeButtons(indexLabel, false);
QIntValidator* indexValidator = new QIntValidator(0, MaxIndex, this);
mIndexEdit = new QLineEdit(this);
mIndexEdit->setValidator(indexValidator);
insertBeforeButtons(mIndexEdit, true);
mIndexBox = new QSpinBox(this);
mIndexBox->setMinimum(0);
mIndexBox->setMaximum(MaxIndex);
insertBeforeButtons(mIndexBox, true);
connect(mNameEdit, SIGNAL(textChanged(const QString&)), this, SLOT(nameChanged(const QString&)));
connect(mIndexEdit, SIGNAL(textChanged(const QString&)), this, SLOT(indexChanged(const QString&)));
connect(mIndexBox, SIGNAL(valueChanged(int)), this, SLOT(indexChanged(int)));
}
void LandTextureCreator::cloneMode(const std::string& originId, const CSMWorld::UniversalId::Type type)
@ -50,26 +49,23 @@ namespace CSVWorld
mNameEdit->setText((table.data(table.getModelIndex(originId, column)).toString()));
column = table.findColumnIndex(CSMWorld::Columns::ColumnId_TextureIndex);
mIndexEdit->setText((table.data(table.getModelIndex(originId, column)).toString()));
mIndexBox->setValue((table.data(table.getModelIndex(originId, column)).toInt()));
}
void LandTextureCreator::focus()
{
mIndexEdit->setFocus();
mIndexBox->setFocus();
}
void LandTextureCreator::reset()
{
GenericCreator::reset();
mNameEdit->setText("");
mIndexEdit->setText("");
mIndexBox->setValue(0);
}
std::string LandTextureCreator::getErrors() const
{
std::string id = getId();
// TODO empty index edit?
if (getData().getLandTextures().searchId(getId()) >= 0)
{
return "Index is already in use";
@ -89,7 +85,7 @@ namespace CSVWorld
std::string LandTextureCreator::getId() const
{
return CSMWorld::LandTexture::createUniqueRecordId(0, mIndex);
return CSMWorld::LandTexture::createUniqueRecordId(0, mIndexBox->value());
}
void LandTextureCreator::nameChanged(const QString& value)
@ -98,9 +94,8 @@ namespace CSVWorld
update();
}
void LandTextureCreator::indexChanged(const QString& value)
void LandTextureCreator::indexChanged(int value)
{
mIndex = value.toInt();
update();
}
}

@ -6,6 +6,7 @@
#include "genericcreator.hpp"
class QLineEdit;
class QSpinBox;
namespace CSVWorld
{
@ -34,15 +35,14 @@ namespace CSVWorld
private slots:
void nameChanged(const QString& val);
void indexChanged(const QString& val);
void indexChanged(int val);
private:
QLineEdit* mNameEdit;
QLineEdit* mIndexEdit;
QSpinBox* mIndexBox;
std::string mName;
int mIndex;
};
}

Loading…
Cancel
Save