Add faction reactions table to dialogue subview. Fix gcc compile issues. Change nested columns to generic ones where possible.

test
cc9cii 10 years ago
parent 88bc62e054
commit ea9563ad92

@ -99,7 +99,7 @@ namespace CSMWorld
Display_NestedDestinationsList,
Display_PathgridPointList,
Display_PathgridEdgeList,
Display_RegionSoundList,
Display_NestedHeader,
Display_EnchantmentType,
Display_BodyPartType,

@ -2357,11 +2357,10 @@ namespace CSMWorld
};
template<typename ESXRecordT>
struct RegionSoundListColumn : public Column<ESXRecordT>
struct NestedParentColumn : public Column<ESXRecordT>
{
RegionSoundListColumn ()
: Column<ESXRecordT> (Columns::ColumnId_RegionSounds,
ColumnBase::Display_RegionSoundList, ColumnBase::Flag_Dialogue)
NestedParentColumn (Columns::ColumnId id)
: Column<ESXRecordT> (id, ColumnBase::Display_NestedHeader, ColumnBase::Flag_Dialogue)
{}
virtual QVariant get (const Record<ESXRecordT>& record) const
@ -2376,11 +2375,10 @@ namespace CSMWorld
};
struct RegionSoundNameColumn : public NestableColumn
struct NestedStringColumn : public NestableColumn
{
RegionSoundNameColumn ()
: NestableColumn (Columns::ColumnId_SoundName,
ColumnBase::Display_String, ColumnBase::Flag_Dialogue)
NestedStringColumn (Columns::ColumnId id)
: NestableColumn (id, ColumnBase::Display_String, ColumnBase::Flag_Dialogue)
{}
virtual bool isEditable() const
@ -2389,11 +2387,10 @@ namespace CSMWorld
}
};
struct RegionSoundChanceColumn : public NestableColumn
struct NestedIntegerColumn : public NestableColumn
{
RegionSoundChanceColumn ()
: NestableColumn (Columns::ColumnId_SoundChance,
ColumnBase::Display_Integer, ColumnBase::Flag_Dialogue)
NestedIntegerColumn (Columns::ColumnId id)
: NestableColumn (id, ColumnBase::Display_Integer, ColumnBase::Flag_Dialogue)
{}
virtual bool isEditable() const

@ -237,6 +237,10 @@ namespace CSMWorld
{ ColumnId_SoundName, "Name"},
{ ColumnId_SoundChance, "Chance"},
{ ColumnId_FactionReactions, "Reactions"},
//{ ColumnId_FactionID, "Faction ID"},
{ ColumnId_FactionReaction, "Reaction"},
{ ColumnId_UseValue1, "Use value 1" },
{ ColumnId_UseValue2, "Use value 2" },
{ ColumnId_UseValue3, "Use value 3" },
@ -263,6 +267,7 @@ namespace CSMWorld
{ ColumnId_Skill4, "Skill 4" },
{ ColumnId_Skill5, "Skill 5" },
{ ColumnId_Skill6, "Skill 6" },
{ ColumnId_Skill7, "Skill 7" },
{ -1, 0 } // end marker
};

@ -226,6 +226,10 @@ namespace CSMWorld
ColumnId_SoundName = 209,
ColumnId_SoundChance = 210,
ColumnId_FactionReactions = 211,
//ColumnId_FactionID = 212,
ColumnId_FactionReaction = 213,
// Allocated to a separate value range, so we don't get a collision should we ever need
// to extend the number of use values.
ColumnId_UseValue1 = 0x10000,
@ -259,7 +263,8 @@ namespace CSMWorld
ColumnId_Skill3 = 0x50002,
ColumnId_Skill4 = 0x50003,
ColumnId_Skill5 = 0x50004,
ColumnId_Skill6 = 0x50005
ColumnId_Skill6 = 0x50005,
ColumnId_Skill7 = 0x50006
};
std::string getName (ColumnId column);

@ -108,6 +108,15 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mFactions.addColumn (new HiddenColumn<ESM::Faction>);
for (int i=0; i<7; ++i)
mFactions.addColumn (new SkillsColumn<ESM::Faction> (i));
// Faction Reactions
NestedParentColumn<ESM::Faction> *reactions =
new NestedParentColumn<ESM::Faction> (Columns::ColumnId_FactionReactions);
mFactions.addColumn (reactions);
mFactions.addAdapter (std::make_pair(reactions, new FactionReactionsAdapter<ESM::Faction> ()));
mFactions.getNestableColumn(mFactions.getColumns()-1)->addColumn(
new NestedStringColumn (Columns::ColumnId_Faction));
mFactions.getNestableColumn(mFactions.getColumns()-1)->addColumn(
new NestedIntegerColumn (Columns::ColumnId_FactionReaction));
mRaces.addColumn (new StringIdColumn<ESM::Race>);
mRaces.addColumn (new RecordStateColumn<ESM::Race>);
@ -140,12 +149,15 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
mRegions.addColumn (new NameColumn<ESM::Region>);
mRegions.addColumn (new MapColourColumn<ESM::Region>);
mRegions.addColumn (new SleepListColumn<ESM::Region>);
// see idadapterimpl.hpp and columnimp.hpp
RegionSoundListColumn<ESM::Region> *soundList = new RegionSoundListColumn<ESM::Region> ();
// Region Sounds
NestedParentColumn<ESM::Region> *soundList =
new NestedParentColumn<ESM::Region> (Columns::ColumnId_RegionSounds);
mRegions.addColumn (soundList);
mRegions.addAdapter (std::make_pair(soundList, new RegionSoundListAdapter<ESM::Region> ()));
mRegions.getNestableColumn(mRegions.getColumns()-1)->addColumn(new RegionSoundNameColumn ());
mRegions.getNestableColumn(mRegions.getColumns()-1)->addColumn(new RegionSoundChanceColumn ());
mRegions.getNestableColumn(mRegions.getColumns()-1)->addColumn(
new NestedStringColumn (Columns::ColumnId_SoundName));
mRegions.getNestableColumn(mRegions.getColumns()-1)->addColumn(
new NestedIntegerColumn (Columns::ColumnId_SoundChance));
mBirthsigns.addColumn (new StringIdColumn<ESM::BirthSign>);
mBirthsigns.addColumn (new RecordStateColumn<ESM::BirthSign>);
@ -341,7 +353,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
addModel (new IdTable (&mGmsts), UniversalId::Type_Gmst);
addModel (new IdTable (&mSkills), UniversalId::Type_Skill);
addModel (new IdTable (&mClasses), UniversalId::Type_Class);
addModel (new IdTable (&mFactions), UniversalId::Type_Faction);
addModel (new IdTree (&mFactions, &mFactions), UniversalId::Type_Faction);
addModel (new IdTable (&mRaces), UniversalId::Type_Race);
addModel (new IdTable (&mSounds), UniversalId::Type_Sound);
addModel (new IdTable (&mScripts), UniversalId::Type_Script);

@ -69,7 +69,7 @@ namespace CSMWorld
IdCollection<ESM::GameSetting> mGmsts;
IdCollection<ESM::Skill> mSkills;
IdCollection<ESM::Class> mClasses;
IdCollection<ESM::Faction> mFactions;
NestedIdCollection<ESM::Faction> mFactions;
IdCollection<ESM::Race> mRaces;
IdCollection<ESM::Sound> mSounds;
IdCollection<ESM::Script> mScripts;

@ -5,6 +5,7 @@
#include <components/esm/loadpgrd.hpp>
#include <components/esm/loadregn.hpp>
#include <components/esm/loadfact.hpp>
#include "idadapter.hpp"
#include "nestedtablewrapper.hpp"
@ -218,7 +219,12 @@ namespace CSMWorld
virtual QVariant getNestedData(const Record<ESXRecordT>& record, int subRowIndex, int subColIndex) const
{
ESM::Pathgrid::Edge edge = record.get().mEdges[subRowIndex];
ESXRecordT pathgrid = record.get();
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (pathgrid.mEdges.size()))
throw std::runtime_error ("index out of range");
ESM::Pathgrid::Edge edge = pathgrid.mEdges[subRowIndex];
switch (subColIndex)
{
case 0: return subRowIndex;
@ -233,6 +239,10 @@ namespace CSMWorld
int subRowIndex, int subColIndex) const
{
ESXRecordT pathgrid = record.get();
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (pathgrid.mEdges.size()))
throw std::runtime_error ("index out of range");
ESM::Pathgrid::Edge edge = pathgrid.mEdges[subRowIndex];
switch (subColIndex)
{
@ -258,6 +268,126 @@ namespace CSMWorld
}
};
template<typename ESXRecordT>
class FactionReactionsAdapter : public NestedIdAdapter<ESXRecordT>
{
public:
FactionReactionsAdapter () {}
virtual void addNestedRow(Record<ESXRecordT>& record, int position) const
{
ESXRecordT faction = record.get();
std::map<std::string, int>& reactions = faction.mReactions;
// blank row
reactions.insert(std::make_pair("", 0));
record.setModified (faction);
}
virtual void removeNestedRow(Record<ESXRecordT>& record, int rowToRemove) const
{
ESXRecordT faction = record.get();
std::map<std::string, int>& reactions = faction.mReactions;
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (reactions.size()))
throw std::runtime_error ("index out of range");
// FIXME: how to ensure that the map entries correspond to table indicies?
// WARNING: Assumed that the table view has the same order as std::map
std::map<std::string, int>::const_iterator iter = reactions.begin();
for(int i = 0; i < rowToRemove; ++i)
iter++;
reactions.erase(iter);
record.setModified (faction);
}
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
{
record.get().mReactions =
static_cast<const NestedTableWrapper<std::map<std::string, int> >&>(nestedTable).mNestedTable;
}
virtual NestedTableWrapperBase* nestedTable(const Record<ESXRecordT>& record) const
{
// deleted by dtor of NestedTableStoring
return new NestedTableWrapper<std::map<std::string, int> >(record.get().mReactions);
}
virtual QVariant getNestedData(const Record<ESXRecordT>& record, int subRowIndex, int subColIndex) const
{
ESXRecordT faction = record.get();
std::map<std::string, int>& reactions = faction.mReactions;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (reactions.size()))
throw std::runtime_error ("index out of range");
// FIXME: how to ensure that the map entries correspond to table indicies?
// WARNING: Assumed that the table view has the same order as std::map
std::map<std::string, int>::const_iterator iter = reactions.begin();
for(int i = 0; i < subRowIndex; ++i)
iter++;
switch (subColIndex)
{
case 0: return QString((*iter).first.c_str());
case 1: return (*iter).second;
default: throw std::runtime_error("Faction reactions subcolumn index out of range");
}
}
virtual void setNestedData(Record<ESXRecordT>& record, const QVariant& value,
int subRowIndex, int subColIndex) const
{
ESXRecordT faction = record.get();
std::map<std::string, int>& reactions = faction.mReactions;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (reactions.size()))
throw std::runtime_error ("index out of range");
// FIXME: how to ensure that the map entries correspond to table indicies?
// WARNING: Assumed that the table view has the same order as std::map
std::map<std::string, int>::const_iterator iter = reactions.begin();
for(int i = 0; i < subRowIndex; ++i)
iter++;
std::string factionId = (*iter).first;
int reaction = (*iter).second;
switch (subColIndex)
{
case 0:
{
reactions.erase(iter);
reactions.insert(std::make_pair(value.toString().toUtf8().constData(), reaction));
break;
}
case 1:
{
reactions[factionId] = value.toInt();
break;
}
default: throw std::runtime_error("Faction reactions subcolumn index out of range");
}
record.setModified (faction);
}
virtual int getNestedColumnsCount(const Record<ESXRecordT>& record) const
{
return 2;
}
virtual int getNestedRowsCount(const Record<ESXRecordT>& record) const
{
return static_cast<int>(record.get().mReactions.size());
}
};
template<typename ESXRecordT>
class RegionSoundListAdapter : public NestedIdAdapter<ESXRecordT>
{
@ -268,10 +398,10 @@ namespace CSMWorld
{
ESXRecordT region = record.get();
std::vector<ESXRecordT::SoundRef>& soundList = region.mSoundList;
std::vector<typename ESXRecordT::SoundRef>& soundList = region.mSoundList;
// blank row
ESXRecordT::SoundRef soundRef;
typename ESXRecordT::SoundRef soundRef;
soundRef.mSound.assign("");
soundRef.mChance = 0;
@ -284,7 +414,7 @@ namespace CSMWorld
{
ESXRecordT region = record.get();
std::vector<ESXRecordT::SoundRef>& soundList = region.mSoundList;
std::vector<typename ESXRecordT::SoundRef>& soundList = region.mSoundList;
if (rowToRemove < 0 || rowToRemove >= static_cast<int> (soundList.size()))
throw std::runtime_error ("index out of range");
@ -297,18 +427,25 @@ namespace CSMWorld
virtual void setNestedTable(Record<ESXRecordT>& record, const NestedTableWrapperBase& nestedTable) const
{
record.get().mSoundList =
static_cast<const NestedTableWrapper<std::vector<ESM::Region::SoundRef> >&>(nestedTable).mNestedTable;
static_cast<const NestedTableWrapper<std::vector<typename ESXRecordT::SoundRef> >&>(nestedTable).mNestedTable;
}
virtual NestedTableWrapperBase* nestedTable(const Record<ESXRecordT>& record) const
{
// deleted by dtor of NestedTableStoring
return new NestedTableWrapper<std::vector<ESM::Region::SoundRef> >(record.get().mSoundList);
return new NestedTableWrapper<std::vector<typename ESXRecordT::SoundRef> >(record.get().mSoundList);
}
virtual QVariant getNestedData(const Record<ESXRecordT>& record, int subRowIndex, int subColIndex) const
{
ESXRecordT::SoundRef soundRef = record.get().mSoundList[subRowIndex];
ESXRecordT region = record.get();
std::vector<typename ESXRecordT::SoundRef>& soundList = region.mSoundList;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (soundList.size()))
throw std::runtime_error ("index out of range");
typename ESXRecordT::SoundRef soundRef = soundList[subRowIndex];
switch (subColIndex)
{
case 0: return QString(soundRef.mSound.toString().c_str());
@ -321,7 +458,13 @@ namespace CSMWorld
int subRowIndex, int subColIndex) const
{
ESXRecordT region = record.get();
ESXRecordT::SoundRef soundRef = region.mSoundList[subRowIndex];
std::vector<typename ESXRecordT::SoundRef>& soundList = region.mSoundList;
if (subRowIndex < 0 || subRowIndex >= static_cast<int> (soundList.size()))
throw std::runtime_error ("index out of range");
typename ESXRecordT::SoundRef soundRef = soundList[subRowIndex];
switch (subColIndex)
{
case 0: soundRef.mSound.assign(value.toString().toUtf8().constData()); break;

Loading…
Cancel
Save