From 7f2bd01f79749d05d18e563c013153376338118e Mon Sep 17 00:00:00 2001 From: cc9cii Date: Wed, 29 Apr 2015 12:08:11 +1000 Subject: [PATCH 1/2] Handle plugins that has 0x00 for levelled list types, for example Ravenloft v5.02d, to use 0x01. --- apps/opencs/model/world/refidadapterimp.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/opencs/model/world/refidadapterimp.hpp b/apps/opencs/model/world/refidadapterimp.hpp index 41d8c65d5..e38554383 100644 --- a/apps/opencs/model/world/refidadapterimp.hpp +++ b/apps/opencs/model/world/refidadapterimp.hpp @@ -2,6 +2,7 @@ #define CSM_WOLRD_REFIDADAPTERIMP_H #include +#include #include @@ -1895,6 +1896,20 @@ namespace CSMWorld { return QString("All Levels"); } + else if (mType == CSMWorld::UniversalId::Type_CreatureLevelledList && + record.get().mFlags == 0x00) + { + std::cerr << "Unknown creature leveled list type: " << record.get().mFlags + << ", Using \"All Levels\""<< std::endl; + return QString("All Levels"); + } + else if (mType == CSMWorld::UniversalId::Type_ItemLevelledList && + record.get().mFlags == 0x00) + { + std::cerr << "Unknown item leveled list type: " << record.get().mFlags + << ", Using \"Each\""<< std::endl; + return QString("Each"); + } else throw std::runtime_error("unknown leveled list type"); } From b04aeb6aad5ca7441d3091a85fc871049db0c8e8 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Fri, 1 May 2015 12:14:09 +1000 Subject: [PATCH 2/2] Fixed levelled lists flags - now bit masks represented by tick boxes in the dialogue subview. --- apps/opencs/model/world/columns.cpp | 5 +- apps/opencs/model/world/columns.hpp | 11 +- apps/opencs/model/world/commands.cpp | 7 +- apps/opencs/model/world/refidadapterimp.hpp | 126 +++++++++++--------- apps/opencs/model/world/refidcollection.cpp | 4 +- apps/opencs/view/world/dialoguesubview.cpp | 5 +- 6 files changed, 89 insertions(+), 69 deletions(-) diff --git a/apps/opencs/model/world/columns.cpp b/apps/opencs/model/world/columns.cpp index 3d735ddca..3172e72e4 100644 --- a/apps/opencs/model/world/columns.cpp +++ b/apps/opencs/model/world/columns.cpp @@ -222,7 +222,6 @@ namespace CSMWorld { ColumnId_HitSound, "Hit Sound" }, { ColumnId_AreaSound, "Area Sound" }, { ColumnId_BoltSound, "Bolt Sound" }, - { ColumnId_OriginalCell, "Original Cell" }, { ColumnId_PathgridPoints, "Points" }, { ColumnId_PathgridIndex, "Index" }, @@ -267,13 +266,15 @@ namespace CSMWorld { ColumnId_LevelledList,"Levelled List" }, { ColumnId_LevelledItemId,"Item ID" }, { ColumnId_LevelledItemLevel,"Level" }, - { ColumnId_LevelledItemType, "Type" }, + { ColumnId_LevelledItemType, "Calculate all levels <= player" }, + { ColumnId_LevelledItemTypeEach, "Select a new item each instance" }, { ColumnId_LevelledItemChanceNone, "Chance None" }, { ColumnId_PowerList, "Powers" }, { ColumnId_SkillImpact, "Skills" }, { ColumnId_InfoList, "Info List" }, + { ColumnId_OriginalCell, "Original Cell" }, { ColumnId_UseValue1, "Use value 1" }, { ColumnId_UseValue2, "Use value 2" }, diff --git a/apps/opencs/model/world/columns.hpp b/apps/opencs/model/world/columns.hpp index 0c525fd11..b87f6c53d 100644 --- a/apps/opencs/model/world/columns.hpp +++ b/apps/opencs/model/world/columns.hpp @@ -257,14 +257,15 @@ namespace CSMWorld ColumnId_LevelledItemId = 234, ColumnId_LevelledItemLevel = 235, ColumnId_LevelledItemType = 236, - ColumnId_LevelledItemChanceNone = 237, + ColumnId_LevelledItemTypeEach = 237, + ColumnId_LevelledItemChanceNone = 238, - ColumnId_PowerList = 238, - ColumnId_SkillImpact = 239, // impact from magic effects + ColumnId_PowerList = 239, + ColumnId_SkillImpact = 240, // impact from magic effects - ColumnId_InfoList = 240, + ColumnId_InfoList = 241, - ColumnId_OriginalCell = 241, + ColumnId_OriginalCell = 242, // Allocated to a separate value range, so we don't get a collision should we ever need // to extend the number of use values. diff --git a/apps/opencs/model/world/commands.cpp b/apps/opencs/model/world/commands.cpp index 232959727..9a0401081 100644 --- a/apps/opencs/model/world/commands.cpp +++ b/apps/opencs/model/world/commands.cpp @@ -21,9 +21,12 @@ CSMWorld::ModifyCommand::ModifyCommand (QAbstractItemModel& model, const QModelI // Replace proxy with actual model mIndex = proxy->mapToSource (index); mModel = proxy->sourceModel(); - } - setText ("Modify " + mModel->headerData (mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); + setText ("Modify " + dynamic_cast(mModel)->nestedHeaderData ( + mIndex.parent().column(), mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); + } + else + setText ("Modify " + mModel->headerData (mIndex.column(), Qt::Horizontal, Qt::DisplayRole).toString()); } void CSMWorld::ModifyCommand::redo() diff --git a/apps/opencs/model/world/refidadapterimp.hpp b/apps/opencs/model/world/refidadapterimp.hpp index e38554383..61e8115c0 100644 --- a/apps/opencs/model/world/refidadapterimp.hpp +++ b/apps/opencs/model/world/refidadapterimp.hpp @@ -1830,10 +1830,10 @@ namespace CSMWorld } + // for non-tables template class NestedListLevListRefIdAdapter : public NestedRefIdAdapterBase { - UniversalId::Type mType; // not implemented @@ -1877,45 +1877,27 @@ namespace CSMWorld const Record& record = static_cast&> (data.getRecord (RefIdData::LocalIndex (index, mType))); - switch (subColIndex) + if (mType == UniversalId::Type_CreatureLevelledList) { - case 0: + switch (subColIndex) { - if (mType == CSMWorld::UniversalId::Type_CreatureLevelledList && - record.get().mFlags == 0x01) - { - return QString("All Levels"); - } - else if(mType == CSMWorld::UniversalId::Type_ItemLevelledList && - record.get().mFlags == 0x01) - { - return QString("Each"); - } - else if(mType == CSMWorld::UniversalId::Type_ItemLevelledList && - record.get().mFlags == 0x02) - { - return QString("All Levels"); - } - else if (mType == CSMWorld::UniversalId::Type_CreatureLevelledList && - record.get().mFlags == 0x00) - { - std::cerr << "Unknown creature leveled list type: " << record.get().mFlags - << ", Using \"All Levels\""<< std::endl; - return QString("All Levels"); - } - else if (mType == CSMWorld::UniversalId::Type_ItemLevelledList && - record.get().mFlags == 0x00) - { - std::cerr << "Unknown item leveled list type: " << record.get().mFlags - << ", Using \"Each\""<< std::endl; - return QString("Each"); - } - else - throw std::runtime_error("unknown leveled list type"); + case 0: return QVariant(); // don't allow checkbox editor to be created + case 1: return record.get().mFlags & ESM::CreatureLevList::AllLevels; + case 2: return static_cast (record.get().mChanceNone); + default: + throw std::runtime_error("Trying to access non-existing column in levelled creatues!"); + } + } + else + { + switch (subColIndex) + { + case 0: return record.get().mFlags & ESM::ItemLevList::Each; + case 1: return record.get().mFlags & ESM::ItemLevList::AllLevels; + case 2: return static_cast (record.get().mChanceNone); + default: + throw std::runtime_error("Trying to access non-existing column in levelled items!"); } - case 1: return static_cast (record.get().mChanceNone); - default: - throw std::runtime_error("Trying to access non-existing column in the nested table!"); } } @@ -1926,34 +1908,63 @@ namespace CSMWorld static_cast&> (data.getRecord (RefIdData::LocalIndex (row, mType))); ESXRecordT leveled = record.get(); - switch(subColIndex) + if (mType == UniversalId::Type_CreatureLevelledList) { - case 0: + switch(subColIndex) { - if (mType == CSMWorld::UniversalId::Type_CreatureLevelledList && - value.toString().toStdString() == "All Levels") + case 0: return; // return without saving + case 1: { - leveled.mFlags = 0x01; - break; + if(value.toBool()) + { + leveled.mFlags |= ESM::CreatureLevList::AllLevels; + break; + } + else + { + leveled.mFlags &= ~ESM::CreatureLevList::AllLevels; + break; + } } - else if(mType == CSMWorld::UniversalId::Type_ItemLevelledList && - value.toString().toStdString() == "Each") + case 2: leveled.mChanceNone = static_cast(value.toInt()); break; + default: + throw std::runtime_error("Trying to set non-existing column in levelled creatures!"); + } + } + else + { + switch(subColIndex) + { + case 0: { - leveled.mFlags = 0x01; - break; + if(value.toBool()) + { + leveled.mFlags |= ESM::ItemLevList::Each; + break; + } + else + { + leveled.mFlags &= ~ESM::ItemLevList::Each; + break; + } } - else if(mType == CSMWorld::UniversalId::Type_ItemLevelledList && - value.toString().toStdString() == "All Levels") + case 1: { - leveled.mFlags = 0x02; - break; + if(value.toBool()) + { + leveled.mFlags |= ESM::ItemLevList::AllLevels; + break; + } + else + { + leveled.mFlags &= ~ESM::ItemLevList::AllLevels; + break; + } } - else - return; // return without saving + case 2: leveled.mChanceNone = static_cast(value.toInt()); break; + default: + throw std::runtime_error("Trying to set non-existing column in levelled items!"); } - case 1: leveled.mChanceNone = static_cast(value.toInt()); break; - default: - throw std::runtime_error("Trying to access non-existing column in the nested table!"); } record.setModified (leveled); @@ -1961,7 +1972,7 @@ namespace CSMWorld virtual int getNestedColumnsCount(const RefIdColumn *column, const RefIdData& data) const { - return 2; + return 3; } virtual int getNestedRowsCount(const RefIdColumn *column, const RefIdData& data, int index) const @@ -1970,6 +1981,7 @@ namespace CSMWorld } }; + // for tables template class NestedLevListRefIdAdapter : public NestedRefIdAdapterBase { diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 4a8f398cd..1941c505a 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -514,7 +514,9 @@ CSMWorld::RefIdCollection::RefIdCollection() new NestedListLevListRefIdAdapter (UniversalId::Type_ItemLevelledList))); mNestedAdapters.push_back (std::make_pair(&mColumns.back(), nestedListLevListMap)); mColumns.back().addColumn( - new RefIdColumn (Columns::ColumnId_LevelledItemType, CSMWorld::ColumnBase::Display_String)); + new RefIdColumn (Columns::ColumnId_LevelledItemTypeEach, CSMWorld::ColumnBase::Display_Boolean)); + mColumns.back().addColumn( + new RefIdColumn (Columns::ColumnId_LevelledItemType, CSMWorld::ColumnBase::Display_Boolean)); mColumns.back().addColumn( new RefIdColumn (Columns::ColumnId_LevelledItemChanceNone, CSMWorld::ColumnBase::Display_Integer)); diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index cf3653c1b..0d0e82dbf 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -29,8 +29,8 @@ #include "../../model/world/record.hpp" #include "../../model/world/tablemimedata.hpp" #include "../../model/world/idtree.hpp" -#include "../../model/doc/document.hpp" #include "../../model/world/commands.hpp" +#include "../../model/doc/document.hpp" #include "recordstatusdelegate.hpp" #include "util.hpp" @@ -444,7 +444,8 @@ void CSVWorld::EditWidget::remake(int row) if (mTable->hasChildren(mTable->index(row, i)) && !(flags & CSMWorld::ColumnBase::Flag_Dialogue_List)) { - mNestedModels.push_back(new CSMWorld::NestedTableProxyModel (mTable->index(row, i), display, dynamic_cast(mTable))); + mNestedModels.push_back(new CSMWorld::NestedTableProxyModel ( + mTable->index(row, i), display, dynamic_cast(mTable))); int idColumn = mTable->findColumnIndex (CSMWorld::Columns::ColumnId_Id); int typeColumn = mTable->findColumnIndex (CSMWorld::Columns::ColumnId_RecordType);