1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 05:53:54 +00:00
openmw/apps/opencs/model/world/columnimp.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

303 lines
7.8 KiB
C++
Raw Normal View History

#include "columnimp.hpp"
2022-10-19 17:02:00 +00:00
#include <apps/opencs/model/world/columnbase.hpp>
#include <apps/opencs/model/world/columns.hpp>
#include <apps/opencs/model/world/land.hpp>
#include <apps/opencs/model/world/landtexture.hpp>
#include <apps/opencs/model/world/record.hpp>
#include <components/esm3/loadland.hpp>
#include <stdexcept>
2017-09-04 00:00:19 +00:00
namespace CSMWorld
{
/* LandTextureNicknameColumn */
LandTextureNicknameColumn::LandTextureNicknameColumn()
: Column<LandTexture>(Columns::ColumnId_TextureNickname, ColumnBase::Display_String)
{
}
QVariant LandTextureNicknameColumn::get(const Record<LandTexture>& record) const
{
return QString::fromUtf8(record.get().mId.getRefIdString().c_str());
}
void LandTextureNicknameColumn::set(Record<LandTexture>& record, const QVariant& data)
{
LandTexture copy = record.get();
copy.mId = ESM::RefId::stringRefId(data.toString().toUtf8().constData());
record.setModified(copy);
}
bool LandTextureNicknameColumn::isEditable() const
{
return true;
}
/* LandTextureIndexColumn */
LandTextureIndexColumn::LandTextureIndexColumn()
: Column<LandTexture>(Columns::ColumnId_TextureIndex, ColumnBase::Display_Integer)
{
}
QVariant LandTextureIndexColumn::get(const Record<LandTexture>& record) const
{
return record.get().mIndex;
}
bool LandTextureIndexColumn::isEditable() const
{
return false;
}
/* LandPluginIndexColumn */
LandPluginIndexColumn::LandPluginIndexColumn()
: Column<Land>(Columns::ColumnId_PluginIndex, ColumnBase::Display_Integer, 0)
{
}
QVariant LandPluginIndexColumn::get(const Record<Land>& record) const
{
return record.get().getPlugin();
}
bool LandPluginIndexColumn::isEditable() const
{
return false;
}
/* LandTexturePluginIndexColumn */
LandTexturePluginIndexColumn::LandTexturePluginIndexColumn()
: Column<LandTexture>(Columns::ColumnId_PluginIndex, ColumnBase::Display_Integer, 0)
{
}
QVariant LandTexturePluginIndexColumn::get(const Record<LandTexture>& record) const
{
return record.get().mPluginIndex;
}
bool LandTexturePluginIndexColumn::isEditable() const
{
return false;
}
2017-09-04 00:00:19 +00:00
/* LandNormalsColumn */
LandNormalsColumn::LandNormalsColumn()
: Column<Land>(Columns::ColumnId_LandNormalsIndex, ColumnBase::Display_String, 0)
{
}
QVariant LandNormalsColumn::get(const Record<Land>& record) const
{
const int Size = Land::LAND_NUM_VERTS * 3;
const Land& land = record.get();
2017-09-04 00:00:19 +00:00
2017-09-23 01:29:40 +00:00
DataType values(Size, 0);
if (land.isDataLoaded(Land::DATA_VNML))
{
2017-09-23 01:29:40 +00:00
for (int i = 0; i < Size; ++i)
values[i] = land.getLandData()->mNormals[i];
}
2017-09-23 01:29:40 +00:00
QVariant variant;
variant.setValue(values);
return variant;
2017-09-04 00:00:19 +00:00
}
void LandNormalsColumn::set(Record<Land>& record, const QVariant& data)
{
2017-09-23 01:29:40 +00:00
DataType values = data.value<DataType>();
2017-09-23 01:29:40 +00:00
if (values.size() != Land::LAND_NUM_VERTS * 3)
throw std::runtime_error("invalid land normals data");
2017-09-04 00:00:19 +00:00
Land copy = record.get();
copy.add(Land::DATA_VNML);
2017-09-23 01:29:40 +00:00
for (int i = 0; i < values.size(); ++i)
2017-09-04 00:00:19 +00:00
{
2017-09-23 01:29:40 +00:00
copy.getLandData()->mNormals[i] = values[i];
2017-09-04 00:00:19 +00:00
}
record.setModified(copy);
}
bool LandNormalsColumn::isEditable() const
{
return true;
}
/* LandHeightsColumn */
LandHeightsColumn::LandHeightsColumn()
: Column<Land>(Columns::ColumnId_LandHeightsIndex, ColumnBase::Display_String, 0)
{
}
QVariant LandHeightsColumn::get(const Record<Land>& record) const
{
2017-09-23 01:29:40 +00:00
const int Size = Land::LAND_NUM_VERTS;
const Land& land = record.get();
2017-09-04 00:00:19 +00:00
2017-09-23 01:29:40 +00:00
DataType values(Size, 0);
if (land.isDataLoaded(Land::DATA_VHGT))
{
2017-09-23 01:29:40 +00:00
for (int i = 0; i < Size; ++i)
values[i] = land.getLandData()->mHeights[i];
}
2017-09-23 01:29:40 +00:00
QVariant variant;
variant.setValue(values);
return variant;
2017-09-04 00:00:19 +00:00
}
void LandHeightsColumn::set(Record<Land>& record, const QVariant& data)
{
2017-09-23 01:29:40 +00:00
DataType values = data.value<DataType>();
2017-09-23 01:29:40 +00:00
if (values.size() != Land::LAND_NUM_VERTS)
throw std::runtime_error("invalid land heights data");
2017-09-04 00:00:19 +00:00
Land copy = record.get();
copy.add(Land::DATA_VHGT);
2017-09-23 01:29:40 +00:00
for (int i = 0; i < values.size(); ++i)
2017-09-04 00:00:19 +00:00
{
2017-09-23 01:29:40 +00:00
copy.getLandData()->mHeights[i] = values[i];
2017-09-04 00:00:19 +00:00
}
record.setModified(copy);
}
bool LandHeightsColumn::isEditable() const
{
return true;
}
/* LandColoursColumn */
LandColoursColumn::LandColoursColumn()
: Column<Land>(Columns::ColumnId_LandColoursIndex, ColumnBase::Display_String, 0)
{
}
QVariant LandColoursColumn::get(const Record<Land>& record) const
{
const int Size = Land::LAND_NUM_VERTS * 3;
const Land& land = record.get();
2017-09-04 00:00:19 +00:00
2017-09-23 01:29:40 +00:00
DataType values(Size, 0);
if (land.isDataLoaded(Land::DATA_VCLR))
{
2017-09-23 01:29:40 +00:00
for (int i = 0; i < Size; ++i)
values[i] = land.getLandData()->mColours[i];
}
2017-09-23 01:29:40 +00:00
QVariant variant;
variant.setValue(values);
return variant;
2017-09-04 00:00:19 +00:00
}
void LandColoursColumn::set(Record<Land>& record, const QVariant& data)
{
2017-09-23 01:29:40 +00:00
DataType values = data.value<DataType>();
2017-09-23 01:29:40 +00:00
if (values.size() != Land::LAND_NUM_VERTS * 3)
throw std::runtime_error("invalid land colours data");
2017-09-04 00:00:19 +00:00
Land copy = record.get();
copy.add(Land::DATA_VCLR);
2017-09-23 01:29:40 +00:00
for (int i = 0; i < values.size(); ++i)
2017-09-04 00:00:19 +00:00
{
2017-09-23 01:29:40 +00:00
copy.getLandData()->mColours[i] = values[i];
2017-09-04 00:00:19 +00:00
}
record.setModified(copy);
}
bool LandColoursColumn::isEditable() const
{
return true;
}
/* LandTexturesColumn */
LandTexturesColumn::LandTexturesColumn()
: Column<Land>(Columns::ColumnId_LandTexturesIndex, ColumnBase::Display_String, 0)
{
}
QVariant LandTexturesColumn::get(const Record<Land>& record) const
{
2017-09-23 01:29:40 +00:00
const int Size = Land::LAND_NUM_TEXTURES;
const Land& land = record.get();
2017-09-04 00:00:19 +00:00
2017-09-23 01:29:40 +00:00
DataType values(Size, 0);
if (land.isDataLoaded(Land::DATA_VTEX))
{
2017-09-23 01:29:40 +00:00
for (int i = 0; i < Size; ++i)
values[i] = land.getLandData()->mTextures[i];
}
2017-09-23 01:29:40 +00:00
QVariant variant;
variant.setValue(values);
return variant;
2017-09-04 00:00:19 +00:00
}
void LandTexturesColumn::set(Record<Land>& record, const QVariant& data)
{
2017-09-23 01:29:40 +00:00
DataType values = data.value<DataType>();
2017-09-23 01:29:40 +00:00
if (values.size() != Land::LAND_NUM_TEXTURES)
throw std::runtime_error("invalid land textures data");
2017-09-04 00:00:19 +00:00
Land copy = record.get();
copy.add(Land::DATA_VTEX);
2017-09-23 01:29:40 +00:00
for (int i = 0; i < values.size(); ++i)
2017-09-04 00:00:19 +00:00
{
2017-09-23 01:29:40 +00:00
copy.getLandData()->mTextures[i] = values[i];
2017-09-04 00:00:19 +00:00
}
record.setModified(copy);
}
bool LandTexturesColumn::isEditable() const
{
return true;
}
/* BodyPartRaceColumn */
BodyPartRaceColumn::BodyPartRaceColumn(const MeshTypeColumn<ESM::BodyPart>* meshType)
: mMeshType(meshType)
{
}
QVariant BodyPartRaceColumn::get(const Record<ESM::BodyPart>& record) const
{
2018-10-09 06:21:12 +00:00
if (mMeshType != nullptr && mMeshType->get(record) == ESM::BodyPart::MT_Skin)
2017-09-04 00:00:19 +00:00
{
return QString::fromUtf8(record.get().mRace.getRefIdString().c_str());
2017-09-04 00:00:19 +00:00
}
return QVariant(QVariant::UserType);
}
void BodyPartRaceColumn::set(Record<ESM::BodyPart>& record, const QVariant& data)
{
ESM::BodyPart record2 = record.get();
record2.mRace = ESM::RefId::stringRefId(data.toString().toUtf8().constData());
2017-09-04 00:00:19 +00:00
record.setModified(record2);
}
bool BodyPartRaceColumn::isEditable() const
{
return true;
}
}