mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-01 08:15:54 +00:00
Added spells table (and it works!)
This commit is contained in:
parent
864b93e745
commit
39545670a8
4 changed files with 94 additions and 2 deletions
|
@ -94,6 +94,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
//Those are top level columns that nest other columns
|
//Those are top level columns that nest other columns
|
||||||
Display_NestedItemList,
|
Display_NestedItemList,
|
||||||
|
Display_NestedSpellList,
|
||||||
|
|
||||||
Display_EnchantmentType,
|
Display_EnchantmentType,
|
||||||
Display_BodyPartType,
|
Display_BodyPartType,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define CSM_WORLD_NESTEDADAPTORS_H
|
#define CSM_WORLD_NESTEDADAPTORS_H
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
|
@ -85,6 +86,92 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename ESXRecordT>
|
||||||
|
class SpellsHelper : public CastableHelper<ESXRecordT>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
SpellsHelper(CSMWorld::UniversalId::Type type)
|
||||||
|
: CastableHelper<ESXRecordT>(type) {}
|
||||||
|
|
||||||
|
virtual void setNestedTable(RefIdData& data,
|
||||||
|
int index,
|
||||||
|
const NestedTableWrapperBase& nestedTable)
|
||||||
|
{
|
||||||
|
CastableHelper<ESXRecordT>::getRecord(data, index).get().mSpells.mList =
|
||||||
|
(static_cast<const NestedTableWrapper<std::vector<std::string> >&>(nestedTable)).mNestedTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual NestedTableWrapperBase* nestedTable(const RefIdData& data,
|
||||||
|
int index) const
|
||||||
|
{
|
||||||
|
return new NestedTableWrapper<std::vector<std::string> >(CastableHelper<ESXRecordT>::getRecord(data, index).get().mSpells.mList);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual QVariant getNestedData(const CSMWorld::RefIdData& data,
|
||||||
|
int index,
|
||||||
|
int subRowIndex,
|
||||||
|
int subColIndex) const
|
||||||
|
{
|
||||||
|
const std::string& content = CastableHelper<ESXRecordT>::getRecord(data, index).get().mSpells.mList.at(subRowIndex);
|
||||||
|
|
||||||
|
if (subColIndex == 0)
|
||||||
|
{
|
||||||
|
return QString::fromUtf8(content.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::logic_error("Trying to access non-existing column in the nested table!");
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void removeNestedRow (RefIdData& data, int index, int rowToRemove) const
|
||||||
|
{
|
||||||
|
std::vector<std::string>& list = CastableHelper<ESXRecordT>::getRecord(data, index).get().mSpells.mList;
|
||||||
|
|
||||||
|
list.erase (list.begin () + rowToRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setNestedData (RefIdData& data,
|
||||||
|
int index,
|
||||||
|
const QVariant& value,
|
||||||
|
int subRowIndex,
|
||||||
|
int subColIndex) const
|
||||||
|
{
|
||||||
|
if (subColIndex == 0)
|
||||||
|
{
|
||||||
|
CastableHelper<ESXRecordT>::getRecord(data, index).get().mSpells.mList.at(subRowIndex) = std::string(value.toString().toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
|
throw std::logic_error("Trying to access non-existing column in the nested table!");
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void addNestedRow (RefIdData& data, int index, int position) const
|
||||||
|
{
|
||||||
|
std::vector<std::string>& list = CastableHelper<ESXRecordT>::getRecord(data, index).get().mSpells.mList;
|
||||||
|
|
||||||
|
std::string newString;
|
||||||
|
if (position >= (int)list.size())
|
||||||
|
{
|
||||||
|
list.push_back(newString);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
list.insert(list.begin()+position, newString);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int getNestedColumnsCount(const RefIdData& data) const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual int getNestedRowsCount(const RefIdData& data,
|
||||||
|
int index) const
|
||||||
|
{
|
||||||
|
return CastableHelper<ESXRecordT>::getRecord(data, index).get().mSpells.mList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
template <typename ESXRecordT>
|
template <typename ESXRecordT>
|
||||||
class InventoryHelper : public CastableHelper<ESXRecordT>
|
class InventoryHelper : public CastableHelper<ESXRecordT>
|
||||||
{
|
{
|
||||||
|
|
|
@ -478,6 +478,7 @@ namespace CSMWorld
|
||||||
std::vector<std::pair <const RefIdColumn*, HelperBase*> > assoCol;
|
std::vector<std::pair <const RefIdColumn*, HelperBase*> > assoCol;
|
||||||
|
|
||||||
assoCol.push_back(std::make_pair(mActors.mInventory, new InventoryHelper<RecordT>(type)));
|
assoCol.push_back(std::make_pair(mActors.mInventory, new InventoryHelper<RecordT>(type)));
|
||||||
|
assoCol.push_back(std::make_pair(mActors.mSpells, new SpellsHelper<RecordT>(type)));
|
||||||
|
|
||||||
setAssocColumns(assoCol);
|
setAssocColumns(assoCol);
|
||||||
}
|
}
|
||||||
|
@ -507,6 +508,9 @@ namespace CSMWorld
|
||||||
if (column==mActors.mInventory)
|
if (column==mActors.mInventory)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (column==mActors.mSpells)
|
||||||
|
return true;
|
||||||
|
|
||||||
std::map<const RefIdColumn *, unsigned int>::const_iterator iter =
|
std::map<const RefIdColumn *, unsigned int>::const_iterator iter =
|
||||||
mActors.mServices.find (column);
|
mActors.mServices.find (column);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#include "refidcollection.hpp"
|
#include "refidcollection.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -99,6 +98,7 @@ CSMWorld::RefIdCollection::RefIdCollection()
|
||||||
actorsColumns.mFight = &mColumns.back();
|
actorsColumns.mFight = &mColumns.back();
|
||||||
mColumns.push_back (RefIdColumn (Columns::ColumnId_AiAlarm, ColumnBase::Display_Integer));
|
mColumns.push_back (RefIdColumn (Columns::ColumnId_AiAlarm, ColumnBase::Display_Integer));
|
||||||
actorsColumns.mAlarm = &mColumns.back();
|
actorsColumns.mAlarm = &mColumns.back();
|
||||||
|
|
||||||
mColumns.push_back(RefIdColumn (Columns::ColumnId_ActorInventory, ColumnBase::Display_NestedItemList, ColumnBase::Flag_Dialogue, true, true, true));
|
mColumns.push_back(RefIdColumn (Columns::ColumnId_ActorInventory, ColumnBase::Display_NestedItemList, ColumnBase::Flag_Dialogue, true, true, true));
|
||||||
actorsColumns.mInventory = &mColumns.back();
|
actorsColumns.mInventory = &mColumns.back();
|
||||||
mColumns.back().addNestedColumn(Columns::ColumnId_InventoryItemId, CSMWorld::ColumnBase::Display_String);
|
mColumns.back().addNestedColumn(Columns::ColumnId_InventoryItemId, CSMWorld::ColumnBase::Display_String);
|
||||||
|
@ -665,6 +665,6 @@ CSMWorld::NestedTableWrapperBase* CSMWorld::RefIdCollection::nestedTable(int row
|
||||||
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
|
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
|
||||||
|
|
||||||
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdaptor (localIndex.second));
|
const CSMWorld::NestedRefIdAdapter& adaptor = dynamic_cast<const CSMWorld::NestedRefIdAdapter&>(findAdaptor (localIndex.second));
|
||||||
|
|
||||||
return adaptor.nestedTable(&mColumns.at(column), mData, localIndex.first);
|
return adaptor.nestedTable(&mColumns.at(column), mData, localIndex.first);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue