mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-05 15:40:10 +00:00
Merge branch 'cs_fix_skill_edit' into 'master'
Show skill name in CS (#7299) Closes #7299 See merge request OpenMW/openmw!2887
This commit is contained in:
commit
de26662c98
@ -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…
x
Reference in New Issue
Block a user