diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index fa9251b949..6d69c706c1 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -340,7 +340,9 @@ CSMWorld::Data::Data(ToUTF8::FromType encoding, const Files::PathContainer& data // Spell effects mSpells.addColumn(new NestedParentColumn(Columns::ColumnId_EffectList)); index = mSpells.getColumns() - 1; - mSpells.addAdapter(std::make_pair(&mSpells.getColumn(index), new EffectsListAdapter())); + auto spellAdapter = new EffectsListAdapter(); + spellAdapter->setMagicEffects(&mMagicEffects); + mSpells.addAdapter(std::make_pair(&mSpells.getColumn(index), spellAdapter)); mSpells.getNestableColumn(index)->addColumn( new NestedChildColumn(Columns::ColumnId_EffectId, ColumnBase::Display_EffectId)); mSpells.getNestableColumn(index)->addColumn( @@ -455,8 +457,9 @@ CSMWorld::Data::Data(ToUTF8::FromType encoding, const Files::PathContainer& data // Enchantment effects mEnchantments.addColumn(new NestedParentColumn(Columns::ColumnId_EffectList)); index = mEnchantments.getColumns() - 1; - mEnchantments.addAdapter( - std::make_pair(&mEnchantments.getColumn(index), new EffectsListAdapter())); + auto enchAdapter = new EffectsListAdapter(); + enchAdapter->setMagicEffects(&mMagicEffects); + mEnchantments.addAdapter(std::make_pair(&mEnchantments.getColumn(index), enchAdapter)); mEnchantments.getNestableColumn(index)->addColumn( new NestedChildColumn(Columns::ColumnId_EffectId, ColumnBase::Display_EffectId)); mEnchantments.getNestableColumn(index)->addColumn( @@ -676,6 +679,8 @@ CSMWorld::Data::Data(ToUTF8::FromType encoding, const Files::PathContainer& data addModel(new IdTable(&mMetaData), UniversalId::Type_MetaData); addModel(new IdTable(&mSelectionGroups), UniversalId::Type_SelectionGroup); + mReferenceables.setMagicEffects(&mMagicEffects); + mActorAdapter = std::make_unique(*this); mRefLoadCache.clear(); // clear here rather than startLoading() and continueLoading() for multiple content files diff --git a/apps/opencs/model/world/nestedcoladapterimp.hpp b/apps/opencs/model/world/nestedcoladapterimp.hpp index 0361187846..bd566c692b 100644 --- a/apps/opencs/model/world/nestedcoladapterimp.hpp +++ b/apps/opencs/model/world/nestedcoladapterimp.hpp @@ -12,6 +12,7 @@ #include #include // for converting magic effect id to string & back +#include "idcollection.hpp" #include "nestedcolumnadapter.hpp" #include "nestedtablewrapper.hpp" @@ -248,9 +249,13 @@ namespace CSMWorld template class EffectsListAdapter : public NestedColumnAdapter { + const IdCollection* mMagicEffects = nullptr; + public: EffectsListAdapter() = default; + void setMagicEffects(const IdCollection* magicEffects) { mMagicEffects = magicEffects; } + void addRow(Record& record, int position) const override { ESXRecordT magic = record.get(); diff --git a/apps/opencs/model/world/refidadapterimp.hpp b/apps/opencs/model/world/refidadapterimp.hpp index fd8f8ffa8c..a9abc67618 100644 --- a/apps/opencs/model/world/refidadapterimp.hpp +++ b/apps/opencs/model/world/refidadapterimp.hpp @@ -38,6 +38,11 @@ #include "refiddata.hpp" #include "universalid.hpp" +namespace ESM +{ + struct MagicEffect; +} + namespace CSMWorld { class RefIdColumn; @@ -427,9 +432,13 @@ namespace CSMWorld ///< If the data type does not match an exception is thrown. }; + template + class IdCollection; + class IngredEffectRefIdAdapter : public NestedRefIdAdapterBase { UniversalId::Type mType; + const IdCollection* mMagicEffects = nullptr; public: IngredEffectRefIdAdapter(); @@ -437,6 +446,8 @@ namespace CSMWorld IngredEffectRefIdAdapter& operator=(const IngredEffectRefIdAdapter&) = delete; ~IngredEffectRefIdAdapter() override = default; + void setMagicEffects(const IdCollection* magicEffects) { mMagicEffects = magicEffects; } + void addNestedRow(const RefIdColumn* column, RefIdData& data, int index, int position) const override; void removeNestedRow(const RefIdColumn* column, RefIdData& data, int index, int rowToRemove) const override; diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index b10340de62..fe2839f853 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -58,6 +58,29 @@ const CSMWorld::RefIdAdapter& CSMWorld::RefIdCollection::findAdapter(UniversalId return *iter->second; } +void CSMWorld::RefIdCollection::setMagicEffects(const IdCollection* magicEffects) +{ + for (auto& nestedPair : mNestedAdapters) + { + if (nestedPair.first->mColumnId == Columns::ColumnId_EffectList) + { + auto itPotion = nestedPair.second.find(UniversalId::Type_Potion); + if (itPotion != nestedPair.second.end()) + { + auto adapter = static_cast*>(itPotion->second); + adapter->setMagicEffects(magicEffects); + } + + auto itIngred = nestedPair.second.find(UniversalId::Type_Ingredient); + if (itIngred != nestedPair.second.end()) + { + auto adapter = static_cast(itIngred->second); + adapter->setMagicEffects(magicEffects); + } + } + } +} + CSMWorld::RefIdCollection::RefIdCollection() { BaseColumns baseColumns; diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index 10892535cf..dc6fcf02f0 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -22,6 +22,7 @@ namespace ESM { class ESMReader; class ESMWriter; + struct MagicEffect; } namespace CSMWorld @@ -31,6 +32,9 @@ namespace CSMWorld struct NestedTableWrapperBase; class NestedRefIdAdapterBase; + template + class IdCollection; + class RefIdColumn : public NestableColumn { bool mEditable; @@ -145,6 +149,9 @@ namespace CSMWorld const RefIdData& getDataSet() const; // I can't figure out a better name for this one :( void copyTo(int index, RefIdCollection& target) const; + + void setMagicEffects(const IdCollection* magicEffects); + /// Attaches MGEF context to adapters that involve magic effects (potions and ingredients) }; }