mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
Fix editing ingredient effects sub-table. Should resolve bug #2978.
This commit is contained in:
parent
843225996c
commit
9f0e059a15
3 changed files with 203 additions and 1 deletions
|
@ -52,6 +52,133 @@ void CSMWorld::PotionRefIdAdapter::setData (const RefIdColumn *column, RefIdData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CSMWorld::IngredientColumns::IngredientColumns (const InventoryColumns& columns)
|
||||||
|
: InventoryColumns (columns) {}
|
||||||
|
|
||||||
|
CSMWorld::IngredientRefIdAdapter::IngredientRefIdAdapter (const IngredientColumns& columns)
|
||||||
|
: InventoryRefIdAdapter<ESM::Ingredient> (UniversalId::Type_Ingredient, columns),
|
||||||
|
mColumns(columns)
|
||||||
|
{}
|
||||||
|
|
||||||
|
QVariant CSMWorld::IngredientRefIdAdapter::getData (const RefIdColumn *column, const RefIdData& data,
|
||||||
|
int index) const
|
||||||
|
{
|
||||||
|
const Record<ESM::Ingredient>& record = static_cast<const Record<ESM::Ingredient>&> (
|
||||||
|
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Ingredient)));
|
||||||
|
|
||||||
|
if (column==mColumns.mEffects)
|
||||||
|
return true; // to show nested tables in dialogue subview, see IdTree::hasChildren()
|
||||||
|
|
||||||
|
return InventoryRefIdAdapter<ESM::Ingredient>::getData (column, data, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMWorld::IngredientRefIdAdapter::setData (const RefIdColumn *column, RefIdData& data, int index,
|
||||||
|
const QVariant& value) const
|
||||||
|
{
|
||||||
|
InventoryRefIdAdapter<ESM::Ingredient>::setData (column, data, index, value);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CSMWorld::IngredEffectRefIdAdapter::IngredEffectRefIdAdapter()
|
||||||
|
: mType(UniversalId::Type_Ingredient)
|
||||||
|
{}
|
||||||
|
|
||||||
|
CSMWorld::IngredEffectRefIdAdapter::~IngredEffectRefIdAdapter()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void CSMWorld::IngredEffectRefIdAdapter::addNestedRow (const RefIdColumn *column,
|
||||||
|
RefIdData& data, int index, int position) const
|
||||||
|
{
|
||||||
|
// Do nothing, this table cannot be changed by the user
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMWorld::IngredEffectRefIdAdapter::removeNestedRow (const RefIdColumn *column,
|
||||||
|
RefIdData& data, int index, int rowToRemove) const
|
||||||
|
{
|
||||||
|
// Do nothing, this table cannot be changed by the user
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMWorld::IngredEffectRefIdAdapter::setNestedTable (const RefIdColumn* column,
|
||||||
|
RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) const
|
||||||
|
{
|
||||||
|
Record<ESM::Ingredient>& record =
|
||||||
|
static_cast<Record<ESM::Ingredient>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
|
||||||
|
ESM::Ingredient ingredient = record.get();
|
||||||
|
|
||||||
|
ingredient.mData =
|
||||||
|
static_cast<const NestedTableWrapper<std::vector<typename ESM::Ingredient::IRDTstruct> >&>(nestedTable).mNestedTable.at(0);
|
||||||
|
|
||||||
|
record.setModified (ingredient);
|
||||||
|
}
|
||||||
|
|
||||||
|
CSMWorld::NestedTableWrapperBase* CSMWorld::IngredEffectRefIdAdapter::nestedTable (const RefIdColumn* column,
|
||||||
|
const RefIdData& data, int index) const
|
||||||
|
{
|
||||||
|
const Record<ESM::Ingredient>& record =
|
||||||
|
static_cast<const Record<ESM::Ingredient>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
|
||||||
|
|
||||||
|
// return the whole struct
|
||||||
|
std::vector<typename ESM::Ingredient::IRDTstruct> wrap;
|
||||||
|
wrap.push_back(record.get().mData);
|
||||||
|
|
||||||
|
// deleted by dtor of NestedTableStoring
|
||||||
|
return new NestedTableWrapper<std::vector<typename ESM::Ingredient::IRDTstruct> >(wrap);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CSMWorld::IngredEffectRefIdAdapter::getNestedData (const RefIdColumn *column,
|
||||||
|
const RefIdData& data, int index, int subRowIndex, int subColIndex) const
|
||||||
|
{
|
||||||
|
const Record<ESM::Ingredient>& record =
|
||||||
|
static_cast<const Record<ESM::Ingredient>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
|
||||||
|
|
||||||
|
if (subRowIndex < 0 || subRowIndex >= 4)
|
||||||
|
throw std::runtime_error ("index out of range");
|
||||||
|
|
||||||
|
switch (subColIndex)
|
||||||
|
{
|
||||||
|
case 0: return record.get().mData.mEffectID[subRowIndex];
|
||||||
|
case 1: return record.get().mData.mSkills[subRowIndex];
|
||||||
|
case 2: return record.get().mData.mAttributes[subRowIndex];
|
||||||
|
default:
|
||||||
|
throw std::runtime_error("Trying to access non-existing column in the nested table!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMWorld::IngredEffectRefIdAdapter::setNestedData (const RefIdColumn *column,
|
||||||
|
RefIdData& data, int row, const QVariant& value, int subRowIndex, int subColIndex) const
|
||||||
|
{
|
||||||
|
Record<ESM::Ingredient>& record =
|
||||||
|
static_cast<Record<ESM::Ingredient>&> (data.getRecord (RefIdData::LocalIndex (row, mType)));
|
||||||
|
ESM::Ingredient ingredient = record.get();
|
||||||
|
|
||||||
|
if (subRowIndex < 0 || subRowIndex >= 4)
|
||||||
|
throw std::runtime_error ("index out of range");
|
||||||
|
|
||||||
|
switch(subColIndex)
|
||||||
|
{
|
||||||
|
case 0: ingredient.mData.mEffectID[subRowIndex] = value.toInt(); break;
|
||||||
|
case 1: ingredient.mData.mSkills[subRowIndex] = value.toInt(); break;
|
||||||
|
case 2: ingredient.mData.mAttributes[subRowIndex] = value.toInt(); break;
|
||||||
|
default:
|
||||||
|
throw std::runtime_error("Trying to access non-existing column in the nested table!");
|
||||||
|
}
|
||||||
|
|
||||||
|
record.setModified (ingredient);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSMWorld::IngredEffectRefIdAdapter::getNestedColumnsCount(const RefIdColumn *column, const RefIdData& data) const
|
||||||
|
{
|
||||||
|
return 3; // effect, skill, attribute
|
||||||
|
}
|
||||||
|
|
||||||
|
int CSMWorld::IngredEffectRefIdAdapter::getNestedRowsCount(const RefIdColumn *column, const RefIdData& data, int index) const
|
||||||
|
{
|
||||||
|
return 4; // up to 4 effects
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CSMWorld::ApparatusRefIdAdapter::ApparatusRefIdAdapter (const InventoryColumns& columns,
|
CSMWorld::ApparatusRefIdAdapter::ApparatusRefIdAdapter (const InventoryColumns& columns,
|
||||||
const RefIdColumn *type, const RefIdColumn *quality)
|
const RefIdColumn *type, const RefIdColumn *quality)
|
||||||
: InventoryRefIdAdapter<ESM::Apparatus> (UniversalId::Type_Apparatus, columns),
|
: InventoryRefIdAdapter<ESM::Apparatus> (UniversalId::Type_Apparatus, columns),
|
||||||
|
|
|
@ -340,6 +340,66 @@ 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 IngredientColumns : public InventoryColumns
|
||||||
|
{
|
||||||
|
const RefIdColumn *mEffects;
|
||||||
|
|
||||||
|
IngredientColumns (const InventoryColumns& columns);
|
||||||
|
};
|
||||||
|
|
||||||
|
class IngredientRefIdAdapter : public InventoryRefIdAdapter<ESM::Ingredient>
|
||||||
|
{
|
||||||
|
IngredientColumns mColumns;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
IngredientRefIdAdapter (const IngredientColumns& 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.
|
||||||
|
};
|
||||||
|
|
||||||
|
class IngredEffectRefIdAdapter : public NestedRefIdAdapterBase
|
||||||
|
{
|
||||||
|
UniversalId::Type mType;
|
||||||
|
|
||||||
|
// not implemented
|
||||||
|
IngredEffectRefIdAdapter (const IngredEffectRefIdAdapter&);
|
||||||
|
IngredEffectRefIdAdapter& operator= (const IngredEffectRefIdAdapter&);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
IngredEffectRefIdAdapter();
|
||||||
|
|
||||||
|
virtual ~IngredEffectRefIdAdapter();
|
||||||
|
|
||||||
|
virtual void addNestedRow (const RefIdColumn *column,
|
||||||
|
RefIdData& data, int index, int position) const;
|
||||||
|
|
||||||
|
virtual void removeNestedRow (const RefIdColumn *column,
|
||||||
|
RefIdData& data, int index, int rowToRemove) const;
|
||||||
|
|
||||||
|
virtual void setNestedTable (const RefIdColumn* column,
|
||||||
|
RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) const;
|
||||||
|
|
||||||
|
virtual NestedTableWrapperBase* nestedTable (const RefIdColumn* column,
|
||||||
|
const RefIdData& data, int index) const;
|
||||||
|
|
||||||
|
virtual QVariant getNestedData (const RefIdColumn *column,
|
||||||
|
const RefIdData& data, int index, int subRowIndex, int subColIndex) const;
|
||||||
|
|
||||||
|
virtual void setNestedData (const RefIdColumn *column,
|
||||||
|
RefIdData& data, int row, const QVariant& value, int subRowIndex, int subColIndex) const;
|
||||||
|
|
||||||
|
virtual int getNestedColumnsCount(const RefIdColumn *column, const RefIdData& data) const;
|
||||||
|
|
||||||
|
virtual int getNestedRowsCount(const RefIdColumn *column, const RefIdData& data, int index) const;
|
||||||
|
};
|
||||||
|
|
||||||
struct EnchantableColumns : public InventoryColumns
|
struct EnchantableColumns : public InventoryColumns
|
||||||
{
|
{
|
||||||
const RefIdColumn *mEnchantment;
|
const RefIdColumn *mEnchantment;
|
||||||
|
|
|
@ -71,6 +71,21 @@ CSMWorld::RefIdCollection::RefIdCollection()
|
||||||
mColumns.push_back (RefIdColumn (Columns::ColumnId_CoinValue, ColumnBase::Display_Integer));
|
mColumns.push_back (RefIdColumn (Columns::ColumnId_CoinValue, ColumnBase::Display_Integer));
|
||||||
inventoryColumns.mValue = &mColumns.back();
|
inventoryColumns.mValue = &mColumns.back();
|
||||||
|
|
||||||
|
IngredientColumns ingredientColumns (inventoryColumns);
|
||||||
|
mColumns.push_back (RefIdColumn (Columns::ColumnId_EffectList,
|
||||||
|
ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue));
|
||||||
|
ingredientColumns.mEffects = &mColumns.back();
|
||||||
|
std::map<UniversalId::Type, NestedRefIdAdapterBase*> ingredientEffectsMap;
|
||||||
|
ingredientEffectsMap.insert(std::make_pair(UniversalId::Type_Ingredient,
|
||||||
|
new IngredEffectRefIdAdapter ()));
|
||||||
|
mNestedAdapters.push_back (std::make_pair(&mColumns.back(), ingredientEffectsMap));
|
||||||
|
mColumns.back().addColumn(
|
||||||
|
new NestedChildColumn (Columns::ColumnId_EffectId, ColumnBase::Display_EffectId));
|
||||||
|
mColumns.back().addColumn(
|
||||||
|
new NestedChildColumn (Columns::ColumnId_Skill, ColumnBase::Display_SkillId));
|
||||||
|
mColumns.back().addColumn(
|
||||||
|
new NestedChildColumn (Columns::ColumnId_Attribute, ColumnBase::Display_Attribute));
|
||||||
|
|
||||||
// nested table
|
// nested table
|
||||||
PotionColumns potionColumns (inventoryColumns);
|
PotionColumns potionColumns (inventoryColumns);
|
||||||
mColumns.push_back (RefIdColumn (Columns::ColumnId_EffectList,
|
mColumns.push_back (RefIdColumn (Columns::ColumnId_EffectList,
|
||||||
|
@ -651,7 +666,7 @@ CSMWorld::RefIdCollection::RefIdCollection()
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Door,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Door,
|
||||||
new DoorRefIdAdapter (nameColumns, openSound, closeSound)));
|
new DoorRefIdAdapter (nameColumns, openSound, closeSound)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Ingredient,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Ingredient,
|
||||||
new InventoryRefIdAdapter<ESM::Ingredient> (UniversalId::Type_Ingredient, inventoryColumns)));
|
new IngredientRefIdAdapter (ingredientColumns)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_CreatureLevelledList,
|
mAdapters.insert (std::make_pair (UniversalId::Type_CreatureLevelledList,
|
||||||
new LevelledListRefIdAdapter<ESM::CreatureLevList> (
|
new LevelledListRefIdAdapter<ESM::CreatureLevList> (
|
||||||
UniversalId::Type_CreatureLevelledList, levListColumns)));
|
UniversalId::Type_CreatureLevelledList, levListColumns)));
|
||||||
|
|
Loading…
Reference in a new issue