mirror of
https://github.com/OpenMW/openmw.git
synced 2025-11-02 11:26:38 +00:00
Show skill name in CS
Instead of RefId converted to string. Show non StringRefId in deserializable format.
This commit is contained in:
parent
bd003f109e
commit
e08d1e2c87
2 changed files with 53 additions and 13 deletions
|
|
@ -8,10 +8,40 @@
|
||||||
|
|
||||||
#include <components/esm3/loadland.hpp>
|
#include <components/esm3/loadland.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace CSMWorld
|
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::LandTextureNicknameColumn()
|
LandTextureNicknameColumn::LandTextureNicknameColumn()
|
||||||
: Column<LandTexture>(Columns::ColumnId_TextureNickname, ColumnBase::Display_String)
|
: Column<LandTexture>(Columns::ColumnId_TextureNickname, ColumnBase::Display_String)
|
||||||
|
|
@ -299,4 +329,17 @@ namespace CSMWorld
|
||||||
{
|
{
|
||||||
return true;
|
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/loadskil.hpp>
|
||||||
#include <components/esm3/variant.hpp>
|
#include <components/esm3/variant.hpp>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
@ -31,6 +33,10 @@
|
||||||
|
|
||||||
namespace CSMWorld
|
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.
|
/// \note Shares ID with VarValueColumn. A table can not have both.
|
||||||
template <typename ESXRecordT>
|
template <typename ESXRecordT>
|
||||||
struct FloatValueColumn : public Column<ESXRecordT>
|
struct FloatValueColumn : public Column<ESXRecordT>
|
||||||
|
|
@ -63,7 +69,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
QVariant get(const Record<ESXRecordT>& record) const override
|
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; }
|
bool isEditable() const override { return false; }
|
||||||
|
|
@ -403,25 +409,16 @@ namespace CSMWorld
|
||||||
|
|
||||||
QVariant get(const Record<ESXRecordT>& record) const override
|
QVariant get(const Record<ESXRecordT>& record) const override
|
||||||
{
|
{
|
||||||
int skill = record.get().mData.getSkill(mIndex, mMajor);
|
return QString::fromStdString(ESM::Skill::sSkillNames[record.get().mData.getSkill(mIndex, mMajor)]);
|
||||||
|
|
||||||
return QString::fromStdString(ESM::Skill::indexToRefId(skill).toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void set(Record<ESXRecordT>& record, const QVariant& data) override
|
void set(Record<ESXRecordT>& record, const QVariant& data) override
|
||||||
{
|
{
|
||||||
std::istringstream stream(data.toString().toUtf8().constData());
|
if (const auto index = getSkillIndex(data.toString().toStdString()))
|
||||||
|
|
||||||
int index = -1;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
stream >> c >> index;
|
|
||||||
|
|
||||||
if (index != -1)
|
|
||||||
{
|
{
|
||||||
ESXRecordT record2 = record.get();
|
ESXRecordT record2 = record.get();
|
||||||
|
|
||||||
record2.mData.getSkill(mIndex, mMajor) = index;
|
record2.mData.getSkill(mIndex, mMajor) = static_cast<int>(*index);
|
||||||
|
|
||||||
record.setModified(record2);
|
record.setModified(record2);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue