added skill columns to class

pull/16/head
Marc Zinnschlag 12 years ago
parent 65cda580db
commit ea3b14f2d2

@ -207,7 +207,7 @@ void CSMDoc::Document::createBase()
{
ESM::Skill record;
record.mIndex = i;
record.mId = ESM::Skill::getIndexToId (record.mIndex);
record.mId = ESM::Skill::indexToId (record.mIndex);
record.blank();
getData().getSkills().add (record);

@ -1,6 +1,8 @@
#ifndef CSM_WOLRD_COLUMNS_H
#define CSM_WOLRD_COLUMNS_H
#include <sstream>
#include <boost/lexical_cast.hpp>
#include "columnbase.hpp"
@ -338,6 +340,50 @@ namespace CSMWorld
return true;
}
};
template<typename ESXRecordT>
struct SkillsColumn : public Column<ESXRecordT>
{
int mIndex;
bool mMajor;
SkillsColumn (int index, bool major)
: Column<ESXRecordT> ((major ? "Major Skill #" : "Minor Skill #")+
boost::lexical_cast<std::string> (index), ColumnBase::Display_String),
mIndex (index), mMajor (major)
{}
virtual QVariant get (const Record<ESXRecordT>& record) const
{
int skill = record.get().mData.mSkills[mIndex][mMajor ? 1 : 0];
return QString::fromUtf8 (ESM::Skill::indexToId (skill).c_str());
}
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
{
std::istringstream stream (data.toString().toUtf8().constData());
int index = -1;
char c;
stream >> c >> index;
if (index!=-1)
{
ESXRecordT record2 = record.get();
record2.mData.mSkills[mIndex][mMajor ? 1 : 0] = index;
record.setModified (record2);
}
}
virtual bool isEditable() const
{
return true;
}
};
}
#endif

@ -50,6 +50,10 @@ CSMWorld::Data::Data()
mClasses.addColumn (new AttributesColumn<ESM::Class> (0));
mClasses.addColumn (new AttributesColumn<ESM::Class> (1));
mClasses.addColumn (new SpecialisationColumn<ESM::Class>);
for (int i=0; i<5; ++i)
mClasses.addColumn (new SkillsColumn<ESM::Class> (i, true));
for (int i=0; i<5; ++i)
mClasses.addColumn (new SkillsColumn<ESM::Class> (i, false));
mClasses.addColumn (new DescriptionColumn<ESM::Class>);
addModel (new IdTable (&mGlobals), UniversalId::Type_Globals, UniversalId::Type_Global);

@ -2,6 +2,8 @@
#include <sstream>
#include <components/misc/stringops.hpp>
#include "esmreader.hpp"
#include "esmwriter.hpp"
@ -103,8 +105,9 @@ void Skill::load(ESMReader &esm)
// create an ID from the index and the name (only used in the editor and likely to change in the
// future)
mId = getIndexToId (mIndex);
mId = indexToId (mIndex);
}
void Skill::save(ESMWriter &esm)
{
esm.writeHNT("INDX", mIndex);
@ -120,7 +123,7 @@ void Skill::save(ESMWriter &esm)
mDescription.clear();
}
std::string Skill::getIndexToId (int index)
std::string Skill::indexToId (int index)
{
std::ostringstream stream;

@ -79,7 +79,7 @@ struct Skill
void blank();
///< Set record to default state (does not touch the ID/index).
static std::string getIndexToId (int index);
static std::string indexToId (int index);
};
}
#endif

Loading…
Cancel
Save