Show skill name in CS

Instead of RefId converted to string.

Show non StringRefId in deserializable format.
depth-refraction
elsid 2 years ago
parent bd003f109e
commit e08d1e2c87
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -8,10 +8,40 @@
#include <components/esm3/loadland.hpp>
#include <algorithm>
#include <stdexcept>
namespace CSMWorld
{
namespace
{
struct GetStringId
{
std::string operator()(ESM::EmptyRefId /*value*/) const { return std::string(); }
std::string operator()(ESM::StringRefId value) const { return value.getValue(); }
std::string operator()(ESM::IndexRefId value) const
{
switch (value.getRecordType())
{
case ESM::REC_SKIL:
return ESM::Skill::sSkillNames[value.getValue()];
default:
break;
}
return value.toDebugString();
}
template <class T>
std::string operator()(const T& value) const
{
return value.toDebugString();
}
};
}
/* LandTextureNicknameColumn */
LandTextureNicknameColumn::LandTextureNicknameColumn()
: Column<LandTexture>(Columns::ColumnId_TextureNickname, ColumnBase::Display_String)
@ -299,4 +329,17 @@ namespace CSMWorld
{
return true;
}
std::optional<std::uint32_t> getSkillIndex(std::string_view value)
{
const auto it = std::find(std::begin(ESM::Skill::sSkillNames), std::end(ESM::Skill::sSkillNames), value);
if (it == std::end(ESM::Skill::sSkillNames))
return std::nullopt;
return static_cast<std::uint32_t>(it - std::begin(ESM::Skill::sSkillNames));
}
std::string getStringId(ESM::RefId value)
{
return visit(GetStringId{}, value);
}
}

@ -18,6 +18,8 @@
#include <components/esm3/loadskil.hpp>
#include <components/esm3/variant.hpp>
#include <optional>
#include <QString>
#include <QVariant>
#include <QVector>
@ -31,6 +33,10 @@
namespace CSMWorld
{
std::optional<std::uint32_t> getSkillIndex(std::string_view value);
std::string getStringId(ESM::RefId value);
/// \note Shares ID with VarValueColumn. A table can not have both.
template <typename ESXRecordT>
struct FloatValueColumn : public Column<ESXRecordT>
@ -63,7 +69,7 @@ namespace CSMWorld
QVariant get(const Record<ESXRecordT>& record) const override
{
return QString::fromStdString(record.get().mId.toString());
return QString::fromStdString(getStringId(record.get().mId));
}
bool isEditable() const override { return false; }
@ -403,25 +409,16 @@ namespace CSMWorld
QVariant get(const Record<ESXRecordT>& record) const override
{
int skill = record.get().mData.getSkill(mIndex, mMajor);
return QString::fromStdString(ESM::Skill::indexToRefId(skill).toString());
return QString::fromStdString(ESM::Skill::sSkillNames[record.get().mData.getSkill(mIndex, mMajor)]);
}
void set(Record<ESXRecordT>& record, const QVariant& data) override
{
std::istringstream stream(data.toString().toUtf8().constData());
int index = -1;
char c;
stream >> c >> index;
if (index != -1)
if (const auto index = getSkillIndex(data.toString().toStdString()))
{
ESXRecordT record2 = record.get();
record2.mData.getSkill(mIndex, mMajor) = index;
record2.mData.getSkill(mIndex, mMajor) = static_cast<int>(*index);
record.setModified(record2);
}

Loading…
Cancel
Save