diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 3d9f1084e8..3943758c60 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -24,7 +24,7 @@ opencs_units (model/world opencs_units_noqt (model/world universalid data record commands columnbase scriptcontext cell refidcollection - refidadapter refiddata refidadapterimp ref collectionbase + refidadapter refiddata refidadapterimp ref collectionbase refcollection ) opencs_hdrs_noqt (model/world diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 1701e42899..a9686928ae 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -22,7 +22,7 @@ void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type mModelIndex.insert (std::make_pair (type2, model)); } -CSMWorld::Data::Data() +CSMWorld::Data::Data() : mRefs (mCells) { mGlobals.addColumn (new StringIdColumn); mGlobals.addColumn (new RecordStateColumn); @@ -128,6 +128,8 @@ CSMWorld::Data::Data() mCells.addColumn (new FlagColumn ("Interior Sky", ESM::Cell::QuasiEx)); mCells.addColumn (new RegionColumn); + mRefs.addColumn (new RecordStateColumn); + addModel (new IdTable (&mGlobals), UniversalId::Type_Globals, UniversalId::Type_Global); addModel (new IdTable (&mGmsts), UniversalId::Type_Gmsts, UniversalId::Type_Gmst); addModel (new IdTable (&mSkills), UniversalId::Type_Skills, UniversalId::Type_Skill); @@ -142,6 +144,7 @@ CSMWorld::Data::Data() addModel (new IdTable (&mCells), UniversalId::Type_Cells, UniversalId::Type_Cell); addModel (new IdTable (&mReferenceables), UniversalId::Type_Referenceables, UniversalId::Type_Referenceable); + addModel (new IdTable (&mRefs), UniversalId::Type_References, UniversalId::Type_Reference); } CSMWorld::Data::~Data() @@ -325,7 +328,11 @@ void CSMWorld::Data::loadFile (const boost::filesystem::path& path, bool base) case ESM::REC_REGN: mRegions.load (reader, base); break; case ESM::REC_BSGN: mBirthsigns.load (reader, base); break; case ESM::REC_SPEL: mSpells.load (reader, base); break; - case ESM::REC_CELL: mCells.load (reader, base); break; + + case ESM::REC_CELL: + mCells.load (reader, base); + mRefs.load (reader, mCells.getSize()-1, base); + break; case ESM::REC_ACTI: mReferenceables.load (reader, base, UniversalId::Type_Activator); break; case ESM::REC_ALCH: mReferenceables.load (reader, base, UniversalId::Type_Potion); break; diff --git a/apps/opencs/model/world/data.hpp b/apps/opencs/model/world/data.hpp index ad6e4ba692..ca030d9b22 100644 --- a/apps/opencs/model/world/data.hpp +++ b/apps/opencs/model/world/data.hpp @@ -22,6 +22,7 @@ #include "universalid.hpp" #include "cell.hpp" #include "refidcollection.hpp" +#include "refcollection.hpp" class QAbstractItemModel; @@ -42,6 +43,7 @@ namespace CSMWorld IdCollection mSpells; IdCollection mCells; RefIdCollection mReferenceables; + RefCollection mRefs; std::vector mModels; std::map mModelIndex; diff --git a/apps/opencs/model/world/refcollection.cpp b/apps/opencs/model/world/refcollection.cpp new file mode 100644 index 0000000000..fd191ba139 --- /dev/null +++ b/apps/opencs/model/world/refcollection.cpp @@ -0,0 +1,39 @@ + +#include "refcollection.hpp" + +#include + +#include "ref.hpp" +#include "cell.hpp" + +CSMWorld::RefCollection::RefCollection (Collection& cells) +: mCells (cells), mNextId (0) +{} + +void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool base) +{ + Record cell = mCells.getRecord (cellIndex); + + Cell& cell2 = base ? cell.mBase : cell.mModified; + + cell2.restore (reader, 0); /// \todo fix the index + + CellRef ref; + + while (cell2.getNextRef (reader, ref)) + { + /// \todo handle deleted and moved references + std::ostringstream stream; + stream << "ref#" << mNextId++; + + ref.load (reader, cell2, stream.str()); + + Record record2; + record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly; + (base ? record2.mBase : record2.mModified) = ref; + + appendRecord (record2); + } + + mCells.setRecord (cellIndex, cell); +} \ No newline at end of file diff --git a/apps/opencs/model/world/refcollection.hpp b/apps/opencs/model/world/refcollection.hpp new file mode 100644 index 0000000000..a2063590b9 --- /dev/null +++ b/apps/opencs/model/world/refcollection.hpp @@ -0,0 +1,27 @@ +#ifndef CSM_WOLRD_REFCOLLECTION_H +#define CSM_WOLRD_REFCOLLECTION_H + +#include "collection.hpp" +#include "ref.hpp" +#include "record.hpp" + +namespace CSMWorld +{ + struct Cell; + + /// \brief References in cells + class RefCollection : public Collection + { + Collection& mCells; + int mNextId; + + public: + + RefCollection (Collection& cells); + + void load (ESM::ESMReader& reader, int cellIndex, bool base); + ///< Load a sequence of references. + }; +} + +#endif diff --git a/apps/opencs/model/world/universalid.cpp b/apps/opencs/model/world/universalid.cpp index bd1632e3e7..b5efe6e220 100644 --- a/apps/opencs/model/world/universalid.cpp +++ b/apps/opencs/model/world/universalid.cpp @@ -31,6 +31,8 @@ namespace { CSMWorld::UniversalId::Class_RecordList, CSMWorld::UniversalId::Type_Cells, "Cells" }, { CSMWorld::UniversalId::Class_RecordList, CSMWorld::UniversalId::Type_Referenceables, "Referenceables" }, + { CSMWorld::UniversalId::Class_RecordList, CSMWorld::UniversalId::Type_References, + "References" }, { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0 } // end marker }; @@ -73,6 +75,7 @@ namespace { CSMWorld::UniversalId::Class_Record, CSMWorld::UniversalId::Type_Repair, "Repair" }, { CSMWorld::UniversalId::Class_Record, CSMWorld::UniversalId::Type_Static, "Static" }, { CSMWorld::UniversalId::Class_Record, CSMWorld::UniversalId::Type_Weapon, "Weapon" }, + { CSMWorld::UniversalId::Class_Record, CSMWorld::UniversalId::Type_Reference, "Reference" }, { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0 } // end marker }; diff --git a/apps/opencs/model/world/universalid.hpp b/apps/opencs/model/world/universalid.hpp index 2c4b14eaf5..bd6fdeb000 100644 --- a/apps/opencs/model/world/universalid.hpp +++ b/apps/opencs/model/world/universalid.hpp @@ -79,8 +79,9 @@ namespace CSMWorld Type_Probe, Type_Repair, Type_Static, - Type_Weapon - + Type_Weapon, + Type_References, + Type_Reference }; private: diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 2857f4a54a..08b4b78fec 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -136,6 +136,9 @@ void CSVDoc::View::setupWorldMenu() connect (referenceables, SIGNAL (triggered()), this, SLOT (addReferenceablesSubView())); world->addAction (referenceables); + QAction *references = new QAction (tr ("References"), this); + connect (references, SIGNAL (triggered()), this, SLOT (addReferencesSubView())); + world->addAction (references); } void CSVDoc::View::setupUi() @@ -346,6 +349,11 @@ void CSVDoc::View::addReferenceablesSubView() addSubView (CSMWorld::UniversalId::Type_Referenceables); } +void CSVDoc::View::addReferencesSubView() +{ + addSubView (CSMWorld::UniversalId::Type_References); +} + void CSVDoc::View::abortOperation (int type) { mDocument->abortOperation (type); diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 0552a86cbb..6b7fd23b34 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -140,6 +140,8 @@ namespace CSVDoc void addReferenceablesSubView(); + void addReferencesSubView(); + void showUserSettings(); }; } diff --git a/apps/opencs/view/world/subviews.cpp b/apps/opencs/view/world/subviews.cpp index 3d05f88608..cd98ed4e06 100644 --- a/apps/opencs/view/world/subviews.cpp +++ b/apps/opencs/view/world/subviews.cpp @@ -28,6 +28,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) CSMWorld::UniversalId::Type_Spells, CSMWorld::UniversalId::Type_Cells, CSMWorld::UniversalId::Type_Referenceables, + CSMWorld::UniversalId::Type_References, CSMWorld::UniversalId::Type_None // end marker };