mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 08:53:52 +00:00
added columns for enchantments
This commit is contained in:
parent
90bae2bead
commit
52d81dc9fa
2 changed files with 83 additions and 13 deletions
|
@ -223,11 +223,11 @@ namespace CSMWorld
|
||||||
InventoryColumns (const NameColumns& base) : NameColumns (base) {}
|
InventoryColumns (const NameColumns& base) : NameColumns (base) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief Adapter for IDs with names (all but levelled lists and statics)
|
/// \brief Adapter for IDs that can go into an inventory
|
||||||
template<typename RecordT>
|
template<typename RecordT>
|
||||||
class InventoryRefIdAdapter : public NameRefIdAdapter<RecordT>
|
class InventoryRefIdAdapter : public NameRefIdAdapter<RecordT>
|
||||||
{
|
{
|
||||||
InventoryColumns mName;
|
InventoryColumns mInventory;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ namespace CSMWorld
|
||||||
template<typename RecordT>
|
template<typename RecordT>
|
||||||
InventoryRefIdAdapter<RecordT>::InventoryRefIdAdapter (UniversalId::Type type,
|
InventoryRefIdAdapter<RecordT>::InventoryRefIdAdapter (UniversalId::Type type,
|
||||||
const InventoryColumns& columns)
|
const InventoryColumns& columns)
|
||||||
: NameRefIdAdapter<RecordT> (type, columns), mName (columns)
|
: NameRefIdAdapter<RecordT> (type, columns), mInventory (columns)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename RecordT>
|
template<typename RecordT>
|
||||||
|
@ -254,13 +254,13 @@ namespace CSMWorld
|
||||||
const Record<RecordT>& record = static_cast<const Record<RecordT>&> (
|
const Record<RecordT>& record = static_cast<const Record<RecordT>&> (
|
||||||
data.getRecord (RefIdData::LocalIndex (index, BaseRefIdAdapter<RecordT>::getType())));
|
data.getRecord (RefIdData::LocalIndex (index, BaseRefIdAdapter<RecordT>::getType())));
|
||||||
|
|
||||||
if (column==mName.mIcon)
|
if (column==mInventory.mIcon)
|
||||||
return QString::fromUtf8 (record.get().mIcon.c_str());
|
return QString::fromUtf8 (record.get().mIcon.c_str());
|
||||||
|
|
||||||
if (column==mName.mWeight)
|
if (column==mInventory.mWeight)
|
||||||
return record.get().mData.mWeight;
|
return record.get().mData.mWeight;
|
||||||
|
|
||||||
if (column==mName.mValue)
|
if (column==mInventory.mValue)
|
||||||
return record.get().mData.mValue;
|
return record.get().mData.mValue;
|
||||||
|
|
||||||
return NameRefIdAdapter<RecordT>::getData (column, data, index);
|
return NameRefIdAdapter<RecordT>::getData (column, data, index);
|
||||||
|
@ -273,11 +273,11 @@ namespace CSMWorld
|
||||||
Record<RecordT>& record = static_cast<Record<RecordT>&> (
|
Record<RecordT>& record = static_cast<Record<RecordT>&> (
|
||||||
data.getRecord (RefIdData::LocalIndex (index, BaseRefIdAdapter<RecordT>::getType())));
|
data.getRecord (RefIdData::LocalIndex (index, BaseRefIdAdapter<RecordT>::getType())));
|
||||||
|
|
||||||
if (column==mName.mIcon)
|
if (column==mInventory.mIcon)
|
||||||
record.get().mIcon = value.toString().toUtf8().constData();
|
record.get().mIcon = value.toString().toUtf8().constData();
|
||||||
else if (column==mName.mWeight)
|
else if (column==mInventory.mWeight)
|
||||||
record.get().mData.mWeight = value.toFloat();
|
record.get().mData.mWeight = value.toFloat();
|
||||||
else if (column==mName.mValue)
|
else if (column==mInventory.mValue)
|
||||||
record.get().mData.mValue = value.toInt();
|
record.get().mData.mValue = value.toInt();
|
||||||
else
|
else
|
||||||
NameRefIdAdapter<RecordT>::setData (column, data, index, value);
|
NameRefIdAdapter<RecordT>::setData (column, data, index, value);
|
||||||
|
@ -299,6 +299,69 @@ namespace CSMWorld
|
||||||
///< If the data type does not match an exception is thrown.
|
///< If the data type does not match an exception is thrown.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct EnchantableColumns : public InventoryColumns
|
||||||
|
{
|
||||||
|
const RefIdColumn *mEnchantment;
|
||||||
|
const RefIdColumn *mEnchantmentPoints;
|
||||||
|
|
||||||
|
EnchantableColumns (const InventoryColumns& base) : InventoryColumns (base) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// \brief Adapter for enchantable IDs
|
||||||
|
template<typename RecordT>
|
||||||
|
class EnchantableRefIdAdapter : public InventoryRefIdAdapter<RecordT>
|
||||||
|
{
|
||||||
|
EnchantableColumns mEnchantable;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
EnchantableRefIdAdapter (UniversalId::Type type, const EnchantableColumns& columns);
|
||||||
|
|
||||||
|
virtual QVariant getData (const RefIdColumn *column, const RefIdData& data, int index)
|
||||||
|
const;
|
||||||
|
|
||||||
|
virtual void setData (const RefIdColumn *column, RefIdData& data, int index,
|
||||||
|
const QVariant& value) const;
|
||||||
|
///< If the data type does not match an exception is thrown.
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename RecordT>
|
||||||
|
EnchantableRefIdAdapter<RecordT>::EnchantableRefIdAdapter (UniversalId::Type type,
|
||||||
|
const EnchantableColumns& columns)
|
||||||
|
: InventoryRefIdAdapter<RecordT> (type, columns), mEnchantable (columns)
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<typename RecordT>
|
||||||
|
QVariant EnchantableRefIdAdapter<RecordT>::getData (const RefIdColumn *column, const RefIdData& data,
|
||||||
|
int index) const
|
||||||
|
{
|
||||||
|
const Record<RecordT>& record = static_cast<const Record<RecordT>&> (
|
||||||
|
data.getRecord (RefIdData::LocalIndex (index, BaseRefIdAdapter<RecordT>::getType())));
|
||||||
|
|
||||||
|
if (column==mEnchantable.mEnchantment)
|
||||||
|
return QString::fromUtf8 (record.get().mEnchant.c_str());
|
||||||
|
|
||||||
|
if (column==mEnchantable.mEnchantmentPoints)
|
||||||
|
return static_cast<int> (record.get().mData.mEnchant);
|
||||||
|
|
||||||
|
return InventoryRefIdAdapter<RecordT>::getData (column, data, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename RecordT>
|
||||||
|
void EnchantableRefIdAdapter<RecordT>::setData (const RefIdColumn *column, RefIdData& data,
|
||||||
|
int index, const QVariant& value) const
|
||||||
|
{
|
||||||
|
Record<RecordT>& record = static_cast<Record<RecordT>&> (
|
||||||
|
data.getRecord (RefIdData::LocalIndex (index, BaseRefIdAdapter<RecordT>::getType())));
|
||||||
|
|
||||||
|
if (column==mEnchantable.mEnchantment)
|
||||||
|
record.get().mEnchant = value.toString().toUtf8().constData();
|
||||||
|
else if (column==mEnchantable.mEnchantmentPoints)
|
||||||
|
record.get().mData.mEnchant = value.toInt();
|
||||||
|
else
|
||||||
|
InventoryRefIdAdapter<RecordT>::setData (column, data, index, value);
|
||||||
|
}
|
||||||
|
|
||||||
class ApparatusRefIdAdapter : public InventoryRefIdAdapter<ESM::Apparatus>
|
class ApparatusRefIdAdapter : public InventoryRefIdAdapter<ESM::Apparatus>
|
||||||
{
|
{
|
||||||
const RefIdColumn *mType;
|
const RefIdColumn *mType;
|
||||||
|
|
|
@ -67,6 +67,13 @@ CSMWorld::RefIdCollection::RefIdCollection()
|
||||||
mColumns.push_back (RefIdColumn ("Value", ColumnBase::Display_Integer));
|
mColumns.push_back (RefIdColumn ("Value", ColumnBase::Display_Integer));
|
||||||
inventoryColumns.mValue = &mColumns.back();
|
inventoryColumns.mValue = &mColumns.back();
|
||||||
|
|
||||||
|
EnchantableColumns enchantableColumns (inventoryColumns);
|
||||||
|
|
||||||
|
mColumns.push_back (RefIdColumn ("Enchantment", ColumnBase::Display_String));
|
||||||
|
enchantableColumns.mEnchantment = &mColumns.back();
|
||||||
|
mColumns.push_back (RefIdColumn ("Enchantment Points", ColumnBase::Display_Integer));
|
||||||
|
enchantableColumns.mEnchantmentPoints = &mColumns.back();
|
||||||
|
|
||||||
mColumns.push_back (RefIdColumn ("Auto Calc", ColumnBase::Display_Boolean));
|
mColumns.push_back (RefIdColumn ("Auto Calc", ColumnBase::Display_Boolean));
|
||||||
const RefIdColumn *autoCalc = &mColumns.back();
|
const RefIdColumn *autoCalc = &mColumns.back();
|
||||||
|
|
||||||
|
@ -83,11 +90,11 @@ CSMWorld::RefIdCollection::RefIdCollection()
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Apparatus,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Apparatus,
|
||||||
new ApparatusRefIdAdapter (inventoryColumns, apparatusType, quality)));
|
new ApparatusRefIdAdapter (inventoryColumns, apparatusType, quality)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Armor,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Armor,
|
||||||
new InventoryRefIdAdapter<ESM::Armor> (UniversalId::Type_Armor, inventoryColumns)));
|
new EnchantableRefIdAdapter<ESM::Armor> (UniversalId::Type_Armor, enchantableColumns)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Book,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Book,
|
||||||
new InventoryRefIdAdapter<ESM::Book> (UniversalId::Type_Book, inventoryColumns)));
|
new EnchantableRefIdAdapter<ESM::Book> (UniversalId::Type_Book, enchantableColumns)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Clothing,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Clothing,
|
||||||
new InventoryRefIdAdapter<ESM::Clothing> (UniversalId::Type_Clothing, inventoryColumns)));
|
new EnchantableRefIdAdapter<ESM::Clothing> (UniversalId::Type_Clothing, enchantableColumns)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Container,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Container,
|
||||||
new NameRefIdAdapter<ESM::Container> (UniversalId::Type_Container, nameColumns)));
|
new NameRefIdAdapter<ESM::Container> (UniversalId::Type_Container, nameColumns)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Creature,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Creature,
|
||||||
|
@ -117,7 +124,7 @@ CSMWorld::RefIdCollection::RefIdCollection()
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Static,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Static,
|
||||||
new ModelRefIdAdapter<ESM::Static> (UniversalId::Type_Static, modelColumns)));
|
new ModelRefIdAdapter<ESM::Static> (UniversalId::Type_Static, modelColumns)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Weapon,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Weapon,
|
||||||
new InventoryRefIdAdapter<ESM::Weapon> (UniversalId::Type_Weapon, inventoryColumns)));
|
new EnchantableRefIdAdapter<ESM::Weapon> (UniversalId::Type_Weapon, enchantableColumns)));
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMWorld::RefIdCollection::~RefIdCollection()
|
CSMWorld::RefIdCollection::~RefIdCollection()
|
||||||
|
|
Loading…
Reference in a new issue